Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Problem filtering servlet response

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to filter my http response coming out of the app server - I've tested with both ATG and jboss. The problem is that when using the filter with a response wrapper the response disappears. In ATG I get a blank page, and jboss a 404.

The filter is very simple at this stage, simply getting the response and wrapping it for modification, and chaining the filter. Eventually I want to modify the html.

I can see the html output in the console, so I know the filter executes, but the page never makes it to the browser. If I change the chain.doFilter(request, buffer) to chain.doFilter(request, response) it works fine - but then I won't be able to modify the response...

I'd appreciate any thoughts, I'm running out of ideas! Thanks.

doFilter():

PrintWriter out = response.getWriter();
ResponseBuffer buffer = new ResponseBuffer((HttpServletResponse) response);
chain.doFilter(request, buffer);

// get page content
String contents = buffer.toString();
log.info(contents);

// TODO stuff here

// send the page to the browser
CharArrayWriter caw = new CharArrayWriter();
caw.write(contents);
response.setContentLength(caw.toString().length());
out.write(caw.toString());
out.close();
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a sample app that captures the text (writes it to System.out) and also sends it to the browser.

The code is quick and dirty but you're welcome to it.
http://simple.souther.us/capture.war

In short, it uses the wrapper pattern.
 
KC Smith
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the sample. Strange, that works in jboss but not ATG. They use the same filter mappings.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't touched ATG Dynamo in years.
What version of the servlet spec does it comply with?
Filters were introduced in 2.3.
 
KC Smith
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's ATG 6.1, uses the 2.3 spec but the old 1.3.1 JDK. That should not cause any trouble. The atg application is Struts, and the filter is set catch any .do requests and post-process the response. Your code displays the html in the console, but the result never makes it to the browser.

It seems like a chaining problem, but the application chains correctly if the original response is used in the chain.doFilter, not the wrapper. Strange...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at my filter code.
It's possible that I'm using some 1.4 functionality.

Try recompiling it with 1.3.
If it barfs, then you know where to start looking.
 
Your mother is a hamster and your father smells of tiny ads!
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic