2010-12-20 222 views
6

我想從java客戶端使用Apache CXF調用Web服務。以下是我的客戶端代碼片段。CXF Web服務客戶端錯誤

Client client = new ClientImpl(new URL("http://localhost:8080/socialkast-web/services/skservice?wsdl")); 
Object[] results = client.invoke("uploadVideoMetaData", new Object[] {metaData}); 
    String result = (String)results[0]; 

雖然我能夠從瀏覽器訪問wsdl文件,但我得到解析錯誤。以下是異常堆棧。

INFO: Pre-instantiating singletons in org.s[email protected]14f5a31: defining beans [cxf,org.apache.cxf.bus.spring.BusApplicationListener,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.binding.corba.CorbaBindingFactory,org.apache.cxf.binding.corba.wsdl.WSDLExtensionRegister#0,org.apache.cxf.jaxws.context.WebServiceContextResourceResolver,org.apache.cxf.jaxws.context.WebServiceContextImpl,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.binding.xml.XMLBindingFactory,org.apache.cxf.ws.addressing.policy.AddressingAssertionBuilder,org.apache.cxf.ws.addressing.policy.AddressingPolicyInterceptorProvider,org.apache.cxf.ws.addressing.policy.UsingAddressingAssertionBuilder,org.apache.cxf.javascript.JavascriptQueryHandlerRegistry,org.apache.cxf.transport.local.LocalTransportFactory,org.apache.cxf.transport.http.policy.HTTPClientAssertionBuilder,org.apache.cxf.transport.http.policy.HTTPServerAssertionBuilder,org.apache.cxf.transport.http.policy.NoOpPolicyInterceptorProvider,org.apache.cxf.transport.http.ClientOnlyHTTPTransportFactory,org.apache.cxf.management.InstrumentationManager,org.apache.cxf.transport.http_jetty.JettyHTTPTransportFactory,org.apache.cxf.transport.jms.JMSTransportFactory,org.apache.cxf.binding.object.ObjectBindingFactory,org.apache.cxf.binding.http.HttpBindingFactory,org.apache.cxf.ws.security.policy.WSSecurityPolicyLoader,org.apache.cxf.ws.policy.AssertionBuilderRegistry,org.apache.cxf.ws.policy.PolicyInterceptorProviderRegistry,org.apache.cxf.ws.policy.attachment.external.DomainExpressionBuilderRegistry,org.apache.cxf.ws.policy.attachment.external.EndpointReferenceDomainExpressionBuilder,org.apache.cxf.ws.policy.PolicyBuilder,org.apache.cxf.ws.policy.PolicyEngine,org.apache.cxf.ws.policy.attachment.wsdl11.Wsdl11AttachmentPolicyProvider,org.apache.cxf.ws.policy.attachment.ServiceModelPolicyProvider,org.apache.cxf.ws.policy.mtom.MTOMAssertionBuilder,org.apache.cxf.ws.policy.mtom.MTOMPolicyInterceptorProvider,org.apache.cxf.ws.rm.RMManager,org.apache.cxf.ws.rm.policy.RMPolicyInterceptorProvider,org.apache.cxf.ws.rm.RMAssertionBuilder,org.apache.cxf.binding.corba.wsdl.WSDLExtensionRegister#1]; root of factory hierarchy 
org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service. 
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:69) 
at org.apache.cxf.endpoint.ClientImpl.<init>(ClientImpl.java:152) 
at org.apache.cxf.endpoint.ClientImpl.<init>(ClientImpl.java:121) 
at tv.socialkast.client.ws.WSClient.<init>(WSClient.java:42) 
at tv.socialkast.upload.client.gui.UploadDirectoryChooser$DoneActionListener.actionPerformed(UploadDirectoryChooser.java:382) 
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.setPressed(Unknown Source) 
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) 
at java.awt.Component.processMouseEvent(Unknown Source) 
at javax.swing.JComponent.processMouseEvent(Unknown Source) 
at java.awt.Component.processEvent(Unknown Source) 
at java.awt.Container.processEvent(Unknown Source) 
at java.awt.Component.dispatchEventImpl(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Window.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.EventQueue.dispatchEvent(Unknown Source) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.run(Unknown Source) 
**Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'http://localhost:8080/socialkast-web/services/skservice?wsdl'.: java.net.ConnectException: Connection refused: connect** 
at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source) 
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source) 
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source) 
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:232) 
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:161) 
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:67) 
... 29 more 

請指教我在這裏錯過了什麼。

謝謝。

回答

0

夠簡單:您的服務器沒有響應。

Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'http://localhost:8080/socialkast-web/services/skservice?wsdl'.: java.net.ConnectException: Connection refused: connect at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source 
+0

請注意,當我從瀏覽器訪問相同的wsdl網址(http:// localhost:8080/socialkast-web/services/skservice?wsdl)時,我得到瀏覽器中顯示的正確wsdl文件。 – Alex 2010-12-23 18:24:41

+0

你可能忽略了將HTTP傳輸放在類路徑中嗎?我建議在cxf.apache.org上發佈帶有測試用例的JIRA,在那裏幫助你會更容易。 – bmargulies 2010-12-23 22:25:13

+0

確定我會發佈一個jira。您能否詳細說明如何將HTTP傳輸放入類路徑中? – Alex 2010-12-24 05:31:14

1

這可能是一件非常明顯的事情,但是您是否嘗試過使用瀏覽器提供的服務?例如,嘗試通過指向你的網頁瀏覽器獲得WSDL:

http://localhost:8080/socialkast-web/services/skservice?wsdl 

如果你不能到那裏,也許您的服務器沒有運行。