简体   繁体   English

如何使HttpClient 5的Conscrypt SSL Provider在Tomcat Web应用程序中工作

[英]How to make Conscrypt SSL Provider with HttpClient 5 work in Tomcat web app

I'm using Apache HttpClient 5 along with Conscrypt to perform simultaneous HTTP 2.0 requests over SSL as shown below: 我正在使用Apache HttpClient 5Conscrypt来通过SSL执行同时的HTTP 2.0请求,如下所示:

final SSLContext sslContext;
    try {
        sslContext = SSLContexts.custom()
                .setProvider(Conscrypt.newProvider())
                .build();
    } catch (Exception e) {
         // ... omitted for brevity
    }

    final PoolingAsyncClientConnectionManager cm = PoolingAsyncClientConnectionManagerBuilder.create()
            .setTlsStrategy(new ConscriptClientTlsStrategy(sslContext))
            .build();

    final CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
            .setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
            .setConnectionManager(cm)
            .build();

    try {
        httpclient.start();
        HttpHost host = new HttpHost("www.wikidata.org");
        final HttpClientContext clientContext = HttpClientContext.create();

        final SimpleHttpRequest request = SimpleHttpRequests.GET.create(host, "/w/api.php?action=wbsearchentities&search=Washington");
            request.addHeader("Accept-Charset", charset);
            FutureCallback<SimpleHttpResponse> callback = // ... omitted for brevity
            httpclient.execute(SimpleRequestProducer.create(request),
                    SimpleResponseConsumer.create(),
                    clientContext,
                    callback);
     }
     catch (Exception e) {
         // ... omitted for brevity
     }

Running the code in a unit test is successful. 在单元测试中运行代码成功。 However, if run as part of a web application running in Tomcat v8, it throws the following exception at the call Conscrypt.newProvider() : message: java.lang.UnsatisfiedLinkError: Failed creating temp file (null) . 但是,如果作为在Tomcat v8中运行的Web应用程序的一部分运行,它将在调用Conscrypt.newProvider()时引发以下异常: message: java.lang.UnsatisfiedLinkError: Failed creating temp file (null) It looks like a privilege problem. 看来是特权问题。 Could someone point out what in this context should I configure to solve the problem? 有人可以指出在这种情况下我应该配置什么来解决问题吗?

You need to set conscrypt-openjdk-uber-1.4.2.jar in classpath instead of conscrypt-openjdk-1.4.2.jar , hope this solves your problem as uber jar will have all the dependencies required for conscrypt. 您需要在类路径中设置conscrypt-openjdk-uber-1.4.2.jar而不是conscrypt-openjdk-1.4.2.jar ,希望这可以解决您的问题,因为uber jar将具有conscrypt所需的所有依赖项。

Also use Http2AsyncClientBuilder instead of HttpAsyncClients for making http2 multiplexing. 还可以使用Http2AsyncClientBuilder而不是HttpAsyncClients进行HTTP2多路复用。

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

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