John
John

Reputation: 41

Java Web Services - Defining Server Location

I have one final hurdle to get over with the web services application I am working with; I need to be able to override the default settings used to set the schema location and soap address location in the generated WSDL file.

When I deploy the application (GlassFish v2.1 on Red Hat linux) it uses the local server name in the URLs but it needs to use the public domain name instead. I was able to save the WSDL file locally, change the URLs, make it public, generate a test application externally from the file, and lastly was able to successfully run a test.

I have now journeyed into the realm of JAX-WS custom bindings but I'm hoping that I either overlooked a simpler solution or the bindings are not as complicated as they look at first glance. The web service implementation is through a stateless EJB (e.g. MyWS.java below). The generated WSDL file would look like MyWSDL.wsdl (see below).

In the xsd:import tag I need to change schemaLocation to

    http://test.mycompany.com/MyWSService/MyWS?xsd=1 

instead of

    http://local-server-name/MyWSService/MyWS?xsd=1 

and in the soap:address tag I need to change location to be

    http://test.mycompany.com/MyWSService/MyWS 

instead of

    http://local-server-name/MyWSService/MyWS.

MyWS.java

@WebService(name="MyWS",
        portName="MyWSPort",
        serviceName="MyWSService",
        targetNamespace="http://test.mycompany.com/")
@Stateless()
public class MyWS {

    @WebMethod(operationName="testLogin")
    public String testLogin(@WebParam(name="username") String username,
            @WebParam(name="password") String password) {
        String retVal = "Test Failed.";

        //do some stuff

        return retVal;
    }

    ...
}

MyWSDL.wsdl

<definitions targetNamespace="http://test.mycompany.com/" name="MyWSService">

  <types>
    <xsd:schema>
      <xsd:import namespace="http://test.mycompany.com/" schemaLocation="http://local-server-name/MyWSService/MyWS?xsd=1"/>
    </xsd:schema>
  </types>

  <service name="MyWSService">
    <port name="MyWSPort" binding="tns:MyWSPortBinding">
      <soap:address location="http://local-server-name/MyWSService/MyWS"/>
    </port>
  </service>
</definitions>

Upvotes: 2

Views: 1950

Answers (2)

John
John

Reputation: 41

I was able to resolve the issue by changing the configuration of the GlassFish HTTP Service. I set the server's alias name to test.mycompany.com:80 for the HTTP listener being used for the web services application. Typically we have this kind of configuration in our web servers so initially I didn't even consider the application server configuration.

Upvotes: 2

Pace
Pace

Reputation: 43867

How are you generating the WSDL? Are you generating it by hand? Are you generating it using wsgen with the -wsdl option?

If you're deploying with JAX-WS you shouldn't actually have to do either of those things. Instead you should be able to go to...

<SERVER_URL>/<CONTEXT_LOCATION>/<SERVLET_URL>?wsdl

...and the JAX-WS servlet will automatically generate a wsdl on the fly with the correct location.

Upvotes: 0

Related Questions