[one-users] xmlrpc client

Prakhar Srivastava prakhar.apj at gmail.com
Thu Dec 8 08:16:30 PST 2011


Hi Ksenija,
Why don't you simply use the Java OpenNebula Cloud
API<http://opennebula.org/documentation:rel3.0:java> that
is packaged with opennebula. If there is no specific scenario, its best to
use them.

Prakhar

On Thu, Dec 8, 2011 at 3:23 PM, Ksenija Poljak
<ksenija.poljak at altus-it.hr>wrote:

> Hi, I'm using opennebula 3 and I'm trying to write an xmlrpc Java client.
> I'm not able to connect my client to opennebula server.
> I keep getting unauthorized exception:
>
> org.apache.xmlrpc.client.XmlRpcHttpTransportException: HTTP server
> returned unexpected status: Unauthorized
>
> My testing program:
>
> package open.nebula.client;
>
>
> import java.net.MalformedURLException;
> import java.net.URL;
>
> import org.apache.xmlrpc.XmlRpcException;
> import org.apache.xmlrpc.client.XmlRpcClient;
> import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
>
> public class OpenNebulaClient{
>  private XmlRpcClient client = new XmlRpcClient();;
> private XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
>  private String session =
> "oneadmin:ffd775fdb8e47ebf5b68513843f31742f74118e8";
>  public OpenNebulaClient(String server_url)
> {
> try{
>  this.config.setServerURL(new URL(server_url));
> this.client.setConfig(this.config);
>  }catch(MalformedURLException e){
> System.err.println(e);
> }
>  }
>  public void getUserInfo(int id) throws XmlRpcException
>  {
> Object[] params = {session,id};
> try {
>             Object[] result = (Object[])this.client.execute("one.user.info
> ",params);
>             if(!result[0].equals(null)) {
>             boolean success = (Boolean)result[0];
>             String str_res = (String)result[1];
>             System.out.println("success="+success);
>             System.out.println("result="+str_res);
>             }else{
>             System.out.println("success=0");
>             }
> }catch (XmlRpcException e) {
> System.err.println(e);
>  //e.printStackTrace();
>         }
> }
>  public static void main(String[] args)
> {
> OpenNebulaClient on_client = new
>
>  OpenNebulaClient("http://server_ip:port/RPC2");
> try{
> on_client.getUserInfo(0);
>  }catch(XmlRpcException xmlrpce){
> System.err.println(xmlrpce);
> }
>  }
> }
>
>
> I'm confused becose when I look at examples on the web, there are methods
> used as one.userinfo, and on opennebula official site they are listed in
> form: one.user.info.
> Session string I used consists of username:password that I get listed with
> command: 'oneuser show 0' on opennebula server.
> Client and opennebula server are on different machines.
> I'm not sure what I do wrong. Any suggestions would be more than helpfull.
> Tnx in advance.
>
> the full stackTrace of error:
>
> org.apache.xmlrpc.client.XmlRpcHttpTransportException: HTTP server
> returned unexpected status: Unauthorized
> at
> org.apache.xmlrpc.client.XmlRpcSunHttpTransport.getInputStream(XmlRpcSunHttpTransport.java:94)
>  at
> org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:152)
> at
> org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:143)
>  at
> org.apache.xmlrpc.client.XmlRpcSunHttpTransport.sendRequest(XmlRpcSunHttpTransport.java:69)
> at
> org.apache.xmlrpc.client.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:56)
>  at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:167)
> at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:137)
>  at org.apache.xmlrpc.client.XmlRpcClient.execute(XmlRpcClient.java:126)
> at
> open.nebula.client.OpenNebulaClient.getUserInfo(OpenNebulaClient.java:30)
>  at open.nebula.client.OpenNebulaClient.main(OpenNebulaClient.java:49)
>
> _______________________________________________
> Users mailing list
> 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/20111208/e3eef791/attachment-0003.htm>


More information about the Users mailing list