public EngineResult engineResult ( HttpRequestBase request ) { EngineResult engineResult = new EngineResult ( ) ; try { HttpResponse response = httpClient . execute ( request ) ; if ( response != null ) { engineResult . responseCode = response . getStatusLine ( ) . getStatusCode ( ) ; HttpEntity responseEntity = response . getEntity ( ) ; long contentLength = responseEntity . getContentLength ( ) ; if ( contentLength < 0 ) { contentLength = 0 ; } ByteArrayOutputStream bOut = new ByteArrayOutputStream ( ( int ) contentLength ) ; InputStream in = responseEntity . getContent ( ) ; int read ; byte [ ] tmpBuf = new byte [ 8192 ] ; while ( ( read = in . read ( tmpBuf ) ) != - 1 ) { bOut . write ( tmpBuf , 0 , read ) ; } in . close ( ) ; bOut . close ( ) ; engineResult . response = bOut . toByteArray ( ) ; switch ( engineResult . responseCode ) { case 200 : engineResult . parse ( xmlValidator ) ; in = new ByteArrayInputStream ( engineResult . response ) ; engineResult . engine = Engine . unmarshall ( in ) ; in . close ( ) ; engineResult . status = ResultStatus . OK ; break ; case 404 : engineResult . status = ResultStatus . NOT_FOUND ; break ; case 500 : engineResult . status = ResultStatus . INTERNAL_ERROR ; break ; default : engineResult . status = ResultStatus . NO_RESPONSE ; break ; } } else { engineResult . status = ResultStatus . NO_RESPONSE ; } } catch ( NoHttpResponseException e ) { engineResult . status = ResultStatus . OFFLINE ; engineResult . t = e ; } catch ( ClientProtocolException e ) { engineResult . status = ResultStatus . RESPONSE_EXCEPTION ; engineResult . t = e ; } catch ( IOException e ) { engineResult . status = ResultStatus . RESPONSE_EXCEPTION ; engineResult . t = e ; } catch ( JAXBException e ) { engineResult . status = ResultStatus . JAXB_EXCEPTION ; engineResult . t = e ; } catch ( XMLStreamException e ) { engineResult . status = ResultStatus . XML_EXCEPTION ; engineResult . t = e ; } return engineResult ; }
Process the engine result XML and turn it into a Java object .