Installing Apache CXF on JBoss AS
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: http://www.jboss.org/jbossws/downloads
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 ant.properties starting from the ant.properties.example
copy ant.properties.example ant.properties
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:
jboss702.home=C:\jboss-as-7.0.2.Final
jbossws.integration.target=jboss702
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:
standalone.bat
Ok. So If everything was successfully installed, you should see the following message when booting the server:
19:12:12,977 INFO [org.jboss.ws.common.management.AbstractServerConfig] (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:
And this is the Service Interface:
You will need to declare this Web service as Servlet in web.xml:
This Web service uses a native Apache CXF functionality called Interceptor.
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:
ExampleWS.war
├───META-INF
│ MANIFEST.MF (With Dependencies in it)
│
└───WEB-INF
│ web.xml
│
├───classes
│ │
│ └───com
│ └───sample
│ └───ws
│ SampleWS.class
│ SampleWSImpl.class
└───lib
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:
If everything was correctly configured, the application will contact the server, returning a message and logging the in/out SOAP messages on the server:
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="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:hello xmlns:ns2="http://ws.sample.com/"><arg0>Frank</arg0></ns2:hello></soap:Body></soap:Envelope>
--------------------------------------
19:24:40,510 INFO [org.apache.cxf.interceptor.LoggingOutInterceptor] (http-127.0.0.1-127.0.0.1-8080-2) Outbound Message
---------------------------
ID: 2
Encoding: UTF-8
Content-Type: text/xml
Headers: {}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><
soap:Body><ns2:helloResponse xmlns:ns2="http://ws.sample.com/"><return>Hello Frank</return></ns2:helloResponse></soap:Body></soap:Envelope>
--------------------------------------
19:24:40,519 INFO [stdout] (http-127.0.0.1-127.0.0.1-8080-1) Hello Frank
In the next tutorial we will have a closer look at the Interceptors functionalities of Apache CXF to achieve some advanced functionalities like Authentication.

