How to change address location of JAX-WS webservice

ImranRazaKhan picture ImranRazaKhan · Jul 20, 2012 · Viewed 20.6k times · Source

We have currently exposed JAX-RPC webservice with following URL

http://xx.xx.xx.xx/myservice/MYGatewaySoapHttpPort?wsdl

We migrated webservice to JAX-WS by generating WebService from above WSDL

But new webservice is accessible from following URL

http://xx.xx.xx.xx/myservice/MYGateway?wsdl

How i can make my JAX-WS webservice to be accessible by same URL mentioned first? so that our customer dont have any problem.

Update:

Service Element of WSDL from which i created is as per expectation

<WL5G3N0:service name="MyGateway">
    <WL5G3N0:port binding="WL5G3N2:MyGatewaySoapHttp" name="MyGatewaySoapHttpPort">
      <WL5G3N3:address location="http://xx.xx.xx/myservice/MyGatewaySoapHttpPort"/>
    </WL5G3N0:port>
  </WL5G3N0:service>

But WSDL of JAX-WS is not same and this WSDL is auto generated.

<WL5G3N0:service name="MyGateway">
- <WL5G3N0:port binding="WL5G3N2:MyGatewaySoapHttp" name="MyGatewaySoapHttpPort">
  <WL5G3N3:address location="http://xx.xx.xx/myservice/MyGateway" /> 
  </WL5G3N0:port>
 </WL5G3N0:service

I created webservice with Oracle Eclipse Indigo.

Can i change with any annotaion?

Regards,

Answer

Adriaan Koster picture Adriaan Koster · Jul 20, 2012

This allows setting the endpoint in the client:

MYGateway service = new MYGateway();
MYGatewaySoapServiceHttpPort port = service.getMYGatewaySoapServiceHttpPort();
BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put(
    BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
    "http://xx.xx.xx.xx/myservice/MYGateway");

(thanks to user FoGH for pointing out that the endpoint should indicate the service, not the WSDL)

EDIT: here is some more information about setting up the org.codehaus.mojo.jaxws-maven-plugin:

In your pom.xml:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>MyGateway</id>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <wsdlDirectory>src/main/resources/META-INF/wsdl</wsdlDirectory>
                <wsdlFiles>
                    <wsdlFile>MyGateway.wsdl</wsdlFile>
                </wsdlFiles>
                <wsdlLocation>MyGatewaySystemId</wsdlLocation>
                <!-- Line below to avoid regeneration bug if you have multiple executions -->   
                <staleFile>${project.build.directory}/jaxws/stale/wsdl.MyGateway.done</staleFile>
            </configuration>
        </execution>
    </executions>
</plugin>

In ./src/main/resources/META-INF/jax-ws-catalog.xml:

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
    <system systemId="MyGatewaySystemId" uri="wsdl/MyGateWay.wsdl"/>
</catalog>

Put your WSDL in ./src/main/resources/META-INF/wsdl/MyGateway.wsdl

So the wsdlLocation in the plugin configuration refers to an entry in the jax-ws-catalog.xml file. This file points to the actual WSDL file using a relative directory notation.

The value 'MyGatewaySystemId' ends up in the generated web service code as the location. So you could change this to the actual URL of the WSDL. Note that you would need configure your pom to set the correct URL for the build environment (dev, test, prod) for this to work consistently. A pointer in the right direction for this is to use maven profiles.

Tip: an easy way to download a copy of an online WSDL (and related XSD's) is to create a SoapUI project for it and then go to the 'WSDL content' tab.