httpclient连接重置

时间:2018-11-13 06:02:27

标签: java apache-httpclient-4.x

使用httpclient 4.3

get request url:https://onlinepay.cupdata.com/wxhx/webApply.do?action=applyProgressInit&bankNum=6304&userId=oTBePjhvJt0Pj4zXPlBrzstCbbzQ

这是代码:

    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();
/**
     * 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;
}

以下是日志:

[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:82)
    at com.ykx.ferrari.bank.HttpClientSession.get(HttpClientSession.java:87)
    at com.ykx.ferrari.bank.HuaXia.getPhoneCode(HuaXia.java:27)
    at com.ykx.ferrari.service.impl.OrderInfoService.getBankSMSCode(OrderInfoService.java:590)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at com.ykx.ferrari.base.advice.ServiceMethodAdvice.invoke(ServiceMethodAdvice.java:31)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy88.getBankSMSCode(Unknown Source)
    at com.ykx.ferrari.web.controller.OrderController.getSMSCode(OrderController.java:214)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:89)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at com.ykx.ferrari.init.UserRequestFilter.doFilter(UserRequestFilter.java:62)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

你能帮我吗?非常感谢;

0 个答案:

没有答案