POX (Plain Old XML) JAX-WS service using CXF and Spring Configuration

The new and upcoming Apache CXF framework is quickly gaining steam and rightfully so. It’s very intuitive, simple to use and functional. Some of it comes from the fact the its roots are in popular XFire and Celtix frameworks. It’s still in the incubation stage at Apache but the current releases are pretty stable. The documentation is not complete right now, but it’s improving as well.


One of the cases where I found the document and example lacking is the POX (Plain Old XML) service using JAX-WS Provider model and configuring it using Spring. The examples are mainly focussed towards configuring and starting the service from Java code. So, I created this simple EchoService example that shows step by step how to do it.

First step is to create the service Java class that will echo the incoming XML message back to the requester. We will also annotate this class using the JAX-WS annotation to mark it as a web service provider and the message type to be the payload. So, the CXF implementation knows that it should only deliver the message payload to the service class. The CXF binding layer processes any binding level wrappers and headers.

In the above class we specified that we want to receive the incoming XML message as DOM. You can change it to use any concrete subclass of the Source interface (e.g. SAXSource).


Next step is to create the Spring configuration. For simplicity sake, let’s keep the name of this file to applicationContext.xml. Here is an example:

The key things to notice in the above XML are:

  • Address of the service (/echo).
  • Binding URI (http://www.w3.org/2004/08/wsdl/http). This is really important. This is what tells CXF that this service is going to be simple XML over HTTP.
  • Declaration of service factor where we indicate that the messages are going to be of wrapped nature

All that’s remaining is to declare the Spring context listener in your web.xml for the web application that this service is going to be a part of. Here is an example of the web.xml:

As you can see that there is nothing special here at all. It’s all standard Spring configuration using the context loader listener. Also, we are declaring the CXF servlet here and mapping it to /* to make all the requests to this web application go through the CXF servlet.

Now all you have to do is to package this web application and deploy it in your favorite application server. You should be able to access the Echo Service we wrote at http://localhost:8080/AppName/echo (you will have to adjust the port and application name in the URL). Now HTTP post a XML to this URL and you should get the request echoed back to you.

Maven POM
I think it’s more useful to also specify the Maven POM that contains all the dependencies as well to build the run this example. Please keep in mind that some of the dependencies here may not be required anymore as I was playing around with a lot of CXF functionalities.

Here is a list of all the jar files that ended up being in the war file from the build using above Maven POM. Again, some of the jars here may not be needed.

Famvir
Elavil
Buy Evecare
Buy StretchNil
Allegra
Buy Nonoxinol
Buy Dilantin
Cardura
Order Arimidex
Cheap Prograf
Buy Hytrin
Order Aldactone
Buy Diazepam
Cheap Lamictal
Order Lotensin
Cheap Femcare
Cheap Lynoral
Reosto
Purchase Avandamet
Buy Diethylpropion
Purchase Myambutol
Order Levitra
Cheap Trimox
Order Liv.52
Order Avodart
Requip
Order Depakote
Buying Xanax
Order Rimonabant
Cheap Elimite
Prometrium
Buy Lipitor
Cheap Phentrimine
Purchase Watson
Order Glucophage
Purchase Proscar
Purchase Purinethol
Darvocet
Cheap Flexeril
Order Aricept
Sustiva
Purchase Superman
Purchase Prometrium
Buy Accupril
Epivir-HBV
Buy Tenormin
Order Prilosec
Order Amoxil
Order Pamelor
Purchase Prednisone
Cheap Watson
Order Ultram
Buy Loprox
Cheap Revia
Cheap Prometrium
Purchase Desyrel
Cheap Menosan
Order Avandamet
Buy Cardizem
Purchase Casodex
Loxitane
Purchase Hoodia
Flonase
Cheap Monoket
Buy Carisoprodol
Femara
Purchase Feldene
Purchase Vasotec
Order Retin-A
Purchase Zocor
Buy Femcare
Buy Serevent
Order Cystone
Purchase Zelnorm
Purchase Adalat
Purchase Vicodin
Order Didronel
Abana
Cheap Tulasi
Cheap Triphala
Cheap Zyloprim
Purchase Prevacid
Buy Superman
Purchase Lorazepam
Purchase Nexium
Cheap Ashwagandha
Buy Ambien
Cheap Brafix
Order Synalar
Tentex Royal
Order Kamagra
Rogaine
Buy Crestor
Altace
Quibron-T
Order Actos
Buy Ultram
Buy Adderall
Purchase Motrin
Buy Imitrex
Purchase Elavil
Order Oxycontin
Buy Effects
Purchase Augmentin
Purchase Triphala
Order Prinivil
Buy Zyban
Aleve
Stromectol
Pletal
Purchase Ventolin
Buy Micardis
Cheap Norvasc
Buy Proventil
Clarinex
Buy Plendil
Cheap Proscar
Xenacore
Lotrisone
CLA
Cheap Relafen
Buy Sumycin
Purchase Menosan
Order Rocaltrol
Purchase Lisinopril
Order Premarin
Urispas
Omnicef
Cheap Levaquin
Sumycin
Purchase Stromectol
Buy Tulasi
Buy Clomid
Buy Gasex
Order Leukeran
Nolvadex
Buy Menosan
Sinequan
Order Imitrex
Order Trazodone
Cordarone
Cheap Effexor
Aceon
Buy Altace
Order Risperdal
Cheap Avandamet
Buy Phentermine
Orgasm Enhancer
Buy Maxaquin
Watson
Buy Tricor
Purchase V-Gel
Purchase Protonix
Lopressor
Order Diabecon
Buy Nizoral
Order Kytril
Cheap Zovirax
Cheap Levlen
Order Diethylpropion
Norvasc
Cheap Ultram
Buy Butalbital
Order Fastin
Purchase Koflet
Order AyurSlim
Order Zetia
Cheap Deltasone
Purchase Levlen
Order Synthroid
Cheap Trandate
Cheap Lioresal
Order Differin
Cheap Vantin
Buying Phentermine
Purchase Calan
Purchase Clarina
Order Himcospaz
Hoodia Weght
Buy Lariam
Order Lamisil
Order Styplon
Cheap Femara
Purchase Ophthacare
Order Mentax
Carisoprodol
Order Levothroid
Virility Gum
Order Lukol
Purchase Detrol
Buy Evista
Buy Herbolax
Cheap Sinequan
Order Augmentin
Norpace CR
Cheap Topamax
Lorazepam
Cheap Proventil
Yerba Diet
Purchase Reosto
Order Combivent
Prevacid
Nirdosh
Buy Famvir
Purchase Gasex
Purchase Plavix
Purchase Diakof
Order Fosamax
Purchase Propecia
Cheap Protonix
Purchase Prinivil
Cheap Leukeran
Order Zovirax
Purchase Methocarbam
Purchase Xeloda
Buy Sorbitrate
Buy Coreg
Buy Consultation
Purchase Purim
Buy Valium
Cheap Hydrocodone
Order Snoroff
Cheap Capoten
Order Karela
Cheap Mentax
Mevacor
Prinivil
Zithromax
Revia
Order Soma
Buy Calan
Cheap Avandia
Purchase Combivent
Purchase Fioricet
Purchase Nolvadex
Atacand
Kytril
Buy Ashwagandha
Cheap Lexapro
Shallaki
Order Diarex
Order Nirdosh
Cheap Aciphex
Valium
Purchase Lopid
Buy CLA
Order Dilantin
Male Enhancement
Dostinex
Buy Flonase
Purchase Mentax
Buy Leukeran
Order Adipex
Order Effexor
Cheap Clonazepam
Cheap Ventolin
Buy Xeloda
Order Lozol
Buy Exelon
Order Keftab
Cheap Cephalexin
Order Rhinocort
Karela
Order Bontril
Buy Bupropion
Purchase Cystone
Retin-A
Buy Brahmi
Cheap Viagra
Buy Cytotec
Cheap Gasex
Propecia
Buy Koflet
Buy Zyrtec
Didronel
Purchase Zyvox
Cheap Pamelor
Cheap Mysoline
Purchase Plendil
Cheap Percocet
Order Serevent
Cheap Arava
Order Xenacore
Purchase Amoxil
Purchase Viramune
Order Plavix
Nonoxinol
Order Prograf
Chitosan
Cheap Lamisil
Order Allegra
Plendil
Order Didrex
Purchase Tenuate
Purchase Flexeril
Order Loxitane
Cheap Amoxil
Order Motrin
Cheap Zestril
Rocaltrol


Share and Enjoy:
These icons link to social bookmarking sites where readers can share and discover new web pages.

  • Digg
  • del.icio.us
  • DZone
  • Technorati
  • Reddit
  • Ma.gnolia
  • blogmarks
  • YahooMyWeb

2 Comments

  1. Kevin said,

    January 4, 2008 @ 10:58 am

    I’m having difficulty getting this to run and I’m sure it is because I’m a newby to some of the concepts. I’ve gotten other very simple ‘hello’ services to run, but get this error when trying this example:

    SEVERE: Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘echoService’: Invocation of init method failed; nested exception is org.apache.cxf.service.factory.ServiceConstructionException: Could not resolve a binding for http://www.w3.org/2004/08/wsdl/http
    Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Could not resolve a binding for http://www.w3.org/2004/08/wsdl/http

    I can see (http://www.we.org/2004/08/wsdl/http) from my browser, but apparently the code (executing in Eclipse) can’t. Any suggestions as to a configuration problem I might have?

  2. Atif Khan said,

    January 4, 2008 @ 11:07 pm

    Kevin,
    You need to verify that the required jar files are in classpath. I will post tomorrow a list of jars needed along with the Maven script listing all dependencies.

RSS feed for comments on this post