简体   繁体   English

com.sun.xml.ws.client.ClientTransportException:HTTP传输错误:java.lang.ClassCastException

[英]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.

相关问题 Glassfish抛出com.sun.xml.ws.client.ClientTransportException:服务器发送了HTTP状态代码500:内部服务器错误 - Glassfish throws com.sun.xml.ws.client.ClientTransportException: The server sent HTTP status code 500: Internal Server Error com.sun.xml.ws.client.ClientTransportException:请求需要HTTP身份验证:未经授权 - com.sun.xml.ws.client.ClientTransportException: request requires HTTP authentication: Unauthorized JAX WS com.sun.xml.internal.ws.client.ClientTransportException:HTTP 传输错误:java.net.ConnectException:连接被拒绝 - JAX WS com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection refused com.sun.xml.internal.ws.client.ClientTransportException:HTTP传输错误:java.net.SocketException:连接重置 - com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.SocketException: Connection reset 使用CXF从Java消耗Web服务会导致com.sun.xml.ws.client.ClientTransportException:服务器发送了HTTP状态代码200:确定 - Consuming webservice from java using CXF results in com.sun.xml.ws.client.ClientTransportException: The server sent HTTP status code 200: OK 线程“ main” com.sun.xml.internal.ws.client.ClientTransportException中的异常:服务器发送了HTTP状态代码502:代理错误 - Exception in thread “main” com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 502: Proxy Error 连接到 web 服务导致 com.sun.xml.internal.ws.client.ClientTransportException:服务器发送 HTTP 状态码 200 - Connecting to webservice results in com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 200: OK ClientTransportException:HTTP传输错误:java.lang.UnsupportedOperationException:方法未实现 - ClientTransportException: HTTP transport error: java.lang.UnsupportedOperationException: Method not implemented Spring XML 5.1.0 java.lang.ClassCastException:com.sun.proxy。$ Proxy9 - Spring XML 5.1.0 java.lang.ClassCastException: com.sun.proxy.$Proxy9 导入com.sun.xml.internal.ws.client.ClientTransportException,无法读取此导入 - import com.sun.xml.internal.ws.client.ClientTransportException, can't read this import
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM