This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

CharResponseWrapper  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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
.newInstance().newDocumentBuilder();
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(XMLError.java:320)
at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:341)
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:303)
at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:206)
at oracle.xml.jaxp.JXDocumentBuilder.parse(JXDocumentBuilder.java:155)
at uk.co.cascaid.control.kadol.PdfFilter.doFilter(PdfFilter.java:98)

Any help, greatly appreciated.

Matt
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • 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.
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!