一:链接超时:connectionTimeoutapp
1:指的是链接一个url的链接等待时间。post
二:读取数据超时:soTimeouturl
1:指的是链接上一个url,获取response的返回等待时间。blog
For example:get
// 设置链接时间 client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); client.getHttpConnectionManager().getParams().setSoTimeout(60000);
/** * 消息发送处理. * HTTP发送方式 * @param content 消息内容 * @return 返回消息 */ private GeneralReturnInfo postHttpData(String content) { GeneralReturnInfo out = new GeneralReturnInfo(); String result = ""; PostMethod postMethod = new PostMethod(serviceUrl); try { postMethod.setParameter("content", content); HttpClient client = new HttpClient(); client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8"); // 设置链接时间 client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); client.getHttpConnectionManager().getParams().setSoTimeout(60000); int status = client.executeMethod(postMethod); if (status == HttpStatus.SC_OK) { result = postMethod.getResponseBodyAsString(); if (StringUtils.isEmpty(result)) { String msg="HTTP访问失败(返回报文为空)(" + serviceUrl + ")."; System.err.println(msg); throw new AdapterException(ErrorType.CLIENT_NET_ERROR, "", msg); } out = JSON.parseObject(result, GeneralReturnInfo.class); } else { String msg="HTTP访问:返回状态不等于200(" + status + ")(" + serviceUrl + "))."; System.err.println(msg); throw new AdapterException(ErrorType.CLIENT_NET_ERROR, "", msg); } } catch (Exception e) { // 将新产生的例外封装 if (e instanceof AdapterException) { throw (AdapterException) e; } else if (e instanceof ConnectException) { System.err.println("HTTP访问失败(链接失败)(" + serviceUrl + "))."); throw new AdapterException(ErrorType.CLIENT_NET_ERROR, e, "HTTP访问失败(链接失败)(" + serviceUrl + "))."); } else if (e instanceof ConnectTimeoutException) { System.err.println("HTTP访问失败(链接超时)(" + serviceUrl + "))."); throw new AdapterException(ErrorType.CLIENT_NET_ERROR, e, "HTTP访问失败(链接超时)(" + serviceUrl + "))."); } else if (e instanceof SocketTimeoutException) { System.err.println("HTTP访问失败(访问超时)(" + serviceUrl + "))."); throw new AdapterException(ErrorType.CLIENT_NET_ERROR, e, "HTTP访问失败(访问超时)(" + serviceUrl + "))."); } else { System.err.println("HTTP访问失败(调用异常)(" + serviceUrl + "))."); throw new AdapterException(ErrorType.CLIENT_NET_ERROR, e, "HTTP访问失败(调用异常)(" + serviceUrl + "))."); } } finally { // 释放链接 postMethod.releaseConnection(); } return out; }
com.creditharmony.apporveadapter.core.client.ClientPoxy 第170行;it