2013-03-25 63 views
0

我是JAXB的新手。我提供了一個wsdl文件,我使用apache-cxf實用程序wsdl2java獲得許多java類,從中我實現了我的web服務。但是,當我開始對我的服務進行客戶端服務器測試時,出現下列異常:CXF WebService測試期間JAXB中的SAXParseException

мар 25, 2013 12:19:36 PM org.apache.cxf.wsdl.EndpointReferenceUtils createSchema 
WARNING: SAXException for newSchema() 
org.xml.sax.SAXParseException; src-import.1.1: The namespace attribute 'http://www.aaa.com/bbb/ccc/ddd' of an <import> element information item must not be the same as the targetNamespace of the schema it exists in. 
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) 
    at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) 
    at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(Unknown Source) 
    at org.apache.xerces.impl.xs.traversers.XSDHandler.constructTrees(Unknown Source) 
    at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source) 
    at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source) 
    at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source) 
    at org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source) 
    at org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source) 
    at org.apache.cxf.wsdl.EndpointReferenceUtils.createSchema(EndpointReferenceUtils.java:698) 
    at org.apache.cxf.wsdl.EndpointReferenceUtils.getSchema(EndpointReferenceUtils.java:743) 
    at org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor.handleMessage(SoapHeaderInterceptor.java:107) 
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271) 
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:800) 
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1590) 
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1488) 
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1307) 
    at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:50) 
    at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:229) 
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56) 
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:622) 
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62) 
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271) 
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530) 
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463) 
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366) 
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319) 
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96) 
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:133) 

............. 
INFO: Schema for: http://www.globe.com/warcraft/wsdl/amax 
<?xml version="1.0" encoding="utf-8"?><xs:schema xmlns:tns="http://www.aaa.com/bbb/ccc/ddd" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.aaa.com/bbb/ccc/ddd" version="1.0"> 
<xs:import namespace="http://www.aaa.com/bbb/ccc/ddd"/> 
........... 

爲什麼會生成這個中間XML,以至於導入本身?該導入標籤的外觀可以以某種方式取消?我想,原因可能在最初的wsdl,或者它可能是一些錯誤。

在此先感謝

回答

2

的。問題是因爲在我的生成ProxyServiceImpl類,我錯過了wsdlLocation在@WebService註釋:

@javax.jws.WebService(
        serviceName = "ServiceName", 
        portName = "ServicePort", 
        targetNamespace = "http://www.aaa.com/bbb/ccc/ddd", 
        wsdlLocation = "path_to_wsdl", 
        endpointInterface = "ProxyService_class") 

當我將它,一切正常。

1

爲例外建議

org.xml.sax.SAXParseException; SRC-import.1.1:一個元素信息項的命名空間屬性「http://www.aaa.com/bbb/ccc/ddd」一定不能一樣,它存在於架構的targetNamespace

更改目標名稱空間,並嘗試參考this

0

您的回答關於wsdlLocation幫助了我,但由於我還不能評論,我只會添加更多信息。 作爲選項,還可以修改pom.xml並在其中添加wsdlLocation

<wsdlOption> 
    <wsdl>${basedir}/src/main/resources/cxf/webservice.wsdl</wsdl> 
    <wsdlLocation>classpath:cxf/webservice.wsdl</wsdlLocation> 
<wsdlOption>