简体   繁体   English

无法发送显示SocketException的帖子https请求:连接重置

[英]Unable to send post https request showing SocketException: Connection reset

I am sending the https request. 我正在发送https请求。 I have added the client certificate and import to jvm still not able to execute the request, Showing connection request. 我已经添加了客户端证书并导入到jvm,但仍然无法执行该请求,显示连接请求。

private static Registry<ConnectionSocketFactory> scheme = null;

static {

    SSLConnectionSocketFactory socketFactory = null;

    try {
        System.setProperty("javax.net.debug", "all");

        String KEYSTORE_LOCATION = "C:\\Users\\pritesha\\Desktop\\TS1_certs\\wwwin-ts1fin.cisco.com.jks";   
        FileInputStream is = new FileInputStream(new File(KEYSTORE_LOCATION));
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(is, "changeit".toCharArray());

        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(trustStore);
        SSLContext ctx = SSLContext.getInstance("TLSv1");
        ctx.init(null, tmf.getTrustManagers(), null);
        SSLSocketFactory sslFactory = ctx.getSocketFactory();


        SSLContextBuilder sslContextBuilder = SSLContexts.custom().useTLS().loadTrustMaterial(trustStore);
        socketFactory = new SSLConnectionSocketFactory(sslContextBuilder.build());
    } catch (KeyStoreException e) {
        System.out.println("Exception in the loading Key Store...  " + e.getMessage());
    } catch (KeyManagementException e) {
        System.out.println("Exception in the loading Key Store...  " + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        System.out.println("Exception in the loading Key Store...  " + e.getMessage());
    } catch (CertificateException e) {
        System.out.println("Exception in the loading Key Store...  " + e.getMessage());
    } catch (IOException e) {
        System.out.println("Exception in the loading Key Store...  " + e.getMessage());
    }
    scheme = RegistryBuilder.<ConnectionSocketFactory>create().register("https", socketFactory).build();
}

public static String connect() {
    CloseableHttpClient httpclient = null;
    try {
        String URL = "https://wwwin-ts1fin.cisco.com/bpelpcicreatereceipt_client_ep";
        String requestBody = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns1=\"http://xmlns.oracle.com/I2C/PrjPCIReceiptCreation/BPELPCICreateReceipt\"><SOAP-ENV:Header/><SOAP-ENV:Body>"
                + "<ns1:process><ns1:SourceSystem>CCW</ns1:SourceSystem> <ns1:PaymentId>" + 123
                + "</ns1:PaymentId> <ns1:Retry>No</ns1:Retry></ns1:process></SOAP-ENV:Body></SOAP-ENV:Envelope>";

        PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(scheme);
        connectionManager.setMaxTotal(200);
        connectionManager.setDefaultMaxPerRoute(20);

        httpclient = HttpClients.custom().setConnectionManager(connectionManager).build();

        HttpPost httpPost = new HttpPost(URL);

        httpPost.setHeader("Content-Type", "text/xml");

        httpPost.setEntity(new StringEntity(requestBody));

        HttpResponse httpResponse = httpclient.execute(httpPost);

        HttpEntity entity = httpResponse.getEntity();

        if (entity != null) {
            return EntityUtils.toString(entity);
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

This is the full stacktrace I get: 这是我得到的完整堆栈跟踪:

[Raw read]: length = 5 0000: 15 03 03 00 02 ..... main, handling exception: java.net.SocketException: Connection reset main, SEND TLSv1 ALERT: fatal, description = unexpected_message main, WRITE: TLSv1 Alert, length = 2 main, Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error main, called closeSocket() [原始读取]:长度= 5 0000:15 03 03 00 02 .....主要,处理异常:java.net.SocketException:连接重置主要,SEND TLSv1警告:致命,描述=意外消息主要,写:TLSv1警报,长度= 2 main,发送异常通知:java.net.SocketException:对等连接重置:套接字写入错误main,称为closeSocket()

First, this being an TLS alert, you need much better insight of what alert it is. 首先,这是TLS警报,您需要更好地了解它是什么警报。 Install wireshark and sniff the session. 安装wireshark并监听会话。 Drill down in the alert msg and wireshark dissectors will explain a bit more the issue. 深入查看警报消息和Wireshk解剖器,将进一步解释该问题。

I suspect you don't have a common cipher suite negociated. 我怀疑您没有协商通用的密码套件。 You chose tls v1 but cicso might have higher version, hence a set cipher suites you chose not to offer by downgrading to tls 1.0 (which is ssl v3, not surprisingly rejected by cisco). 您选择了tls v1,但是cicso可能具有更高的版本,因此您选择不降级到tls 1.0(这是ssl v3,并不令人惊讶地被cisco拒绝)而提供的一组密码套件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM