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

时间:2014-02-19 17:31:58

标签: java web-services soap

我目前正在尝试从Weblogic 12c和Java 7环境调用JAX-WS。我使用maven的weblogic客户端生成器插件生成了客户端存根,具体为:

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

客户端罐子似乎生成了罚款。我能够在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>

我在Glassfish设置Here

下看到了同样的问题

但没有解决方案。

现在我已经尝试过SOAP UI,服务从这里响应得很好,我尝试过使用weblogic 11g,并且产生了同样的错误。我正在记录在生成异常之前发出的实际SOAP消息,并且xml是准确的,并且在从SOAP UI运行时起作用。

导致这种情况的原因是什么?

谢谢

2 个答案:

答案 0 :(得分:2)

我花了几个小时来解决这个问题。我使用了错误的BindingProviderProperties接口。

BindingProviderProperties接口存在于两个不同的包中。 (适用于不同的Java / JAX-WS版本)

如果您收到ClassCastException,则很可能需要在soap服务类中导入不同的包。

更改

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

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

答案 1 :(得分:0)

问题是您正在使用String值设置超时属性,但是在内部createHttpConnection()中的类HttpClientTransport期望该属性为整数:

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

然后,如果您将属性传递为String,它将抛出ClassCastException。所以我想你有类似的东西:

String timeoutInMillis = "30000";

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

例如,必须使用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));

或者,您也可以将超时定义为int

int timeoutInMillis = 30000;

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