jens
jens

Reputation: 1862

JAX-WS - how to configure complete URL

I have a Java class that has a @WebService annotation and is packaged in a WAR. When deploying the WAR to different JavaEE 6 application servers I want to have the same URL (of course with different hosts and ports...).

The default naming seems to be appserver-dependent. Some examples:

Glassfish:

http://{hostname or ip}:{port}/{service name}/{port name}

JBoss:

http://{hostname or ip}:{port}/{ejb-jar-name}/{service name}/{port name}

WebSphere:

http://{hostname or ip}:{port}/{ejb-jar-name}/{service name}

What is the easiest way for configuring this for all server vendors?

Upvotes: 2

Views: 2557

Answers (1)

Rafael Guillen
Rafael Guillen

Reputation: 1673

If you are creating a web service based in a POJO class, then you only need to pack your war file inside an ear file and define the context root of the web module in the application.xml configuration file. Here is an application.xml file example:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
  <display-name>simple-ws-app</display-name>
  <module>
    <web>
      <web-uri>simple-ws-war.war</web-uri>
      <context-root>/simple-ws-app</context-root>
    </web>
  </module>
  <library-directory>lib</library-directory>
</application>

In the annotation @WebService you can configure the expected web service configuration, if you have a wsdl file then is easier to define the web service. Here is an example of the complete @WebService annotation configuration, use only the properties you need.

@WebService(name = "SimpleService",
        serviceName = "SimpleService",
        portName = "SimpleServicePort",
        endpointInterface = "simple.ws.srv.SimpleServicePortType",
        targetNamespace = "http://www.ws.simple/srv",
        wsdlLocation = "WEB-INF/wsdl/simple-ws.wsdl"
)

Note that if you are using a wsdl file the default location to place it is inside WEB-INF/wsdl.

Now, the expected wsdl URL for this configuration is

http://hostname:port/simple-ws-app/SimpleService?wsdl

This may not work fot all app-servers, I know it works for Glassfish, WildFly and Weblogic.

Finally, the default naming for enterprise web services (for example EJB WebServices, ejb-jar inside ear file) is in deed appserver-dependent. I've been googling and trying to accomplish this configuration for several months with the same result. No matters if you provide a complete @WebService annotation configuration including a valid wsdl with the expected endpoint configuration, app-servers override the wsdl endpoint URL.

Upvotes: 3

Related Questions