aspose file tools*
The moose likes Servlets and the fly likes Replace request data using Filter - HttpServletRequestWrapper Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Replace request data using Filter - HttpServletRequestWrapper" Watch "Replace request data using Filter - HttpServletRequestWrapper" New topic
Author

Replace request data using Filter - HttpServletRequestWrapper

Kee Bler
Greenhorn

Joined: Sep 27, 2004
Posts: 2
Here's my problem. The software I'm using has a servlet that listens for XML feeds (XML posted via HTTP). As you can image, it is expecting the XML to adhere to a certain schema. Now...I have a little integration project where the XML that will be sent has a different structure. I want to add a filter to intercept the request and transform the XML into the format that the software expects before passing it along to the servlet.

The XML is posted w/a utility class that creates an HttpURLConnection and writes the XML straight into the HttpURLConnection's OutputStream (that is to say, it is not parameterized). Please, don't ask...

Is there anyway to use HttpServletRequestWrapper to read the the data (using the request's BufferedReader), transform the XML and then put the new XML into wrapped request - essentially replacing the the original data (so that I don't have to muck with any of the servlet's code)??

I'm guessing I'm up the proverbial creek here, but thought someone on this forum with more brain cells and experience might have a slick trick up their sleeve.

Thanks,
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
It sounds like you already know what you need to do .... extending the wrapper to implement whatever functionality you're trying to do is the right creek.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Kee Bler
Greenhorn

Joined: Sep 27, 2004
Posts: 2
I guess what I am struggling with is how do I replace the body of the request? I can call the getReader() method but how do I change/replace the character stream from the old XML to the new XML - meaning, how do I swap in a new character stream into the request's BufferedReader?

I don't want to have to touch the servlet code at all but the servlet simply calls the request's getReader() method and expects the XML to be in a certain format. I might be on the right creek, but I sure feel like I don't have a paddle...

Thanks,

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Replace request data using Filter - HttpServletRequestWrapper