You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlrpc-auto@ws.apache.org by "Chris Cooper (JIRA)" <xm...@ws.apache.org> on 2009/10/13 16:23:31 UTC

[jira] Created: (XMLRPC-178) ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String

ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String
-------------------------------------------------------------------------------------

                 Key: XMLRPC-178
                 URL: https://issues.apache.org/jira/browse/XMLRPC-178
             Project: XML-RPC
          Issue Type: Bug
          Components: Releases
    Affects Versions: 3.1.2
         Environment: Windows Server 2003
            Reporter: Chris Cooper


I have a fairly simple client server application. One of my exposed server methods returns a String[]. I am getting a ClassCastException on the client side when getting the result. The class cast exception occurs in ClientFactory.class in the newInstance function. I am stepping through the code, and it happens on the line "return typeConverter.convert(result);". Stepping into this function hasn't really helped as it causes the ClassCastException. I am not sure what the problem is, on the server side I have debugged and determined that my function is indeed returning a String[] as it should be, but for some reason when it comes over to the client side there is a problem. I can post you the stack trace:

Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
	at $Proxy1.getInstances(Unknown Source)
	at com.rsa.grinderbot.controller.perfmon.WindowsProxy.getInstances(WindowsProxy.java:46) -> this is the proxy object calling my server's function
	at com.rsa.grinderbot.controller.perfmon.WindowsStats.<init>(WindowsStats.java:37)
	at com.rsa.grinderbot.controller.perfmon.PerformanceMonitor.<init>(PerformanceMonitor.java:33)
	at com.rsa.grinderbot.controller.Controller.run(Controller.java:268)
	at com.rsa.grinderbot.controller.Controller.main(Controller.java:333)

Here is my constructor that creates the proxy object using the client factory.

public WindowsProxy(Server server) {
		this.server = server;
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		try {
			config.setServerURL(new URL("http://" + server.getHostname() + ":" + server.getPort() + "/xmlrpc"));
			config.setReplyTimeout(0);
			config.setConnectionTimeout(0);
			XmlRpcClient client = new XmlRpcClient();
		    client.setConfig(config);
		    ClientFactory factory = new ClientFactory(client);
		    windows = (WindowsServerAPI) factory.newInstance(WindowsServerAPI.class);
		} catch (MalformedURLException e) {
			//TODO log4j
			e.printStackTrace();
		}
	}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (XMLRPC-178) ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String

Posted by "Jochen Wiedmann (JIRA)" <xm...@ws.apache.org>.
     [ https://issues.apache.org/jira/browse/XMLRPC-178?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jochen Wiedmann resolved XMLRPC-178.
------------------------------------

    Resolution: Invalid
      Assignee: Jochen Wiedmann

See

http://ws.apache.org/xmlrpc/faq.html#arrays


> ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String
> -------------------------------------------------------------------------------------
>
>                 Key: XMLRPC-178
>                 URL: https://issues.apache.org/jira/browse/XMLRPC-178
>             Project: XML-RPC
>          Issue Type: Bug
>          Components: Releases
>    Affects Versions: 3.1.2
>         Environment: Windows Server 2003
>            Reporter: Chris Cooper
>            Assignee: Jochen Wiedmann
>
> I have a fairly simple client server application. One of my exposed server methods returns a String[]. I am getting a ClassCastException on the client side when getting the result. The class cast exception occurs in ClientFactory.class in the newInstance function. I am stepping through the code, and it happens on the line "return typeConverter.convert(result);". Stepping into this function hasn't really helped as it causes the ClassCastException. I am not sure what the problem is, on the server side I have debugged and determined that my function is indeed returning a String[] as it should be, but for some reason when it comes over to the client side there is a problem. I can post you the stack trace:
> Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
> 	at $Proxy1.getInstances(Unknown Source)
> 	at com.rsa.grinderbot.controller.perfmon.WindowsProxy.getInstances(WindowsProxy.java:46) -> this is the proxy object calling my server's function
> 	at com.rsa.grinderbot.controller.perfmon.WindowsStats.<init>(WindowsStats.java:37)
> 	at com.rsa.grinderbot.controller.perfmon.PerformanceMonitor.<init>(PerformanceMonitor.java:33)
> 	at com.rsa.grinderbot.controller.Controller.run(Controller.java:268)
> 	at com.rsa.grinderbot.controller.Controller.main(Controller.java:333)
> Here is my constructor that creates the proxy object using the client factory.
> public WindowsProxy(Server server) {
> 		this.server = server;
> 		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
> 		try {
> 			config.setServerURL(new URL("http://" + server.getHostname() + ":" + server.getPort() + "/xmlrpc"));
> 			config.setReplyTimeout(0);
> 			config.setConnectionTimeout(0);
> 			XmlRpcClient client = new XmlRpcClient();
> 		    client.setConfig(config);
> 		    ClientFactory factory = new ClientFactory(client);
> 		    windows = (WindowsServerAPI) factory.newInstance(WindowsServerAPI.class);
> 		} catch (MalformedURLException e) {
> 			//TODO log4j
> 			e.printStackTrace();
> 		}
> 	}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (XMLRPC-178) ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String

Posted by "Jochen Wiedmann (JIRA)" <xm...@ws.apache.org>.
    [ https://issues.apache.org/jira/browse/XMLRPC-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765119#action_12765119 ] 

Jochen Wiedmann commented on XMLRPC-178:
----------------------------------------

Of course, it must be

    Object [] instances = windowsProxy.getInstances("Network Interface");

otherwise you're casting again. And, please, don't abuse the bug tracking system for issues, which belong to the xmlrpc-users mailing list.

> ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String
> -------------------------------------------------------------------------------------
>
>                 Key: XMLRPC-178
>                 URL: https://issues.apache.org/jira/browse/XMLRPC-178
>             Project: XML-RPC
>          Issue Type: Bug
>          Components: Releases
>    Affects Versions: 3.1.2
>         Environment: Windows Server 2003
>            Reporter: Chris Cooper
>            Assignee: Jochen Wiedmann
>
> I have a fairly simple client server application. One of my exposed server methods returns a String[]. I am getting a ClassCastException on the client side when getting the result. The class cast exception occurs in ClientFactory.class in the newInstance function. I am stepping through the code, and it happens on the line "return typeConverter.convert(result);". Stepping into this function hasn't really helped as it causes the ClassCastException. I am not sure what the problem is, on the server side I have debugged and determined that my function is indeed returning a String[] as it should be, but for some reason when it comes over to the client side there is a problem. I can post you the stack trace:
> Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
> 	at $Proxy1.getInstances(Unknown Source)
> 	at com.rsa.grinderbot.controller.perfmon.WindowsProxy.getInstances(WindowsProxy.java:46) -> this is the proxy object calling my server's function
> 	at com.rsa.grinderbot.controller.perfmon.WindowsStats.<init>(WindowsStats.java:37)
> 	at com.rsa.grinderbot.controller.perfmon.PerformanceMonitor.<init>(PerformanceMonitor.java:33)
> 	at com.rsa.grinderbot.controller.Controller.run(Controller.java:268)
> 	at com.rsa.grinderbot.controller.Controller.main(Controller.java:333)
> Here is my constructor that creates the proxy object using the client factory.
> public WindowsProxy(Server server) {
> 		this.server = server;
> 		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
> 		try {
> 			config.setServerURL(new URL("http://" + server.getHostname() + ":" + server.getPort() + "/xmlrpc"));
> 			config.setReplyTimeout(0);
> 			config.setConnectionTimeout(0);
> 			XmlRpcClient client = new XmlRpcClient();
> 		    client.setConfig(config);
> 		    ClientFactory factory = new ClientFactory(client);
> 		    windows = (WindowsServerAPI) factory.newInstance(WindowsServerAPI.class);
> 		} catch (MalformedURLException e) {
> 			//TODO log4j
> 			e.printStackTrace();
> 		}
> 	}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (XMLRPC-178) ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String

Posted by "Chris Cooper (JIRA)" <xm...@ws.apache.org>.
    [ https://issues.apache.org/jira/browse/XMLRPC-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765086#action_12765086 ] 

Chris Cooper commented on XMLRPC-178:
-------------------------------------

Just to add a comment, when I debug the code at the line
TypeConverter typeConverter = typeConverterFactory.getTypeConverter(pMethod.getReturnType());

when I look at pMethod variable, return type is indeed "class [Ljava.lang.String;"

> ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String
> -------------------------------------------------------------------------------------
>
>                 Key: XMLRPC-178
>                 URL: https://issues.apache.org/jira/browse/XMLRPC-178
>             Project: XML-RPC
>          Issue Type: Bug
>          Components: Releases
>    Affects Versions: 3.1.2
>         Environment: Windows Server 2003
>            Reporter: Chris Cooper
>
> I have a fairly simple client server application. One of my exposed server methods returns a String[]. I am getting a ClassCastException on the client side when getting the result. The class cast exception occurs in ClientFactory.class in the newInstance function. I am stepping through the code, and it happens on the line "return typeConverter.convert(result);". Stepping into this function hasn't really helped as it causes the ClassCastException. I am not sure what the problem is, on the server side I have debugged and determined that my function is indeed returning a String[] as it should be, but for some reason when it comes over to the client side there is a problem. I can post you the stack trace:
> Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
> 	at $Proxy1.getInstances(Unknown Source)
> 	at com.rsa.grinderbot.controller.perfmon.WindowsProxy.getInstances(WindowsProxy.java:46) -> this is the proxy object calling my server's function
> 	at com.rsa.grinderbot.controller.perfmon.WindowsStats.<init>(WindowsStats.java:37)
> 	at com.rsa.grinderbot.controller.perfmon.PerformanceMonitor.<init>(PerformanceMonitor.java:33)
> 	at com.rsa.grinderbot.controller.Controller.run(Controller.java:268)
> 	at com.rsa.grinderbot.controller.Controller.main(Controller.java:333)
> Here is my constructor that creates the proxy object using the client factory.
> public WindowsProxy(Server server) {
> 		this.server = server;
> 		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
> 		try {
> 			config.setServerURL(new URL("http://" + server.getHostname() + ":" + server.getPort() + "/xmlrpc"));
> 			config.setReplyTimeout(0);
> 			config.setConnectionTimeout(0);
> 			XmlRpcClient client = new XmlRpcClient();
> 		    client.setConfig(config);
> 		    ClientFactory factory = new ClientFactory(client);
> 		    windows = (WindowsServerAPI) factory.newInstance(WindowsServerAPI.class);
> 		} catch (MalformedURLException e) {
> 			//TODO log4j
> 			e.printStackTrace();
> 		}
> 	}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (XMLRPC-178) ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String

Posted by "Gamaliel Amaudruz (JIRA)" <xm...@ws.apache.org>.
    [ https://issues.apache.org/jira/browse/XMLRPC-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12791976#action_12791976 ] 

Gamaliel Amaudruz commented on XMLRPC-178:
------------------------------------------

Hello,
I have a similar issue when I use the proxy method with a function defined in the Interface as returning a String[]. I get the error even if I do no casting on it, just invoking the method:
myProxyObject.theMethodReturningAStringArray(someParams);
raises a "java.lang.ClassCastException: [Ljava.lang.Object;" in the proxy object.

The "fix" defined here http://ws.apache.org/xmlrpc/faq.html#arrays is not for the proxy method. I tried many different casting options but I can't find the correct one.
If the proxy method cannot handle functions which return Array, I think it would be good to indicate this limitation on the website here:
http://ws.apache.org/xmlrpc/advanced.html

Or maybe I'm not getting something right...
Regards,
Gam


PS: I implemented the old way where you have to do everything by hand and it works fine.

> ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String
> -------------------------------------------------------------------------------------
>
>                 Key: XMLRPC-178
>                 URL: https://issues.apache.org/jira/browse/XMLRPC-178
>             Project: XML-RPC
>          Issue Type: Bug
>          Components: Releases
>    Affects Versions: 3.1.2
>         Environment: Windows Server 2003
>            Reporter: Chris Cooper
>            Assignee: Jochen Wiedmann
>
> I have a fairly simple client server application. One of my exposed server methods returns a String[]. I am getting a ClassCastException on the client side when getting the result. The class cast exception occurs in ClientFactory.class in the newInstance function. I am stepping through the code, and it happens on the line "return typeConverter.convert(result);". Stepping into this function hasn't really helped as it causes the ClassCastException. I am not sure what the problem is, on the server side I have debugged and determined that my function is indeed returning a String[] as it should be, but for some reason when it comes over to the client side there is a problem. I can post you the stack trace:
> Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
> 	at $Proxy1.getInstances(Unknown Source)
> 	at com.rsa.grinderbot.controller.perfmon.WindowsProxy.getInstances(WindowsProxy.java:46) -> this is the proxy object calling my server's function
> 	at com.rsa.grinderbot.controller.perfmon.WindowsStats.<init>(WindowsStats.java:37)
> 	at com.rsa.grinderbot.controller.perfmon.PerformanceMonitor.<init>(PerformanceMonitor.java:33)
> 	at com.rsa.grinderbot.controller.Controller.run(Controller.java:268)
> 	at com.rsa.grinderbot.controller.Controller.main(Controller.java:333)
> Here is my constructor that creates the proxy object using the client factory.
> public WindowsProxy(Server server) {
> 		this.server = server;
> 		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
> 		try {
> 			config.setServerURL(new URL("http://" + server.getHostname() + ":" + server.getPort() + "/xmlrpc"));
> 			config.setReplyTimeout(0);
> 			config.setConnectionTimeout(0);
> 			XmlRpcClient client = new XmlRpcClient();
> 		    client.setConfig(config);
> 		    ClientFactory factory = new ClientFactory(client);
> 		    windows = (WindowsServerAPI) factory.newInstance(WindowsServerAPI.class);
> 		} catch (MalformedURLException e) {
> 			//TODO log4j
> 			e.printStackTrace();
> 		}
> 	}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (XMLRPC-178) ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String

Posted by "Chris Cooper (JIRA)" <xm...@ws.apache.org>.
    [ https://issues.apache.org/jira/browse/XMLRPC-178?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765117#action_12765117 ] 

Chris Cooper commented on XMLRPC-178:
-------------------------------------

I'm not sure that is my problem, I have changed my code and I am still getting the exception.

Object [] instances = (String []) windowsProxy.getInstances("Network Interface");

public String[] getInstances(String category) throws IllegalArgumentException, InvalidCounterException {
	return (String []) windows.getInstances(category);
}

public String[] getInstances(String category) throws IllegalArgumentException, InvalidCounterException {
	if (category.equals("") || category == null) {
		throw new IllegalArgumentException("Category cannot be blank or null");
	}
	String [] instances = nativeGetInstances(category); // native function call
	if (instances.length == 0) {
		throw new InvalidCounterException("Invalid Category: " + category);
	}
	return (String []) instances;
}

> ClassCastException in client proxy cannot cast Ljava.lang.Object to Ljava.lang.String
> -------------------------------------------------------------------------------------
>
>                 Key: XMLRPC-178
>                 URL: https://issues.apache.org/jira/browse/XMLRPC-178
>             Project: XML-RPC
>          Issue Type: Bug
>          Components: Releases
>    Affects Versions: 3.1.2
>         Environment: Windows Server 2003
>            Reporter: Chris Cooper
>            Assignee: Jochen Wiedmann
>
> I have a fairly simple client server application. One of my exposed server methods returns a String[]. I am getting a ClassCastException on the client side when getting the result. The class cast exception occurs in ClientFactory.class in the newInstance function. I am stepping through the code, and it happens on the line "return typeConverter.convert(result);". Stepping into this function hasn't really helped as it causes the ClassCastException. I am not sure what the problem is, on the server side I have debugged and determined that my function is indeed returning a String[] as it should be, but for some reason when it comes over to the client side there is a problem. I can post you the stack trace:
> Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
> 	at $Proxy1.getInstances(Unknown Source)
> 	at com.rsa.grinderbot.controller.perfmon.WindowsProxy.getInstances(WindowsProxy.java:46) -> this is the proxy object calling my server's function
> 	at com.rsa.grinderbot.controller.perfmon.WindowsStats.<init>(WindowsStats.java:37)
> 	at com.rsa.grinderbot.controller.perfmon.PerformanceMonitor.<init>(PerformanceMonitor.java:33)
> 	at com.rsa.grinderbot.controller.Controller.run(Controller.java:268)
> 	at com.rsa.grinderbot.controller.Controller.main(Controller.java:333)
> Here is my constructor that creates the proxy object using the client factory.
> public WindowsProxy(Server server) {
> 		this.server = server;
> 		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
> 		try {
> 			config.setServerURL(new URL("http://" + server.getHostname() + ":" + server.getPort() + "/xmlrpc"));
> 			config.setReplyTimeout(0);
> 			config.setConnectionTimeout(0);
> 			XmlRpcClient client = new XmlRpcClient();
> 		    client.setConfig(config);
> 		    ClientFactory factory = new ClientFactory(client);
> 		    windows = (WindowsServerAPI) factory.newInstance(WindowsServerAPI.class);
> 		} catch (MalformedURLException e) {
> 			//TODO log4j
> 			e.printStackTrace();
> 		}
> 	}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.