Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using filters to manipulate the servlet request

 
maher dabbas
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
maher dabbas
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael ,

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

Regards,

Maher Dabbas.
 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic