<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
Hi,<br>
<br>
I refer to the ./src/oca/java/org/opennebula/client/Client.java. Its
"call" method is defind as:<br>
<br>
<font color="#3333ff"> public OneResponse call(String action,
Object...args)<br>
{<br>
boolean success = false;<br>
String msg = null;<br>
<br>
try<br>
{<br>
Object[] params = new Object[args.length + 1];<br>
<br>
params[0] = oneAuth;<br>
<br>
for(int i=0; i<args.length; i++)<br>
params[i+1] = args[i];<br>
<br>
<b>Object[] result = (Object[])
client.execute("one."+action, params);</b><br>
<br>
<b> success = (Boolean) result[0];</b><br>
<br>
// In some cases, the xml-rpc response only has a
boolean<br>
// OUT parameter<br>
if(result.length > 1)<br>
{<br>
try<br>
{<br>
msg = (String) result[1];<br>
}<br>
catch (ClassCastException e)<br>
{<br>
// The result may be an Integer<br>
<b>msg = ((Integer) result[1]).toString();</b><br>
}<br>
}<br>
<br>
<br>
}<br>
catch (XmlRpcException e)<br>
{<br>
msg = e.getMessage();<br>
}<br>
<br>
return new OneResponse(success, msg);<br>
}</font><br>
<br>
You're right. Apologize for my incorrect advice. :-P<br>
<br>
On 2011/5/2 18:34, Giuseppe Carella wrote:
<blockquote
cite="mid:BANLkTimUWmtJegePcEw1aE-ZBuL_rVzxDw@mail.gmail.com"
type="cite">It works!
<div><br>
</div>
<div>in the web site example there is not this cast:</div>
<div><br>
</div>
<div> Object untypedResult=null;</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>try
{</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>untypedResult
= client.execute( "<a moz-do-not-send="true"
href="http://one.vmpool.info">one.vmpool.info</a>", params );</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>}
catch (XmlRpcException e) {</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>e.printStackTrace();</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span>}</div>
<div><span class="Apple-tab-span" style="white-space: pre;"> </span><span
class="Apple-style-span" style="background-color: rgb(255,
255, 51);"> Object[] result = (Object[]) untypedResult;</span></div>
<div> </div>
<div>Thank you Joey,</div>
<div><br>
</div>
<div>Best,</div>
<div><br>
</div>
<div>Giuseppe<br>
<br>
<div class="gmail_quote">2011/5/2 Joey Ma <span dir="ltr"><<a
moz-do-not-send="true" href="mailto:majunjiev@gmail.com">majunjiev@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">Hi,
<div><br>
</div>
<div>Maybe you should cast the returned type of Object to
the OneResponse, "One<span style="color: rgb(85, 85, 85);
font-family: monospace; font-size: 13px; line-height:
18px; white-space: pre-wrap;"><span
style="text-decoration: none; font-size: 1em; color:
rgb(0, 0, 102);">Response</span> result <span
style="color: rgb(102, 204, 102);">=</span>
(OneResponse)client.<span style="color: rgb(0, 102, 0);">execute</span><span
style="color: rgb(102, 204, 102);">(</span> <span
style="color: rgb(255, 0, 0);">"one.vm.allocate"</span>,
params <span style="color: rgb(102, 204, 102);">)</span><span
style="color: rgb(102, 204, 102);">;"</span></span>. </div>
<div>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.</div>
<div><br>
</div>
<div>Best Regards,</div>
<div>Joey</div>
<div>
<br>
<div class="gmail_quote">
<div>
<div class="h5">On Mon, May 2, 2011 at 5:57 PM,
Giuseppe Carella <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:cargius@gmail.com" target="_blank">cargius@gmail.com</a>></span>
wrote:<br>
</div>
</div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt
0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
<div>
<div class="h5">
Hi all,
<div><br>
</div>
<div>I have a problem with XMLRPC API using it
with JAVA.</div>
<div>When I send a request to opennebula XMLRPC
server, I receive </div>
<div>a response like this:</div>
<div>
<div><br>
</div>
<div>[Ljava.lang.Object;@19968e23</div>
</div>
<div><br>
</div>
<div>How can I extract the vid from this response
object?</div>
<div><br>
</div>
<div>I have followed all the instructions in the
java example of the web site.</div>
<div><span style="font-family:
Arial,Verdana,Geneva,Helvetica,sans-serif;
font-size: 13px; line-height: 18px;">
<pre style="padding: 0.5em; border: 1px dashed rgb(85, 85, 85); color: rgb(85, 85, 85); background-color: rgb(245, 245, 245); overflow: scroll; line-height: 18px; margin: 10px;"><span style="color: rgb(177, 177, 0);">public</span> <span style="color: rgb(177, 177, 0);">class</span> XmlRpcTest <span style="color: rgb(102, 204, 102);">{</span>
<span style="color: rgb(177, 177, 0);">public</span> <span style="color: rgb(177, 177, 0);">static</span> <span style="color: rgb(153, 51, 51);">void</span> main<span style="color: rgb(102, 204, 102);">(</span> <a moz-do-not-send="true" href="http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky" style="color: rgb(0, 152, 195); text-decoration: none; font-size: 1em;" target="_blank"><span style="color: rgb(0, 0, 102);">String</span></a> args<span style="color: rgb(102, 204, 102);">[</span><span style="color: rgb(102, 204, 102);">]</span> <span style="color: rgb(102, 204, 102);">)</span> <span style="color: rgb(177, 177, 0);">throws</span> <a moz-do-not-send="true" href="http://www.google.com/search?hl=en&q=allinurl%3Aexception+java.sun.com&btnI=I%27m%20Feeling%20Lucky" style="color: rgb(0, 152, 195); text-decoration: none; font-size: 1em;" target="_blank"><span style="color: rgb(0, 0, 102);">Exception</span></a>
<span style="color: rgb(102, 204, 102);">{</span>
XmlRpcClient client <span style="color: rgb(102, 204, 102);">=</span> <span style="color: rgb(177, 177, 0);">new</span> XmlRpcClient<span style="color: rgb(102, 204, 102);">(</span> <span style="color: rgb(255, 0, 0);">"<a moz-do-not-send="true" href="http://localhost:2633/RPC2" target="_blank">http://localhost:2633/RPC2</a>"</span> <span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<a moz-do-not-send="true" href="http://www.google.com/search?hl=en&q=allinurl%3Avector+java.sun.com&btnI=I%27m%20Feeling%20Lucky" style="color: rgb(0, 152, 195); text-decoration: none; font-size: 1em;" target="_blank"><span style="color: rgb(0, 0, 102);">Vector</span></a> params <span style="color: rgb(102, 204, 102);">=</span> <span style="color: rgb(177, 177, 0);">new</span> <a moz-do-not-send="true" href="http://www.google.com/search?hl=en&q=allinurl%3Avector+java.sun.com&btnI=I%27m%20Feeling%20Lucky" style="color: rgb(0, 152, 195); text-decoration: none; font-size: 1em;" target="_blank"><span style="color: rgb(0, 0, 102);">Vector</span></a><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
params.<span style="color: rgb(0, 102, 0);">addElement</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">"SESSION-GOLA&4H910"</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
params.<span style="color: rgb(0, 102, 0);">addElement</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">"MEMORY=345 CPU=4 DISK=[FILE=<span style="color: rgb(0, 0, 153); font-weight: bold;">\"</span>img<span style="color: rgb(0, 0, 153); font-weight: bold;">\"</span>,TYPE=cd]"</span>
<span style="color: rgb(255, 0, 0);">"DISK=[FILE=<span style="color: rgb(0, 0, 153); font-weight: bold;">\"</span>../f<span style="color: rgb(0, 0, 153); font-weight: bold;">\"</span>]"</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<a moz-do-not-send="true" href="http://www.google.com/search?hl=en&q=allinurl%3Aobject+java.sun.com&btnI=I%27m%20Feeling%20Lucky" style="color: rgb(0, 152, 195); text-decoration: none; font-size: 1em;" target="_blank"><span style="color: rgb(0, 0, 102);">Object</span></a> result <span style="color: rgb(102, 204, 102);">=</span> client.<span style="color: rgb(0, 102, 0);">execute</span><span style="color: rgb(102, 204, 102);">(</span> <span style="color: rgb(255, 0, 0);">"one.vm.allocate"</span>, params <span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(177, 177, 0);">if</span> <span style="color: rgb(102, 204, 102);">(</span> result <span style="color: rgb(102, 204, 102);">!=</span> <span style="color: rgb(0, 0, 0); font-weight: bold;">null</span> <span style="color: rgb(102, 204, 102);">)</span>
<a moz-do-not-send="true" href="http://www.google.com/search?hl=en&q=allinurl%3Asystem+java.sun.com&btnI=I%27m%20Feeling%20Lucky" style="color: rgb(0, 152, 195); text-decoration: none; font-size: 1em;" target="_blank"><span style="color: rgb(0, 0, 102);">System</span></a>.<span style="color: rgb(0, 102, 0);">out</span>.<span style="color: rgb(0, 102, 0);">println</span><span style="color: rgb(102, 204, 102);">(</span> result.<span style="color: rgb(0, 102, 0);">toString</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(102, 204, 102);">)</span> <span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(102, 204, 102);">}</span>
<span style="color: rgb(102, 204, 102);">}</span></pre>
</span></div>
<div><br>
</div>
<div>Your help is kindly appreciated!</div>
<div><br>
</div>
<div>thanks,</div>
<div><br>
</div>
<font color="#888888">
<div>Giuseppe </div>
</font><br>
</div>
</div>
_______________________________________________<br>
Users mailing list<br>
<a moz-do-not-send="true"
href="mailto:Users@lists.opennebula.org"
target="_blank">Users@lists.opennebula.org</a><br>
<a moz-do-not-send="true"
href="http://lists.opennebula.org/listinfo.cgi/users-opennebula.org"
target="_blank">http://lists.opennebula.org/listinfo.cgi/users-opennebula.org</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
<br>
</body>
</html>