Java – Change schemaLocation and soap:address location in runtime generated WSDL with JAX-WS

javajax-wsweb serviceswsdl

Is it possible to configure the location (schemaLocation and soap:address location) in a JAX-WS WSDL?
When I deploy the sample below, 'servername' would be localhost and 'serverport' would be the local port number for the web application.

However, I want to reconfigure these to be a proxy servername and serverport which redirects to the service. Is this possible and how would I achieve it?

The deployment environment is Tomcat and Apache.

I have the following service class:

@WebService
public class AuthenticationService {
....
public AuthenticationService(){}

@WebMethod
    public AuthenticationResult checkAuthentication(
        @WebParam(name = "authentication") Authentication authentication,
        @WebParam(name = "privilege") Privilege privilege) {
    ....
}
}

When ran, the WSDL looks like this:

<definitions targetNamespace="http://authentication.service.ws.ijs/" name="AuthenticationServiceService">
<types>

    <xsd:schema>
        <xsd:import namespace="http://authentication.service.ws.ijs/" schemaLocation="http://servername:serverport/WebAppName/AuthenticationService?xsd=1"/>
    </xsd:schema>
</types>

<message name="checkAuthentication">
    <part name="parameters" element="tns:checkAuthentication"/>
</message>

<message name="checkAuthenticationResponse">
    <part name="parameters" element="tns:checkAuthenticationResponse"/>
</message>

<portType name="AuthenticationService">

    <operation name="checkAuthentication">
        <input wsam:Action="http://authentication.service.ws.ijs/AuthenticationService/checkAuthenticationRequest" message="tns:checkAuthentication"/>
        <output wsam:Action="http://authentication.service.ws.ijs/AuthenticationService/checkAuthenticationResponse" message="tns:checkAuthenticationResponse"/>
    </operation>

</portType>

<binding name="AuthenticationServicePortBinding" type="tns:AuthenticationService">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>

    <operation name="checkAuthentication">
        <soap:operation soapAction=""/>

        <input>
            <soap:body use="literal"/>
        </input>

        <output>
            <soap:body use="literal"/>
        </output>
    </operation>

</binding>

<service name="AuthenticationServiceService">

    <port name="AuthenticationServicePort" binding="tns:AuthenticationServicePortBinding">
        <soap:address location="http://servername:serverport/WebAppName/AuthenticationService"/>
    </port>
</service>
</definitions>

Any help would be greatly appreciated.

Best Answer

If you keep the original hostname in your request (e.g use ProxyPreserveHost On if you use mod_proxy) this should fix your URLs, if you use the same protocol. You may still have problems if your proxy switches between https and http.

Related Topic