HttpClient异常总结
2015-10-14 15:27
531 查看
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。
相关文章推荐
- HttpClient 笔记、资料总结和汇总
- 项目总结-利用HttpClient发送表单数据
- ranong项目总结-HttpClient-HttpDelete支持HttpEntity
- HttpClient解析页面总结
- Golang http.DefaultClient 连接服务端压测时出现大量TIME_WAIT异常
- Android 通过httpclient 调用碰到的问题总结
- HttpClient 异常出现不关闭引发的血案
- Android异常总结---type Status report message HTTP method GET is not supported by this URL
- 基础学习总结(八)--HttpClient
- HttpClient 4.01 使用总结
- HttpClient和HtmlUnit的比较总结
- HttpClient对象的应用与总结
- (十五)httpClient、HttpUrlConnecttion调研总结
- HttpClient 初步——总结
- HTTP Client使用总结
- JAVA总结:常见的Java异常归类表 http://webservices.ctocio.com.cn/java/64/9361564_1.shtml
- HttpClient的CircularRedirectException异常原因及解决办法
- HTTP传输层异常处理办法及测试总结
- Httpclient使用总结
- 【Java网络编程】HttpClient、URLConnection的再次总结