SOAP HTTPS测试获取类强制转换异常(String to Integer)

时间:2015-12-14 21:33:13

标签: java soap https

我正在使用HTTPS上的独立应用程序测试SOAP请求。我有从WSDL创建的必需类(使用wsimport),我使用一些模拟值填充了对象值。

令人惊讶的是我的所有XML值都在String中,但我得到一个类强制转换异常为#34; String to Integer"

客户代码

EWOProviderWSEWOWsdl ewoProvider = new EWOProviderWSEWOWsdl();
EWOWsdlPortType servicePort = ewoProvider.getEWOProviderWSEWOWsdlPort();

BindingProvider bindingProvider = (BindingProvider) servicePort;
Map<String, Object> requestContext = bindingProvider
            .getRequestContext();

// Target End Point URL is set in the context here
requestContext
        .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                    "https://MY Url where WSDL is deployed");

// Timeouts in milliseconds
requestContext.put("com.sun.xml.internal.ws.request.timeout", "25000");
requestContext.put("com.sun.xml.internal.ws.connect.timeout", "15000");

// Credentials are set in over here
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Username", Collections.singletonList("UserName"));
headers.put("Password", Collections.singletonList("Password"));
requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
System.setProperty("proxySet", "true");
System.setProperty("proxyPort", "80");
System.setProperty("proxyHost", "myproxy_host");

JAXBElement<EWOOrders> ewoOrders = generateWSRequestObject();

String generatedXml = generateXmlRequestForProgistix(ewoOrders);
System.out.println("XML >> " + generatedXml);

DocTypeRefStatusMessageResponse responseMessage = servicePort
    .postEWOOrder(ewoOrders.getValue());

异常消息

Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
    at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:117)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:194)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:122)
    at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:123)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:626)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467)
    at com.sun.xml.internal.ws.client.Stub.process(Stub.java:308)
    at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:163)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
    at com.sun.proxy.$Proxy24.postEWOOrder(Unknown Source)
    at com.test.TestMain.main(TestMain.java:99)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
    at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.createHttpConnection(HttpClientTransport.java:263)
    at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:102)
    ... 14 more

1 个答案:

答案 0 :(得分:4)

当您在BindingProvider设置超时时,您可能会使用错误的类型。

requestContext.put("com.sun.xml.internal.ws.request.timeout", "25000");
requestContext.put("com.sun.xml.internal.ws.connect.timeout", "15000");

应该是:

requestContext.put("com.sun.xml.internal.ws.request.timeout", 25000);
requestContext.put("com.sun.xml.internal.ws.connect.timeout", 15000);

找到相关的源代码here