Source:
public Response postRequest(URI url, String payload, Map<String, String> headers, MediaType mediaType, String metricsPrefix) throws GatewayClientException { Stopwatch responseTimeStopwatch = Stopwatch.createStarted(); try { Response response = client.target(url.toString()) .request() .headers(new MultivaluedHashMap<>(headers)) .post(Entity.entity(payload, mediaType)); throwIfErrorResponse(response, metricsPrefix); return response; } catch (ProcessingException pe) { metricRegistry.counter(metricsPrefix + ".failures").inc(); if (pe.getCause() != null) { if (pe.getCause() instanceof UnknownHostException) { logger.error(format("DNS resolution error for gateway url=%s", url.toString()), pe); throw new WebApplicationException("Gateway Url DNS resolution error"); } if (pe.getCause() instanceof SocketTimeoutException) { logger.error(format("Connection timed out error for gateway url=%s", url.toString()), pe); throw new WebApplicationException("Gateway connection timeout error"); } if (pe.getCause() instanceof SocketException) { logger.error(format("Socket Exception for gateway url=%s", url.toString()), pe); throw new WebApplicationException("Gateway connection socket error"); } } logger.error(format("Exception for gateway url=%s", url.toString()), pe); throw new WebApplicationException(pe.getMessage()); } catch (Exception e) { metricRegistry.counter(metricsPrefix + ".failures").inc(); logger.error(format("Exception for gateway url=%s", url.toString()), e); throw new WebApplicationException(e.getMessage()); } finally { responseTimeStopwatch.stop(); metricRegistry.histogram(metricsPrefix + ".response_time").update(responseTimeStopwatch.elapsed(TimeUnit.MILLISECONDS)); } }

Target:
public Response postRequest(URI url, String payload, Map<String, String> headers, MediaType mediaType, String metricsPrefix) throws GatewayClientException { Stopwatch responseTimeStopwatch = Stopwatch.createStarted(); try { Invocation.Builder clientBuilder = client.target(url.toString()) .request(); headers.keySet().forEach(headerKey -> clientBuilder.header(headerKey, headers.get(headerKey))); Response response = clientBuilder .post(Entity.entity(payload, mediaType)); throwIfErrorResponse(response, metricsPrefix); return response; } catch (ProcessingException pe) { metricRegistry.counter(metricsPrefix + ".failures").inc(); if (pe.getCause() != null) { if (pe.getCause() instanceof UnknownHostException) { logger.error(format("DNS resolution error for gateway url=%s", url.toString()), pe); throw new WebApplicationException("Gateway Url DNS resolution error"); } if (pe.getCause() instanceof SocketTimeoutException) { logger.error(format("Connection timed out error for gateway url=%s", url.toString()), pe); throw new WebApplicationException("Gateway connection timeout error"); } if (pe.getCause() instanceof SocketException) { logger.error(format("Socket Exception for gateway url=%s", url.toString()), pe); throw new WebApplicationException("Gateway connection socket error"); } } logger.error(format("Exception for gateway url=%s", url.toString()), pe); throw new WebApplicationException(pe.getMessage()); } catch (RuntimeException e) { metricRegistry.counter(metricsPrefix + ".failures").inc(); logger.error(format("Exception for gateway url=%s", url.toString()), e); throw new WebApplicationException(e.getMessage()); } finally { responseTimeStopwatch.stop(); metricRegistry.histogram(metricsPrefix + ".response_time").update(responseTimeStopwatch.elapsed(TimeUnit.MILLISECONDS)); } }