/** * Parse the room read response received from reservation backend. * * <p>This will request the retry if the response status code differs from 200, 201 or 4xx. * * @param response The Apache HTTP client response * @throws IOException * @throws ParseException * @throws FaultTolerantRESTRequest.RetryRequestedException */ @Override protected void parse(HttpResponse response) throws IOException, ParseException, FaultTolerantRESTRequest.RetryRequestedException { int statusCode = response.getStatusLine().getStatusCode(); logger.info("STATUS CODE: " + statusCode); if (200 == statusCode || 201 == statusCode) { // OK conference = readConferenceResponse(conference, response); result = new ApiResult(statusCode, conference); } else if ((statusCode >= 400) && (statusCode < 500)) { // Client side error, indicates that the reservation // backend do not want the resubmission ErrorResponse error = readErrorResponse(response); result = new ApiResult(statusCode, error); } else { // Unusual status code, request the retry throw new FaultTolerantRESTRequest.RetryRequestedException(); } }
public String readResponse(HttpResponse response) { String output = ""; HttpEntity entity = response.getEntity(); try { trapException(response.getStatusLine().getStatusCode()); } catch (CrowdFlowerException e1) { e1.printStackTrace(); } InputStream instream; try { instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); // do something useful with the response output = output + reader.readLine(); instream.close(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return output; }
public Result<InputStream> getInputStream(String endpoint) throws IOException { HttpClient cli = createClient(); HttpGet get = createGet(endpoint); HttpResponse res = cli.execute(get); Object result = null; if (res.getStatusLine().getStatusCode() == 200) result = res.getEntity().getContent(); else { RestResponse resp = new RestResponse(res); result = unmarshalPOJO(resp, InputStream.class); cli.getConnectionManager().shutdown(); } return new Result<InputStream>(result); }