/** * @since 4.4 */ public ManagedHttpClientConnectionFactory( final HttpMessageWriterFactory<HttpRequest> requestWriterFactory, final HttpMessageParserFactory<HttpResponse> responseParserFactory, final ContentLengthStrategy incomingContentStrategy, final ContentLengthStrategy outgoingContentStrategy) { super(); this.requestWriterFactory = requestWriterFactory != null ? requestWriterFactory : DefaultHttpRequestWriterFactory.INSTANCE; this.responseParserFactory = responseParserFactory != null ? responseParserFactory : DefaultHttpResponseParserFactory.INSTANCE; this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy : LaxContentLengthStrategy.INSTANCE; this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy : StrictContentLengthStrategy.INSTANCE; }
@SuppressWarnings("deprecation") protected void service(@NotNull SessionInputBuffer inputBuffer, @NotNull SessionOutputBuffer outputBuffer, @NotNull HttpMessageParser<HttpRequest> parser, @NotNull HttpMessageWriter<HttpResponse> writer) throws IOException, HttpException { try { final HttpRequest request = parser.parse(); final HttpEntity entity; if (request instanceof HttpEntityEnclosingRequest) { final EntityDeserializer deserializer = new EntityDeserializer(new LaxContentLengthStrategy()); entity = deserializer.deserialize(inputBuffer, request); ((HttpEntityEnclosingRequest) request).setEntity(entity); } else { entity = null; } final HttpResponse response = service(request); if (entity != null) { entity.getContent().close(); } if (response.getEntity() != null) { response.addHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(response.getEntity().getContentLength())); response.addHeader(response.getEntity().getContentType()); response.addHeader(response.getEntity().getContentEncoding()); } response.setHeader(HttpHeaders.SERVER, "Protobuf RPC"); writer.write(response); if (response.getEntity() != null) { final EntitySerializer serializer = new EntitySerializer(new LaxContentLengthStrategy()); serializer.serialize(outputBuffer, response, response.getEntity()); } } finally { outputBuffer.flush(); } }
private static void parseEntity(HttpEntityEnclosingRequest request, SessionInputBuffer buf) throws IOException, HttpException{ if(request.getParams().isParameterTrue(CoreProtocolPNames.STRICT_TRANSFER_ENCODING)){ HttpParams params = request.getParams(); params.setBooleanParameter(CoreProtocolPNames.STRICT_TRANSFER_ENCODING, false); } EntityDeserializer deserial = new EntityDeserializer(new LaxContentLengthStrategy()); request.setEntity(deserial.deserialize(buf, request)); }
private static void parseEntity(HttpResponse response, SessionInputBuffer buf) throws IOException, HttpException{ if(response.getParams().isParameterTrue(CoreProtocolPNames.STRICT_TRANSFER_ENCODING)){ HttpParams params = response.getParams(); params.setBooleanParameter(CoreProtocolPNames.STRICT_TRANSFER_ENCODING, false); } EntityDeserializer deserial = new EntityDeserializer(new LaxContentLengthStrategy()); response.setEntity(deserial.deserialize(buf, response)); }
/** * Creates an instance of {@link EntityDeserializer} with the * {@link LaxContentLengthStrategy} implementation to be used for * de-serializing entities received over this connection. * <p> * This method can be overridden in a super class in order to create * instances of {@link EntityDeserializer} using a custom * {@link ContentLengthStrategy}. * * @return HTTP entity deserializer */ protected EntityDeserializer createEntityDeserializer() { return new EntityDeserializer(new LaxContentLengthStrategy()); }
/** * Creates an instance of {@link EntityDeserializer} with the * {@link LaxContentLengthStrategy} implementation to be used for * de-serializing entities received over this connection. * <p> * This method can be overridden in a super class in order to create * instances of {@link EntityDeserializer} using a custom * {@link ContentLengthStrategy}. * * @return HTTP entity deserializer */ protected EntityDeserializer createEntityDeserializer() { return new EntityDeserializer(new DisallowIdentityContentLengthStrategy( new LaxContentLengthStrategy(0))); }