Uploaded image for project: 'ServiceMix'
  1. ServiceMix
  2. SM-570

HTTP connector can blow up while trying to report a problem

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.0-M2
    • 3.0.1, 3.1
    • servicemix-components
    • None

    Description

      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.

      Attachments

        Activity

          People

            gnodet Guillaume Nodet
            rpollack Robert H. Pollack
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: