@Override public HTTPProcessor createProcessor(ExecutorService executorService) { return new JDKHTTPProcessor(executorService); }
@Override protected <T> HTTPResponseAdapter<T> process( final HTTPMethod method, final String endpointWithParameter, final KvPCollection header, final HTTPContentWriter contentWriter, final HTTPContentReader<T> contentReader, final HTTPConnectionParameter connectionParameter) throws Exception { HttpURLConnection urlcon = openConnection(endpointWithParameter); urlcon.setRequestMethod(method.name()); applyHeader(urlcon, header); applyConnectionParameter(urlcon, connectionParameter); String contentCharset = getCharsetFromContentTypeHeader(header); sendContent(urlcon, contentCharset, header, contentWriter, connectionParameter.isAllowChunkedRequestContent()); HTTPResponseAdapter<T> response = prepareResponse(endpointWithParameter, urlcon); readResponseContent(urlcon, response, contentReader, connectionParameter); return response; }
private <T> void readResponseContent( HttpURLConnection urlcon, HTTPResponseAdapter<T> response, HTTPContentReader<T> contentReader, HTTPConnectionParameter connectionParameter) throws Exception { InputStream input = openInputStream(urlcon, connectionParameter); if (connectionParameter.isUseContentEncoding()) { // clear content encoding header, if transparent use response.getModifiableHeader().set(HTTPHeader.CONTENT_ENCODING.getName(), null); } if (input == null) { // no content provided return; } readResponseContent(input, response, contentReader); }
private <T> HTTPResponseAdapter<T> prepareResponse( String endpoint, HttpURLConnection urlcon) throws IOException { int code = urlcon.getResponseCode(); KvPCollection headers = new KvPCollection().addAll(urlcon.getHeaderFields()); return createResponseAdapter(endpoint, code, headers); }