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.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 2.2-beta-1
    • 2.0-beta-2, 2.0.1.GA
    • jaxrs
    • None
    • Workaround Exists
    • 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.

      Attachments

        Activity

          People

            patriot1burke@gmail.com Bill Burke (Inactive)
            sublette131 John Sublette (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: