连接已关闭:javax.net.ssl.SSLException:SSL对等体错误关闭

时间:2019-04-03 15:24:40

标签: java rest ssl jersey-client

我正在尝试与azure vsts连接,并使用java获取工作项数据及其修订版数据。但有时我会收到如下错误: com.sun.jersey.api.client.ClientHandlerException:javax.net.ssl.SSLException:连接已关闭:javax.net.ssl.SSLException:SSL对等点错误关闭。我在以下代码的这一行上收到此错误:data = clientResponse.getEntity(String.class);                     jsonResponse =新的JSONObject(data);

我尝试设置System.setProperty(“ https.protocols”,“ TLSv1,TLSv1.1,TLSv1.2”);我也尝试过使用Java配置设置手动选择仅TLSv1.2,但仍然存在错误。我观察到问题并非每次都出现。到时候了 我的代码:

if (i == 0)
                    logger.info("fetching data one by one pls wait.....");

                ClientResponse responsenew = null;

                if (tfsurl.contains("https")) {

                    try {

                        /*
                         * webResourceNew = clientNew.resource(tfsurl + "/" +
                         * prjName + "/_apis/wit/workitems/" + ((JSONObject)
                         * ids.get(i)).getString("id"));
                         */
                        url = tfsurl + "/" + prjName + "/_apis/wit/workitems?ids=" + partitions.get(i)
                                + "&api-version=5.0";
                        url=url.replace("[", "").replace("]", "").replaceAll(" ", "");
                        logger.info(url + "url>>>>>>>>>>");
                        webResourceNew = clientNew.resource(url);
                    }

                    catch (Exception e) {
                        logger.info("error in sending request to client");
                        e.printStackTrace();
                    }

 try {
                    responsenew = webResourceNew.type("application/json").accept("application/json")
                            .header("Authorization", "Basic " + authStringEnc).get(ClientResponse.class);

                } catch (Exception e) {
                    logger.info("error in response of workitems data");
                    e.printStackTrace();
                }

                logger.info(responsenew.toString());
                responses.add(responsenew);

            } else {

                webResource = client.resource("http://" + username + ":" + token + "@"
                        + tfsurl.substring(7, tfsurl.length()) + "/" + collectionName + "/"
                        + "/_apis/wit/workitems/" + ((JSONObject) ids.get(i)).getString("id"));

                /*
                 * System.out.println("http://" + username + ":" + token +
                 * "@" + tfsurl.substring(7, tfsurl.length()) + "/" +
                 * collectionName + "/" + "/_apis/wit/workitems/" +
                 * ((JSONObject) ids.get(i)).getString("id"));
                 */
                response = webResource.type("application/json").accept("application/json")
                        .get(ClientResponse.class);

                responses.add(response);

            }

        }
        clientNew.destroy();

        // @Author RAJESH
        // Getting value for one defects at a time
        for (ClientResponse clientResponse : responses) {
            try {
                data = "";
                JSONObject jsonResponse;
                data = clientResponse.getEntity(String.class);
                jsonResponse = new JSONObject(data);
                System.out.println("printing workitems json>>>" +
                         jsonResponse);
                /* Thread.sleep(3000); */
                /*
                 * System.out.println("printing workitems data>>>" + data);
                 * System.out.println("printing workitems json>>>" +
                 * jsonResponse);
                 */String ProjectNme = "", projectInput = "";
                projectInput = prjName;
                JSONArray val=jsonResponse.getJSONArray("value");


                for(int a=0;a<val.length();a++)
                {

                    JSONObject workitemData = val.getJSONObject(a);

                JSONObject fieldsJson = workitemData.getJSONObject("fields");

我遇到的错误:

    com.sun.jersey.api.client.ClientHandlerException: 
    javax.net.ssl.SSLException: Connection has been shutdown: 
    javax.net.ssl.SSLException: SSL peer shut down incorrectly
    at com.sun.jersey.api.client.ClientResponse.close(ClientResponse.java:603)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:562)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:506)
at com.lntinfotech.tcoe.tfs.TFSDataFetcher.indexTFS(TFSDataFetcher.java:427)
at com.lntinfotech.tcoe.controller.TcoeWordcloudController.indexData(TcoeWordcloudController.java:4083)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.lntinfotech.tcoe.supportClasses.CrossScriptingFilter.doFilter(CrossScriptingFilter.java:30)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: SSL peer shut down incorrectly
at sun.security.ssl.SSLSocketImpl.checkEOF(Unknown Source)
at sun.security.ssl.AppInputStream.available(Unknown Source)
at java.io.BufferedInputStream.available(Unknown Source)
at sun.net.www.MeteredStream.available(Unknown Source)
at sun.net.www.http.KeepAliveStream.close(Unknown Source)
at java.io.FilterInputStream.close(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.close(Unknown Source)
at com.sun.jersey.api.client.ClientResponse.close(ClientResponse.java:601)
... 45 more
Caused by: javax.net.ssl.SSLException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.readV3Record(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.net.www.MeteredStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.Reader.read(Unknown Source)
at com.sun.jersey.core.util.ReaderWriter.readFromAsString(ReaderWriter.java:171)
at com.sun.jersey.core.util.ReaderWriter.readFromAsString(ReaderWriter.java:157)
at com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.readFromAsString(AbstractMessageReaderWriterProvider.java:114)
at com.sun.jersey.core.impl.provider.entity.StringProvider.readFrom(StringProvider.java:73)
at com.sun.jersey.core.impl.provider.entity.StringProvider.readFrom(StringProvider.java:58)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:553)
... 44 more
2019-04-03 18:58:45 ERROR TFSDataFetcher:1169 - failed in indexing for tfs after getting workitems
2019-04-03 18:58:45 INFO  TcoeWordcloudController:4235 - Indexing Completed
data rajesh>>>>> Error failed in indexing for tfs after getting workitems

0 个答案:

没有答案