Discussion:
Upgrading from Httpclient 3.1 to 4.5 - localhost:443 not responding
Hassan Khan
2017-04-17 13:16:19 UTC
Permalink
+
Hi All,
We are upgrading the httpclient in our software from 3.1 to 4.5 (we are
adding both core and client). But we are having some issues in the client
and server communications. We are using the below client code (simplified
the code ) to make a call every 60 secs and we are getting localhost not
responding after few tries.
RequestConfig config = RequestConfig.*custom*()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.*setStaleConnectionCheckEnabled**(**true**)*
.setSocketTimeout(10 * 60 * 1000).build();
*this*.client = HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
log error
}
//using the object stream to read data..
ois = *new* ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread making a
request every 60 secs. When we used a spooling manager always one route was
used..
May be both thread that are calling the same URL simultaneously are
sharing one connection , but they should share different connections..
Thanks
*Hassan Khan*
Software Developer
Gary Gregory
2017-04-17 17:35:53 UTC
Permalink
Hassan,

Your attachments were filtered out. You might want to try an image sharing
site.

Gary
Post by Hassan Khan
+
Hi All,
We are upgrading the httpclient in our software from 3.1 to 4.5 (we
are adding both core and client). But we are having some issues in the
client and server communications. We are using the below client code
(simplified the code ) to make a call every 60 secs and we are getting
localhost not responding after few tries.
RequestConfig config = RequestConfig.*custom*()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.*setStaleConnectionCheckEnabled**(**true**)*
.setSocketTimeout(10 * 60 * 1000).build();
*this*.client = HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
log error
}
//using the object stream to read data..
ois = *new* ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread making a
request every 60 secs. When we used a spooling manager always one route was
used..
May be both thread that are calling the same URL simultaneously are
sharing one connection , but they should share different connections..
Thanks
*Hassan Khan*
Software Developer
--
E-Mail: ***@gmail.com | ***@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Hassan Khan
2017-04-18 13:27:24 UTC
Permalink
Hi ,

Sorry the log images was filtered out. you can look at the uploaded image.

http://imgur.com/a/Nxpcw

in text the logs say: I/O read timed out.

Thanks
Hassan
Post by Gary Gregory
Hassan,
Your attachments were filtered out. You might want to try an image sharing
site.
Gary
Post by Hassan Khan
+
Hi All,
We are upgrading the httpclient in our software from 3.1 to 4.5 (we
are adding both core and client). But we are having some issues in the
client and server communications. We are using the below client code
(simplified the code ) to make a call every 60 secs and we are getting
localhost not responding after few tries.
RequestConfig config = RequestConfig.*custom*()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.*setStaleConnectionCheckEnabled**(**true**)*
.setSocketTimeout(10 * 60 * 1000).build();
*this*.client = HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
log error
}
//using the object stream to read data..
ois = *new* ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread making a
request every 60 secs. When we used a spooling manager always one route
was
Post by Hassan Khan
used..
May be both thread that are calling the same URL simultaneously are
sharing one connection , but they should share different connections..
Thanks
*Hassan Khan*
Software Developer
--
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_
tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_
tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_
tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Hassan Khan
Hassan Khan
2017-04-21 14:21:56 UTC
Permalink
Hi all,

We have pinpointed the issue and looks like the code that deals with
streaming a object from the client to the server.
With the old code (Httpclient 3.1) we would stream the object through a
ObjectOutputStream and on the server side read it through a
ObjectInputStream.
But looks like that workflow is not working in the new httpclient 4.5.
Is there any example or resource that specifically shows how streaming
objects work ?

Thanks
Hassan
Post by Hassan Khan
Hi ,
Sorry the log images was filtered out. you can look at the uploaded image.
http://imgur.com/a/Nxpcw
in text the logs say: I/O read timed out.
Thanks
Hassan
Post by Gary Gregory
Hassan,
Your attachments were filtered out. You might want to try an image sharing
site.
Gary
Post by Hassan Khan
+
Hi All,
We are upgrading the httpclient in our software from 3.1 to 4.5 (we
are adding both core and client). But we are having some issues in the
client and server communications. We are using the below client code
(simplified the code ) to make a call every 60 secs and we are getting
localhost not responding after few tries.
RequestConfig config = RequestConfig.*custom*()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.*setStaleConnectionCheckEnabled**(**true**)*
.setSocketTimeout(10 * 60 * 1000).build();
*this*.client = HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
log error
}
//using the object stream to read data..
ois = *new* ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread making a
request every 60 secs. When we used a spooling manager always one
route was
Post by Hassan Khan
used..
May be both thread that are calling the same URL simultaneously are
sharing one connection , but they should share different connections..
Thanks
*Hassan Khan*
Software Developer
--
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
Code=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
Code=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
nk_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Hassan Khan
--
Hassan Khan
Oleg Kalnichevski
2017-04-22 16:26:06 UTC
Permalink
Post by Hassan Khan
Hi all,
  We have pinpointed the issue and looks like the code that deals
with
streaming a object from the client to the server.
  With the old code (Httpclient 3.1) we would stream the object
through a
ObjectOutputStream and on the server side read it through a
ObjectInputStream.
  But looks like that workflow is not working in the new httpclient
4.5.
  Is there any example or resource that specifically shows how
streaming
objects work ?
See this section of the tutorial

http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamen
tals.html#d5e95


What you most likely want is SerializableEntity

http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/apidocs/org/apa
che/http/entity/SerializableEntity.html

Oleg
Post by Hassan Khan
Thanks
Hassan
Post by Hassan Khan
Hi ,
Sorry the log images was filtered out. you can look at the uploaded image.
http://imgur.com/a/Nxpcw
in text the logs say: I/O read timed out.
Thanks
Hassan
om>
Post by Gary Gregory
Hassan,
Your attachments were filtered out. You might want to try an image sharing
site.
Gary
.com>
+
Hi All,
   We are upgrading the httpclient in our software from 3.1
to 4.5 (we
are adding both core and client). But we are having some issues in the
client and server communications. We are using the below client code
(simplified the code ) to make a  call every 60 secs and we
are getting
localhost not responding after few tries.
RequestConfig config = RequestConfig.*custom*()
              .setConnectTimeout(20 * 1000)
              .setConnectionRequestTimeout(10* 60 * 1000)
              .*setStaleConnectionCheckEnabled**(**true**)*
              .setSocketTimeout(10 * 60 * 1000).build();
*this*.client =
HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
      log error
}
//using the object stream to read data..
ois = *new*
ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread making a
request every 60 secs. When we used a spooling manager always one
route was
used..
    May be both thread that are calling the same URL
simultaneously are
sharing one connection , but they should share different
connections..
Thanks
*Hassan Khan*
Software Developer
--
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
Code=as2&tag=garygregory-
20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
Code=as2&tag=garygregory-
20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
nk_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Hassan Khan
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Hassan Khan
2017-04-23 01:35:43 UTC
Permalink
Hi Oleg,

Thanks for answering ... very excited (and humbled) to hear from you...

Thanks
Hassan
Post by Oleg Kalnichevski
Post by Hassan Khan
Hi all,
We have pinpointed the issue and looks like the code that deals with
streaming a object from the client to the server.
With the old code (Httpclient 3.1) we would stream the object through a
ObjectOutputStream and on the server side read it through a
ObjectInputStream.
But looks like that workflow is not working in the new httpclient 4.5.
Is there any example or resource that specifically shows how streaming
objects work ?
See this section of the tutorial
http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamen
tals.html#d5e95
What you most likely want is SerializableEntity
http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/apidocs/org/apa
che/http/entity/SerializableEntity.html
Oleg
Post by Hassan Khan
Thanks
Hassan
Post by Hassan Khan
Hi ,
Sorry the log images was filtered out. you can look at the uploaded image.
http://imgur.com/a/Nxpcw
in text the logs say: I/O read timed out.
Thanks
Hassan
om>
Post by Gary Gregory
Hassan,
Your attachments were filtered out. You might want to try an image sharing
site.
Gary
.com>
Post by Hassan Khan
+
Hi All,
We are upgrading the httpclient in our software from 3.1 to 4.5 (we
are adding both core and client). But we are having some issues in the
client and server communications. We are using the below client code
(simplified the code ) to make a call every 60 secs and we are getting
localhost not responding after few tries.
RequestConfig config = RequestConfig.*custom*()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.*setStaleConnectionCheckEnabled**(**true**)*
.setSocketTimeout(10 * 60 * 1000).build();
*this*.client =
HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
log error
}
//using the object stream to read data..
ois = *new*
ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread making a
request every 60 secs. When we used a spooling manager always one
route was
Post by Hassan Khan
used..
May be both thread that are calling the same URL
simultaneously are
sharing one connection , but they should share different connections..
Thanks
*Hassan Khan*
Software Developer
--
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
Code=as2&tag=garygregory-
20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
Code=as2&tag=garygregory-
20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
nk_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Hassan Khan
---------------------------------------------------------------------
--
Hassan Khan
Hassan Khan
2017-04-25 19:45:57 UTC
Permalink
Hi All,

I have been trying to solve the below issue that show up in logs and
unable to solve it from 2 weeks:

04/25/2017 15:37:30:513 FINEST: Invoking post method:
https://localhost/localTomcat8_Rendezvous/comm/sendPayload [Thread-23:
Downloader for default channel (C:\Program Files\Apache Software
Foundation\Tomcat 8.5\Instance1\webapps\localTomcat8_Rendezvous\common),
com.novoInnovations.network.protocol.Connection:sendRequest]

04/25/2017 15:22:33:677 WARNING: Could not get payload from
localTomcat8_Rendezvous located at the path
localhost/localTomcat8_Rendezvous/comm [Thread-23: Downloader for
default channel (C:\Program Files\Apache Software Foundation\Tomcat
8.5\Instance1\webapps\localTomcat8_Rendezvous\common),
com.novoInnovations.network.protocol.N2RProtocol:recvPayload]
localhost:443 failed to respond

org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)

org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)

org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)

org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)

org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)

org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)

org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)

org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)

org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)

org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)

org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)

org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)

org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)

com.novoInnovations.network.protocol.Connection.sendRequest(Connection.java:329)

com.novoInnovations.network.protocol.N2RProtocol.recvPayload(N2RProtocol.java:137)

com.novoInnovations.network.node.Downloader.getFromRendezvous(Downloader.java:411)
com.novoInnovations.network.node.Downloader.run(Downloader.java:141)
the next failure is at 15:22:53:743 , 15:23:13:853, .. so on

The code is below (commented out are the many other ways that i tried to
solve the issue...), this code is called every 20 secs by a thread, the
target is a url and 443 port since it is https , it works the first time ..
the post methid has this url set :
https://localhost/localTomcat8_Rendezvous/comm/sendPayload as
postMethod = new HttpPost(this.url);

Main function :
public String sendRequest(Object obj) throws Exception {
// temporary output stream to stream objects into
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
if (isValid) {
myNovoLogger.finest("Writing node communicator version: " +
VERSION);
oos.writeObject(VERSION);
myNovoLogger.finest("Writing node id: " + this.node.id());
oos.writeObject(this.node.id());
myNovoLogger.finest("Writing node's state");
oos.writeObject(this.state);
myNovoLogger.finest("Writing communication channel: " +
this.getCommunicationChannel());

oos.writeObject(Integer.toString(this.getCommunicationChannel()));
if (obj != null) {
myNovoLogger.finest("Streaming provided object.");
oos.writeObject(obj);
}
// create an input stream out of the stream
// we put objects into
/* InputStream tis = new
ByteArrayInputStream(baos.toByteArray());
/// take the created inputstream and make this the method's bidy
InputStreamEntity inputStreamEntity = new
InputStreamEntity(tis);
HttpEntity httpEntity = new InputStreamEntity(tis,
tis.available());
//ISSUE in uploading is from here
postMethod.setEntity(inputStreamEntity);*/

InputStreamEntity temp = new InputStreamEntity(new
ByteArrayInputStream(baos.toByteArray()));
postMethod.setEntity(temp);



//postMethod.setRequestBody(tis);

RequestConfig config = RequestConfig.custom()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.setStaleConnectionCheckEnabled(true)
.setSocketTimeout(10 * 60 * 1000).build();

myNovoLogger.finest("Invoking post method: " +
postMethod.getURI().toString());
// execute method on server

PoolingHttpClientConnectionManager connManager = new
PoolingHttpClientConnectionManager();
connManager.setValidateAfterInactivity(200);
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setBufferSize(1000)
.build();
// HttpClientBuilder clientBuilder = HttpClients.custom();
// clientBuilder.setRetryHandler(new
DefaultHttpRequestRetryHandler(3, false));
// HttpClient client =
clientBuilder.setDefaultConnectionConfig(connectionConfig).build();
//HttpHost targetHost = new HttpHost(url, 443, "https");
//CloseableHttpResponse response = client1.execute(targetHost,
postMethod);



this.response = client.execute(postMethod); //====> line 329
String responseLine = null;

/* HttpHost targetHost = new HttpHost(this.url);
this.response = client.execute(targetHost, postMethod);*/
int rc =0;
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
entity = new BufferedHttpEntity(entity);
}
if (entity != null) {
ObjectInputStream instream = new
ObjectInputStream(entity.getContent());
try {
myNovoLogger.finest("Getting response code.");
myNovoLogger.finest("Got response:" +
response.getStatusLine());
rc = response.getStatusLine().getStatusCode();
if (rc > 200) {
myNovoLogger.warning("Response of " + rc);
myNovoLogger.warning("ResponseBody:" +
response.getStatusLine().getReasonPhrase());
}
myNovoLogger.finest("Getting input stream.");
//ois = new ObjectInputStream(entity.getContent());
//ois = new
ObjectInputStream(postMethod.getResponseBodyAsStream());
myNovoLogger.finest("Done sending request.");
if(instream != null) {
myNovoLogger.finest("responseLine instream"+
EntityUtils.toString(entity));
responseLine = (String) instream.readObject();
setResponseLine(responseLine);
if (Protocol.ACK.equals(responseLine)) {
Object o = instream.readObject();
setPayload((Payload) o);
}
Object o2 = instream.readObject();
setDiscardList((HashMap) o2);
//EntityUtils.consume(response.getEntity());
}
} finally {
myNovoLogger.finest("closing instream");
if(instream != null) {
myNovoLogger.finest("closing instream");
instream.close();
myNovoLogger.finest("after closing instream");

}
this.client.close();
isValid = false;
connManager.close();
}
}
} finally {
myNovoLogger.finest("Attempt to send request "+rc);

return responseLine;
}

(Additional info : It works the first call then it fails consecutively...we
are upgrading from client 3.2 to 4.5 , have included both core and client
in the tomcat load path)

Can some one find any problem , any inputs are welcome. I am new to
httpclient coding.

Thanks
Hassan
Post by Hassan Khan
Hi Oleg,
Thanks for answering ... very excited (and humbled) to hear from you...
Thanks
Hassan
Post by Oleg Kalnichevski
Post by Hassan Khan
Hi all,
We have pinpointed the issue and looks like the code that deals with
streaming a object from the client to the server.
With the old code (Httpclient 3.1) we would stream the object through a
ObjectOutputStream and on the server side read it through a
ObjectInputStream.
But looks like that workflow is not working in the new httpclient 4.5.
Is there any example or resource that specifically shows how streaming
objects work ?
See this section of the tutorial
http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamen
tals.html#d5e95
<http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamentals.html#d5e95>
What you most likely want is SerializableEntity
http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/apidocs/org/apa
che/http/entity/SerializableEntity.html
<http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/apidocs/org/apache/http/entity/SerializableEntity.html>
Oleg
Post by Hassan Khan
Thanks
Hassan
Post by Hassan Khan
Hi ,
Sorry the log images was filtered out. you can look at the uploaded image.
http://imgur.com/a/Nxpcw
in text the logs say: I/O read timed out.
Thanks
Hassan
om>
Post by Gary Gregory
Hassan,
Your attachments were filtered out. You might want to try an image sharing
site.
Gary
.com>
Post by Hassan Khan
+
Hi All,
We are upgrading the httpclient in our software from 3.1
to 4.5 (we
are adding both core and client). But we are having some
issues in the
client and server communications. We are using the below client code
(simplified the code ) to make a call every 60 secs and we
are getting
localhost not responding after few tries.
RequestConfig config = RequestConfig.*custom*()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.*setStaleConnectionCheckEnabled**(**true**)*
.setSocketTimeout(10 * 60 * 1000).build();
*this*.client =
HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
log error
}
//using the object stream to read data..
ois = *new*
ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread making a
request every 60 secs. When we used a spooling manager always one
route was
Post by Hassan Khan
used..
May be both thread that are calling the same URL
simultaneously are
sharing one connection , but they should share different connections..
Thanks
*Hassan Khan*
Software Developer
--
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
Code=as2&tag=garygregory-
20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
Code=as2&tag=garygregory-
20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
nk_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Hassan Khan
---------------------------------------------------------------------
--
Hassan Khan
--
Hassan Khan
Hassan Khan
2017-04-26 20:17:44 UTC
Permalink
Hi ,

Wanted to know if some one can answer top of their head if
OutputObjectStreams are supported in 4.5 (3.0 does).
All our objects are marked as serializable.
we are using it like below to send a ObjectOutputStream to the post method:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
if (obj != null) {
oos.writeObject(obj);
}
// create an input stream out of the stream
// we put objects into
InputStreamEntity temp = new InputStreamEntity(new
ByteArrayInputStream(baos.toByteArray()));
postMethod.setEntity(temp);


Also while receiving the response, is the method to get response as a
stream changed from

3.0 ==> ObjectInputStream instream = postMethod.getResponseBodyAsStream()

to

4.5 ==> ObjectInputStream instream = new
ObjectInputStream(entity.getContent()) ?

Thanks
Hassan
Hi All,
I have been trying to solve the below issue that show up in logs and
Downloader for default channel (C:\Program Files\Apache Software
Foundation\Tomcat 8.5\Instance1\webapps\localTomcat8_Rendezvous\common),
com.novoInnovations.network.protocol.Connection:sendRequest]
04/25/2017 15:22:33:677 WARNING: Could not get payload from
localTomcat8_Rendezvous located at the path localhost/localTomcat8_Rendezvous/comm
[Thread-23: Downloader for default channel (C:\Program Files\Apache
Software Foundation\Tomcat 8.5\Instance1\webapps\localTomcat8_Rendezvous\common),
com.novoInnovations.network.protocol.N2RProtocol:recvPayload]
localhost:443 failed to respond
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(
DefaultHttpResponseParser.java:143)
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(
DefaultHttpResponseParser.java:57)
org.apache.http.impl.io.AbstractMessageParser.parse(
AbstractMessageParser.java:259)
org.apache.http.impl.DefaultBHttpClientConnection.
receiveResponseHeader(DefaultBHttpClientConnection.java:163)
org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(
CPoolProxy.java:167)
org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(
HttpRequestExecutor.java:273)
org.apache.http.protocol.HttpRequestExecutor.execute(
HttpRequestExecutor.java:125)
org.apache.http.impl.execchain.MainClientExec.
execute(MainClientExec.java:271)
org.apache.http.impl.execchain.ProtocolExec.
execute(ProtocolExec.java:184)
org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
org.apache.http.impl.execchain.RedirectExec.
execute(RedirectExec.java:110)
org.apache.http.impl.client.InternalHttpClient.doExecute(
InternalHttpClient.java:184)
org.apache.http.impl.client.CloseableHttpClient.execute(
CloseableHttpClient.java:82)
org.apache.http.impl.client.CloseableHttpClient.execute(
CloseableHttpClient.java:107)
com.novoInnovations.network.protocol.Connection.
sendRequest(Connection.java:329)
com.novoInnovations.network.protocol.N2RProtocol.
recvPayload(N2RProtocol.java:137)
com.novoInnovations.network.node.Downloader.
getFromRendezvous(Downloader.java:411)
com.novoInnovations.network.node.Downloader.run(Downloader.java:141)
the next failure is at 15:22:53:743 , 15:23:13:853, .. so on
The code is below (commented out are the many other ways that i tried to
solve the issue...), this code is called every 20 secs by a thread, the
target is a url and 443 port since it is https , it works the first time ..
the post methid has this url set :https://localhost/
localTomcat8_Rendezvous/comm/sendPayload as
postMethod = new HttpPost(this.url);
public String sendRequest(Object obj) throws Exception {
// temporary output stream to stream objects into
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
if (isValid) {
myNovoLogger.finest("Writing node communicator version: " +
VERSION);
oos.writeObject(VERSION);
myNovoLogger.finest("Writing node id: " + this.node.id());
oos.writeObject(this.node.id());
myNovoLogger.finest("Writing node's state");
oos.writeObject(this.state);
myNovoLogger.finest("Writing communication channel: " +
this.getCommunicationChannel());
oos.writeObject(Integer.toString(this.
getCommunicationChannel()));
if (obj != null) {
myNovoLogger.finest("Streaming provided object.");
oos.writeObject(obj);
}
// create an input stream out of the stream
// we put objects into
/* InputStream tis = new ByteArrayInputStream(baos.
toByteArray());
/// take the created inputstream and make this the method's bidy
InputStreamEntity inputStreamEntity = new
InputStreamEntity(tis);
HttpEntity httpEntity = new InputStreamEntity(tis,
tis.available());
//ISSUE in uploading is from here
postMethod.setEntity(inputStreamEntity);*/
InputStreamEntity temp = new InputStreamEntity(new
ByteArrayInputStream(baos.toByteArray()));
postMethod.setEntity(temp);
//postMethod.setRequestBody(tis);
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.setStaleConnectionCheckEnabled(true)
.setSocketTimeout(10 * 60 * 1000).build();
myNovoLogger.finest("Invoking post method: " +
postMethod.getURI().toString());
// execute method on server
PoolingHttpClientConnectionManager connManager = new
PoolingHttpClientConnectionManager();
connManager.setValidateAfterInactivity(200);
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setBufferSize(1000)
.build();
// HttpClientBuilder clientBuilder = HttpClients.custom();
// clientBuilder.setRetryHandler(new
DefaultHttpRequestRetryHandler(3, false));
// HttpClient client = clientBuilder.
setDefaultConnectionConfig(connectionConfig).build();
//HttpHost targetHost = new HttpHost(url, 443, "https");
//CloseableHttpResponse response = client1.execute(targetHost,
postMethod);
this.response = client.execute(postMethod); //====> line 329
String responseLine = null;
/* HttpHost targetHost = new HttpHost(this.url);
this.response = client.execute(targetHost, postMethod);*/
int rc =0;
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
entity = new BufferedHttpEntity(entity);
}
if (entity != null) {
ObjectInputStream instream = new ObjectInputStream(entity.
getContent());
try {
myNovoLogger.finest("Getting response code.");
myNovoLogger.finest("Got response:" +
response.getStatusLine());
rc = response.getStatusLine().getStatusCode();
if (rc > 200) {
myNovoLogger.warning("Response of " + rc);
myNovoLogger.warning("ResponseBody:" +
response.getStatusLine().getReasonPhrase());
}
myNovoLogger.finest("Getting input stream.");
//ois = new ObjectInputStream(entity.
getContent());
//ois = new ObjectInputStream(postMethod.
getResponseBodyAsStream());
myNovoLogger.finest("Done sending request.");
if(instream != null) {
myNovoLogger.finest("responseLine instream"+
EntityUtils.toString(entity));
responseLine = (String) instream.readObject();
setResponseLine(responseLine);
if (Protocol.ACK.equals(responseLine)) {
Object o = instream.readObject();
setPayload((Payload) o);
}
Object o2 = instream.readObject();
setDiscardList((HashMap) o2);
//EntityUtils.consume(response.getEntity());
}
} finally {
myNovoLogger.finest("closing instream");
if(instream != null) {
myNovoLogger.finest("closing instream");
instream.close();
myNovoLogger.finest("after closing instream");
}
this.client.close();
isValid = false;
connManager.close();
}
}
} finally {
myNovoLogger.finest("Attempt to send request "+rc);
return responseLine;
}
(Additional info : It works the first call then it fails
consecutively...we are upgrading from client 3.2 to 4.5 , have included
both core and client in the tomcat load path)
Can some one find any problem , any inputs are welcome. I am new to
httpclient coding.
Thanks
Hassan
Post by Hassan Khan
Hi Oleg,
Thanks for answering ... very excited (and humbled) to hear from you...
Thanks
Hassan
Post by Oleg Kalnichevski
Post by Hassan Khan
Hi all,
We have pinpointed the issue and looks like the code that deals with
streaming a object from the client to the server.
With the old code (Httpclient 3.1) we would stream the object through a
ObjectOutputStream and on the server side read it through a
ObjectInputStream.
But looks like that workflow is not working in the new httpclient 4.5.
Is there any example or resource that specifically shows how streaming
objects work ?
See this section of the tutorial
http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamen
tals.html#d5e95
<http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamentals.html#d5e95>
What you most likely want is SerializableEntity
http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/apidocs/org/apa
che/http/entity/SerializableEntity.html
<http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/apidocs/org/apache/http/entity/SerializableEntity.html>
Oleg
Post by Hassan Khan
Thanks
Hassan
Post by Hassan Khan
Hi ,
Sorry the log images was filtered out. you can look at the uploaded image.
http://imgur.com/a/Nxpcw
in text the logs say: I/O read timed out.
Thanks
Hassan
om>
Post by Gary Gregory
Hassan,
Your attachments were filtered out. You might want to try an image sharing
site.
Gary
.com>
Post by Hassan Khan
+
Hi All,
We are upgrading the httpclient in our software from 3.1
to 4.5 (we
are adding both core and client). But we are having some
issues in the
client and server communications. We are using the below
client code
(simplified the code ) to make a call every 60 secs and we
are getting
localhost not responding after few tries.
RequestConfig config = RequestConfig.*custom*()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.*setStaleConnectionCheckEnabled**(**true**)*
.setSocketTimeout(10 * 60 * 1000).build();
*this*.client =
HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
log error
}
//using the object stream to read data..
ois = *new*
ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread making a
request every 60 secs. When we used a spooling manager always one
route was
Post by Hassan Khan
used..
May be both thread that are calling the same URL
simultaneously are
sharing one connection , but they should share different connections..
Thanks
*Hassan Khan*
Software Developer
--
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
Code=as2&tag=garygregory-
20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
Code=as2&tag=garygregory-
20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
nk_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Hassan Khan
---------------------------------------------------------------------
--
Hassan Khan
--
Hassan Khan
--
Hassan Khan
Bernd Eckenfels
2017-04-26 22:53:53 UTC
Permalink
BTW: If you serialized your object into a BOS you catcall toByteArray() and give that as an in memory entity content, there is no point to put an input stream on top of it to feed the entity.

Gruss
Bernd
--
http://bernd.eckenfels.net
________________________________
From: Hassan Khan <***@gmail.com>
Sent: Wednesday, April 26, 2017 10:17:44 PM
To: HttpClient User Discussion
Subject: Re: Upgrading from Httpclient 3.1 to 4.5 - localhost:443 not responding

Hi ,

Wanted to know if some one can answer top of their head if
OutputObjectStreams are supported in 4.5 (3.0 does).
All our objects are marked as serializable.
we are using it like below to send a ObjectOutputStream to the post method:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
if (obj != null) {
oos.writeObject(obj);
}
// create an input stream out of the stream
// we put objects into
InputStreamEntity temp = new InputStreamEntity(new
ByteArrayInputStream(baos.toByteArray()));
postMethod.setEntity(temp);


Also while receiving the response, is the method to get response as a
stream changed from

3.0 ==> ObjectInputStream instream = postMethod.getResponseBodyAsStream()

to

4.5 ==> ObjectInputStream instream = new
ObjectInputStream(entity.getContent()) ?

Thanks
Hassan
Hi All,
I have been trying to solve the below issue that show up in logs and
Downloader for default channel (C:\Program Files\Apache Software
Foundation\Tomcat 8.5\Instance1\webapps\localTomcat8_Rendezvous\common),
com.novoInnovations.network.protocol.Connection:sendRequest]
04/25/2017 15:22:33:677 WARNING: Could not get payload from
localTomcat8_Rendezvous located at the path localhost/localTomcat8_Rendezvous/comm
[Thread-23: Downloader for default channel (C:\Program Files\Apache
Software Foundation\Tomcat 8.5\Instance1\webapps\localTomcat8_Rendezvous\common),
com.novoInnovations.network.protocol.N2RProtocol:recvPayload]
localhost:443 failed to respond
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(
DefaultHttpResponseParser.java:143)
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(
DefaultHttpResponseParser.java:57)
org.apache.http.impl.io.AbstractMessageParser.parse(
AbstractMessageParser.java:259)
org.apache.http.impl.DefaultBHttpClientConnection.
receiveResponseHeader(DefaultBHttpClientConnection.java:163)
org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(
CPoolProxy.java:167)
org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(
HttpRequestExecutor.java:273)
org.apache.http.protocol.HttpRequestExecutor.execute(
HttpRequestExecutor.java:125)
org.apache.http.impl.execchain.MainClientExec.
execute(MainClientExec.java:271)
org.apache.http.impl.execchain.ProtocolExec.
execute(ProtocolExec.java:184)
org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
org.apache.http.impl.execchain.RedirectExec.
execute(RedirectExec.java:110)
org.apache.http.impl.client.InternalHttpClient.doExecute(
InternalHttpClient.java:184)
org.apache.http.impl.client.CloseableHttpClient.execute(
CloseableHttpClient.java:82)
org.apache.http.impl.client.CloseableHttpClient.execute(
CloseableHttpClient.java:107)
com.novoInnovations.network.protocol.Connection.
sendRequest(Connection.java:329)
com.novoInnovations.network.protocol.N2RProtocol.
recvPayload(N2RProtocol.java:137)
com.novoInnovations.network.node.Downloader.
getFromRendezvous(Downloader.java:411)
com.novoInnovations.network.node.Downloader.run(Downloader.java:141)
the next failure is at 15:22:53:743 , 15:23:13:853, .. so on
The code is below (commented out are the many other ways that i tried to
solve the issue...), this code is called every 20 secs by a thread, the
target is a url and 443 port since it is https , it works the first time ..
the post methid has this url set :https://localhost/
localTomcat8_Rendezvous/comm/sendPayload as
postMethod = new HttpPost(this.url);
public String sendRequest(Object obj) throws Exception {
// temporary output stream to stream objects into
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
if (isValid) {
myNovoLogger.finest("Writing node communicator version: " +
VERSION);
oos.writeObject(VERSION);
myNovoLogger.finest("Writing node id: " + this.node.id());
oos.writeObject(this.node.id());
myNovoLogger.finest("Writing node's state");
oos.writeObject(this.state);
myNovoLogger.finest("Writing communication channel: " +
this.getCommunicationChannel());
oos.writeObject(Integer.toString(this.
getCommunicationChannel()));
if (obj != null) {
myNovoLogger.finest("Streaming provided object.");
oos.writeObject(obj);
}
// create an input stream out of the stream
// we put objects into
/* InputStream tis = new ByteArrayInputStream(baos.
toByteArray());
/// take the created inputstream and make this the method's
bidy
InputStreamEntity inputStreamEntity = new
InputStreamEntity(tis);
HttpEntity httpEntity = new InputStreamEntity(tis,
tis.available());
//ISSUE in uploading is from here
postMethod.setEntity(inputStreamEntity);*/
InputStreamEntity temp = new InputStreamEntity(new
ByteArrayInputStream(baos.toByteArray()));
postMethod.setEntity(temp);
//postMethod.setRequestBody(tis);
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.setStaleConnectionCheckEnabled(true)
.setSocketTimeout(10 * 60 * 1000).build();
myNovoLogger.finest("Invoking post method: " +
postMethod.getURI().toString());
// execute method on server
PoolingHttpClientConnectionManager connManager = new
PoolingHttpClientConnectionManager();
connManager.setValidateAfterInactivity(200);
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setBufferSize(1000)
.build();
// HttpClientBuilder clientBuilder = HttpClients.custom();
// clientBuilder.setRetryHandler(new
DefaultHttpRequestRetryHandler(3, false));
// HttpClient client = clientBuilder.
setDefaultConnectionConfig(connectionConfig).build();
//HttpHost targetHost = new HttpHost(url, 443, "https");
//CloseableHttpResponse response = client1.execute(targetHost,
postMethod);
this.response = client.execute(postMethod); //====> line 329
String responseLine = null;
/* HttpHost targetHost = new HttpHost(this.url);
this.response = client.execute(targetHost, postMethod);*/
int rc =0;
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
entity = new BufferedHttpEntity(entity);
}
if (entity != null) {
ObjectInputStream instream = new ObjectInputStream(entity.
getContent());
try {
myNovoLogger.finest("Getting response code.");
myNovoLogger.finest("Got response:" +
response.getStatusLine());
rc = response.getStatusLine().getStatusCode();
if (rc > 200) {
myNovoLogger.warning("Response of " + rc);
myNovoLogger.warning("ResponseBody:" +
response.getStatusLine().getReasonPhrase());
}
myNovoLogger.finest("Getting input stream.");
//ois = new ObjectInputStream(entity.
getContent());
//ois = new ObjectInputStream(postMethod.
getResponseBodyAsStream());
myNovoLogger.finest("Done sending request.");
if(instream != null) {
myNovoLogger.finest("responseLine instream"+
EntityUtils.toString(entity));
responseLine = (String) instream.readObject();
setResponseLine(responseLine);
if (Protocol.ACK.equals(responseLine)) {
Object o = instream.readObject();
setPayload((Payload) o);
}
Object o2 = instream.readObject();
setDiscardList((HashMap) o2);
//EntityUtils.consume(response.getEntity());
}
} finally {
myNovoLogger.finest("closing instream");
if(instream != null) {
myNovoLogger.finest("closing instream");
instream.close();
myNovoLogger.finest("after closing instream");
}
this.client.close();
isValid = false;
connManager.close();
}
}
} finally {
myNovoLogger.finest("Attempt to send request "+rc);
return responseLine;
}
(Additional info : It works the first call then it fails
consecutively...we are upgrading from client 3.2 to 4.5 , have included
both core and client in the tomcat load path)
Can some one find any problem , any inputs are welcome. I am new to
httpclient coding.
Thanks
Hassan
Post by Hassan Khan
Hi Oleg,
Thanks for answering ... very excited (and humbled) to hear from you...
Thanks
Hassan
Post by Oleg Kalnichevski
Post by Hassan Khan
Hi all,
We have pinpointed the issue and looks like the code that deals with
streaming a object from the client to the server.
With the old code (Httpclient 3.1) we would stream the object through a
ObjectOutputStream and on the server side read it through a
ObjectInputStream.
But looks like that workflow is not working in the new httpclient 4.5.
Is there any example or resource that specifically shows how streaming
objects work ?
See this section of the tutorial
http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamen
tals.html#d5e95
<http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/html/fundamentals.html#d5e95>
What you most likely want is SerializableEntity
http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/apidocs/org/apa
che/http/entity/SerializableEntity.html
<http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/apidocs/org/apache/http/entity/SerializableEntity.html>
Oleg
Post by Hassan Khan
Thanks
Hassan
Post by Hassan Khan
Hi ,
Sorry the log images was filtered out. you can look at the uploaded image.
http://imgur.com/a/Nxpcw
in text the logs say: I/O read timed out.
Thanks
Hassan
om>
Post by Gary Gregory
Hassan,
Your attachments were filtered out. You might want to try an image sharing
site.
Gary
.com>
Post by Hassan Khan
+
Hi All,
We are upgrading the httpclient in our software from 3.1
to 4.5 (we
are adding both core and client). But we are having some
issues in the
client and server communications. We are using the below
client code
(simplified the code ) to make a call every 60 secs and we
are getting
localhost not responding after few tries.
RequestConfig config = RequestConfig.*custom*()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.*setStaleConnectionCheckEnabled**(**true**)*
.setSocketTimeout(10 * 60 * 1000).build();
*this*.client =
HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
log error
}
//using the object stream to read data..
ois = *new*
ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread making a
request every 60 secs. When we used a spooling manager always one
route was
Post by Hassan Khan
used..
May be both thread that are calling the same URL
simultaneously are
sharing one connection , but they should share different connections..
Thanks
*Hassan Khan*
Software Developer
--
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
Code=as2&tag=garygregory-
20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
Code=as2&tag=garygregory-
20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
nk_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Hassan Khan
---------------------------------------------------------------------
--
Hassan Khan
--
Hassan Khan
--
Hassan Khan
Hassan Khan
2017-05-03 21:36:17 UTC
Permalink
Thanks for the tip....
After further debugging ... have a usual solution... the code work great
with apache 2.4 ... but not with tomcat 8.5
The changes needed were looks like the http 4.5 SSL validation is more
stricter.
With 3.1 ===> our certificate was applicable for *.Domain, our server using
it was names X.V.Domain == it worked...
With 4.5 ===> the SSL connection gave us a error so we cut our server name
to V.Domian and it worked...

But the most interesting thing that I cannot understand during stepping
throught he code in eclipse the problem was noted in the code below in
DefaultHttpResponseParser.java file for the function (Line 138) :

protected HttpResponse parseHead(
final SessionInputBuffer sessionBuffer) throws IOException,
HttpException {
//read out the HTTP status string
int count = 0;
ParserCursor cursor = null;
do {
// clear the buffer
this.lineBuf.clear();
final int i = sessionBuffer.readLine(this.lineBuf); //====>
whys is this empty for tomcat 8.5 sometimes and not for apache server 2.4
if (i == -1 && count == 0) {
// The server just dropped connection on us
throw new NoHttpResponseException("The target server failed
to respond");
}
cursor = new ParserCursor(0, this.lineBuf.length());

So kinda looks like there is socket level setting i am missing....
Note : evey 20 secs we are pinging a servlet to get data from the server...

Any ideas let me know.

Thanks
Hassan
Post by Bernd Eckenfels
BTW: If you serialized your object into a BOS you catcall toByteArray()
and give that as an in memory entity content, there is no point to put an
input stream on top of it to feed the entity.
Gruss
Bernd
--
http://bernd.eckenfels.net
________________________________
Sent: Wednesday, April 26, 2017 10:17:44 PM
To: HttpClient User Discussion
Subject: Re: Upgrading from Httpclient 3.1 to 4.5 - localhost:443 not responding
Hi ,
Wanted to know if some one can answer top of their head if
OutputObjectStreams are supported in 4.5 (3.0 does).
All our objects are marked as serializable.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
if (obj != null) {
oos.writeObject(obj);
}
// create an input stream out of the stream
// we put objects into
InputStreamEntity temp = new InputStreamEntity(new
ByteArrayInputStream(baos.toByteArray()));
postMethod.setEntity(temp);
Also while receiving the response, is the method to get response as a
stream changed from
3.0 ==> ObjectInputStream instream = postMethod.getResponseBodyAsStream()
to
4.5 ==> ObjectInputStream instream = new
ObjectInputStream(entity.getContent()) ?
Thanks
Hassan
Hi All,
I have been trying to solve the below issue that show up in logs and
https://localhost/localTomcat8_Rendezvous/comm/sendPayload
Downloader for default channel (C:\Program Files\Apache Software
Foundation\Tomcat 8.5\Instance1\webapps\localTomcat8_Rendezvous\common),
com.novoInnovations.network.protocol.Connection:sendRequest]
04/25/2017 15:22:33:677 WARNING: Could not get payload from
localTomcat8_Rendezvous located at the path localhost/localTomcat8_
Rendezvous/comm
[Thread-23: Downloader for default channel (C:\Program Files\Apache
Software Foundation\Tomcat 8.5\Instance1\webapps\
localTomcat8_Rendezvous\common),
com.novoInnovations.network.protocol.N2RProtocol:recvPayload]
localhost:443 failed to respond
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(
DefaultHttpResponseParser.java:143)
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(
DefaultHttpResponseParser.java:57)
org.apache.http.impl.io.AbstractMessageParser.parse(
AbstractMessageParser.java:259)
org.apache.http.impl.DefaultBHttpClientConnection.
receiveResponseHeader(DefaultBHttpClientConnection.java:163)
org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(
CPoolProxy.java:167)
org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(
HttpRequestExecutor.java:273)
org.apache.http.protocol.HttpRequestExecutor.execute(
HttpRequestExecutor.java:125)
org.apache.http.impl.execchain.MainClientExec.
execute(MainClientExec.java:271)
org.apache.http.impl.execchain.ProtocolExec.
execute(ProtocolExec.java:184)
org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
org.apache.http.impl.execchain.RedirectExec.
execute(RedirectExec.java:110)
org.apache.http.impl.client.InternalHttpClient.doExecute(
InternalHttpClient.java:184)
org.apache.http.impl.client.CloseableHttpClient.execute(
CloseableHttpClient.java:82)
org.apache.http.impl.client.CloseableHttpClient.execute(
CloseableHttpClient.java:107)
com.novoInnovations.network.protocol.Connection.
sendRequest(Connection.java:329)
com.novoInnovations.network.protocol.N2RProtocol.
recvPayload(N2RProtocol.java:137)
com.novoInnovations.network.node.Downloader.
getFromRendezvous(Downloader.java:411)
com.novoInnovations.network.node.Downloader.run(Downloader.java:141)
the next failure is at 15:22:53:743 , 15:23:13:853, .. so on
The code is below (commented out are the many other ways that i tried to
solve the issue...), this code is called every 20 secs by a thread, the
target is a url and 443 port since it is https , it works the first time
..
the post methid has this url set :https://localhost/
localTomcat8_Rendezvous/comm/sendPayload as
postMethod = new HttpPost(this.url);
public String sendRequest(Object obj) throws Exception {
// temporary output stream to stream objects into
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
if (isValid) {
myNovoLogger.finest("Writing node communicator version: " +
VERSION);
oos.writeObject(VERSION);
myNovoLogger.finest("Writing node id: " + this.node.id());
oos.writeObject(this.node.id());
myNovoLogger.finest("Writing node's state");
oos.writeObject(this.state);
myNovoLogger.finest("Writing communication channel: " +
this.getCommunicationChannel());
oos.writeObject(Integer.toString(this.
getCommunicationChannel()));
if (obj != null) {
myNovoLogger.finest("Streaming provided object.");
oos.writeObject(obj);
}
// create an input stream out of the stream
// we put objects into
/* InputStream tis = new ByteArrayInputStream(baos.
toByteArray());
/// take the created inputstream and make this the method's bidy
InputStreamEntity inputStreamEntity = new
InputStreamEntity(tis);
HttpEntity httpEntity = new InputStreamEntity(tis,
tis.available());
//ISSUE in uploading is from here
postMethod.setEntity(inputStreamEntity);*/
InputStreamEntity temp = new InputStreamEntity(new
ByteArrayInputStream(baos.toByteArray()));
postMethod.setEntity(temp);
//postMethod.setRequestBody(tis);
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.setStaleConnectionCheckEnabled(true)
.setSocketTimeout(10 * 60 * 1000).build();
myNovoLogger.finest("Invoking post method: " +
postMethod.getURI().toString());
// execute method on server
PoolingHttpClientConnectionManager connManager = new
PoolingHttpClientConnectionManager();
connManager.setValidateAfterInactivity(200);
ConnectionConfig connectionConfig = ConnectionConfig.custom()
.setBufferSize(1000)
.build();
// HttpClientBuilder clientBuilder = HttpClients.custom();
// clientBuilder.setRetryHandler(new
DefaultHttpRequestRetryHandler(3, false));
// HttpClient client = clientBuilder.
setDefaultConnectionConfig(connectionConfig).build();
//HttpHost targetHost = new HttpHost(url, 443, "https");
//CloseableHttpResponse response =
client1.execute(targetHost,
postMethod);
this.response = client.execute(postMethod); //====> line
329
String responseLine = null;
/* HttpHost targetHost = new HttpHost(this.url);
this.response = client.execute(targetHost, postMethod);*/
int rc =0;
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
entity = new BufferedHttpEntity(entity);
}
if (entity != null) {
ObjectInputStream instream = new
ObjectInputStream(entity.
getContent());
try {
myNovoLogger.finest("Getting response code.");
myNovoLogger.finest("Got response:" +
response.getStatusLine());
rc = response.getStatusLine().getStatusCode();
if (rc > 200) {
myNovoLogger.warning("Response of " + rc);
myNovoLogger.warning("ResponseBody:" +
response.getStatusLine().getReasonPhrase());
}
myNovoLogger.finest("Getting input stream.");
//ois = new ObjectInputStream(entity.
getContent());
//ois = new ObjectInputStream(postMethod.
getResponseBodyAsStream());
myNovoLogger.finest("Done sending request.");
if(instream != null) {
myNovoLogger.finest("responseLine instream"+
EntityUtils.toString(entity));
responseLine = (String)
instream.readObject();
setResponseLine(responseLine);
if (Protocol.ACK.equals(responseLine)) {
Object o = instream.readObject();
setPayload((Payload) o);
}
Object o2 = instream.readObject();
setDiscardList((HashMap) o2);
//EntityUtils.consume(response.getEntity());
}
} finally {
myNovoLogger.finest("closing instream");
if(instream != null) {
myNovoLogger.finest("closing instream");
instream.close();
myNovoLogger.finest("after closing instream");
}
this.client.close();
isValid = false;
connManager.close();
}
}
} finally {
myNovoLogger.finest("Attempt to send request "+rc);
return responseLine;
}
(Additional info : It works the first call then it fails
consecutively...we are upgrading from client 3.2 to 4.5 , have included
both core and client in the tomcat load path)
Can some one find any problem , any inputs are welcome. I am new to
httpclient coding.
Thanks
Hassan
Post by Hassan Khan
Hi Oleg,
Thanks for answering ... very excited (and humbled) to hear from you...
Thanks
Hassan
Post by Oleg Kalnichevski
Post by Hassan Khan
Hi all,
We have pinpointed the issue and looks like the code that deals with
streaming a object from the client to the server.
With the old code (Httpclient 3.1) we would stream the object through a
ObjectOutputStream and on the server side read it through a
ObjectInputStream.
But looks like that workflow is not working in the new httpclient 4.5.
Is there any example or resource that specifically shows how streaming
objects work ?
See this section of the tutorial
http://hc.apache.org/httpcomponents-client-4.5.x/
tutorial/html/fundamen
Post by Hassan Khan
Post by Oleg Kalnichevski
tals.html#d5e95
<http://hc.apache.org/httpcomponents-client-4.5.x/
tutorial/html/fundamentals.html#d5e95>
Post by Hassan Khan
Post by Oleg Kalnichevski
What you most likely want is SerializableEntity
http://hc.apache.org/httpcomponents-core-4.4.x/
httpcore/apidocs/org/apa
Post by Hassan Khan
Post by Oleg Kalnichevski
che/http/entity/SerializableEntity.html
<http://hc.apache.org/httpcomponents-core-4.4.x/
httpcore/apidocs/org/apache/http/entity/SerializableEntity.html>
Post by Hassan Khan
Post by Oleg Kalnichevski
Oleg
Post by Hassan Khan
Thanks
Hassan
On Tue, Apr 18, 2017 at 9:27 AM, Hassan Khan <
Post by Hassan Khan
Hi ,
Sorry the log images was filtered out. you can look at the uploaded image.
http://imgur.com/a/Nxpcw
in text the logs say: I/O read timed out.
Thanks
Hassan
om>
Post by Gary Gregory
Hassan,
Your attachments were filtered out. You might want to try an
image sharing
site.
Gary
.com>
Post by Hassan Khan
+
Hi All,
We are upgrading the httpclient in our software from 3.1
to 4.5 (we
are adding both core and client). But we are having some
issues in the
client and server communications. We are using the below
client code
(simplified the code ) to make a call every 60 secs and we
are getting
localhost not responding after few tries.
RequestConfig config = RequestConfig.*custom*()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.*setStaleConnectionCheckEnabled**(**true**)*
.setSocketTimeout(10 * 60 * 1000).build();
*this*.client =
HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
log error
}
//using the object stream to read data..
ois = *new*
ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread
making a
request every 60 secs. When we used a spooling manager always
one
route was
Post by Hassan Khan
used..
May be both thread that are calling the same URL
simultaneously are
sharing one connection , but they should share different
connections..
Thanks
*Hassan Khan*
Software Developer
--
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
Code=as2&tag=garygregory-
20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
Code=as2&tag=garygregory-
20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
nk_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Hassan Khan
---------------------------------------------------------------------
--
Hassan Khan
--
Hassan Khan
--
Hassan Khan
--
Hassan Khan
Hassan Khan
2017-05-04 14:41:16 UTC
Permalink
Hi,

I had one quick question .... The documentation at
https://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/io/SessionInputBuffer.html
says that

*Session input buffer for blocking connections*. This interface is similar
to InputStream class, but it also provides methods for reading lines of
text.

My 443 connector is a non-blocking one... how can I fix this issue....
*Htppclient
has a input buffer for non-blocking connections ?*

My tomcat 8.5 connector definition is :
<!-- Define a SSL HTTP/1.1 Connector on port 443
Uncomment the section below for a locally installed
connectionTimeout="-1"
Novo Grid and use of a self signed certificate is required
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
for communication to a locally installed Rendezvous -->

<Connector port="443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
====> Non-blocking connector
maxThreads="200" SSLEnabled="true" compression="on"
minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" connectionTimeout="-1"
scheme="https" secure="true">

<SSLHostConfig honorCipherOrder="false" >
<Certificate certificateKeystoreFile="XXX"
certificateKeystorePassword="XXX"
certificateKeyAlias="localhost"
type="RSA" />
</SSLHostConfig>
</Connector>

Any inputs?

Thanks
Hassan
Post by Hassan Khan
Thanks for the tip....
After further debugging ... have a usual solution... the code work great
with apache 2.4 ... but not with tomcat 8.5
The changes needed were looks like the http 4.5 SSL validation is more
stricter.
With 3.1 ===> our certificate was applicable for *.Domain, our server
using it was names X.V.Domain == it worked...
With 4.5 ===> the SSL connection gave us a error so we cut our server name
to V.Domian and it worked...
But the most interesting thing that I cannot understand during stepping
throught he code in eclipse the problem was noted in the code below in
protected HttpResponse parseHead(
final SessionInputBuffer sessionBuffer) throws IOException,
HttpException {
//read out the HTTP status string
int count = 0;
ParserCursor cursor = null;
do {
// clear the buffer
this.lineBuf.clear();
final int i = sessionBuffer.readLine(this.lineBuf); //====>
whys is this empty for tomcat 8.5 sometimes and not for apache server 2.4
if (i == -1 && count == 0) {
// The server just dropped connection on us
throw new NoHttpResponseException("The target server
failed to respond");
}
cursor = new ParserCursor(0, this.lineBuf.length());
So kinda looks like there is socket level setting i am missing....
Note : evey 20 secs we are pinging a servlet to get data from the server...
Any ideas let me know.
Thanks
Hassan
Post by Bernd Eckenfels
BTW: If you serialized your object into a BOS you catcall toByteArray()
and give that as an in memory entity content, there is no point to put an
input stream on top of it to feed the entity.
Gruss
Bernd
--
http://bernd.eckenfels.net
________________________________
Sent: Wednesday, April 26, 2017 10:17:44 PM
To: HttpClient User Discussion
Subject: Re: Upgrading from Httpclient 3.1 to 4.5 - localhost:443 not responding
Hi ,
Wanted to know if some one can answer top of their head if
OutputObjectStreams are supported in 4.5 (3.0 does).
All our objects are marked as serializable.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
if (obj != null) {
oos.writeObject(obj);
}
// create an input stream out of the stream
// we put objects into
InputStreamEntity temp = new InputStreamEntity(new
ByteArrayInputStream(baos.toByteArray()));
postMethod.setEntity(temp);
Also while receiving the response, is the method to get response as a
stream changed from
3.0 ==> ObjectInputStream instream = postMethod.getResponseBodyAsStream()
to
4.5 ==> ObjectInputStream instream = new
ObjectInputStream(entity.getContent()) ?
Thanks
Hassan
Hi All,
I have been trying to solve the below issue that show up in logs and
https://localhost/localTomcat8_Rendezvous/comm/sendPayload
Downloader for default channel (C:\Program Files\Apache Software
Foundation\Tomcat 8.5\Instance1\webapps\localTom
cat8_Rendezvous\common),
com.novoInnovations.network.protocol.Connection:sendRequest]
04/25/2017 15:22:33:677 WARNING: Could not get payload from
localTomcat8_Rendezvous located at the path
localhost/localTomcat8_Rendezvous/comm
[Thread-23: Downloader for default channel (C:\Program Files\Apache
Software Foundation\Tomcat 8.5\Instance1\webapps\localTom
cat8_Rendezvous\common),
com.novoInnovations.network.protocol.N2RProtocol:recvPayload]
localhost:443 failed to respond
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(
DefaultHttpResponseParser.java:143)
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(
DefaultHttpResponseParser.java:57)
org.apache.http.impl.io.AbstractMessageParser.parse(
AbstractMessageParser.java:259)
org.apache.http.impl.DefaultBHttpClientConnection.
receiveResponseHeader(DefaultBHttpClientConnection.java:163)
org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(
CPoolProxy.java:167)
org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(
HttpRequestExecutor.java:273)
org.apache.http.protocol.HttpRequestExecutor.execute(
HttpRequestExecutor.java:125)
org.apache.http.impl.execchain.MainClientExec.
execute(MainClientExec.java:271)
org.apache.http.impl.execchain.ProtocolExec.
execute(ProtocolExec.java:184)
org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
org.apache.http.impl.execchain.RedirectExec.
execute(RedirectExec.java:110)
org.apache.http.impl.client.InternalHttpClient.doExecute(
InternalHttpClient.java:184)
org.apache.http.impl.client.CloseableHttpClient.execute(
CloseableHttpClient.java:82)
org.apache.http.impl.client.CloseableHttpClient.execute(
CloseableHttpClient.java:107)
com.novoInnovations.network.protocol.Connection.
sendRequest(Connection.java:329)
com.novoInnovations.network.protocol.N2RProtocol.
recvPayload(N2RProtocol.java:137)
com.novoInnovations.network.node.Downloader.
getFromRendezvous(Downloader.java:411)
com.novoInnovations.network.node.Downloader.run(Downloader.
java:141)
the next failure is at 15:22:53:743 , 15:23:13:853, .. so on
The code is below (commented out are the many other ways that i tried to
solve the issue...), this code is called every 20 secs by a thread, the
target is a url and 443 port since it is https , it works the first
time ..
the post methid has this url set :https://localhost/
localTomcat8_Rendezvous/comm/sendPayload as
postMethod = new HttpPost(this.url);
public String sendRequest(Object obj) throws Exception {
// temporary output stream to stream objects into
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
if (isValid) {
myNovoLogger.finest("Writing node communicator version: " +
VERSION);
oos.writeObject(VERSION);
myNovoLogger.finest("Writing node id: " + this.node.id());
oos.writeObject(this.node.id());
myNovoLogger.finest("Writing node's state");
oos.writeObject(this.state);
myNovoLogger.finest("Writing communication channel: " +
this.getCommunicationChannel());
oos.writeObject(Integer.toString(this.
getCommunicationChannel()));
if (obj != null) {
myNovoLogger.finest("Streaming provided object.");
oos.writeObject(obj);
}
// create an input stream out of the stream
// we put objects into
/* InputStream tis = new ByteArrayInputStream(baos.
toByteArray());
/// take the created inputstream and make this the method's bidy
InputStreamEntity inputStreamEntity = new
InputStreamEntity(tis);
HttpEntity httpEntity = new InputStreamEntity(tis,
tis.available());
//ISSUE in uploading is from here
postMethod.setEntity(inputStreamEntity);*/
InputStreamEntity temp = new InputStreamEntity(new
ByteArrayInputStream(baos.toByteArray()));
postMethod.setEntity(temp);
//postMethod.setRequestBody(tis);
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.setStaleConnectionCheckEnabled(true)
.setSocketTimeout(10 * 60 * 1000).build();
myNovoLogger.finest("Invoking post method: " +
postMethod.getURI().toString());
// execute method on server
PoolingHttpClientConnectionManager connManager = new
PoolingHttpClientConnectionManager();
connManager.setValidateAfterInactivity(200);
ConnectionConfig connectionConfig =
ConnectionConfig.custom()
.setBufferSize(1000)
.build();
// HttpClientBuilder clientBuilder = HttpClients.custom();
// clientBuilder.setRetryHandler(new
DefaultHttpRequestRetryHandler(3, false));
// HttpClient client = clientBuilder.
setDefaultConnectionConfig(connectionConfig).build();
//HttpHost targetHost = new HttpHost(url, 443, "https");
//CloseableHttpResponse response =
client1.execute(targetHost,
postMethod);
this.response = client.execute(postMethod); //====> line
329
String responseLine = null;
/* HttpHost targetHost = new HttpHost(this.url);
this.response = client.execute(targetHost, postMethod);*/
int rc =0;
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
entity = new BufferedHttpEntity(entity);
}
if (entity != null) {
ObjectInputStream instream = new
ObjectInputStream(entity.
getContent());
try {
myNovoLogger.finest("Getting response code.");
myNovoLogger.finest("Got response:" +
response.getStatusLine());
rc = response.getStatusLine().getStatusCode();
if (rc > 200) {
myNovoLogger.warning("Response of " + rc);
myNovoLogger.warning("ResponseBody:" +
response.getStatusLine().getReasonPhrase());
}
myNovoLogger.finest("Getting input stream.");
//ois = new ObjectInputStream(entity.
getContent());
//ois = new ObjectInputStream(postMethod.
getResponseBodyAsStream());
myNovoLogger.finest("Done sending request.");
if(instream != null) {
myNovoLogger.finest("responseLine
instream"+
EntityUtils.toString(entity));
responseLine = (String)
instream.readObject();
setResponseLine(responseLine);
if (Protocol.ACK.equals(responseLine)) {
Object o = instream.readObject();
setPayload((Payload) o);
}
Object o2 = instream.readObject();
setDiscardList((HashMap) o2);
//EntityUtils.consume(response.getEntity());
}
} finally {
myNovoLogger.finest("closing instream");
if(instream != null) {
myNovoLogger.finest("closing instream");
instream.close();
myNovoLogger.finest("after closing instream");
}
this.client.close();
isValid = false;
connManager.close();
}
}
} finally {
myNovoLogger.finest("Attempt to send request "+rc);
return responseLine;
}
(Additional info : It works the first call then it fails
consecutively...we are upgrading from client 3.2 to 4.5 , have included
both core and client in the tomcat load path)
Can some one find any problem , any inputs are welcome. I am new to
httpclient coding.
Thanks
Hassan
Post by Hassan Khan
Hi Oleg,
Thanks for answering ... very excited (and humbled) to hear from
you...
Post by Hassan Khan
Thanks
Hassan
Post by Oleg Kalnichevski
Post by Hassan Khan
Hi all,
We have pinpointed the issue and looks like the code that deals with
streaming a object from the client to the server.
With the old code (Httpclient 3.1) we would stream the object through a
ObjectOutputStream and on the server side read it through a
ObjectInputStream.
But looks like that workflow is not working in the new httpclient 4.5.
Is there any example or resource that specifically shows how streaming
objects work ?
See this section of the tutorial
http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/
html/fundamen
Post by Hassan Khan
Post by Oleg Kalnichevski
tals.html#d5e95
<http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/
html/fundamentals.html#d5e95>
Post by Hassan Khan
Post by Oleg Kalnichevski
What you most likely want is SerializableEntity
http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/
apidocs/org/apa
Post by Hassan Khan
Post by Oleg Kalnichevski
che/http/entity/SerializableEntity.html
<http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/
apidocs/org/apache/http/entity/SerializableEntity.html>
Post by Hassan Khan
Post by Oleg Kalnichevski
Oleg
Post by Hassan Khan
Thanks
Hassan
On Tue, Apr 18, 2017 at 9:27 AM, Hassan Khan <
Post by Hassan Khan
Hi ,
Sorry the log images was filtered out. you can look at the
uploaded
Post by Hassan Khan
Post by Oleg Kalnichevski
Post by Hassan Khan
Post by Hassan Khan
image.
http://imgur.com/a/Nxpcw
in text the logs say: I/O read timed out.
Thanks
Hassan
On Mon, Apr 17, 2017 at 1:35 PM, Gary Gregory
om>
Post by Gary Gregory
Hassan,
Your attachments were filtered out. You might want to try an
image sharing
site.
Gary
On Mon, Apr 17, 2017 at 6:16 AM, Hassan Khan
.com>
Post by Hassan Khan
+
Hi All,
We are upgrading the httpclient in our software from 3.1
to 4.5 (we
are adding both core and client). But we are having some
issues in the
client and server communications. We are using the below
client code
(simplified the code ) to make a call every 60 secs and we
are getting
localhost not responding after few tries.
RequestConfig config = RequestConfig.*custom*()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.*setStaleConnectionCheckEnabled**(**true**)*
.setSocketTimeout(10 * 60 * 1000).build();
*this*.client =
HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
log error
}
//using the object stream to read data..
ois = *new*
ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread
making a
request every 60 secs. When we used a spooling manager
always
Post by Hassan Khan
Post by Oleg Kalnichevski
Post by Hassan Khan
Post by Hassan Khan
Post by Gary Gregory
Post by Hassan Khan
one
route was
Post by Hassan Khan
used..
May be both thread that are calling the same URL
simultaneously are
sharing one connection , but they should share different
connections..
Thanks
*Hassan Khan*
Software Developer
--
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
Code=as2&tag=garygregory-
20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
Code=as2&tag=garygregory-
20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
nk_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Hassan Khan
---------------------------------------------------------------------
--
Hassan Khan
--
Hassan Khan
--
Hassan Khan
--
Hassan Khan
--
Hassan Khan
Hassan Khan
2017-05-05 13:49:53 UTC
Permalink
Hi,

Finally I could solve the issue... the problem was using NIO connector with
httpclient 4.5

once I changed the connector to APR the problem went away.
The right setting is:
<Connector protocol="org.apache.coyote.http11.Http11AprProtocol"
port="443" clientAuth="false" sslProtocol="TLS"
SSLEnabled="true" maxThreads="150" scheme="https" secure="true"
SSLCertificateFile="ABC.crt"
SSLCertificateKeyFile="TRE.key"
SSLEngine="on" SSLVerifyDepth="2"
/>

Still do not understand how httpclient 3.1 would work with Nio connector
properly.

May be it does not understand NIO principles. Any way thank you all for
your patience.

Thanks
Hassan
Hi,
I had one quick question .... The documentation at https://hc.apache.org/
httpcomponents-core-ga/httpcore/apidocs/org/apache/
http/io/SessionInputBuffer.html says that
*Session input buffer for blocking connections*. This interface is
similar to InputStream class, but it also provides methods for reading
lines of text.
My 443 connector is a non-blocking one... how can I fix this issue.... *Htppclient
has a input buffer for non-blocking connections ?*
<!-- Define a SSL HTTP/1.1 Connector on port 443
Uncomment the section below for a locally installed
connectionTimeout="-1"
Novo Grid and use of a self signed certificate is required
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
for communication to a locally installed Rendezvous -->
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
====> Non-blocking connector
maxThreads="200" SSLEnabled="true" compression="on"
minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" connectionTimeout="-1"
scheme="https" secure="true">
<SSLHostConfig honorCipherOrder="false" >
<Certificate certificateKeystoreFile="XXX"
certificateKeystorePassword="XXX"
certificateKeyAlias="localhost"
type="RSA" />
</SSLHostConfig>
</Connector>
Any inputs?
Thanks
Hassan
Post by Hassan Khan
Thanks for the tip....
After further debugging ... have a usual solution... the code work great
with apache 2.4 ... but not with tomcat 8.5
The changes needed were looks like the http 4.5 SSL validation is more
stricter.
With 3.1 ===> our certificate was applicable for *.Domain, our server
using it was names X.V.Domain == it worked...
With 4.5 ===> the SSL connection gave us a error so we cut our server
name to V.Domian and it worked...
But the most interesting thing that I cannot understand during stepping
throught he code in eclipse the problem was noted in the code below in
protected HttpResponse parseHead(
final SessionInputBuffer sessionBuffer) throws IOException,
HttpException {
//read out the HTTP status string
int count = 0;
ParserCursor cursor = null;
do {
// clear the buffer
this.lineBuf.clear();
final int i = sessionBuffer.readLine(this.lineBuf); //====>
whys is this empty for tomcat 8.5 sometimes and not for apache server 2.4
if (i == -1 && count == 0) {
// The server just dropped connection on us
throw new NoHttpResponseException("The target server
failed to respond");
}
cursor = new ParserCursor(0, this.lineBuf.length());
So kinda looks like there is socket level setting i am missing....
Note : evey 20 secs we are pinging a servlet to get data from the server...
Any ideas let me know.
Thanks
Hassan
Post by Bernd Eckenfels
BTW: If you serialized your object into a BOS you catcall toByteArray()
and give that as an in memory entity content, there is no point to put an
input stream on top of it to feed the entity.
Gruss
Bernd
--
http://bernd.eckenfels.net
________________________________
Sent: Wednesday, April 26, 2017 10:17:44 PM
To: HttpClient User Discussion
Subject: Re: Upgrading from Httpclient 3.1 to 4.5 - localhost:443 not responding
Hi ,
Wanted to know if some one can answer top of their head if
OutputObjectStreams are supported in 4.5 (3.0 does).
All our objects are marked as serializable.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
if (obj != null) {
oos.writeObject(obj);
}
// create an input stream out of the stream
// we put objects into
InputStreamEntity temp = new InputStreamEntity(new
ByteArrayInputStream(baos.toByteArray()));
postMethod.setEntity(temp);
Also while receiving the response, is the method to get response as a
stream changed from
3.0 ==> ObjectInputStream instream = postMethod.getResponseBodyAsSt
ream()
to
4.5 ==> ObjectInputStream instream = new
ObjectInputStream(entity.getContent()) ?
Thanks
Hassan
Hi All,
I have been trying to solve the below issue that show up in logs and
https://localhost/localTomcat8_Rendezvous/comm/sendPayload
Downloader for default channel (C:\Program Files\Apache Software
Foundation\Tomcat 8.5\Instance1\webapps\localTom
cat8_Rendezvous\common),
com.novoInnovations.network.protocol.Connection:sendRequest]
04/25/2017 15:22:33:677 WARNING: Could not get payload from
localTomcat8_Rendezvous located at the path
localhost/localTomcat8_Rendezvous/comm
[Thread-23: Downloader for default channel (C:\Program Files\Apache
Software Foundation\Tomcat 8.5\Instance1\webapps\localTom
cat8_Rendezvous\common),
com.novoInnovations.network.protocol.N2RProtocol:recvPayload]
localhost:443 failed to respond
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(
DefaultHttpResponseParser.java:143)
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(
DefaultHttpResponseParser.java:57)
org.apache.http.impl.io.AbstractMessageParser.parse(
AbstractMessageParser.java:259)
org.apache.http.impl.DefaultBHttpClientConnection.
receiveResponseHeader(DefaultBHttpClientConnection.java:163)
org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(
CPoolProxy.java:167)
org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(
HttpRequestExecutor.java:273)
org.apache.http.protocol.HttpRequestExecutor.execute(
HttpRequestExecutor.java:125)
org.apache.http.impl.execchain.MainClientExec.
execute(MainClientExec.java:271)
org.apache.http.impl.execchain.ProtocolExec.
execute(ProtocolExec.java:184)
org.apache.http.impl.execchain.RetryExec.execute(RetryExec.
java:88)
org.apache.http.impl.execchain.RedirectExec.
execute(RedirectExec.java:110)
org.apache.http.impl.client.InternalHttpClient.doExecute(
InternalHttpClient.java:184)
org.apache.http.impl.client.CloseableHttpClient.execute(
CloseableHttpClient.java:82)
org.apache.http.impl.client.CloseableHttpClient.execute(
CloseableHttpClient.java:107)
com.novoInnovations.network.protocol.Connection.
sendRequest(Connection.java:329)
com.novoInnovations.network.protocol.N2RProtocol.
recvPayload(N2RProtocol.java:137)
com.novoInnovations.network.node.Downloader.
getFromRendezvous(Downloader.java:411)
com.novoInnovations.network.node.Downloader.run(Downloader.
java:141)
the next failure is at 15:22:53:743 , 15:23:13:853, .. so on
The code is below (commented out are the many other ways that i tried
to
solve the issue...), this code is called every 20 secs by a thread, the
target is a url and 443 port since it is https , it works the first
time ..
the post methid has this url set :https://localhost/
localTomcat8_Rendezvous/comm/sendPayload as
postMethod = new HttpPost(this.url);
public String sendRequest(Object obj) throws Exception {
// temporary output stream to stream objects into
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
if (isValid) {
myNovoLogger.finest("Writing node communicator version: " +
VERSION);
oos.writeObject(VERSION);
myNovoLogger.finest("Writing node id: " + this.node.id());
oos.writeObject(this.node.id());
myNovoLogger.finest("Writing node's state");
oos.writeObject(this.state);
myNovoLogger.finest("Writing communication channel: " +
this.getCommunicationChannel());
oos.writeObject(Integer.toString(this.
getCommunicationChannel()));
if (obj != null) {
myNovoLogger.finest("Streaming provided object.");
oos.writeObject(obj);
}
// create an input stream out of the stream
// we put objects into
/* InputStream tis = new ByteArrayInputStream(baos.
toByteArray());
/// take the created inputstream and make this the method's bidy
InputStreamEntity inputStreamEntity = new
InputStreamEntity(tis);
HttpEntity httpEntity = new InputStreamEntity(tis,
tis.available());
//ISSUE in uploading is from here
postMethod.setEntity(inputStreamEntity);*/
InputStreamEntity temp = new InputStreamEntity(new
ByteArrayInputStream(baos.toByteArray()));
postMethod.setEntity(temp);
//postMethod.setRequestBody(tis);
RequestConfig config = RequestConfig.custom()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.setStaleConnectionCheckEnabled(true)
.setSocketTimeout(10 * 60 * 1000).build();
myNovoLogger.finest("Invoking post method: " +
postMethod.getURI().toString());
// execute method on server
PoolingHttpClientConnectionManager connManager = new
PoolingHttpClientConnectionManager();
connManager.setValidateAfterInactivity(200);
ConnectionConfig connectionConfig =
ConnectionConfig.custom()
.setBufferSize(1000)
.build();
// HttpClientBuilder clientBuilder = HttpClients.custom();
// clientBuilder.setRetryHandler(new
DefaultHttpRequestRetryHandler(3, false));
// HttpClient client = clientBuilder.
setDefaultConnectionConfig(connectionConfig).build();
//HttpHost targetHost = new HttpHost(url, 443, "https");
//CloseableHttpResponse response =
client1.execute(targetHost,
postMethod);
this.response = client.execute(postMethod); //====> line
329
String responseLine = null;
/* HttpHost targetHost = new HttpHost(this.url);
this.response = client.execute(targetHost, postMethod);*/
int rc =0;
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
entity = new BufferedHttpEntity(entity);
}
if (entity != null) {
ObjectInputStream instream = new
ObjectInputStream(entity.
getContent());
try {
myNovoLogger.finest("Getting response code.");
myNovoLogger.finest("Got response:" +
response.getStatusLine());
rc = response.getStatusLine().getStatusCode();
if (rc > 200) {
myNovoLogger.warning("Response of " + rc);
myNovoLogger.warning("ResponseBody:" +
response.getStatusLine().getReasonPhrase());
}
myNovoLogger.finest("Getting input stream.");
//ois = new ObjectInputStream(entity.
getContent());
//ois = new ObjectInputStream(postMethod.
getResponseBodyAsStream());
myNovoLogger.finest("Done sending request.");
if(instream != null) {
myNovoLogger.finest("responseLine
instream"+
EntityUtils.toString(entity));
responseLine = (String)
instream.readObject();
setResponseLine(responseLine);
if (Protocol.ACK.equals(responseLine)) {
Object o = instream.readObject();
setPayload((Payload) o);
}
Object o2 = instream.readObject();
setDiscardList((HashMap) o2);
//EntityUtils.consume(response.getEntity());
}
} finally {
myNovoLogger.finest("closing instream");
if(instream != null) {
myNovoLogger.finest("closing instream");
instream.close();
myNovoLogger.finest("after closing instream");
}
this.client.close();
isValid = false;
connManager.close();
}
}
} finally {
myNovoLogger.finest("Attempt to send request "+rc);
return responseLine;
}
(Additional info : It works the first call then it fails
consecutively...we are upgrading from client 3.2 to 4.5 , have included
both core and client in the tomcat load path)
Can some one find any problem , any inputs are welcome. I am new to
httpclient coding.
Thanks
Hassan
Post by Hassan Khan
Hi Oleg,
Thanks for answering ... very excited (and humbled) to hear from
you...
Post by Hassan Khan
Thanks
Hassan
Post by Oleg Kalnichevski
Post by Hassan Khan
Hi all,
We have pinpointed the issue and looks like the code that deals with
streaming a object from the client to the server.
With the old code (Httpclient 3.1) we would stream the object through a
ObjectOutputStream and on the server side read it through a
ObjectInputStream.
But looks like that workflow is not working in the new httpclient 4.5.
Is there any example or resource that specifically shows how streaming
objects work ?
See this section of the tutorial
http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/ht
ml/fundamen
Post by Hassan Khan
Post by Oleg Kalnichevski
tals.html#d5e95
<http://hc.apache.org/httpcomponents-client-4.5.x/tutorial/h
tml/fundamentals.html#d5e95>
Post by Hassan Khan
Post by Oleg Kalnichevski
What you most likely want is SerializableEntity
http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/apid
ocs/org/apa
Post by Hassan Khan
Post by Oleg Kalnichevski
che/http/entity/SerializableEntity.html
<http://hc.apache.org/httpcomponents-core-4.4.x/httpcore/api
docs/org/apache/http/entity/SerializableEntity.html>
Post by Hassan Khan
Post by Oleg Kalnichevski
Oleg
Post by Hassan Khan
Thanks
Hassan
On Tue, Apr 18, 2017 at 9:27 AM, Hassan Khan <
Post by Hassan Khan
Hi ,
Sorry the log images was filtered out. you can look at the
uploaded
Post by Hassan Khan
Post by Oleg Kalnichevski
Post by Hassan Khan
Post by Hassan Khan
image.
http://imgur.com/a/Nxpcw
in text the logs say: I/O read timed out.
Thanks
Hassan
On Mon, Apr 17, 2017 at 1:35 PM, Gary Gregory
om>
Post by Gary Gregory
Hassan,
Your attachments were filtered out. You might want to try an
image sharing
site.
Gary
On Mon, Apr 17, 2017 at 6:16 AM, Hassan Khan
.com>
Post by Hassan Khan
+
Hi All,
We are upgrading the httpclient in our software from 3.1
to 4.5 (we
are adding both core and client). But we are having some
issues in the
client and server communications. We are using the below
client code
(simplified the code ) to make a call every 60 secs and we
are getting
localhost not responding after few tries.
RequestConfig config = RequestConfig.*custom*()
.setConnectTimeout(20 * 1000)
.setConnectionRequestTimeout(10* 60 * 1000)
.*setStaleConnectionCheckEnab
led**(**true**)*
Post by Hassan Khan
Post by Oleg Kalnichevski
Post by Hassan Khan
Post by Hassan Khan
Post by Gary Gregory
Post by Hassan Khan
.setSocketTimeout(10 * 60 * 1000).build();
*this*.client =
HttpClients.*custom*().setDefaultRequestConfig(config
).build();
HttpResponse response = client.execute(postMethod);
*int* rc = response.getStatusLine().getStatusCode();
*if* (rc > 200) {
log error
}
//using the object stream to read data..
ois = *new*
ObjectInputStream(response.getEntity().getContent());
//at the end we close it
postMethod.releaseConnection();
Any recommendations would be appreciated. we have 2 thread
making a
request every 60 secs. When we used a spooling manager
always
Post by Hassan Khan
Post by Oleg Kalnichevski
Post by Hassan Khan
Post by Hassan Khan
Post by Gary Gregory
Post by Hassan Khan
one
route was
Post by Hassan Khan
used..
May be both thread that are calling the same URL
simultaneously are
sharing one connection , but they should share different
connections..
Thanks
*Hassan Khan*
Software Developer
--
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
Code=as2&tag=garygregory-
20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
Code=as2&tag=garygregory-
20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
nk_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
--
Hassan Khan
------------------------------------------------------------
---------
Post by Hassan Khan
--
Hassan Khan
--
Hassan Khan
--
Hassan Khan
--
Hassan Khan
--
Hassan Khan
--
Hassan Khan
Oleg Kalnichevski
2017-05-06 08:37:44 UTC
Permalink
Post by Hassan Khan
Hi,
Finally I could solve the issue... the problem was using NIO
connector with
httpclient 4.5
once I changed the connector to APR the problem went away.
        <Connector
protocol="org.apache.coyote.http11.Http11AprProtocol"
port="443" clientAuth="false" sslProtocol="TLS"
SSLEnabled="true" maxThreads="150" scheme="https" secure="true"
SSLCertificateFile="ABC.crt"
SSLCertificateKeyFile="TRE.key"
    SSLEngine="on" SSLVerifyDepth="2"
   />
Still do not understand how httpclient 3.1 would work with Nio
connector
properly.
httpclient 3.1 does not perform hostname verification of any kind. I
strongly suspect that if you disable hostname verification in
httpclient 4.x it should work with the NIO connector as well.

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Hassan Khan
2017-05-17 16:55:15 UTC
Permalink
Thank oleg for the tip..

I did not change the connector till now.. but with APR itself I starting
using the prod CA certificate that our company has... instead of the self
signed certificate...

With httpClient 3.1 all communication work fine.

But when I upgraded prod to use the new code having httpclient 4.5.... I
get this exception in SSL handshake...
Certificate for XVT doesn't match any of the subject alternative names:
ABC, GFD]

So looks like I need to turn off the hostname verification in the code or
update the Com[any certificate to have CN populated with the values.

I wanted to know what brought the need to have CN in every Certificate
populated gong forward?

Thanks
Hassan
Post by Oleg Kalnichevski
Post by Hassan Khan
Hi,
Finally I could solve the issue... the problem was using NIO
connector with
httpclient 4.5
once I changed the connector to APR the problem went away.
<Connector
protocol="org.apache.coyote.http11.Http11AprProtocol"
port="443" clientAuth="false" sslProtocol="TLS"
SSLEnabled="true" maxThreads="150" scheme="https" secure="true"
SSLCertificateFile="ABC.crt"
SSLCertificateKeyFile="TRE.key"
SSLEngine="on" SSLVerifyDepth="2"
/>
Still do not understand how httpclient 3.1 would work with Nio connector
properly.
httpclient 3.1 does not perform hostname verification of any kind. I
strongly suspect that if you disable hostname verification in
httpclient 4.x it should work with the NIO connector as well.
Oleg
---------------------------------------------------------------------
--
Hassan Khan
Oleg Kalnichevski
2017-05-18 07:35:36 UTC
Permalink
Post by Hassan Khan
Thank oleg for the tip..
I did not change the connector till now.. but with APR itself I starting
using the prod CA certificate that our company has... instead of the self
signed certificate...
With httpClient 3.1 all communication work fine.
As I have already explained earlier. HC 3.x does _not_ do any hostname
validation. It just does not.
Post by Hassan Khan
But when I upgraded prod to use the new code having httpclient
4.5.... I
get this exception in SSL handshake...
    Certificate for XVT doesn't match any of the subject alternative
ABC, GFD]
So looks like I need to turn off the hostname verification in the code or
update the Com[any certificate to have CN populated with the values.
No, you should rather make sure that the hostname and the cert
presented by the server match.
Post by Hassan Khan
I wanted to know what brought the need to have CN in every
Certificate
populated gong forward?
Eh, like, CN being mandatory for a cert, should be a good reason,
should it not?

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-***@hc.apache.org
For additional commands, e-mail: httpclient-users-***@hc.apache.org
Hassan Khan
2017-05-18 11:41:35 UTC
Permalink
You are right.. Thanks.. It was kinda of a wrong question to ask ...
Post by Oleg Kalnichevski
Post by Hassan Khan
Thank oleg for the tip..
I did not change the connector till now.. but with APR itself I starting
using the prod CA certificate that our company has... instead of the self
signed certificate...
With httpClient 3.1 all communication work fine.
As I have already explained earlier. HC 3.x does _not_ do any hostname
validation. It just does not.
Post by Hassan Khan
But when I upgraded prod to use the new code having httpclient 4.5.... I
get this exception in SSL handshake...
ABC, GFD]
So looks like I need to turn off the hostname verification in the code or
update the Com[any certificate to have CN populated with the values.
No, you should rather make sure that the hostname and the cert
presented by the server match.
Post by Hassan Khan
I wanted to know what brought the need to have CN in every
Certificate
populated gong forward?
Eh, like, CN being mandatory for a cert, should be a good reason,
should it not?
Oleg
---------------------------------------------------------------------
--
Hassan Khan
Loading...