当前位置:  开发笔记 > 编程语言 > 正文

SOAP HTTPS测试获取类强制转换异常(字符串到整数)

如何解决《SOAPHTTPS测试获取类强制转换异常(字符串到整数)》经验,为你挑选了1个好方法。

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

令人惊讶的是,我所有的XML值都在String中,但是我得到了一个类强制转换异常,例如“ String to Integer”

客户代码

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

BindingProvider bindingProvider = (BindingProvider) servicePort;
Map 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> headers = new HashMap>();
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 = 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

Brian.. 7

在您的设置超时时,您似乎使用了错误的类型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);

相关源代码在这里找到。



1> Brian..:

在您的设置超时时,您似乎使用了错误的类型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);

相关源代码在这里找到。

推荐阅读
mobiledu2402851173
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有