2014-01-28 55 views
1

我正在使用Maven,Java 1.6,Apache CXF。我在某些類的Apache CXF中調用Soap API時遇到了一些類轉換異常。這是堆棧跟蹤。使用Apache CXF調用SOAP API時的ClassCastException

 
javax.xml.ws.soap.SOAPFaultException: java.net.URL cannot be cast to java.lang.String 
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:157) 
    at com.sun.proxy.$Proxy83.importCapturedData(Unknown Source) 
    at com.flipkart.dynamics.api.DynamicsClientService.handleDataLoadRequest(DynamicsClientService.java:109) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) 
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) 
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) 
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) 
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) 
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) 
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) 
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1480) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1411) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1360) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1350) 
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) 
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538) 
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at com.flipkart.recon.api.filter.ContentTypeFilter.doFilter(ContentTypeFilter.java:73) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) 
    at java.lang.Thread.run(Thread.java:695) 
Caused by: java.lang.ClassCastException: java.net.URL cannot be cast to java.lang.String 
    at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:99) 
    at org.apache.cxf.endpoint.UpfrontConduitSelector.prepare(UpfrontConduitSelector.java:63) 
    at org.apache.cxf.endpoint.ClientImpl.prepareConduitSelector(ClientImpl.java:886) 
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:560) 
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:474) 
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:377) 
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:330) 
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) 
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135) 
    ... 41 more 
[2014-01-28 16:07:44.572] ERROR [http-bio-8082-exec-2][ContentTypeFilter][ContentTypeFilter.java:93] Unhandled Exception. 
javax.xml.ws.soap.SOAPFaultException: java.net.URL cannot be cast to java.lang.String 
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:157) ~[cxf-2.7.8.jar:2.7.8] 
    at com.sun.proxy.$Proxy83.importCapturedData(Unknown Source) ~[na:na] 
    at com.flipkart.dynamics.api.DynamicsClientService.handleDataLoadRequest(DynamicsClientService.java:109) ~[DynamicsClientService.class:na] 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_65] 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_65] 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_65] 
    at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_65] 
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1480) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1411) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1360) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1350) ~[jersey-server-1.14.jar:1.14] 
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) ~[jersey-servlet-1.14.jar:1.14] 
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538) ~[jersey-servlet-1.14.jar:1.14] 
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716) ~[jersey-servlet-1.14.jar:1.14] 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) ~[servlet-api.jar:na] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) [catalina.jar:7.0.47] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.47] 
    at com.flipkart.recon.api.filter.ContentTypeFilter.doFilter(ContentTypeFilter.java:73) ~[ContentTypeFilter.class:na] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) [catalina.jar:7.0.47] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) [catalina.jar:7.0.47] 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) [catalina.jar:7.0.47] 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) [catalina.jar:7.0.47] 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [catalina.jar:7.0.47] 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) [catalina.jar:7.0.47] 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) [catalina.jar:7.0.47] 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) [catalina.jar:7.0.47] 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) [catalina.jar:7.0.47] 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) [catalina.jar:7.0.47] 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) [tomcat-coyote.jar:7.0.47] 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) [tomcat-coyote.jar:7.0.47] 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) [tomcat-coyote.jar:7.0.47] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [na:1.6.0_65] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [na:1.6.0_65] 
    at java.lang.Thread.run(Thread.java:695) [na:1.6.0_65] 
Caused by: java.lang.ClassCastException: java.net.URL cannot be cast to java.lang.String 
    at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:99) ~[cxf-2.7.8.jar:2.7.8] 
    at org.apache.cxf.endpoint.UpfrontConduitSelector.prepare(UpfrontConduitSelector.java:63) ~[cxf-2.7.8.jar:2.7.8] 
    at org.apache.cxf.endpoint.ClientImpl.prepareConduitSelector(ClientImpl.java:886) ~[cxf-2.7.8.jar:2.7.8] 
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:560) ~[cxf-2.7.8.jar:2.7.8] 
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:474) ~[cxf-2.7.8.jar:2.7.8] 
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:377) ~[cxf-2.7.8.jar:2.7.8] 
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:330) ~[cxf-2.7.8.jar:2.7.8] 
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) ~[cxf-2.7.8.jar:2.7.8] 
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135) ~[cxf-2.7.8.jar:2.7.8] 
    ... 41 common frames omitted 

這裏是我使用的代碼:

try 
    { 
     wsdlURL = 
       new URL("some http url with requiring basic authentication"); 
    } 
    catch (MalformedURLException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    System.out.println(wsdlURL); 

    OPSRequestManagement opsRequestManagement = new OPSRequestManagement(wsdlURL, SERVICE_NAME); 
    OPSRequestManagementPort opsRequestManagementPort = opsRequestManagement.getOPSRequestManagementPort(); 

    Map<String, Object> req_ctx = ((BindingProvider) opsRequestManagementPort).getRequestContext(); 
    req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlURL); 

    Map<String, List<String>> headers = new HashMap<String, List<String>>(); 
    headers.put("Username", Collections.singletonList("domain\\username")); 
    headers.put("Password", Collections.singletonList("password")); 
    req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers); 

    boolean resp; 

    List<CapturedData> capturedDataList = dynamicsDao.getCapturedData(startDate.getTime(), endDate.getTime()); 
    FKPG fkpg = new FKPG(); 
    fkpg.getContent().addAll(capturedDataList); 
    resp = opsRequestManagementPort.importCapturedData(fkpg); 
+0

請,你能不能帶我們去的行號拋出異常? –

回答

3

@sadhu的答案指出我在正確的方向爲我自己的問題,但它對我來說太神祕了。

把這個片斷:

wsdlURL = new URL("some http url with requiring basic authentication"); 

這就告訴我們WSDLURL是java.net.URL類型。下一步,我們發現這樣的:

Map<String, Object> req_ctx = ((BindingProvider) opsRequestManagementPort).getRequestContext(); 
req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlURL); 

要解決此問題,更改最後一行:

req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlURL.toExternalForm()); 

的一點是,你應該把一個String對象的映射,而不是URL實例。


爲了避免將來發生這種情況,請務必檢查Javadoc。這就是關於ENDPOINT_ADDRESS_PROPERTY的說法:(強調我的)

標準屬性:目標服務端點地址。端點地址規範的URI方案必須與使用中綁定的協議/傳輸綁定相對應。

類型:java.lang.String中

0

我敢肯定,WSDLURL的類型爲字符串,它不應該。反而

URL wsdlURL 
相關問題