调用web服务时获取socketexception

tag5nh1u  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(245)

我有三个环境(test、dev和prod)。我编写了一个调用web服务的代码。它在测试和开发环境中工作(三种环境有不同的web服务htttp链接),但是当涉及到prod web服务链接时。我的代码出现以下错误;
错误:

java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:210)
        at java.net.SocketInputStream.read(SocketInputStream.java:141)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
        at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
        at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735)
        at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
        at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:706)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1593)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
        at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
        at com.turkcell.cloudidm.callbackservices.CallBackResponse.invokedirectCRMURL(CallBackResponse.java:348)
        at com.turkcell.cloudidm.callbackservices.CallBackResponse.callCRMStatus(CallBackResponse.java:160)
        at com.turkcell.cloudidm.CallBackManagementTask.callBackRequests(CallBackManagementTask.java:152)
        at com.turkcell.cloudidm.CallBackManagementTask.execute(CallBackManagementTask.java:36)
        at oracle.iam.scheduler.vo.TaskSupport.invokeExecute(TaskSupport.java:434)
        at oracle.iam.scheduler.vo.TaskSupport.access$000(TaskSupport.java:63)
        at oracle.iam.scheduler.vo.TaskSupport$1.processWithoutResult(TaskSupport.java:342)
        at oracle.iam.platform.tx.OIMTransactionCallbackWithoutResult.process(OIMTransactionCallbackWithoutResult.java:9)
        at oracle.iam.platform.tx.OIMTransactionCallback.doInTransaction(OIMTransactionCallback.java:13)
        at oracle.iam.platform.tx.OIMTransactionCallback.doInTransaction(OIMTransactionCallback.java:6)
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
        at oracle.iam.platform.tx.OIMTransactionManager.executeTransaction(OIMTransactionManager.java:47)
        at oracle.iam.scheduler.vo.TaskSupport.executeJob(TaskSupport.java:336)
        at sun.reflect.GeneratedMethodAccessor2484.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at oracle.iam.scheduler.impl.quartz.QuartzJob$TaskExecutionAction.run(QuartzJob.java:293)
        at java.security.AccessController.doPrivileged(Native Method)
        at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:259)
        at oracle.security.jps.internal.jaas.AccActionExecutor.execute(AccActionExecutor.java:61)
        at oracle.security.jps.internal.jaas.AbstractSubjectSecurity$ActionExecutorWrapper.execute(AbstractSubjectSecurity.java:268)
        at oracle.security.jps.internal.jaas.CascadeActionExecutor$SubjectPrivilegedAction.run(CascadeActionExecutor.java:67)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:344)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:137)
        at weblogic.security.Security.runAs(Security.java:42)
        at oracle.security.jps.wls.jaas.WlsActionExecutor.execute(WlsActionExecutor.java:46)
        at oracle.security.jps.internal.jaas.CascadeActionExecutor.execute(CascadeActionExecutor.java:49)
        at oracle.security.jps.internal.jaas.AbstractSubjectSecurity$ActionExecutorWrapper.execute(AbstractSubjectSecurity.java:268)
        at Thor.API.Security.LoginHandler.AssertionLoginSession.runAs(AssertionLoginSession.java:93)
        at oracle.iam.scheduler.impl.quartz.QuartzJob.execute(QuartzJob.java:87)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:223)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
03/12/2020 21:35:36 [com.turkcell.cloudidm.callbackservices.CallBackResponse] --> Retrun Value: FAIL, Error while calling web service: java.net.SocketException: Connection reset

代码:

public String invokedirectCRMURL (StringBuilder strBuilder, String wsEndPoint) throws Exception {

    callBackResponseUtils.outLog(this.getClass().getName()," invokedirectCRMURL method is started, URL is:  ----> " +wsEndPoint );
    int responseCode = 0;

        try {

            String responseString = "";
            String outputString = "";

            //invokeHttpsRequestOverGateway 

            URL url;
            url = new URL(null, wsEndPoint, new sun.net.www.protocol.http.Handler());
            URLConnection connection = url.openConnection();

            HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();

            // HttpURLConnection httpConn = (HttpURLConnection) connection;
            ByteArrayOutputStream bout = new ByteArrayOutputStream();

            String xmlInput = strBuilder.toString();
            String parsexmlinput = xmlInput;
            parsexmlinput = callBackResponseUtils.formatXML(parsexmlinput);
            // !! YORUM SATIRI !!
            callBackResponseUtils.outLog(this.getClass().getName(), "After format xml parse string xml body");
            parsexmlinput = xmlInput.substring(xmlInput.indexOf("<soap:Body>"), xmlInput.length());
            callBackResponseUtils.outLog(this.getClass().getName(), "Call CRM Web Service with following SOAP Body:" );
//          callBackResponseUtils.outLog(this.getClass().getName(), parsexmlinput);
            byte[] buffer = new byte[xmlInput.length()];
            buffer = xmlInput.getBytes();
            bout.write(buffer);
            byte[] b = bout.toByteArray();
            System.out.println("Before SOAP action");
            String SOAPAction = "getIdmCallBackStatus";
            httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
            httpConn.setRequestProperty("Content-Type", "application/soap+xml;charset=UTF-8");
            httpConn.setRequestProperty("SOAPAction", SOAPAction);

            callBackResponseUtils.outLog(this.getClass().getName(), "Response Code : " + responseCode);

            httpConn.setRequestMethod("POST");
            httpConn.setDoOutput(true);
            httpConn.setDoInput(true);
            OutputStream out = httpConn.getOutputStream();
            // Write the content of the request to the outputstream of the HTTP
            // Connection.
            out.write(b);
            out.close();
            // Ready with sending the request.
            // Read the response.
            responseCode = httpConn.getResponseCode();

            InputStreamReader isr = new InputStreamReader(httpConn.getInputStream(), Charset.forName("UTF-8"));
            BufferedReader in = new BufferedReader(isr);
            // Write the SOAP message response to a String.
            while ((responseString = in.readLine()) != null) {
                outputString = outputString + responseString;
            }
            // Write the SOAP message formatted to the console.
            String formattedSOAPResponse = callBackResponseUtils.formatXML(outputString);

            callBackResponseUtils.outLog(this.getClass().getName(),
                    "ResultObject Code " + callBackResponseUtils.parseCRMResponse(formattedSOAPResponse));
            callBackResponseUtils.outLog(this.getClass().getName(), "Response Code: " + httpConn.getResponseCode());
            if (httpConn.getResponseCode() >= 200 && httpConn.getResponseCode() < 300
                    && callBackResponseUtils.parseCRMResponse(formattedSOAPResponse).equalsIgnoreCase("0")) {
                callBackResponseUtils.outLog(this.getClass().getName(), "Retrun Value: SUCCESS");
                return "SUCCESS";
            } 

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            callBackResponseUtils.outLog(this.getClass().getName(), "Retrun Value: FAIL, Error while calling web service: " + e.toString());

        }

你知道是什么导致这个问题吗?
当做,

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题