67,513
社区成员
发帖
与我相关
我的任务
分享
[DEBUG] 2018-11-13 12:57:47,903 [http-bio-8080-exec-3] [org.apache.http.client.protocol.RequestAddCookies:122] [reqid=F6MG3H9MV5] - CookieSpec selected: best-match
[DEBUG] 2018-11-13 12:57:47,924 [http-bio-8080-exec-3] [org.apache.http.client.protocol.RequestAuthCache:75] [reqid=F6MG3H9MV5] - Auth cache not set in the context
[DEBUG] 2018-11-13 12:57:47,926 [http-bio-8080-exec-3] [org.apache.http.impl.conn.PoolingHttpClientConnectionManager:215] [reqid=F6MG3H9MV5] - Connection request: [route: {s}->https://onlinepay.cupdata.com:443][total kept alive: 0; route allocated: 0 of 400; total allocated: 0 of 800]
[DEBUG] 2018-11-13 12:57:47,957 [http-bio-8080-exec-3] [org.apache.http.impl.conn.PoolingHttpClientConnectionManager:246] [reqid=F6MG3H9MV5] - Connection leased: [id: 0][route: {s}->https://onlinepay.cupdata.com:443][total kept alive: 0; route allocated: 1 of 400; total allocated: 1 of 800]
[DEBUG] 2018-11-13 12:57:47,962 [http-bio-8080-exec-3] [org.apache.http.impl.execchain.MainClientExec:216] [reqid=F6MG3H9MV5] - Opening connection {s}->https://onlinepay.cupdata.com:443
[DEBUG] 2018-11-13 12:57:48,173 [http-bio-8080-exec-3] [org.apache.http.conn.HttpClientConnectionManager:114] [reqid=F6MG3H9MV5] - Connecting to onlinepay.cupdata.com/115.231.23.70:443
[DEBUG] 2018-11-13 12:57:48,235 [http-bio-8080-exec-3] [org.apache.http.impl.conn.DefaultManagedHttpClientConnection:87] [reqid=F6MG3H9MV5] - http-outgoing-0: Shutdown connection
[DEBUG] 2018-11-13 12:57:48,235 [http-bio-8080-exec-3] [org.apache.http.impl.execchain.MainClientExec:126] [reqid=F6MG3H9MV5] - Connection discarded
[DEBUG] 2018-11-13 12:57:48,235 [http-bio-8080-exec-3] [org.apache.http.impl.conn.DefaultManagedHttpClientConnection:79] [reqid=F6MG3H9MV5] - http-outgoing-0: Close connection
[DEBUG] 2018-11-13 12:57:48,235 [http-bio-8080-exec-3] [org.apache.http.impl.conn.PoolingHttpClientConnectionManager:282] [reqid=F6MG3H9MV5] - Connection released: [id: 0][route: {s}->https://onlinepay.cupdata.com:443][total kept alive: 0; route allocated: 0 of 400; total allocated: 0 of 800]
[INFO ] 2018-11-13 12:57:48,235 [http-bio-8080-exec-3] [org.apache.http.impl.execchain.RetryExec:93] [reqid=F6MG3H9MV5] - I/O exception (java.net.SocketException) caught when processing request: Connection reset
[DEBUG] 2018-11-13 12:57:48,235 [http-bio-8080-exec-3] [org.apache.http.impl.execchain.RetryExec:98] [reqid=F6MG3H9MV5] - Connection reset
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:262)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:118)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:8
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HeaderIterator;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
import org.apache.http.impl.client.DefaultRedirectStrategy;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
public class HttpClientSession {
public Log logger = LogFactory.getLog(HttpClientSession.class);
public CloseableHttpClient httpClient = null;
public HttpClientContext context = null;
public CookieStore cookieStore = null;
public RequestConfig requestConfig = null;
private static int maxConnTotal = 800;
private static int maxConnPerRoute = 400;
public HttpClientSession() {
context = HttpClientContext.create();
cookieStore = new BasicCookieStore();
requestConfig = RequestConfig.custom().setConnectTimeout(120000).setSocketTimeout(60000).setConnectionRequestTimeout(60000).build();
httpClient = HttpClientBuilder.create().setMaxConnTotal(maxConnTotal).setMaxConnPerRoute(maxConnPerRoute).setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()).setRedirectStrategy(new DefaultRedirectStrategy()).setDefaultRequestConfig(requestConfig).setDefaultCookieStore(cookieStore).build();
}
public void colsed() {
try {
httpClient.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* http get
*
* @param url
* @return response
* @throws ClientProtocolException
* @throws IOException
*/
public CloseableHttpResponse get(String url) throws ClientProtocolException, IOException {
HttpGet httpget = new HttpGet(url);
httpget.setHeader("Connection", "close");
httpget.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
CloseableHttpResponse response = httpClient.execute(httpget, context);
if (response.getStatusLine().getStatusCode() != 200) {
httpget.abort();
return null;
}
try {
System.err.println(url);
cookieStore = context.getCookieStore();
List<org.apache.http.cookie.Cookie> cookies = cookieStore.getCookies();
for (org.apache.http.cookie.Cookie cookie : cookies) {
logger.debug("key:" + cookie.getName() + " value:" + cookie.getValue());
}
} finally {
// response.close();
}
return response;
}
}