HTTP connector can blow up while trying to report a problem
-----------------------------------------------------------

                 Key: SM-570
                 URL: https://issues.apache.org/activemq/browse/SM-570
             Project: ServiceMix
          Issue Type: Bug
          Components: servicemix-components
    Affects Versions: 3.0-M2
            Reporter: Robert H. Pollack
            Priority: Minor
         Attachments: HttpBindingSupport.java

The HttpBindingSupport class has a general exception reporter that handles 
uncaught exceptions by sending them back to the client as HTML messages.  The 
code looks like this:

        PrintWriter writer = response.getWriter();
        writer.println("Request failed with error: " + e);
        e.printStackTrace(writer);

But the HttpMarshaler class, in preparing the normal response, has the 
following line:

        getTransformer().toResult(message.getContent(), new 
StreamResult(response.getOutputStream()));

If this transformer fails, the error reporting logic will get an 
IllegalStateException, because you cannot ask for the response writer after you 
have already obtained the response output stream.  The solution is to ask for 
the output stream again (you are allowed to get it more than once) and created 
a new PrintWriter:  The following code seems to work just fine:

        PrintWriter writer = null;
        try {
            writer = response.getWriter();
        } catch (IllegalStateException ise) {
            OutputStream os = response.getOutputStream();
            writer = new PrintWriter (os);
        }
        writer.println("Request failed with error: " + e);
        e.printStackTrace(writer);

A corrected version of the source file  (you also need another import 
statement) is attached.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to