1

このコードを使用して、HTTP/2 公開 URL をヒットします。

        H2Config h2Config = H2Config.custom().setPushEnabled(false)
            .setCompressionEnabled(true) // Make it a prop
            .setHeaderTableSize(INIT_HEADER_TABLE_SIZE)
            .setMaxConcurrentStreams(Integer.MAX_VALUE) // no limit
            .setMaxFrameSize(INIT_MAX_FRAME_SIZE)
            .setInitialWindowSize(INIT_WINDOW_SIZE)
            .setMaxHeaderListSize(Integer.MAX_VALUE)
            .build(); // unlimited
    CloseableHttpAsyncClient asyncClient = HttpAsyncClients.customHttp2()
        .setTlsStrategy(ClientTlsStrategyBuilder.create()
                .setSslContext(SSLContexts.createSystemDefault())
                .setTlsVersions(TLS.V_1_2)
                .build())
        .setH2Config(h2Config)
        .setIOReactorConfig(IOReactorConfig.custom()
                .setSoTimeout(Timeout.ofSeconds(5))
                .build())
        .setDefaultRequestConfig(org.apache.hc.client5.http.config.RequestConfig.custom()
                .setConnectTimeout(Timeout.ofSeconds(5))
                .setResponseTimeout(Timeout.ofSeconds(5))
                .setCookieSpec(StandardCookieSpec.STRICT)
                .build())
        .build();
    
    org.apache.hc.core5.http.HttpRequest httpGet = new BasicHttpRequest(Method.GET, new URL("XXXX").toURI());       
    BasicAsyncEntityConsumer entityConsumer = new BasicAsyncEntityConsumer();
    CompletableFuture<byte[]> result = new CompletableFuture<>();
    FutureCallback<Message<HttpResponse, byte[]>> callback = new Callback2<byte[]>(result, "Test");
    BasicRequestProducer basicRequestProducer = new BasicRequestProducer(httpGet, null);
    asyncClient.execute(basicRequestProducer, new BasicResponseConsumer<>(entityConsumer),
        null, callback);

コールバック 2:

public class Callback2<T> implements FutureCallback<Message<HttpResponse, T>> {

private String message;
protected CompletableFuture<T> result;

public Callback(CompletableFuture<T> result, String message) {
    this.result = result;
    this.message = message;
}

@Override
public void cancelled() {
    result.cancel(true);
}

@Override
public void completed(Message<HttpResponse, T> arg0) {
    HttpResponse response = arg0.getHead();
    System.out.println(String.format(message + " completed : http response %s", response));
    result.complete(arg0.getBody());
}

@Override
public void failed(Exception arg0) {
    result.completeExceptionally(arg0);
}

}

失敗し、理解できないこのスタックトレースがあります:

java.nio.BufferOverflowException
at java.base/java.nio.HeapByteBuffer.put(HeapByteBuffer.java:233)
at org.apache.hc.core5.http2.impl.nio.FrameInputBuffer.put(FrameInputBuffer.java:89)
at org.apache.hc.core5.http2.impl.nio.AbstractH2StreamMultiplexer.onInput(AbstractH2StreamMultiplexer.java:437)
at org.apache.hc.core5.http2.impl.nio.AbstractH2IOEventHandler.inputReady(AbstractH2IOEventHandler.java:65)
at org.apache.hc.core5.http2.impl.nio.ClientH2IOEventHandler.inputReady(ClientH2IOEventHandler.java:39)
at org.apache.hc.core5.reactor.ssl.SSLIOSession.decryptData(SSLIOSession.java:553)
at org.apache.hc.core5.reactor.ssl.SSLIOSession.access$400(SSLIOSession.java:72)
at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.inputReady(SSLIOSession.java:172)
at org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:131)
at org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)
at org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:178)
at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:127)
at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:85)
at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
at java.base/java.lang.Thread.run(Thread.java:834)

ログを追加すると (log4j2.xml を追加するだけ)、別の例外が発生します。

        2021-03-01 22:02:16,505 DEBUG [org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] ex-00000003: preparing request execution
    2021-03-01 22:02:16,505 DEBUG [org.apache.hc.client5.http.protocol.RequestAddCookies] Cookie spec selected: strict
    2021-03-01 22:02:16,505 DEBUG [org.apache.hc.client5.http.protocol.RequestAuthCache] Auth cache not set in the context
    2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.async.AsyncProtocolExec] ex-00000003: target auth state: UNCHALLENGED
    2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.async.AsyncProtocolExec] ex-00000003: proxy auth state: UNCHALLENGED
    2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.async.AsyncConnectExec] ex-00000003: acquiring connection with route {s}->https://www.example.com:443
    2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.async.InternalH2AsyncClient] ex-00000003: acquiring endpoint (5 SECONDS)
    2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] https://www.example.com:443: resolving remote address
    2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] https://www.example.com:443: resolved to [www.example.com/2.23.92.197, www.example.com/2.23.92.194, www.example.com/2a02:26f0:2f00:0:0:0:17d5:630, www.example.com/2a02:26f0:2f00:0:0:0:17d5:649]
    2021-03-01 22:02:16,506 DEBUG [org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] https://www.example.com:443: connecting null to www.example.com/2.23.92.197:443 (5 SECONDS)
    2021-03-01 22:02:16,513 DEBUG [org.apache.hc.client5.http.impl.nio.MultihomeIOSessionRequester] https://www.example.com:443: connected c-0000000002 /192.168.0.33:36526->www.example.com/2.23.92.197:443
    2021-03-01 22:02:16,514 DEBUG [org.apache.hc.client5.http.impl.async.InternalH2AsyncClient] ex-00000003: acquired endpoint
    2021-03-01 22:02:16,514 DEBUG [org.apache.hc.client5.http.impl.async.H2AsyncMainClientExec] ex-00000003: executing GET /xxx/test.txt HTTP/1.1
    2021-03-01 22:02:16,514 DEBUG [org.apache.hc.client5.http.impl.async.InternalH2AsyncClient] c-0000000002: start execution ex-00000003
    2021-03-01 22:02:16,514 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy] Enabled protocols: [TLSv1.2]
    2021-03-01 22:02:16,515 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy] Enabled cipher suites:[TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
    2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy] Secure session established
    2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy]  negotiated protocol: TLSv1.2
    2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy]  negotiated cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
    2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy]  peer principal: CN=xxxx.e.example.net, O="Foo, Inc.", L=CA, ST=MA, C=US
    2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy]  peer alternative names: [a248.e.example.net, *.example.net, *.example-staging.net, *.example.net, *.example-staging.net]
    2021-03-01 22:02:16,538 DEBUG [org.apache.hc.client5.http.ssl.AbstractClientTlsStrategy]  issuer principal: CN=DigiCert Secure Site ECC CA-1, OU=www.example.com, O=DigiCert Inc, C=US
    2021-03-01 22:02:16,539 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 >> "PRI * HTTP/2.0[\r][\n]"
    2021-03-01 22:02:16,539 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 >> "[\r][\n]"
    2021-03-01 22:02:16,539 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 >> "SM[\r][\n]"
    2021-03-01 22:02:16,539 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 >> "[\r][\n]"
    2021-03-01 22:02:16,540 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 >> "[0x0][0x0]$[0x4][0x0][0x0][0x0][0x0][0x0][0x0][0x1][0x0][0x0][0x10][0x0][0x0][0x2][0x0][0x0][0x0][0x0][0x0][0x3][0x7f][0xffffffff][0xffffffff][0xffffffff][0x0][0x4][0x0][0x0][0xffffffff][0xffffffff][0x0][0x5][0x0][0x0]@[0x0][0x0][0x6][0x7f][0xffffffff][0xffffffff][0xffffffff]"
    2021-03-01 22:02:16,540 DEBUG [org.apache.hc.client5.http.wire] c-0000000002 >> "[0x0][0x0][0x4][0x8][0x0][0x0][0x0][0x0][0x0][0x7f][0xffffffff][0x0][0x0]"
    2021-03-01 22:02:16,546 DEBUG [org.apache.hc.client5.http.impl.async.H2AsyncMainClientExec] ex-00000003: execution failed: Connection is closed
    2021-03-01 22:02:16,546 DEBUG [org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient] ex-00000003: request failed: Connection is closed
    2021-03-01 22:02:16,546 DEBUG [org.apache.hc.client5.http.impl.async.InternalH2AsyncClient] c-0000000002: endpoint closed
    XXX failed
    org.apache.hc.core5.http.ConnectionClosedException: Connection is closed
        at org.apache.hc.core5.http2.impl.nio.AbstractH2StreamMultiplexer.onException(AbstractH2StreamMultiplexer.java:661)
        at org.apache.hc.core5.http2.impl.nio.AbstractH2IOEventHandler.exception(AbstractH2IOEventHandler.java:91)
        at org.apache.hc.core5.http2.impl.nio.ClientH2IOEventHandler.exception(ClientH2IOEventHandler.java:39)
        at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.exception(SSLIOSession.java:204)
        at org.apache.hc.core5.reactor.InternalDataChannel.onException(InternalDataChannel.java:169)
        at org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:55)
        at org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:178)
        at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:127)
        at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:85)
        at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
        at java.base/java.lang.Thread.run(Thread.java:834)

そう:

  1. ロギングを追加するだけで状況が変わる理由は、速度に関係していると思います
  2. 最初の例外の意味は何ですか?
  3. どうすれば修正できますか?
4

0 に答える 0