0

我是 JAXB 的新手。为我提供了一个 wsdl 文件,我使用apache-cxf实用程序wsdl2java获得了一些 java 类,我从中实现了我的 web 服务。但是当我在我的服务上开始客户端服务器测试时,我得到以下异常:

мар 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,或者可能是一些错误。

提前致谢

4

3 回答 3

2

问题是因为在我生成的 ProxyServiceImpl 类中,我在 @WebService 注释中缺少一个wsdlLocation :

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

当我添加它时,一切正常。

于 2013-06-04T08:45:03.163 回答
1

正如例外所暗示的

org.xml.sax.SAXParseException;src-import.1.1:元素信息项的命名空间属性“ http://www.aaa.com/bbb/ccc/ddd ”不得与其所在架构的targetNamespace相同。

更改目标名称空间并尝试参考这个

于 2013-03-25T13:38:11.013 回答
0

您对 wsdlLocation 的回答对我有所帮助,但由于我还不能发表评论,所以我只会添加更多信息。作为一个选项,也可以修改 pom.xml 并在那里添加 wsdlLocation

<wsdlOption>
    <wsdl>${basedir}/src/main/resources/cxf/webservice.wsdl</wsdl>
    <wsdlLocation>classpath:cxf/webservice.wsdl</wsdlLocation>
<wsdlOption>
于 2014-12-17T14:20:27.240 回答