Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Need to modify XML input on-the-fly

Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the application that I am working for my client, soap message is passed as input to a web service method which accepts a Java bean as an argument. The mapping from the xml input to Java Bean is being handled by Apache CXF which is internally using JAXB for unmarshalling.

The application requires incorrect input data to get replaced by some default value. For eg, if the web service method accepts PersonBean as argument, the XML input would have elements like name, age etc. Now, if the age field in the input comes in as anything other than a number, the value to set in the bean should be a default one specified for it (this may sound strange, but it is for an EAI project and this is what the client wants)

To achieve this without disturbing the architecture in place, I created my own custom CXF interceptor and placed it before the interceptor which unmarshalls the input data in the interceptor chain. Thus I was able to catch the exception when incorrect data was encountered. But, I was not able to find a way to replace the incorrect data with default values. The Message reference passed to the interceptor seems to provide only read-only access to the input XML. I am sorry that I am not supposed to post the actual code here. The custom interceptor that I have developed looks something like this –

So guys, please suggest me your opinions on this. It would be great if anyone here can suggest a way to modify the data wrapped in the message reference passed to the handleMessage method shown above. It would also be good to know about other ways to resolve my problem.
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you could get away from the CXF requirement, this looks like a job for ......

XML Pipeline Processing! Harold's online book chapter gives you the basics of using SAX filters to modify XML on the fly.

I actually wrote a couple of articles on Pipeline processing of XML - see the links on my home page.

It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic