简体   繁体   English

具有客户端认证连接的HTTP客户端的SOAP请求超时异常

[英]SOAP Request with HTTP Client with client certification connection timed out Exception

I am trying to hit an url with client certification have generate key with: 我试图通过客户端认证获得一个url生成密钥:

keytool -genkey -alias server -keyalg RSA -keystore /example.jks -validity 10950

and key store with: 和钥匙店:

keytool -import -trustcacerts -alias root -file /example.cer -keystore /example.jks

and trying to connect: 并尝试连接:

System.out.println("------------------------------------------- In         SendRequest ------------------------------------################");
SSLContext context = SSLContext.getInstance("TLS");
Certificate cert=getCertificate();
URL url = new URL("url");
URLConnection urlConnection = url.openConnection();
HttpsURLConnection httpsUrlConnection = (HttpsURLConnection) urlConnection;
SSLSocketFactory sslSocketFactory = getFactory();
httpsUrlConnection.setSSLSocketFactory(sslSocketFactory);
DataOutputStream wr = new         DataOutputStream(httpsUrlConnection.getOutputStream());
System.out.println(wr.toString());
File req_xml = new File("request.xml");
//SOAPMessage req = TestCase.createSoapSubsribeRequest("SUBSCRIBE");
HttpPost post = new HttpPost("url");
post.setEntity(new InputStreamEntity(new FileInputStream(req_xml), req_xml.length()));
post.setHeader("Content-type", "text/xml; charset=UTF-8");
//post.setHeader("SOAPAction", "");
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(post);

LOG.info("************************************************************RESPONSE****************"+response.getStatusLine());
// SOAP response(xml) get        String res_xml = EntityUtils.toString(response.getEntity());
    LOG.info("Response"+res_xml);
}
private SSLSocketFactory getFactory( )  {
    try{ 
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        System.out.println("------------------------------------------- In getFactory ------------------------------------################");
        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
        //InputStream keyInput = new FileInputStream(pKeyFile);
        String password = "obsmesh";
                    char[] passwd = password.toCharArray(example.jks");
        keystore.load(is, passwd);
        // keyInput.close();
        keyManagerFactory.init(keystore, password.toCharArray());
        System.out.println("------------------------------------------- In jsdkl ------------------------------------################");
        SSLContext context = SSLContext.getInstance("TLS");
        TrustManager[] trust = null;
        context.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());
        return context.getSocketFactory();
}catch(Exception e){
    System.out.println(e);
}
return null;

} }

Try with this code I hope it will help you. 尝试使用此代码我希望它能帮到你。

     KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());

    // Trust own CA and all self-signed certs
    SSLContext sslcontext = SSLContexts.custom()
            .loadTrustMaterial(new File("//your jks file path "), "//key password here",
                    new TrustSelfSignedStrategy())
            .build();
    // Allow TLSv1 protocol only
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
            sslcontext,
            new String[] { "TLSv1" },
            null,
            SSLConnectionSocketFactory.getDefaultHostnameVerifier());
    CloseableHttpClient httpclient = HttpClients.custom()
            .setSSLSocketFactory(sslsf)
            .build();
    try {


     File req_xml = new File("// your request xml file path");


   HttpPost post = new HttpPost("//https client url");
   post.setEntity(new InputStreamEntity(new FileInputStream(req_xml), req_xml.length()));
   post.setHeader("Content-type", "text/xml; charset=UTF-8");

        System.out.println("Executing request " + post.getRequestLine());

        CloseableHttpResponse response = httpclient.execute(post);
        try {
            HttpEntity entity = response.getEntity();

            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            EntityUtils.consume(entity);
            System.out.println(response.getEntity());
        } finally {
            response.close();
        }
    } finally {
        httpclient.close();
    }

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

相关问题 Soap Connection在Java客户端中超时,但在SOAPUI中超时 - Soap Connection timed out in Java client but not in SOAPUI HTTP传输错误:java.net.ConnectException:连接超时:在Soap ws客户端中连接 - HTTP transport error: java.net.ConnectException: Connection timed out: connect in Soap ws client 具有Android客户端的Linux服务器:连接超时 - Linux server with Android client: connection timed out “java.io.IOException:连接超时”VS HttpTimeoutException 在 java 11 HTTP 客户端上 - “java.io.IOException: Connection timed out” VS HttpTimeoutException On java 11 HTTP Client 休息客户端 java.net.ConnectException:连接超时:连接 - Rest client java.net.ConnectException: Connection timed out: connect Java客户端-服务器项目中的连接超时错误 - Connection timed out error in java client-server project 客户端检查连接的尝试已超时。-Mulesoft 错误 - An attempt by a client to checkout a Connection has timed out.-Mulesoft Error 尝试发出简单的 Http GET 请求时连接超时 - Connection timed out when trying to make a simple Http GET request SOAP客户端应用程序异常 - SOAP client application exception 客户端请求示例SOAP - Example client request SOAP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM