简体   繁体   中英

JAX-WS: multiple “xsd:schema” under “wsdl:types”, why?

I'm trying to write test web-service application with separated Ednpoint-s like so:

package test;

import ...

public class Main {

    HttpsServer server;
    HashMap<String, Endpoint> endpointMap;

    public Main() {
        try {
            SSLContext ssl = ...
            this.server = HttpsServer.create(
                    new InetSocketAddress("localhost", 8089),
                    8089);
            this.endpointMap = new HashMap();
            endpointMap.put("/test11", Endpoint.create(new SOAPService1()));
            endpointMap.put("/test22", Endpoint.create(new SOAPService2()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void start() {
        server.start();
        for (String uri : endpointMap.keySet()) {
            endpointMap.get(uri).publish(
                    server.createContext(uri));
        }
    }

    public static void main(String[] args) throws Exception {
        new Main().start();
    }
}

As a result I get a wsdl available at

https://localhost:8089/test11?wsdl

with multiple xsd:schema under types :

<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://test1.service.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://test1.service.com" name="TEST1Service">
    <types>
        <xsd:schema>
            <xsd:import namespace="http://test2.service.com" schemaLocation="https://localhost:8089/test11?xsd=1"/>
        </xsd:schema>
        <xsd:schema>
            <xsd:import namespace="http://test1.service.com" schemaLocation="https://localhost:8089/test11?xsd=2"/>
        </xsd:schema>
    </types>
    <message name="test">
        <part name="parameters" element="tns:test"/>
    </message>
    <message name="testResponse">
        <part name="parameters" element="tns:testResponse"/>
    </message>
    <portType name="SOAPService1">
        <operation name="test">
            <input wsam:Action="http://test1.service.com/SOAPService1/testRequest" message="tns:test"/>
            <output wsam:Action="http://test1.service.com/SOAPService1/testResponse" message="tns:testResponse"/>
        </operation>
    </portType>
    <binding name="TEST1PortBinding" type="tns:SOAPService1">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <operation name="test">
            <soap:operation soapAction=""/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <service name="TEST1Service">
        <port name="TEST1Port" binding="tns:TEST1PortBinding">
            <soap:address location="https://localhost:8089/test11"/>
        </port>
    </service>
</definitions>

And the WSDL available at the second url

https://localhost:8089/test22?wsdl

does not:

<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://test2.service.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://test2.service.com" name="TEST2Service">
    <types>
        <xsd:schema>
            <xsd:import namespace="http://test2.service.com" schemaLocation="https://localhost:8089/test22?xsd=1"/>
        </xsd:schema>
    </types>
    <message name="test">
        <part name="parameters" element="tns:test"/>
    </message>
    <message name="testResponse">
        <part name="parameters" element="tns:testResponse"/>
    </message>
    <portType name="SOAPServiceInterface2">
        <operation name="test">
            <input wsam:Action="http://test2.service.com/SOAPServiceInterface2/testRequest" message="tns:test"/>
            <output wsam:Action="http://test2.service.com/SOAPServiceInterface2/testResponse" message="tns:testResponse"/>
        </operation>
    </portType>
    <binding name="TEST2PortBinding" type="tns:SOAPServiceInterface2">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <operation name="test">
            <soap:operation soapAction=""/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <service name="TEST2Service">
        <port name="TEST2Port" binding="tns:TEST2PortBinding">
            <soap:address location="https://localhost:8089/test22"/>
        </port>
    </service>
</definitions>

I want them to be completely separate without knowing about each other, but as you can see the first one even includes the schema of second one. What I'm doing wrong?

I will answer my own question. By annotating the service class with

@SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.BARE)

it removes extra XSD and solves the problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM