private Message createResponseMessage ( HttpResponse httpResponse ) throws IOException , AxisFault { int statusCode = httpResponse . getStatusCode ( ) ; String contentType = httpResponse . getContentType ( ) ; // The conditions below duplicate the logic in CommonsHTTPSender and HTTPSender. boolean shouldParseResponse = ( statusCode > 199 && statusCode < 300 ) || ( contentType != null && ! contentType . equals ( "text/html" ) && statusCode > 499 && statusCode < 600 ) ; // Wrap the content input stream in a notifying stream so the stream event listener will be // notified when it is closed. InputStream responseInputStream = new NotifyingInputStream ( httpResponse . getContent ( ) , inputStreamEventListener ) ; if ( ! shouldParseResponse ) { // The contents are not an XML response, so throw an AxisFault with // the HTTP status code and message details. String statusMessage = httpResponse . getStatusMessage ( ) ; AxisFault axisFault = new AxisFault ( "HTTP" , "(" + statusCode + ")" + statusMessage , null , null ) ; axisFault . addFaultDetail ( Constants . QNAME_FAULTDETAIL_HTTPERRORCODE , String . valueOf ( statusCode ) ) ; try ( InputStream stream = responseInputStream ) { byte [ ] contentBytes = ByteStreams . toByteArray ( stream ) ; axisFault . setFaultDetailString ( Messages . getMessage ( "return01" , String . valueOf ( statusCode ) , new String ( contentBytes , UTF_8 ) ) ) ; } throw axisFault ; } // Response is an XML response. Do not consume and close the stream in this case, since that // will happen later when the response is deserialized by Axis (as confirmed by unit tests for // this class). Message responseMessage = new Message ( responseInputStream , false , contentType , httpResponse . getHeaders ( ) . getLocation ( ) ) ; responseMessage . setMessageType ( Message . RESPONSE ) ; return responseMessage ; }
Returns a new Axis Message based on the contents of the HTTP response .