On Thu, 2023-02-23 at 02:11 +0530, sreenivas somavarapu wrote:
> Hi Oleg,
>
> Real problem was in our customized AbstractClassicEntityProducer
> class produce method, buffer flush was missing which was causing the
> issue (*Connection
> Closed* in case of GET requests and *Connection forcibly closed* in
> case of
> POST requests). If we don't add a request method check for skipping
> adding
> of entity to request, httpclient produces ContentLength header with 0
> (In
> *RequestContent.java* process method there is a check for entity and
> if
> entity present it adds ContentLength header by default). Currently I
> see
> the only way to avoid not adding ContentLength header is to not set
> an
> entity to request in specific conditions (i.e., GET requests etc.,).
> Is
> there any other way we can make httpclient skip adding ContentLength
> header
> with 0?
>
> Here is sample code with below modifications to actual code being
> used
> - ContentType, ProtocolVersion and inputstream (i.e., Content) we get
> as
> input from servlet
> - AbstractClassicEntityProducer has been customized to generate
> content
> length as well and is not using any executor instead produceData API
> is
> predefined in that custom class
>
> *Code*
> HttpHost host = new HttpHost("host", "/printenv.pl", 80);
> InputStream content = new BufferedInputStream(<Stream from
> servlet>);
> AsyncRequestProducer request =
> AsyncRequestBuilder.get().setHttpHost(host).setEntity(
> new AbstractClassicEntityProducer(1024,
> ContentType.TEXT_XML, Executors.newSingleThreadExecutor()) {
> @Override
> protected void produceData(ContentType ct,
> OutputStream
> os) throws IOException {
> if (content != null) {
> byte[] b = new byte[1024];
> int bytesRead = 0;
> while (content.read(b) != -1) {
> os.write(b, bytesRead, b.length);
> bytesRead += b.length;
> }
> }
> }
> }).build();
>
This is where your code is wrong: if the request is not supposed to
have an entity it should not have a entity producer, _at all_.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]