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.
JAX-WS is not supported out of the box. But its very easy to make it run on Tomcat or any other web server for that matter.
I would recommend Netbeans IDE for starters, as its very easy to quickly code and run a webservice.
This is how the implementation looks like. Note that its a POJO with a few annotations.
package com.swayam.webservice;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
/**
*
* @author paawak
*/
@WebService()
public class UserManager {
/**
* Web service operation
*/
@WebMethod(operationName = "addUser")
public boolean addUser(@WebParam(name = "userName")
String userName) {
System.out.println(userName);
return true;
}
}
In addition to this, you also have to edit the WEB-INF/web.xml as follows:
<?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">
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>jax-ws</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jax-ws</servlet-name>
<url-pattern>/UserManager</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>
Also, you have to tell the JAX-WS runtime about the endpoint or the implementation. This is done by having a non-standard file called WEB-INF/sun-jaxws.xml. The entry is:
<?xml version="1.0" encoding="UTF-8"?>
<endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
<endpoint implementation="com.swayam.webservice.UserManager" name="UserManager" url-pattern="/UserManager"/>
</endpoints>
Once this is done, download JAX-WS from here. A small word of warning. Version 2.2 is buggy, so its advisable to use an older one. I used 2.1.7 without any issues. Put all the jars from the lib folder into the WEB-INF/lib folder of your webapp. Now you are ready to go. Deploy it on Tomcat, it should work like breeze.
You will find the sources here. This is a Netbeans project. Also, you can try the war file directly.