Error in Java XML RPC code

O

Ojesh Dugar

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", "(e-mail address removed)");
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.
 
A

Arne Vajhøj

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
 
O

Ojesh Dugar

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
 
A

Arne Vajhøj

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top