Error in Java XML RPC code

Discussion in 'Java' started by Ojesh Dugar, Feb 9, 2014.

  1. Ojesh Dugar

    Ojesh Dugar Guest

    I am trying to access a webservice api through XMLRPC from java client code..
    But getting some error.Pls Help.

    My Code:

    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.HashMap;
    import java.util.Map;
    import org.apache.commons.httpclient.HttpClient;
    import org.apache.xmlrpc.XmlRpcException;
    import org.apache.xmlrpc.client.XmlRpcClient;
    import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
    import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;

    public class BugCreator2 {
    public static void main(String s[])
    throws MalformedURLException, XmlRpcException {

    HttpClient httpClient = new HttpClient();
    XmlRpcClient rpcClient = new XmlRpcClient();
    XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(rpcClient);
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();

    factory.setHttpClient(httpClient);
    rpcClient.setTransportFactory(factory);
    config.setServerURL(new URL("http://URL/bugzilla/xmlrpc.cgi"));
    rpcClient.setConfig(config);

    // map of the login data
    Map loginMap = new HashMap();
    loginMap.put("login", "");
    loginMap.put("password", "*********");
    loginMap.put("rememberlogin", "Bugzilla_remember");

    // login to bugzilla
    Object loginResult = rpcClient.execute("User.login", new Object[]{loginMap});
    System.err.println ("loginResult=" + loginResult);

    // map of the bug data
    Map bugMap = new HashMap();

    bugMap.put("product", "Demo");
    bugMap.put("component", "Demo_project");
    bugMap.put("summary", "Bug created for test");
    bugMap.put("description", "This is text ");
    bugMap.put("version", "unspecified");
    bugMap.put("op_sys", "Windows");
    bugMap.put("platform", "PC");
    bugMap.put("priority", "P2");
    bugMap.put("severity", "Normal");
    bugMap.put("status", "NEW");

    // create bug
    Object createResult = rpcClient.execute("Bug.create", new Object[]{bugMap});
    System.err.println("createResult = " + createResult);
    }


    Error:

    BugCreator2.java:20: error: cannot find symbol factory.setHttpClient(httpClient); ^ symbol: method setHttpClient(HttpClient) location: variable factory of type XmlRpcCommonsTransportFactor Note: BugCreator2.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error

    Jars Used:

    commons-httpclient-3.0.1
    java-rt-jar-stubs-1.5.0
    ws-commons-util-1.0.1
    ws-commons-util-1.0.1-sources
    xmlrpc-3.0
    xmlrpc-3.0-common

    Thanks.
     
    Ojesh Dugar, Feb 9, 2014
    #1
    1. Advertising

  2. Ojesh Dugar

    Arne Vajhøj Guest

    On 2/9/2014 5:50 AM, Ojesh Dugar wrote:
    > I am trying to access a webservice api through XMLRPC from java client code.
    > But getting some error.Pls Help.
    >
    > My Code:


    import org.apache.commons.httpclient.HttpClient;
    > import org.apache.xmlrpc.XmlRpcException;
    > import org.apache.xmlrpc.client.XmlRpcClient;
    > import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
    > import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;


    > HttpClient httpClient = new HttpClient();
    > XmlRpcClient rpcClient = new XmlRpcClient();
    > XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(rpcClient);
    > XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    >
    > factory.setHttpClient(httpClient);


    > Error:
    >
    > BugCreator2.java:20: error: cannot find symbol factory.setHttpClient(httpClient); ^ symbol: method setHttpClient(HttpClient) location: variable factory of type XmlRpcCommonsTransportFactor Note: BugCreator2.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error
    >
    > Jars Used:
    >
    > commons-httpclient-3.0.1
    > java-rt-jar-stubs-1.5.0
    > ws-commons-util-1.0.1
    > ws-commons-util-1.0.1-sources
    > xmlrpc-3.0
    > xmlrpc-3.0-common


    setHttpClient is is latest XML-RPC version 3.1.3 but is not in the
    version you are using 3.0.

    My suggestion: try update.

    Arne
     
    Arne Vajhøj, Feb 9, 2014
    #2
    1. Advertising

  3. Ojesh Dugar

    Ojesh Dugar Guest

    Thanks Arne. But still code doesnot seem to run!!
    I included these jars
    1.xmlrpc-client-3.1.3.jar
    2.xmlrpc-common-3.1.3.jar
    3.commons-httpclient-3.1.jar
    4,commons-logging-1.1.3.jar
    5.ws-commons-util-1.0.2.jar

    ERROR:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
    at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
    at org.apache.commons.httpclient.methods.ExpectContinueMethod.<init>(ExpectContinueMethod.java:93)
    at org.apache.commons.httpclient.methods.EntityEnclosingMethod.<init>(EntityEnclosingMethod.java:119)
    at org.apache.commons.httpclient.methods.PostMethod.<init>(PostMethod.java:106)
    at org.apache.xmlrpc.client.XmlRpcCommonsTransport.newPostMethod(XmlRpcCommonsTransport.java:100)
    at org.apache.xmlrpc.client.XmlRpcCommonsTransport.initHttpHeaders(XmlRpcCommonsTransport.java:87)
    at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:142)
    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 XMLRPC.BugCreator.main(BugCreator.java:35)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 12 more
     
    Ojesh Dugar, Feb 10, 2014
    #3
  4. Ojesh Dugar

    Arne Vajhøj Guest

    On 2/10/2014 4:14 AM, Ojesh Dugar wrote:
    > Thanks Arne. But still code doesnot seem to run!!
    > I included these jars
    > 1.xmlrpc-client-3.1.3.jar
    > 2.xmlrpc-common-3.1.3.jar
    > 3.commons-httpclient-3.1.jar
    > 4,commons-logging-1.1.3.jar
    > 5.ws-commons-util-1.0.2.jar
    >
    > ERROR:
    >
    > Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException


    > Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException


    You are missing the class org.apache.commons.codec.DecoderException
    which seems to be part of common-codec.

    Arne
     
    Arne Vajhøj, Feb 10, 2014
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mgalaty
    Replies:
    0
    Views:
    2,768
    mgalaty
    Sep 10, 2004
  2. Pere Montolio

    XML RPC to ONC XDR RPC

    Pere Montolio, Aug 11, 2004, in forum: XML
    Replies:
    0
    Views:
    785
    Pere Montolio
    Aug 11, 2004
  3. Ymtrader
    Replies:
    1
    Views:
    620
    Adam Tauno Williams
    Mar 15, 2011
  4. Shirish Joshi

    Ruby and Sun-RPC or ONC-RPC ?

    Shirish Joshi, Apr 7, 2004, in forum: Ruby
    Replies:
    0
    Views:
    228
    Shirish Joshi
    Apr 7, 2004
  5. Vladimir Konrad

    rpc (not xml-rpc)

    Vladimir Konrad, Sep 2, 2005, in forum: Ruby
    Replies:
    5
    Views:
    156
    Austin Ziegler
    Sep 3, 2005
Loading...

Share This Page