HttpClient异常总结

Exception handling

(排在前面的异常的优先级低)

http://hc.apache.org/httpclient-3.x/exception-handling.html

There are two main type of exceptions that the user of HttpClient may encounter when executing HTTP methods:

 

1.transport exceptions

 

java.io.IOException

java的IOException代表HttpClient的通用的transport exceptions

 

org.apache.commons.httpclient.NoHttpResponseException

  • In some circumstances, usually when under heavy load, the web server may be able to receive requests but unable to process them. A lack of sufficient resources like worker threads is a good example. This may cause the server to drop the connection to the client without giving any response. HttpClient throws NoHttpResponseException when it encounters such a condition. In most cases it is safe to retry a method that failed with NoHttpResponseException.
  • 在某些情况下,通常在高负载时,web server可以接收到请求,但无法处理它们。缺乏足够的资源,如缺少工作线程。这可能会导致服务器将连接丢回到客户端,而不给予任何回应。HttpClient抛出nohttpresponseexception遇到这种情况的时候。在大多数情况下,一个方法抛出NoHttpResponseException,重试是一个安全的办法。

 

org.apache.commons.httpclient.ConnectTimeoutException

  • This exception signals that HttpClient is unable to establish a connection with the target server or proxy server within the given period of time.
  • HttpClient无法在指定的时间内与目标服务器或代理服务器建立连接。

 

org.apache.commons.httpclient.ConnectionPoolTimeoutException

  • This exception can only occur when using the multithreaded connection manager. The exception signals that the connection manager fails to obtain a free connection from the connection pool within the given period of time.
  • ConnectionPoolTimeoutException只会发生在使用多线程connection manager的时候。connection manager无法在一定时间内获连接池中空闲的连接,就会抛出这个异常。

 

2.protocol exceptions

 

org.apache.commons.httpclient.HttpException

  • HttpException represents an abstract logical error in HttpClient. Generally this kind of exception cannot be automatically recovered from.
  • HttpClient中用HttpException代表抽象的逻辑错误,通常这种异常不能自动恢复。

 

org.apache.commons.httpclient.ProtocolException

  • ProtocolException signals a violation of the HTTP specification. It is important to note that HTTP proxies and HTTP servers can have different level of HTTP specification compliance. It may be possible to recover from some HTTP protocol exceptions by configuring HttpClient to be more lenient about non-fatal protocol violations.
  • ProtocolException 表示违反HTTP规范。

 

中间还有一些HttpClient的内部异常

 

org.apache.commons.httpclient.RedirectException

  • RedirectException signals violation of the HTTP specification caused by an invalid redirect response. If the application that uses HttpClient needs to be more lenient about redirect responses, it may choose to disable automatic redirect processing and implement a custom redirect strategy.
  • 无效的重定向相应。可以选择禁用自动重定向处理,并实现自定义的重定向策略。

 

org.apache.commons.httpclient.URIException

  • URIException is thrown when the request URI violates the URI specification.
  • 请求uri不符合规范会抛出URIException。

 

你可能感兴趣的:(http)