Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh


Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I've read all of the forums but I'm stuck trying to use Filters to intercept a struts .do action using OC4J. I'm trying to intercept it to turn the html into a pdf. The filter is setup and working ok, but the code breaks when trying to get the CharResponseWrapper.

public final void doFilter(
final ServletRequest request,
final ServletResponse response,
final FilterChain chain) throws IOException, ServletException {

if (request instanceof HttpServletRequest) {
HttpServletRequest httpReq = (HttpServletRequest) request;
HttpServletResponse httpResp = (HttpServletResponse) response;

CharResponseWrapper wrapper = new CharResponseWrapper(httpResp);

System.out.println("*** wrapper: |" + wrapper.toString() + "|");
chain.doFilter(request, wrapper);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {

DocumentBuilder builder = DocumentBuilderFactory
Document doc = builder.parse(new InputSource(
new StringReader(wrapper.toString())));


The wrapper.toString() is empty! The CharResponseWrapper is the same as everyone else is using so can't see there being any problems there.

The exception is...

oracle.xml.parser.v2.XMLParseException: Start of root element expected.
at oracle.xml.parser.v2.XMLError.flushErrors1(
at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(
at oracle.xml.parser.v2.XMLParser.parse(
at oracle.xml.jaxp.JXDocumentBuilder.parse(

Any help, greatly appreciated.

Posts: 4179
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> The wrapper.toString() is empty!

Not surprising. The CharResponseWrapper will print the contents of the response in the toString() method. You put the
System.out.println("*** wrapper: |" + wrapper.toString() + "|");
line before the chain.doFilter(...) call, so you are trying to print the line before any response is written to it.

Try moving the System.out line after the chain.doFilter and see what output you get.
There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once.
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic