[英]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. 我目前正在尝试从Weblogic 12c和Java 7环境中调用JAX-WS。 I've generated the client stubs using the weblogic client generator plugin from maven, specifically:
我已经使用来自maven的weblogic客户端生成器插件生成了客户端存根,特别是:
<b>groupId:com.oracle.weblogic</b><br>
<b>artifactId:weblogic-maven-plugin</b>
client jars seem to generate fine. 客户端jar似乎可以正常运行。 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:
我可以用Java生成客户端存根,但是当通过将SOAP消息发送到服务的存根调用实际的API时,出现以下奇怪的异常:
<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 我看到了同样的问题一个GlassFish的设置下被张贴在这里
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. 现在,我尝试了SOAP UI,该服务从这里响应良好,我尝试使用weblogic 11g,并且产生了相同的错误。 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.
我正在记录在产生异常之前发出的实际SOAP消息,并且xml是准确的,并且在从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.
我使用了错误的BindingProviderProperties接口。
The BindingProviderProperties interface exists in two different packages. BindingProviderProperties接口存在于两个不同的程序包中。 (for different Java/JAX-WS versions)
(用于不同的Java / JAX-WS版本)
If you are getting ClassCastException most probably you need import different package in your soap service class. 如果您最可能收到ClassCastException,则可能需要在soap服务类中导入其他包。
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: 问题是您正在使用
String
值设置超时属性,但是内部内部createHttpConnection()
方法中的HttpClientTransport
类期望此属性为整数:
...
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
. 然后,如果您将属性作为
String
传递,它将抛出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)
: 而不是必须使用
Integer.valueOf(String value)
将属性值设置为int:
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
:
int timeoutInMillis = 30000;
dispatcher.getRequestContext().put(BindingProviderProperties.REQUEST_TIMEOUT, timeoutInMillis);
dispatcher.getRequestContext().put(BindingProviderProperties.CONNECT_TIMEOUT, timeoutInMillis);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.