Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need to modify XML input on-the-fly  RSS feed

 
Pradeep Mudaliar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!