Source:
private Response transmit( final URL url, final List<Map.Entry<String, String>> headers, final String method, final byte[] payload) throws IOException { final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); if (conn instanceof HttpsURLConnection && SSL_SOCKET_FACTORY != null) ((HttpsURLConnection) conn).setSSLSocketFactory(SSL_SOCKET_FACTORY); conn.setRequestMethod(method); conn.setRequestProperty("Accept", MIME_TYPE); conn.setRequestProperty("Content-Type", MIME_TYPE); for (final Map.Entry<String, String> h : headers) { conn.setRequestProperty(h.getKey(), h.getValue()); } for (final String authHeader : authorizationHeaders) { conn.setRequestProperty("Authorization", authHeader); } logger.debug("{} {}", method, url.toString()); if (logger.isTraceEnabled()) { for (final Map.Entry<String, List<String>> header : conn.getRequestProperties().entrySet()) { final StringBuilder stringBuilder = new StringBuilder(); final Iterator<String> iterator = header.getValue().iterator(); stringBuilder.append(iterator.next()); while (iterator.hasNext()) { String headerValue = iterator.next(); stringBuilder.append(", ").append(headerValue); } logger.trace("{}: {}", header.getKey(), header.getValue()); } } if (payload != null) { conn.setDoOutput(true); if (logger.isTraceEnabled()) logger.trace("Adding payload: {}", new String(payload, "UTF-8")); conn.setRequestProperty("Content-Length", Integer.toString(payload.length)); conn.getOutputStream().write(payload); conn.getOutputStream().close(); } try { final int responseCode = conn.getResponseCode(); final byte[] responseBody = (responseCode < 400) ? Utils.inputStreamToByteArray(conn.getInputStream()) : Utils.inputStreamToByteArray(conn.getErrorStream()); return new Response(responseCode, responseBody); } catch (IOException e) { logger.error(e.getMessage()); final byte[] bytes = Utils.inputStreamToByteArray(conn.getErrorStream()); if (bytes != null && logger.isDebugEnabled()) logger.debug(new String(bytes, "UTF-8")); throw e; } }

Target:
private Response transmit( final URL url, final List<Map.Entry<String, String>> headers, final String method, final byte[] payload) throws IOException { final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); if (conn instanceof HttpsURLConnection && SSL_SOCKET_FACTORY != null) ((HttpsURLConnection) conn).setSSLSocketFactory(SSL_SOCKET_FACTORY); conn.setRequestMethod(method); conn.setRequestProperty("Accept", MIME_TYPE); conn.setRequestProperty("Content-Type", MIME_TYPE); for (final Map.Entry<String, String> h : headers) { conn.setRequestProperty(h.getKey(), h.getValue()); } logger.debug("{} {}", method, url.toString()); for (final String authHeader : authorizationHeaders) { conn.setRequestProperty("Authorization", authHeader); logger.trace("Authorization: {}", authHeader); } if (logger.isTraceEnabled()) { for (final Map.Entry<String, List<String>> header : conn.getRequestProperties().entrySet()) { final StringBuilder stringBuilder = new StringBuilder(); final Iterator<String> iterator = header.getValue().iterator(); stringBuilder.append(iterator.next()); while (iterator.hasNext()) { String headerValue = iterator.next(); stringBuilder.append(", ").append(headerValue); } logger.trace("{}: {}", header.getKey(), header.getValue()); } } if (payload != null) { conn.setDoOutput(true); if (logger.isTraceEnabled()) logger.trace("Adding payload: {}", new String(payload, "UTF-8")); conn.setRequestProperty("Content-Length", Integer.toString(payload.length)); conn.getOutputStream().write(payload); conn.getOutputStream().close(); } try { final int responseCode = conn.getResponseCode(); final byte[] responseBody = (responseCode < 400) ? Utils.inputStreamToByteArray(conn.getInputStream()) : Utils.inputStreamToByteArray(conn.getErrorStream()); return new Response(responseCode, responseBody); } catch (IOException e) { logger.error(e.getMessage()); final byte[] bytes = Utils.inputStreamToByteArray(conn.getErrorStream()); if (bytes != null && logger.isDebugEnabled()) logger.debug(new String(bytes, "UTF-8")); throw e; } }