我正在通过HTTPS使用独立的应用程序测试SOAP请求。我有从WSDL创建的必需类(使用wsimport),我已经使用一些模拟值填充了对象值。
令人惊讶的是,我所有的XML值都在String中,但是我得到了一个类强制转换异常,例如“ String to Integer”
客户代码
EWOProviderWSEWOWsdl ewoProvider = new EWOProviderWSEWOWsdl(); EWOWsdlPortType servicePort = ewoProvider.getEWOProviderWSEWOWsdlPort(); BindingProvider bindingProvider = (BindingProvider) servicePort; MaprequestContext = 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);
相关源代码在这里找到。
在您的设置超时时,您似乎使用了错误的类型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);
相关源代码在这里找到。