@Test(expected = IOException.class) public void testSendPostFail() throws IOException { AddressService addressService = new DefaultAddressService(); DefaultHttpRequestProcessor p = new DefaultHttpRequestProcessor(addressService, new LookoutConfig()); HttpPost httpPost = new HttpPost("http: try { httpPost.setEntity(new StringEntity("a")); } catch (UnsupportedEncodingException e) { } p.sendPostRequest(httpPost, null); }
@Override public boolean sendPostRequest(final HttpPost httpPost, Map<String, String> metadata) throws IOException { if (metadata != null && PRIORITY.LOW.name().equalsIgnoreCase(metadata.get(PRIORITY_NAME)) && clearIdleConnectionsTask != null) { clearIdleConnectionsTask.run(); } addCommonHeaders(httpPost, metadata); httpPost.setConfig(reqConf); try { return sendRequest(httpPost, new ResponseHandler<Boolean>() { @Override public Boolean handleResponse(HttpResponse response) throws IOException { try { if (200 != response.getStatusLine().getStatusCode()) { refreshAddressCache(); handleErrorResponse(response, httpPost); Registry r = Lookout.registry(); r.counter( r.createId(LOOKOUT_REPORT_FAIL_COUNT_ID).withTag(LOW_PRIORITY_TAG)) .inc(); return false; } else { logger.debug("report to lookout gateway ok.{}", httpPost.toString()); } } finally { EntityUtils.consumeQuietly(response.getEntity()); } return true; } }); } catch (IOException e) { refreshAddressCache(); throw e; } }
DefaultHttpRequestProcessor extends ReportDecider { @Override public boolean sendPostRequest(final HttpPost httpPost, Map<String, String> metadata) throws IOException { if (metadata != null && PRIORITY.LOW.name().equalsIgnoreCase(metadata.get(PRIORITY_NAME)) && clearIdleConnectionsTask != null) { clearIdleConnectionsTask.run(); } addCommonHeaders(httpPost, metadata); httpPost.setConfig(reqConf); try { return sendRequest(httpPost, new ResponseHandler<Boolean>() { @Override public Boolean handleResponse(HttpResponse response) throws IOException { try { if (200 != response.getStatusLine().getStatusCode()) { refreshAddressCache(); handleErrorResponse(response, httpPost); Registry r = Lookout.registry(); r.counter( r.createId(LOOKOUT_REPORT_FAIL_COUNT_ID).withTag(LOW_PRIORITY_TAG)) .inc(); return false; } else { logger.debug("report to lookout gateway ok.{}", httpPost.toString()); } } finally { EntityUtils.consumeQuietly(response.getEntity()); } return true; } }); } catch (IOException e) { refreshAddressCache(); throw e; } } }
DefaultHttpRequestProcessor extends ReportDecider { @Override public boolean sendPostRequest(final HttpPost httpPost, Map<String, String> metadata) throws IOException { if (metadata != null && PRIORITY.LOW.name().equalsIgnoreCase(metadata.get(PRIORITY_NAME)) && clearIdleConnectionsTask != null) { clearIdleConnectionsTask.run(); } addCommonHeaders(httpPost, metadata); httpPost.setConfig(reqConf); try { return sendRequest(httpPost, new ResponseHandler<Boolean>() { @Override public Boolean handleResponse(HttpResponse response) throws IOException { try { if (200 != response.getStatusLine().getStatusCode()) { refreshAddressCache(); handleErrorResponse(response, httpPost); Registry r = Lookout.registry(); r.counter( r.createId(LOOKOUT_REPORT_FAIL_COUNT_ID).withTag(LOW_PRIORITY_TAG)) .inc(); return false; } else { logger.debug("report to lookout gateway ok.{}", httpPost.toString()); } } finally { EntityUtils.consumeQuietly(response.getEntity()); } return true; } }); } catch (IOException e) { refreshAddressCache(); throw e; } } DefaultHttpRequestProcessor(AddressService addressService, MetricConfig metricConfig); }
DefaultHttpRequestProcessor extends ReportDecider { @Override public boolean sendPostRequest(final HttpPost httpPost, Map<String, String> metadata) throws IOException { if (metadata != null && PRIORITY.LOW.name().equalsIgnoreCase(metadata.get(PRIORITY_NAME)) && clearIdleConnectionsTask != null) { clearIdleConnectionsTask.run(); } addCommonHeaders(httpPost, metadata); httpPost.setConfig(reqConf); try { return sendRequest(httpPost, new ResponseHandler<Boolean>() { @Override public Boolean handleResponse(HttpResponse response) throws IOException { try { if (200 != response.getStatusLine().getStatusCode()) { refreshAddressCache(); handleErrorResponse(response, httpPost); Registry r = Lookout.registry(); r.counter( r.createId(LOOKOUT_REPORT_FAIL_COUNT_ID).withTag(LOW_PRIORITY_TAG)) .inc(); return false; } else { logger.debug("report to lookout gateway ok.{}", httpPost.toString()); } } finally { EntityUtils.consumeQuietly(response.getEntity()); } return true; } }); } catch (IOException e) { refreshAddressCache(); throw e; } } DefaultHttpRequestProcessor(AddressService addressService, MetricConfig metricConfig); @Override boolean sendGetRequest(final HttpGet httpGet, Map<String, String> metadata); @Override boolean sendGetRequest(final HttpGet httpGet, Map<String, String> metadata,
                                  final ResultConsumer resultConsumer); @Override boolean sendPostRequest(final HttpPost httpPost, Map<String, String> metadata); void handleErrorResponse(HttpResponse response, HttpRequestBase request); @Override List<LookoutMeasurement> filter(List<LookoutMeasurement> measures); }
DefaultHttpRequestProcessor extends ReportDecider { @Override public boolean sendPostRequest(final HttpPost httpPost, Map<String, String> metadata) throws IOException { if (metadata != null && PRIORITY.LOW.name().equalsIgnoreCase(metadata.get(PRIORITY_NAME)) && clearIdleConnectionsTask != null) { clearIdleConnectionsTask.run(); } addCommonHeaders(httpPost, metadata); httpPost.setConfig(reqConf); try { return sendRequest(httpPost, new ResponseHandler<Boolean>() { @Override public Boolean handleResponse(HttpResponse response) throws IOException { try { if (200 != response.getStatusLine().getStatusCode()) { refreshAddressCache(); handleErrorResponse(response, httpPost); Registry r = Lookout.registry(); r.counter( r.createId(LOOKOUT_REPORT_FAIL_COUNT_ID).withTag(LOW_PRIORITY_TAG)) .inc(); return false; } else { logger.debug("report to lookout gateway ok.{}", httpPost.toString()); } } finally { EntityUtils.consumeQuietly(response.getEntity()); } return true; } }); } catch (IOException e) { refreshAddressCache(); throw e; } } DefaultHttpRequestProcessor(AddressService addressService, MetricConfig metricConfig); @Override boolean sendGetRequest(final HttpGet httpGet, Map<String, String> metadata); @Override boolean sendGetRequest(final HttpGet httpGet, Map<String, String> metadata,
                                  final ResultConsumer resultConsumer); @Override boolean sendPostRequest(final HttpPost httpPost, Map<String, String> metadata); void handleErrorResponse(HttpResponse response, HttpRequestBase request); @Override List<LookoutMeasurement> filter(List<LookoutMeasurement> measures); static final String CLIENT_IP_HEADER_NAME; static final String LOOKOUT_REPORT_FAIL_COUNT_ID; static final String WAIT_MINUTES; }