简体   繁体   中英

com.sun.xml.ws.client.ClientTransportException: HTTP transport error: java.lang.ClassCastException

I am currently trying to call a JAX-WS from a Weblogic 12c and Java 7 environment. I've generated the client stubs using the weblogic client generator plugin from maven, specifically:

<b>groupId:com.oracle.weblogic</b><br>
<b>artifactId:weblogic-maven-plugin</b>

client jars seem to generate fine. I am able to generate the client stub in java, but when the actual API is called through the stub that will send the SOAP message to the service, I get the following strange exception:

<b>com.sun.xml.ws.client.ClientTransportException: HTTP transport error: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
com.sun.xml.ws.client.ClientTransportException: HTTP transport error: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
        at com.sun.xml.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:131)
        at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:219)
        at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:143)
        at com.sun.xml.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:138)
        at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:892)
        at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:841)
        at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:804)
        at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:706)
        at com.sun.xml.ws.client.Stub.process(Stub.java:385)
        at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:189)
        at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)
        at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:102)
        at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:172)
        at $Proxy130.getSearchResults(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at weblogic.wsee.jaxws.spi.ClientInstanceInvocationHandler.invoke(ClientInstanceInvocationHandler.java:84)</b>

I saw this same question being posted under a glassfish setup Here

But with no solution.

Now i've tried SOAP UI, the service responds fine from here, i've tried using weblogic 11g, and same error is produced. I am logging the actual SOAP message that is going out before the exception is produced, and the xml is accurate and works when run from SOAP UI.

What could be causing this?

Thanks

It took me couple of hours to fix the problem. I was using the wrong BindingProviderProperties interface.

The BindingProviderProperties interface exists in two different packages. (for different Java/JAX-WS versions)

If you are getting ClassCastException most probably you need import different package in your soap service class.

change

import com.sun.xml.ws.client.BindingProviderProperties;

to

import com.sun.xml.internal.ws.client.BindingProviderProperties;

The problem is that you're setting timeout properties using String value, however internally the class HttpClientTransport in createHttpConnection() method is expecting an integer for this property:

...
Integer reqTimeout = (Integer)context.invocationProperties.get(BindingProviderProperties.REQUEST_TIMEOUT);
if (reqTimeout != null) {
    httpConnection.setReadTimeout(reqTimeout);
}
...

Then if you're passing the property as String , it throws the ClassCastException . So I suppose you've something like:

String timeoutInMillis = "30000";

dispatcher.getRequestContext().put(BindingProviderProperties.REQUEST_TIMEOUT, timeoutInMillis);
dispatcher.getRequestContext().put(BindingProviderProperties.CONNECT_TIMEOUT, timeoutInMillis);

Instead of you must set the property value as int for example using Integer.valueOf(String value) :

String timeoutInMillis = "30000";

dispatcher.getRequestContext().put(BindingProviderProperties.REQUEST_TIMEOUT, Integer.valueOf(timeoutInMillis));
dispatcher.getRequestContext().put(BindingProviderProperties.CONNECT_TIMEOUT, Integer.valueOf(timeoutInMillis));

Or alternatively you can also define the timeout as int :

int timeoutInMillis = 30000;

dispatcher.getRequestContext().put(BindingProviderProperties.REQUEST_TIMEOUT, timeoutInMillis);
dispatcher.getRequestContext().put(BindingProviderProperties.CONNECT_TIMEOUT, timeoutInMillis);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM