Advertise with us

Search Mastertheboss

Our eBooks

Installing Apache CXF on JBoss AS

webservices apache cxf tutorial jbossIn this tutorial we will show how you can easily to install Apache-CXF on the new JBoss AS 7 application server.

Why Do we need to installing Apache CXF on JBoss AS ? JBoss AS 6/7 by default ships with Apache CXF's JAX-WS implementation,
so if you need to develop regular JAX-WS Web services you have already all you need. However if you need specific Apache CXF functionalities
you need to install them on the application server.

So Let's see how to install Apache CXF on your JBoss AS.

Apache CXF downloads are available at:
At the time of writing the latest release is jbossws-cxf-4.0.0.CR1

Unpack the distribution and, at the root of it create a new file starting from the


Now customize this file for your server release, for example, if you are going to installa Apache CXF on JBoss AS 7
you have to customize these rows:


Now issue the following ant task:

ant -Dspring=true deploy-jboss702

This will install both Apache CXF libraries and Spring support as modules in JBoss AS 7.

Now restart JBoss AS.
If you are using JBoss AS 7.0.0 - 7.0.2 then you need to use the standalone-preview.xml configuration:
standalone.bat --server-config=standalone-preview.xml
If you are using JBoss AS 7.1.0, then the Web service domain is available as the default configuration:

Ok. So If everything was successfully installed, you should see the following message when booting the server:

19:12:12,977 INFO  [] (MSC service thread 1-2) JBoss Web Services - Stack CXF Server 4.0.0.CR1

Now let's test a sample Web service which uses native Apache CXF functionalities. Create a new Web project from your favourite IDE:


import javax.jws.WebService;
import org.apache.cxf.interceptor.*;

@WebService(endpointInterface = "", serviceName = "SampleWS")
@InInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingInInterceptor")
@OutInterceptors(interceptors = "org.apache.cxf.interceptor.LoggingOutInterceptor")

public class SampleWSImpl implements SampleWS {
 public String hello(String s) {
 return "Hello "+s;

And this is the Service Interface:


import javax.jws.WebMethod;
import javax.jws.WebService;


public interface SampleWS {
 public String hello(String s);

You will need to declare this Web service as Servlet in web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app  xmlns:xsi=""  xmlns=""  xmlns:web=""  xsi:schemaLocation="" id="WebApp_ID"  version="3.0">


This Web service uses a native Apache CXF functionality called Interceptor.
Interceptors are the fundamental processing unit inside CXF. When a service is invoked, an InterceptorChain is created and invoked. Each interceptor gets a chance to do what they want with the message. This can include reading it, transforming it, processing headers, validating the message, etc.
This kind of Interceptor will print the SOAP envelope which is received by the server and the one which is returned to the client.

Last thing we need to add are Spring and JAX-WS libraries. Since we have just installed them on the application server, all you need is adding a Dependency to these modules into the META-INF/MANIFEST.MF file:

Manifest-Version: 1.0
Dependencies: org.apache.cxf org.springframework.spring

Now your application is completed and when packaged, it should look like this:

?         MANIFEST.MF (With Dependencies in it)
?   web.xml
?        ?
?        ????com
?                ????sample
?                       ????ws
?                                   SampleWS.class
?                                   SampleWSImpl.class

Deploy your application and verify from the logs that it was correctly deployed.

Now let’s build a regular JAX-WS client for our Web service:


import java.util.Map;

import javax.xml.namespace.QName;

public class TestWS {

public static void main(String[] args) throws Exception {
   URL wsdlURL = new URL("http://localhost:8080/ExampleWS/ws?wsdl");  
   QName SERVICE_NAME = new QName("", "SampleWS");
   Service service = Service.create(wsdlURL, SERVICE_NAME);
   SampleWS client = service.getPort(SampleWS.class);
   String s = client.hello("Frank");


If everything was correctly configured, the application will contact the server, returning a message and logging the in/out SOAP messages on the server:

{xtypo_code}ID: 1
Address: http://localhost:8080/ExampleWS/ws
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml; charset=UTF-8
Headers: {Accept=[*/*], Authorization=[], cache-control=[n
o-cache], connection=[keep-alive], Content-Length=[184], content-type=[text/xml;
charset=UTF-8], host=[localhost:8080], pragma=[no-cache], SOAPAction=[""], user
-agent=[Apache CXF 2.4.4]}
Payload: <soap:Envelope xmlns:soap=""><soap:Body><ns2:hello xmlns:ns2=""><arg0>Frank</arg0></ns2:hello></soap:Body></soap:Envelope>
19:24:40,510 INFO  [org.apache.cxf.interceptor.LoggingOutInterceptor] (http- Outbound Message
ID: 2
Encoding: UTF-8
Content-Type: text/xml
Headers: {}
Payload: <soap:Envelope xmlns:soap=""><
soap:Body><ns2:helloResponse xmlns:ns2=""><return>Hello Frank</return></ns2:helloResponse></soap:Body></soap:Envelope>
19:24:40,519 INFO  [stdout] (http- Hello Frank{/xtypo_code}

In the next tutorial we will have a closer look at the Interceptors functionalities of Apache CXF to achieve some advanced functionalities like Authentication.


© 2020 All Rights Reserved.

Please publish modules in offcanvas position.