Grupy dyskusyjne Google nie obsługują już nowych postów ani subskrypcji z Usenetu. Treści historyczne nadal będą dostępne.

Apache XML-RPC Client for Java

877 wyświetleń
Przejdź do pierwszej nieodczytanej wiadomości

Janni Duerr

nieprzeczytany,
20 sty 2010, 12:12:5920.01.2010
do support-...@lists.mozilla.org
Hi Everybody,

I'm having some trouble using the Bugzilla Webservice APIs with the Apache XML-RPC Client for Java.
Bugzilla with the extention Testopia is running perfectly on localhost on a win7 system and i managed to login and execute some methods like "Bug.get" via XML-RPC. Executing other methods always thows one and the same java.lang.ClassCastExeption though, and i can't figure out what the problem is.

Does anyone have an idea what is wrong? I thought it might be a problem with the method parameters but i can't fix it. The Java sourcecode is below.
Help is greatly apreciated.

-Janni



import java.net.*;
import java.util.*;
import org.apache.commons.httpclient.HttpClient;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.*;


public class JakartaTest {

ᅵᅵᅵ
ᅵᅵᅵ public static void main(String[] args) {
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ try {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ config.setServerURL(new URL("http://localhost/xmlrpc.cgi"));
ᅵᅵᅵ ᅵᅵᅵ } catch (MalformedURLException e) {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ // TODO Auto-generated catch block
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ e.printStackTrace();
ᅵᅵᅵ ᅵᅵᅵ }
ᅵᅵᅵ ᅵᅵᅵ XmlRpcClient client = new XmlRpcClient();
ᅵᅵᅵ ᅵᅵᅵ HttpClient httpClient = new HttpClient();
ᅵᅵᅵ ᅵᅵᅵ XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(client);
ᅵᅵᅵ ᅵᅵᅵ factory.setHttpClient(httpClient);
ᅵᅵᅵ ᅵᅵᅵ client.setTransportFactory(factory);
ᅵᅵᅵ ᅵᅵᅵ client.setConfig(config);
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ HashMap<String,String> paramsLogin = new HashMap<String, String>();
ᅵᅵᅵ ᅵᅵᅵ paramsLogin.put("login", "ja...@user.de");
ᅵᅵᅵ ᅵᅵᅵ paramsLogin.put("password", "pass");
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ HashMap loginResult = null;
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ try {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ loginResult = (HashMap) client.execute("User.login", new Object[] {paramsLogin});
ᅵᅵᅵ ᅵᅵᅵ } catch (XmlRpcException e) {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ e.printStackTrace();
ᅵᅵᅵ ᅵᅵᅵ }
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ System.out.println(loginResult.get("id"));
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ HashMap paramsInfo = new HashMap();
ᅵᅵᅵ ᅵᅵᅵ Vector array = new Vector();
ᅵᅵᅵ ᅵᅵᅵ array.addElement(2);
ᅵᅵᅵ ᅵᅵᅵ paramsInfo.put("ids", array);
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ HashMap bugInfo = null;
ᅵᅵᅵ ᅵᅵᅵ Object bugs[] = null;
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ try {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ bugInfo = (HashMap) client.execute("Bug.get", new Object[] {paramsInfo});
ᅵᅵᅵ ᅵᅵᅵ } catch (XmlRpcException e) {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ // TODO Auto-generated catch block
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ e.printStackTrace();
ᅵᅵᅵ ᅵᅵᅵ }
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ bugs = (Object[]) bugInfo.get("bugs");
ᅵᅵᅵ ᅵᅵᅵ System.out.println(((HashMap) bugs[0]).get("summary"));
ᅵᅵᅵ ᅵᅵ

ᅵᅵᅵ ᅵᅵᅵ HashMap caseParam = new HashMap();
ᅵᅵᅵ ᅵᅵᅵ caseParam.put("case_id", 2);
ᅵᅵᅵ ᅵᅵᅵ HashMap caseResult = new HashMap();
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ try {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ caseResult = (HashMap) client.execute("TestCase.get", new Object[] {caseParam});ᅵᅵ ᅵᅵ //TestCase.get is a Testopia method
ᅵᅵᅵ ᅵᅵᅵ } catch (XmlRpcException e1) {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ // TODO Auto-generated catch block
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ e1.printStackTrace();
ᅵᅵᅵ ᅵᅵᅵ }
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ System.out.println(caseResult);
ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ try {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ client.execute("User.logout", new Object[0]);
ᅵᅵᅵ ᅵᅵᅵ } catch (XmlRpcException e) {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ // TODO Auto-generated catch block
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ e.printStackTrace();
ᅵᅵᅵ ᅵᅵᅵ }
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ }

}


and the console output: (line79 in JakartaTest is in bold letters)

2
MyBug1
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
ᅵᅵᅵ at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult(XmlRpcResponseParser.java:61)
ᅵᅵᅵ at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag(RecursiveTypeParserImpl.java:78)
ᅵᅵᅵ at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement(XmlRpcResponseParser.java:186)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
ᅵᅵᅵ at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:186)
ᅵᅵᅵ at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
ᅵᅵᅵ at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:115)
ᅵᅵᅵ 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 JakartaTest.main(JakartaTest.java:79)


Luciano

nieprzeczytany,
20 sty 2010, 12:37:4120.01.2010
do
Hello,

I'm having same problem. You able to resolve this?

I see this issue maybe in libraries. Since in debug mode this method
not returned values and show message error, do you understand me?
I changed Xerces library for Apache Xerces, and error messages now is
it:

org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse
server's response: java.lang.String cannot be cast to
java.lang.Integer
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse
(XmlRpcStreamTransport.java:188)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest
(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest
(XmlRpcHttpTransport.java:115)
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 Teste.main(Teste.java:47)
Caused by: java.lang.ClassCastException: java.lang.String cannot be
cast to java.lang.Integer
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1111)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse
(XmlRpcStreamTransport.java:186)
... 7 more
Caused by: java.lang.ClassCastException: java.lang.String cannot be
cast to java.lang.Integer
at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult
(XmlRpcResponseParser.java:61)
at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag
(RecursiveTypeParserImpl.java:78)
at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement
(XmlRpcResponseParser.java:186)
at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:
1403)
at org.apache.xerces.validators.common.XMLValidator.callEndElement
(XMLValidator.java:1550)
at org.apache.xerces.framework.XMLDocumentScanner
$ContentDispatcher.dispatch(XMLDocumentScanner.java:1204)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome
(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
... 8 more
Caused by:


java.lang.ClassCastException: java.lang.String cannot be cast to
java.lang.Integer

at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1111)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse
(XmlRpcStreamTransport.java:186)
at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest
(XmlRpcStreamTransport.java:156)
at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest
(XmlRpcHttpTransport.java:115)
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 Teste.main(Teste.java:47)
Caused by: java.lang.ClassCastException: java.lang.String cannot be
cast to java.lang.Integer
at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult
(XmlRpcResponseParser.java:61)
at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag
(RecursiveTypeParserImpl.java:78)
at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement
(XmlRpcResponseParser.java:186)
at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:
1403)
at org.apache.xerces.validators.common.XMLValidator.callEndElement
(XMLValidator.java:1550)
at org.apache.xerces.framework.XMLDocumentScanner
$ContentDispatcher.dispatch(XMLDocumentScanner.java:1204)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome
(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
... 8 more


If you have a solution, that's great.

Thanks a lot.


On Jan 20, 3:12 pm, Janni Duerr <janni-du...@gmx.de> wrote:
> Hi Everybody,
> I'm having some trouble using the Bugzilla Webservice APIs with the Apache XML-RPC Client for Java.
> Bugzilla with the extention Testopia is running perfectly on localhost on a win7 system and i managed to login and execute some methods like "Bug.get" via XML-RPC. Executing other methods always thows one and the same java.lang.ClassCastExeption though, and i can't figure out what the problem is.
> Does anyone have an idea what is wrong? I thought it might be a problem with the method parameters but i can't fix it. The Java sourcecode is below.
> Help is greatly apreciated.
> -Janni
> import java.net.*;
> import java.util.*;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.xmlrpc.XmlRpcException;
> import org.apache.xmlrpc.client.*;
> public class JakartaTest {

> public static void main(String[] args) {

> XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();

> try {


> config.setServerURL(new URL("http://localhost/xmlrpc.cgi"));

> } catch (MalformedURLException e) {


> // TODO Auto-generated catch block

> e.printStackTrace();


> }
> XmlRpcClient client = new XmlRpcClient();

> HttpClient httpClient = new HttpClient();

> XmlRpcCommonsTransportFactory factory = new XmlRpcCommonsTransportFactory(client);

> factory.setHttpClient(httpClient);
> client.setTransportFactory(factory);
> client.setConfig(config);


> HashMap<String,String> paramsLogin = new HashMap<String, String>();

> paramsLogin.put("login","ja...@user.de");

> paramsLogin.put("password", "pass");

> HashMap loginResult = null;
> try {


> loginResult = (HashMap) client.execute("User.login", new Object[] {paramsLogin});

> } catch (XmlRpcException e) {
> e.printStackTrace();
> }
> System.out.println(loginResult.get("id"));


> HashMap paramsInfo = new HashMap();

> Vector array = new Vector();

> array.addElement(2);
> paramsInfo.put("ids", array);
> HashMap bugInfo = null;
> Object bugs[] = null;
> try {


> bugInfo = (HashMap) client.execute("Bug.get", new Object[] {paramsInfo});

> } catch (XmlRpcException e) {


> // TODO Auto-generated catch block

> e.printStackTrace();


> }
> bugs = (Object[]) bugInfo.get("bugs");

> System.out.println(((HashMap) bugs[0]).get("summary"));

> HashMap caseParam = new HashMap();

> caseParam.put("case_id", 2);


> HashMap caseResult = new HashMap();

> try {caseResult = (HashMap) client.execute("TestCase.get", new Object[] {caseParam}); //TestCase.get is a Testopia method
> } catch (XmlRpcException e1) {


> // TODO Auto-generated catch block

> e1.printStackTrace();
> }
> System.out.println(caseResult);
> try {


> client.execute("User.logout", new Object[0]);

> } catch (XmlRpcException e) {


> // TODO Auto-generated catch block

> e.printStackTrace();


> }
> }
> }
> and the console output: (line79 in JakartaTest is in bold letters)
> 2
> MyBug1
> Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

> at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult(XmlRpcResponseParser.java:61)
> at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag(RecursiveTypeParserImpl.java:78)
> at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement(XmlRpcResponseParser.java:186)
> at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
> at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
> at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
> at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
> at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
> at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
> at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
> at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
> at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
> at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
> at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
> at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:186)
> at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
> at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:115)
> 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 JakartaTest.main(JakartaTest.java:79)

Luciano

nieprzeczytany,
20 sty 2010, 13:01:2720.01.2010
do
Hey Janni,


Try use this server like a test https://landfill.bugzilla.org/bugzilla-3.0-branch/xmlrpc.cgi
I tried and works, so that's problem maybe in my bugzilla server
configuration, ok?

Janni Duerr

nieprzeczytany,
20 sty 2010, 14:57:5120.01.2010
do support-...@lists.mozilla.org

Tried that.
I successfully connected to "http://landfill.bugzilla.org./testopia2/xml.rpc.cgi"  since i am trying to remotely call Testopia related methods too. I get the same ClassCastException as i described in the first email. So the configuration of my server shouldn't be the reason. Since the installed Bugzilla version on the landfill server is  3.0  instead of 3.2.5 as on my server. it helped me to find out that the Exception is thrown if you remotely call a method doesn't exist. the "Bug.get" method in 3.2.5 is named "Bug.get_bugs" in 3.0

But still, calling "TestCase.get" throws this Exception. I tried "Testopia.Testcase.get", "testcase.get" and others.

If anyone knows what the problem is, this should be fairly easy to solve.
Some help, please

-Janni



Luciano schrieb:
_______________________________________________
support-bugzilla mailing list
support-...@lists.mozilla.org
https://lists.mozilla.org/listinfo/support-bugzilla
PLEASE put support-...@lists.mozilla.org in the To: field when you reply.

  

Janni Duerr

nieprzeczytany,
21 sty 2010, 11:06:0321.01.2010
do support-...@lists.mozilla.org
I solved the problem. For future reference:

Anyone encountering this ClassCastExeption make sure that the name of the method you are trying to call via XML-RPC is spelled correctly, including case sensivity and Bugzilla version differences. Also, when trying to call Testopia methods (or of other extentions i guess) the URL you tell your XML-RPC client to connect to might not the same as for Bugzilla methods.
i.e. where Bugzilla methods can be executed connecting to http://<yourServerURL>/xmlrpc.cgi , Testopia methods have to be executed connecting to http://<yourServerURL>/tr_xmlrpc.cgi





Janni Duerr schrieb:
Hi Everybody,

I'm having some trouble using the Bugzilla Webservice APIs with the Apache XML-RPC Client for Java.
Bugzilla with the extention Testopia is running perfectly on localhost on a win7 system and i managed to login and execute some methods like "Bug.get" via XML-RPC. Executing other methods always thows one and the same java.lang.ClassCastExeption though, and i can't figure out what the problem is.

Does anyone have an idea what is wrong? I thought it might be a problem with the method parameters but i can't fix it. The Java sourcecode is below.
Help is greatly apreciated.

-Janni



import java.net.*;
import java.util.*;
import org.apache.commons.httpclient.HttpClient;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.*;


public class JakartaTest {

ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ bugInfo = (HashMap) client.execute("Bug.get", new Object[] {paramsInfo});

ᅵᅵᅵ ᅵᅵᅵ } catch (XmlRpcException e) {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ // TODO Auto-generated catch block

ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ e.printStackTrace();
ᅵᅵᅵ ᅵᅵᅵ }
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ bugs = (Object[]) bugInfo.get("bugs");
ᅵᅵᅵ ᅵᅵᅵ System.out.println(((HashMap) bugs[0]).get("summary"));
ᅵᅵᅵ ᅵᅵ

ᅵᅵᅵ ᅵᅵᅵ HashMap caseParam = new HashMap();
ᅵᅵᅵ ᅵᅵᅵ caseParam.put("case_id", 2);
ᅵᅵᅵ ᅵᅵᅵ HashMap caseResult = new HashMap();
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ try {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ caseResult = (HashMap) client.execute("TestCase.get", new Object[] {caseParam});ᅵᅵ ᅵᅵ //TestCase.get is a Testopia method
ᅵᅵᅵ ᅵᅵᅵ } catch (XmlRpcException e1) {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ // TODO Auto-generated catch block
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ e1.printStackTrace();
ᅵᅵᅵ ᅵᅵᅵ }
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ System.out.println(caseResult);
ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ ᅵᅵᅵ try {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ client.execute("User.logout", new Object[0]);

ᅵᅵᅵ ᅵᅵᅵ } catch (XmlRpcException e) {
ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ // TODO Auto-generated catch block

ᅵᅵᅵ ᅵᅵᅵ ᅵᅵᅵ e.printStackTrace();
ᅵᅵᅵ ᅵᅵᅵ }
ᅵᅵᅵ ᅵᅵᅵ
ᅵᅵᅵ }

}


and the console output: (line79 in JakartaTest is in bold letters)

2
MyBug1
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
ᅵᅵᅵ at org.apache.xmlrpc.parser.XmlRpcResponseParser.addResult(XmlRpcResponseParser.java:61)
ᅵᅵᅵ at org.apache.xmlrpc.parser.RecursiveTypeParserImpl.endValueTag(RecursiveTypeParserImpl.java:78)
ᅵᅵᅵ at org.apache.xmlrpc.parser.XmlRpcResponseParser.endElement(XmlRpcResponseParser.java:186)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
ᅵᅵᅵ at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
ᅵᅵᅵ at org.apache.xmlrpc.client.XmlRpcStreamTransport.readResponse(XmlRpcStreamTransport.java:186)
ᅵᅵᅵ at org.apache.xmlrpc.client.XmlRpcStreamTransport.sendRequest(XmlRpcStreamTransport.java:156)
ᅵᅵᅵ at org.apache.xmlrpc.client.XmlRpcHttpTransport.sendRequest(XmlRpcHttpTransport.java:115)
ᅵᅵᅵ 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 JakartaTest.main(JakartaTest.java:79)


lina_gsp

nieprzeczytany,
21 maj 2012, 11:01:0021.05.2012
do support-...@lists.mozilla.org

Hi,
Would you please write an example.... I trying to load all products fro a
specific user... but I always have the same problem.I checkes the
documentation and bugzilla versions all are fine...! Do not know what to
do..... Any suggestion???




Janni Duerr wrote:
>
>
>
>
>
>
>
> I solved the problem. For future reference:
>
> Anyone encountering this ClassCastExeption make sure that the name of
> the method you are trying to call via XML-RPC is spelled correctly,
> including case sensivity and Bugzilla version differences. Also, when
> trying to call Testopia methods (or of other extentions i guess) the
> URL you tell your XML-RPC client to connect to might not the same as
> for Bugzilla methods.
> i.e. where Bugzilla methods can be executed connecting to
> http:// &lt;yourServerURL&gt;/xmlrpc.cgi , Testopia methods have to be
> executed connecting to http:// &lt;yourServerURL&gt;/tr_xmlrpc.cgi
>
>
>
>
>
> Janni Duerr schrieb:
> Hi Everybody,
>
> I'm having some trouble using the Bugzilla Webservice APIs with the
> Apache XML-RPC Client for Java.
> Bugzilla with the extention Testopia is running perfectly on localhost
> on a win7 system and i managed to login and execute some methods like
> "Bug.get" via XML-RPC. Executing other methods always thows one and the
> same java.lang.ClassCastExeption though, and i can't figure out what
> the problem is.
>
> Does anyone have an idea what is wrong? I thought it might be a problem
> with the method parameters but i can't fix it. The Java sourcecode is
> below.
> Help is greatly apreciated.
>
> -Janni
>
>
>
> import java.net.*;
> import java.util.*;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.xmlrpc.XmlRpcException;
> import org.apache.xmlrpc.client.*;
>
>
> public class JakartaTest {
>
>    
>     public static void main(String[] args) {
>        
>        
>         XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
>        
>         try {
>             config.setServerURL(new URL( "http://localhost/xmlrpc.cgi" ));
>         } catch (MalformedURLException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
>         XmlRpcClient client = new XmlRpcClient();
>         HttpClient httpClient = new HttpClient();
>         XmlRpcCommonsTransportFactory factory = new
> XmlRpcCommonsTransportFactory(client);
>         factory.setHttpClient(httpClient);
>         client.setTransportFactory(factory);
>         client.setConfig(config);
>        
>        
>        
>        
>         HashMap&lt;String,String&gt; paramsLogin = new
> HashMap&lt;String, String&gt;();
>         paramsLogin.put("login", "ja...@user.de" );
>         paramsLogin.put("password", "pass");
>            
>         HashMap loginResult = null;
>        
>            
>         try {
>             loginResult = (HashMap) client.execute("User.login", new
> Object[] {paramsLogin});
>         } catch (XmlRpcException e) {
>                
>             e.printStackTrace();
>         }
>        
>         System.out.println(loginResult.get("id"));
>        
>         HashMap paramsInfo = new HashMap();
>         Vector array = new Vector();
>         array.addElement(2);
>         paramsInfo.put("ids", array);
>        
>         HashMap bugInfo = null;
>         Object bugs[] = null;
>        
>         try {
>             bugInfo = (HashMap) client.execute("Bug.get", new Object[]
> {paramsInfo});
>         } catch (XmlRpcException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
>        
>         bugs = (Object[]) bugInfo.get("bugs");
>         System.out.println(((HashMap) bugs[0]).get("summary"));
>       
>
>         HashMap caseParam = new HashMap();
>         caseParam.put("case_id", 2);
>         HashMap caseResult = new HashMap();
>        
>        
>        
>         try {
>             caseResult = (HashMap) client.execute("TestCase.get",
> new Object[] {caseParam});      //TestCase.get is a Testopia method
>         } catch (XmlRpcException e1) {
>             // TODO Auto-generated catch block
>             e1.printStackTrace();
>         }
>        
>         System.out.println(caseResult);
>    
>        
>         try {
>             client.execute("User.logout", new Object[0]);
>         } catch (XmlRpcException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
>        
>     }
>
> }
>
>
> and the console output: (line79 in JakartaTest is in bold letters)
>
> 2
> MyBug1
> Exception in thread "main" java.lang.ClassCastException:
> java.lang.String cannot be cast to java.lang.Integer
> _______________________________________________
> support-bugzilla mailing list
> support-...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/support-bugzilla
> PLEASE put support-...@lists.mozilla.org in the To: field when you
> reply.
>
>
>
>
>
> _______________________________________________
> support-bugzilla mailing list
> support-...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/support-bugzilla
> PLEASE put support-...@lists.mozilla.org in the To: field when you
> reply.
>

--
View this message in context: http://old.nabble.com/Apache-XML-RPC-Client-for-Java-tp27245323p33883261.html
Sent from the Bugzilla - Users mailing list archive at Nabble.com.

Nowe wiadomości: 0