Technical blog

May 8, 2010

JAX-WS with JBoss

Filed under: java — Tags: , , , — paawak @ 18:39

JBoss supports JAX-WS out of the box. There is not much configuration files needed, only a servlet-mapping in the web.xml. This is how the web-service java file looks like:

 
package com.swayam.demo.webservice;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
 
/**
 *
 * @author paawak
 */
@WebService()
public class UserService {
 
    /**
     * Web service operation
     */
    @WebMethod(operationName = "addUser")
    public Boolean addUser(@WebParam(name = "userName")
    String userName) {
 
        System.out.println("add user");
 
        return Boolean.TRUE;
 
    }
 
}

Its a POJO with a @WebService annotation. All you have to do is map this as a servlet in the desired context. Though this is not a servlet per-se, the JBoss web container does the rest. This is how the web.xml looks like:

 
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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/web-app_2_5.xsd">
    <servlet>
        <servlet-name>UserService</servlet-name>
        <servlet-class>com.swayam.demo.webservice.UserService</servlet-class>
        <load-on-startup>1</load-on-startup>
        </servlet>
    <servlet-mapping>
        <servlet-name>UserService</servlet-name>
        <url-pattern>/UserService</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

After deploying, you can access the webservice by http://localhost:8080/JBossWebServiceTest/UserService?wsdl.

You can find the sources here and the war here.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress