Version 4

    JAX-WS APIs support for creating a jaxws service endpint starting from an annotated POJO class. POJO classes in a legacy system or in the current application can be annotated with web service annotations to be published as a jaxws webservice endpoint. JBossWS implementation can take care of generating the WSDL contract as well as publishing the service endpoint from the annotated class containing all required service information.

     

    Annotate POJO class

    JSR 181 API provides @Webservice annotation to mark a java class as implementing a Web Service. This annotation is required for JBossWS implementation to get all the required information, including service name, targetNamespace, portType name, etc. Let's take a look at a simple POJO endpoint implementation with web service annotation:

    @WebService
    @SOAPBinding(style = SOAPBinding.Style.RPC)
    public class JSEBean01
    {   
        @WebMethod
        public String echo(String input)
        {
        ...   
        }
    }
    

     

    In this example, there are two annotations, @SOAPBinding and @WebMethod to define the soap binding style and mark echo method that is exposed as a web service operation. If you want to customize the other details for the deployed webservice, please check the JSR 181 spec[1] and/or the rest of this documentation.

     

    Write the web service deployment descriptor

    The annotated POJO endpoint class is configured a servlet in the web.xml. JBossWS implementation will look for the class, detect it's a WS endpoint implementation instead of an actual servlet and start this web service endpoint automatically.              

    <web-app ...> 
     <servlet> 
      <servlet-name>TestService</servlet-name> 
      <servlet-class>org.jboss.test.ws.jaxws.samples.jsr181pojo.JSEBean01</servlet-class> 
     </servlet> 
     <servlet-mapping>
      <servlet-name>TestService</servlet-name> 
      <url-pattern>/*</url-pattern> 
     </servlet-mapping>
    </web-app>
    

     

    Build and package the web application archive

    Finally, it's required to compile and package the pojo class and descriptor in a war file with ant task or maven plugin. Here is an ant task example to package all the things into a war file.

    <war warfile="${output.dir}/ws-from-pojo.war" webxml="${tests.dir}/resources/web.xml">
      <classes dir="${tests.dir}/test-classes">
        <include name="org/jboss/test/ws/jaxws/samples/jsr181pojo/JSEBean01.class"/>
      </classes>
    </war>
    

     

    After finishing all these steps, deploy this war file into JBoss. Write a simple webservice client or simply access http://localhost:8080/ws-from-pojo?wsdl to check if the endpoint is published and created properly.