wood burning stoves*
The moose likes Servlets and the fly likes Using filters to manipulate the servlet request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Using filters to manipulate the servlet request" Watch "Using filters to manipulate the servlet request" New topic
Author

Using filters to manipulate the servlet request

maher dabbas
Greenhorn

Joined: Dec 02, 2001
Posts: 26
Hi all,
I need to use a filter to manipulate the request body , my case is that i am having a compressed request , and i want to uncompress it and forward it to the servlet , below is the method that handle the compressed data , any ideas?
public static final String uncompress(final byte [] compressed) throws IOException{
String uncompressed = "";
try{
ByteArrayInputStream bais = new ByteArrayInputStream(compressed);
InflaterInputStream zis = new InflaterInputStream(bais);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int numBytesRead = 0;
byte [] tempBytes = new byte[DEFAULT_BUFFER_SIZE];
while ((numBytesRead = zis.read(tempBytes, 0, tempBytes.length)) != -1){
baos.write(tempBytes, 0, numBytesRead);
}
uncompressed = new String(baos.toByteArray());
}
catch (ZipException e){
e.printStackTrace();
}//catch
return uncompressed;
}//method
Regards,

Maher Dabbas.
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
Hi Maher
Is your question about the code you posted, or about how to use a filter to apply this code?
If it is about the code posted - what is the problem with it?
Michael


"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
maher dabbas
Greenhorn

Joined: Dec 02, 2001
Posts: 26
Hi Michael ,

My problem is about how to use the filter to apply this code ,

Regards,

Maher Dabbas.
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
Maher
It's actually quite straightforward - probably a lot easier than you think. Have a look at this introductory tutorial.. That should get you up and running.
Michael
 
GeeCON Prague 2014
 
subject: Using filters to manipulate the servlet request