0

I am using Apache http client 3 in the multithreaded environment and sending http post request as xml based to other party server.

I can able to simulate in my local system

  1. java.net.ConnectException => when server is down
  2. java.net.SocketTimeoutException => when server accepted my connection and not able to send response back to my application within some time which we configured.

but in the real-time running environment , i have received the new exception like org.apache.commons.httpclient.ConnectTimeoutException

Questions:

  1. what is the difference b/w java.net.ConnectException vs org.apache.commons.httpclient.ConnectTimeoutException

  2. how to simulate org.apache.commons.httpclient.ConnectTimeoutException in local system

any inputs will use full.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
Mohan
  • 35
  • 6

1 Answers1

0

The main difference between java.net.ConnectException (next just ConnectException) and org.apache.commons.httpclient.ConnectTimeoutException (next just ConnectTimeoutException) is that ConnectException is thrown when a connection cannot be established to the server, while ConnectTimeoutException is thrown when the connection to the server is established but the server takes too long time to respond.

  1. You can read more about ConnectException here and here.
  2. As for ConnectTimeoutException - here and here - I don’t know which exact version you are using.

To simulate ConnectTimeoutException in your local system, you can try the following:

  1. Start a local server that takes a long time to respond to requests.
  2. In your Java code, set a small connection timeout for the Apache HttpClient by using the HttpConnectionParams.setConnectionTimeout(int timeout) method.
Volodya Lombrozo
  • 2,325
  • 2
  • 16
  • 34