Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-456

ClientResponse.getEntity(*) JaxB failure prevents future calls of getEntity(*) with other parameters: org.xml.sax.SAXParseException: Premature end of file.

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 2.0-beta-2, 2.0.1.GA
    • Fix Version/s: 2.2-beta-1
    • Component/s: jaxrs
    • Labels:
      None
    • Workaround:
      Workaround Exists
    • Workaround Description:
      Hide

      The workaround is to manually reset the input stream before calling getEntity again, but there's no direct functions to do that in ClientResponse. You have to make the assumption that it'll be a BaseClientResponse as in:

      if (response instanceof BaseClientResponse<?>)

      { //We unfortunately need to reset the stream manually InputStream responseBodyStream = ((BaseClientResponse<T>)response).getStreamFactory().getInputStream(); responseBodyStream.reset(); }
      Show
      The workaround is to manually reset the input stream before calling getEntity again, but there's no direct functions to do that in ClientResponse. You have to make the assumption that it'll be a BaseClientResponse as in: if (response instanceof BaseClientResponse<?>) { //We unfortunately need to reset the stream manually InputStream responseBodyStream = ((BaseClientResponse<T>)response).getStreamFactory().getInputStream(); responseBodyStream.reset(); }

      Description

      If a JAXB exception occurs when parsing a server response, the input stream never gets reset. Thus if you try to call it again with another JaxB entity, you get a SAXParseException (org.xml.sax.SAXParseException: Premature end of file.)

      protected <T> T processResultsResponse(ClientResponse<T> response) {
      try

      { T entity = response.getEntity(); return entity; }

      catch (JAXBUnmarshalException e)

      { // --- insert workaround here -- // //This call below throws the SAXParseException) MyJaxBErrorClass = response.getEntity(MyJaxBErrorClass.class); throw MyJaxBErrorClass.createException(); }

      }

      You can manually reset the input stream as described in the workaround, but there's no way to do that directly from the ClientResponse. I would prefer that if a getEntity call failed, it would reset itself such that it could be called again immediately - but would be happy with a resetStream() addition to the ClientResponse interface or something similar.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                bill.burke Bill Burke
                Reporter:
                sublette131 John Sublette
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: