在集合中发布wsdl模式名称冲突

时间:2016-07-18 09:34:20

标签: java web-services xsd wsdl apache-servicemix

我在使用jaxws

跨servicemix发布wsdl时遇到问题

我有像wsdl这样的文件:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="CartesSim" targetNamespace="http://monappli.com/cartesSim/cartesSim/V1"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://monappli.com/cartesSim/cartesSim/V1"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:cs="http://monappli.com/cartesSim/datatypes/V1">
<wsdl:types>
    <xsd:schema targetNamespace="http://monappli.com/cartesSim/cartesSim/V1">
        <xsd:import namespace="http://monappli.com/cartesSim/datatypes/V1" schemaLocation="cartesSim.xsd" />

        <xsd:element name="chargerCartesSimInput" type="cs:referentielCartesSim" />
        <xsd:element name="chargerCartesSimOutput" type="cs:rapportImport" />

        <xsd:element name="chargerConsoCartesSimInput" type="cs:consommationCartesSim" />
        <xsd:element name="chargerConsoCartesSimOutput" type="cs:rapportImport" />
    </xsd:schema>
</wsdl:types>

<wsdl:message name="chargerCartesSim">
    <wsdl:part element="tns:chargerCartesSimInput" name="parameters"/>
</wsdl:message>
<wsdl:message name="chargerCartesSimResponse">
    <wsdl:part element="tns:chargerCartesSimOutput" name="parameters"/>
</wsdl:message>
<wsdl:message name="chargerConsoCartesSim">
    <wsdl:part element="tns:chargerConsoCartesSimInput" name="parameters"/>
</wsdl:message>
<wsdl:message name="chargerConsoCartesSimResponse">
    <wsdl:part element="tns:chargerConsoCartesSimOutput" name="parameters"/>
</wsdl:message>
<!-- fault -->
<wsdl:message name="cartesSimFault" >
    <wsdl:part type="xsd:string" name="errorMessage" />
</wsdl:message>

<wsdl:portType name="CartesSim">
    <wsdl:operation name="chargerCartesSim">
        <wsdl:input message="tns:chargerCartesSim"/>
        <wsdl:output message="tns:chargerCartesSimResponse"/>
        <wsdl:fault message="tns:cartesSimFault" name="cartesSimFault"/>
    </wsdl:operation>
    <wsdl:operation name="chargerConsoCartesSim">
        <wsdl:input message="tns:chargerConsoCartesSim"/>
        <wsdl:output message="tns:chargerConsoCartesSimResponse"/>
        <wsdl:fault message="tns:cartesSimFault" name="cartesSimFault"/>
    </wsdl:operation>
</wsdl:portType>

<wsdl:binding name="CartesSimSOAP" type="tns:CartesSim">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="chargerCartesSim">
        <soap:operation soapAction="chargerCartesSim"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
        <wsdl:fault name="cartesSimFault">
            <soap:body use="literal"/>
        </wsdl:fault>
    </wsdl:operation>
    <wsdl:operation name="chargerConsoCartesSim">
        <soap:operation soapAction="chargerConsoCartesSim"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
        <wsdl:fault name="cartesSimFault">
            <soap:body use="literal"/>
        </wsdl:fault>
    </wsdl:operation>
</wsdl:binding>

<wsdl:service name="CartesSim">
    <wsdl:port binding="tns:CartesSimSOAP" name="CartesSimSOAP">
        <soap:address location="http://localhost/CartesSim"/>
    </wsdl:port>
</wsdl:service>

和xsd是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://monappli.com/cartesSim/datatypes/V1" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:complexType name="referentielCartesSim">
    <xsd:sequence>
        <xsd:element name="fichier" type="xsd:base64Binary"/>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="consommationCartesSim">
    <xsd:sequence>
        <xsd:element name="fichier" type="xsd:base64Binary"/>
        <xsd:element name="mois" type="xsd:gYearMonth" />
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="rapportImport">
    <xsd:sequence>
        <xsd:element name="fichier" type="xsd:base64Binary"/>
    </xsd:sequence>
</xsd:complexType>

使用wsdl2java生成工作正常。

但是当我在蓝图中发布端点时:

<jaxws:endpoint implementor="#webServiceCartesSim"
    address="/cartesim">
    <jaxws:dataBinding>
        <bean class="org.apache.cxf.jaxb.JAXBDataBinding"/>
    </jaxws:dataBinding>
</jaxws:endpoint>

我在servicemix中遇到了这个错误:

Caused by: javax.xml.ws.WebServiceException: org.apache.ws.commons.schema.XmlSchemaException: Schema name conflict in collection
    at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:371)
    at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:251)
    at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:539)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.7.0_71]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_71]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_71]
    at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_71]
    at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:297)[18:org.apache.aries.blueprint.core:1.4.3]
    at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:958)[18:org.apache.aries.blueprint.core:1.4.3]
    at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:712)[18:org.apache.aries.blueprint.core:1.4.3]
    ... 39 more
Caused by: org.apache.ws.commons.schema.XmlSchemaException: Schema name conflict in collection
    at org.apache.ws.commons.schema.XmlSchema.<init>(XmlSchema.java:126)
    at org.apache.ws.commons.schema.XmlSchema.<init>(XmlSchema.java:140)
    at org.apache.cxf.common.xmlschema.SchemaCollection.newXmlSchemaInCollection(SchemaCollection.java:194)
    at org.apache.cxf.jaxb.JAXBSchemaInitializer.createBridgeXsElement(JAXBSchemaInitializer.java:355)
    at org.apache.cxf.jaxb.JAXBSchemaInitializer.checkForExistence(JAXBSchemaInitializer.java:333)
    at org.apache.cxf.jaxb.JAXBSchemaInitializer.begin(JAXBSchemaInitializer.java:150)
    at org.apache.cxf.service.ServiceModelVisitor.visitOperation(ServiceModelVisitor.java:120)
    at org.apache.cxf.service.ServiceModelVisitor.walk(ServiceModelVisitor.java:74)
    at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:396)
    at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:467)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:712)
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:527)
    at org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:261)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)
    at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159)
    at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
    at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456)
    at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334)
    ... 48 more

我找不到问题:(

XmlSchema的源代​​码是:

 if (parent != null) {
        XmlSchemaCollection.SchemaKey schemaKey = new XmlSchemaCollection.SchemaKey(this.logicalTargetNamespace, systemId);

        if (parent.containsSchema(schemaKey)) {
            throw new XmlSchemaException("Schema name conflict in collection");
        }
        parent.addSchema(schemaKey, this);
    }

但是apache不能在日志中打印schemaKey,所以我不知道错误在哪里。

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

最终我找到了解决方案:

我声明我的端点就像这样,一切正常!

<jaxws:endpoint implementor="#webServiceCartesSim"
wsdlLocation="classpath:cartesSim.wsdl"
                    address="/cartesSim"
                    xmlns:s="http://monappli.com/cartesSim/cartesSim/V1"
                    serviceName="s:CartesSim"
                    >
    <jaxws:dataBinding>
        <bean class="org.apache.cxf.jaxb.JAXBDataBinding"/>
    </jaxws:dataBinding>
</jaxws:endpoint>