如何在JAXWS中生成具有相同wsdl的多个端口

时间:2015-03-02 18:41:18

标签: java spring web-services wsdl jax-ws

我有这个WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
        targetNamespace="http://xmlns.oracle.com/bpmn/bpmnProcess/Process2"
        xmlns:tns="http://xmlns.oracle.com/bpmn/bpmnProcess/Process2"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" >
    <wsdl:types>
        <xsd:schema targetNamespace="http://xmlns.oracle.com/bpmn/bpmnProcess/Process2">
            <xsd:element name="startType">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="argument1" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="endResponseType">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="argument1" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="startRequest">
        <wsdl:part name="parameters" element="tns:startType"/>
    </wsdl:message>
    <wsdl:message name="endResponse">
        <wsdl:part name="parameters" element="tns:endResponseType"/>
    </wsdl:message>
    <wsdl:portType name="Process2PortType">
        <wsdl:operation name="start">
            <wsdl:input message="tns:startRequest" name="startRequest"/>
            <!--<wsdl:output message="tns:endResponse"/>-->
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:portType name="Process2PortTypeCallBack">
        <wsdl:operation name="end">
            <wsdl:input message="tns:endResponse"  name="endResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="process2Soap11" type="tns:Process2PortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="start">
            <soap:operation soapAction="startAction"/>
            <wsdl:input name="startRequest">
                <soap:body use="literal"/>
            </wsdl:input>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="process2CallBack" type="tns:Process2PortTypeCallBack">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="end">
            <soap:operation soapAction="end"/>
            <wsdl:input name="endResponse">
                <soap:body use="literal"/>
            </wsdl:input>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="process">
        <wsdl:port name="processSoap" binding="tns:process2Soap11">
            <soap:address location="http://localhost/sample"/>
        </wsdl:port>
        <wsdl:port name="processSoapCallback" binding="tns:process2CallBack">
            <soap:address location="http://localhost/sampleCallback"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

我正在尝试使用带有JAXWS端点和Spring的Apache CXF创建服务实现,我知道如何在Spring上下文文件中使用类似的东西为每个端口创建端点:

<jaxws:endpoint id="personEndpoint1"
                implementor="#process"
                serviceName="hello1"
                endpointName="a"
                address="/process">

    <jaxws:properties>
        <entry key="schema-validation-enabled" value="true"/>
    </jaxws:properties>
</jaxws:endpoint>
<jaxws:endpoint id="personEndpoint2"
                implementor="#processCallback"
                serviceName="hello1"
                endpointName="a"
                address="/process2">

    <jaxws:properties>
        <entry key="schema-validation-enabled" value="true"/>
    </jaxws:properties>
</jaxws:endpoint>

但是,此解决方案使用不同的WSDL URL创建两个端点:

http://localhost:8080/process?wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.springframework.org/schema/beans" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://xmlns.oracle.com/bpmn/bpmnProcess/Process2" name="hello1" targetNamespace="http://www.springframework.org/schema/beans">
    <wsdl:import location="http://localhost:8080/process?wsdl=Process2PortType.wsdl" namespace="http://xmlns.oracle.com/bpmn/bpmnProcess/Process2"/>
    <wsdl:binding name="hello1SoapBinding" type="ns1:Process2PortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="start">
            <soap:operation soapAction="startAction" style="document"/>
            <wsdl:input name="start">
                <soap:body use="literal"/>
            </wsdl:input>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="hello1">
        <wsdl:port binding="tns:hello1SoapBinding" name="a">
            <soap:address location="http://localhost:8080/process"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

http://localhost:8080/process2?wsdl

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.springframework.org/schema/beans" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://xmlns.oracle.com/bpmn/bpmnProcess/Process2" name="hello1" targetNamespace="http://www.springframework.org/schema/beans">
    <wsdl:import location="http://localhost:8080/process2?wsdl=Process2PortTypeCallBack.wsdl" namespace="http://xmlns.oracle.com/bpmn/bpmnProcess/Process2"/>
    <wsdl:binding name="hello1SoapBinding" type="ns1:Process2PortTypeCallBack">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="end">
            <soap:operation soapAction="end" style="document"/>
            <wsdl:input name="end">
                <soap:body use="literal"/>
            </wsdl:input>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="hello1">
        <wsdl:port binding="tns:hello1SoapBinding" name="a">
            <soap:address location="http://localhost:8080/process2"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

这不是我需要的,我需要使用与原始WSDL相同的WSDL地址来使用这两个端口。如何使用JAXWS和Spring配置实现这一目标?

1 个答案:

答案 0 :(得分:0)

这可能会老化但是对于经过的人来说;我有完全相同的情况。只需让服务标签中的端口定义指向同一位置即可。即:

<soap:address location="http://localhost/sample"/>

<soap:address location="http://localhost/sampleCallback"/>

在原始WSDL点的同一位置,它将检索原始WSDL。