Developing Web services on JBoss AS 7
In this tutorial we will show how to deploy a JAX-WS Web service on JBoss AS 7. You will see how you can easily deploy and test a Web service in the new application server release.
In order to use Web services in the new application server release you need the following extension in your configuration file:
<extension module="org.jboss.as.webservices"/>
At the moment this extension (and the webservice subsystem) is included only in the -preview.xml configuration files so for example if you want to start the standalone server and user webservices you need to use the --server-config option. For example:
standalone.bat --server-config=standalone-preview.xml
JBoss AS 7 ships with Apache CXF web services implementation. Apache CXF is an open source services framework. CXF helps you build and develop services using frontend programming APIs, like JAX-WS and JAX-RS. These services can speak a variety of protocols such as SOAP, XML/HTTP, RESTful HTTP, or CORBA and work over a variety of transports such as HTTP, JMS or JBI.
So let's create a simple Web service contained in a Web application:
And this is the corresponding Web service implementation:
As this Web service is implemented as a Servlet, we need registering the Servlet into the web.xml as usual:
Now deploy the Web application and verify from that the Web service has been published. (We have used a Web application named balance.war).
In AS7 you don't have anymore the jbossws Web application but you can use the new Web management at http://localhost:9900/console
In the Web tab you can find the Web services link where you can see the list of the Web services published.
Now writing an Apache CXF client is just a matter of seconds:
{codecitation class="brush: java; gutter: true;"}
package com.sample;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
public class Client {
public static void main(String args[]) throws Exception {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(Math.class);
factory.setAddress("http://localhost:8080/balance");
Math client = (Math) factory.create();
System.out.println("Server said: " + client.sum(3,4));
}
}

