[one-users] RPCXML response problem

Joey majunjiev at gmail.com
Mon May 2 07:19:54 PDT 2011


Hi,

I refer to the ./src/oca/java/org/opennebula/client/Client.java. Its 
"call" method is defind as:

     public OneResponse call(String action, Object...args)
     {
         boolean success = false;
         String  msg = null;

         try
         {
             Object[] params = new Object[args.length + 1];

             params[0] = oneAuth;

             for(int i=0; i<args.length; i++)
                 params[i+1] = args[i];

*Object[] result = (Object[]) client.execute("one."+action, params);*

*success = (Boolean) result[0];*

             // In some cases, the xml-rpc response only has a boolean
             // OUT parameter
             if(result.length > 1)
             {
                 try
                 {
                     msg = (String) result[1];
                 }
                 catch (ClassCastException e)
                 {
                     // The result may be an Integer
*msg = ((Integer) result[1]).toString();*
                 }
             }


         }
         catch (XmlRpcException e)
         {
             msg = e.getMessage();
         }

         return new OneResponse(success, msg);
     }

You're right. Apologize for my incorrect advice. :-P

On 2011/5/2 18:34, Giuseppe Carella wrote:
> It works!
>
> in the web site example there is not this cast:
>
>                 Object untypedResult=null;
> try {
> untypedResult = client.execute( "one.vmpool.info 
> <http://one.vmpool.info>", params );
> } catch (XmlRpcException e) {
> e.printStackTrace();
> }
> Object[] result = (Object[]) untypedResult;
> Thank you Joey,
>
> Best,
>
> Giuseppe
>
> 2011/5/2 Joey Ma <majunjiev at gmail.com <mailto:majunjiev at gmail.com>>
>
>     Hi,
>
>     Maybe you should cast the returned type of Object to the
>     OneResponse, "OneResponse result = (OneResponse)client.execute(
>     "one.vm.allocate", params );".
>     The java unit testing source code in java oca, located in
>     ./src/oca/java/test, may helps you understanding the usage of
>      java methods for xml-rpc calling.
>
>     Best Regards,
>     Joey
>
>     On Mon, May 2, 2011 at 5:57 PM, Giuseppe Carella
>     <cargius at gmail.com <mailto:cargius at gmail.com>> wrote:
>
>         Hi all,
>
>         I have a problem with XMLRPC API using it with JAVA.
>         When I send a request to opennebula XMLRPC server, I receive
>         a response like this:
>
>         [Ljava.lang.Object;@19968e23
>
>         How can I extract the vid from this response object?
>
>         I have followed all the instructions in the java example of
>         the web site.
>
>         public  class  XmlRpcTest{
>              public  static  void  main(  String  <http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky>  args[]  )  throws  Exception  <http://www.google.com/search?hl=en&q=allinurl%3Aexception+java.sun.com&btnI=I%27m%20Feeling%20Lucky>  {
>                  XmlRpcClient client=  new  XmlRpcClient(  "http://localhost:2633/RPC2"  );
>                  Vector  <http://www.google.com/search?hl=en&q=allinurl%3Avector+java.sun.com&btnI=I%27m%20Feeling%20Lucky>  params=  new  Vector  <http://www.google.com/search?hl=en&q=allinurl%3Avector+java.sun.com&btnI=I%27m%20Feeling%20Lucky>();
>                  params.addElement("SESSION-GOLA&4H910");
>                  params.addElement("MEMORY=345 CPU=4 DISK=[FILE=\"img\",TYPE=cd]"
>         "DISK=[FILE=\"../f\"]");
>
>                  Object  <http://www.google.com/search?hl=en&q=allinurl%3Aobject+java.sun.com&btnI=I%27m%20Feeling%20Lucky>  result=  client.execute(  "one.vm.allocate", params);
>
>                  if  (  result!=  null  )
>                      System  <http://www.google.com/search?hl=en&q=allinurl%3Asystem+java.sun.com&btnI=I%27m%20Feeling%20Lucky>.out.println(  result.toString()  );
>              }
>         }
>
>
>         Your help is kindly appreciated!
>
>         thanks,
>
>         Giuseppe
>
>         _______________________________________________
>         Users mailing list
>         Users at lists.opennebula.org <mailto:Users at lists.opennebula.org>
>         http://lists.opennebula.org/listinfo.cgi/users-opennebula.org
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opennebula.org/pipermail/users-opennebula.org/attachments/20110502/75e04737/attachment-0003.htm>


More information about the Users mailing list