Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ssl CXF RESTful客户端_Ssl_Https_Jax Rs_Cxf_Web Client - Fatal编程技术网

Ssl CXF RESTful客户端

Ssl CXF RESTful客户端,ssl,https,jax-rs,cxf,web-client,Ssl,Https,Jax Rs,Cxf,Web Client,我有一个restorg.apache.cxf.jaxrs.client.WebClient客户端用于测试: WebClient client = WebClient.create(URL); 我想用cxf jax rs发出https请求 我怎么做?示例?好的,这是我的解决方案: public static void configureSSLOnTheClient(WebClient client, String keyStoreFileName, String

我有一个restorg.apache.cxf.jaxrs.client.WebClient客户端用于测试:

        WebClient client = WebClient.create(URL);
我想用cxf jax rs发出https请求


我怎么做?示例?

好的,这是我的解决方案:

public static void configureSSLOnTheClient(WebClient client,
        String keyStoreFileName, String keyStorePassword,
        String trustStoreFileName, String trustStorePassword) {

    HTTPConduit httpConduit = (HTTPConduit) WebClient.getConfig(client).getConduit();
    try {
        TLSClientParameters tlsParams = new TLSClientParameters();

        KeyStore keyStore;
        KeyStore trustStore;
        try {

            keyStore = KeyStore.getInstance("JKS");
            keyStore.load(ClassLoader.getSystemResourceAsStream(keyStoreFileName), keyStorePassword.toCharArray());

            KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            keyManagerFactory.init(keyStore, keyStorePassword.toCharArray());

            trustStore = KeyStore.getInstance("JKS");
            trustStore.load(ClassLoader.getSystemResourceAsStream(trustStoreFileName), trustStorePassword.toCharArray());

            TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            trustManagerFactory.init(trustStore);

            SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
            sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());

            tlsParams.setSSLSocketFactory(sslContext.getSocketFactory());

        } catch (KeyStoreException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // These filters ensure that a ciphersuite with export-suitable or null encryption is used,
        // but exclude anonymous Diffie-Hellman key change as this is vulnerable to man-in-the-middle attacks

        FiltersType filters = new FiltersType();
        filters.getInclude().add(".*_EXPORT_.*");
        filters.getInclude().add(".*_EXPORT1024_.*");
        filters.getInclude().add(".*_WITH_DES_.*");
        filters.getInclude().add(".*_WITH_AES_.*");
        filters.getInclude().add(".*_WITH_NULL_.*");
        filters.getExclude().add(".*_DH_anon_.*");

        tlsParams.setCipherSuitesFilter(filters);

        httpConduit.setTlsClientParameters(tlsParams);

    } catch (Exception exception) {
        LOGGER.error("Security configuration failed with the following: " + exception.getCause(), exception);
    }
}

你看过文件了吗?是的,但是我还没有找到一个完整的带有https请求的jax rs cxf rest客户机示例。请使用https而不是http。或者你在证书方面有问题吗?曼纽尔,你可以接受你自己的答案——这是一个很好的答案!