• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using filters to manipulate the servlet request

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic