1

WSClientPlay ドキュメントに従って作成しました。そして、そのクライアント オブジェクトを使用して、WSRequest を使用して応答を取得します。しかし、私が得ているのはnull本体と0サーバーの応答コードだけです。そして、私が要求した場所にデバッグするget()と、 java.lang.illegalstateexception: closed.

以下は私のコードです。

WS クライアント

 private WSClient wsClient() throws IOException {
   akka.stream.Materializer materializer = akka.stream.ActorMaterializer.create(akka.actor.ActorSystem.create());
    // Set up the client config (you can also use a parser here):
    scala.Option<String> noneString = scala.None$.empty();
    WSClientConfig wsClientConfig = new WSClientConfig(
            Duration.apply(120000, TimeUnit.SECONDS), // connectionTimeout
            Duration.apply(120000, TimeUnit.SECONDS), // idleTimeout
            Duration.apply(120000, TimeUnit.SECONDS), // requestTimeout
            true, // followRedirects
            true, // useProxyProperties
            noneString, // userAgent
            true, // compressionEnabled / enforced
            SSLConfigFactory.defaultConfig());

    AhcWSClientConfig clientConfig = AhcWSClientConfigFactory.forClientConfig(wsClientConfig);

    // Add underlying asynchttpclient options to WSClient
    AhcConfigBuilder builder = new AhcConfigBuilder(clientConfig);
    DefaultAsyncHttpClientConfig.Builder ahcBuilder = builder.configure();
    AsyncHttpClientConfig.AdditionalChannelInitializer logging = new AsyncHttpClientConfig.AdditionalChannelInitializer() {
        @Override
        public void initChannel(io.netty.channel.Channel channel) throws IOException {
            channel.pipeline().addFirst("log", new io.netty.handler.logging.LoggingHandler("debug"));
        }
    };
    ahcBuilder.setHttpAdditionalChannelInitializer(logging);

    WSClient customWSClient = new play.libs.ws.ahc.AhcWSClient(ahcBuilder.build(), materializer);

    customWSClient.close();
    return customWSClient;
}

リクエストハンドラ

Future future = executorService.submit(new Runnable() {
                @Override
                public void run() {
                    WSRequest wsRequest = wsClient.url(url);

                    WSRequest complexRequest = wsRequest.setHeader(header.getKey(), header.getValue())
                            .setRequestTimeout(120000).setMethod(requestMethod);

                    CompletionStage<WSResponse> responsePromise = complexRequest.get();

                    CompletionStage<Result> promiseResult = responsePromise.thenApplyAsync(responseAfter -> {

                        int responseStatus = responseAfter.getStatus();
                        String body = responseAfter.getBody();
                        restResponse.setBody(body);
                        restResponse.setStatus(responseStatus);

                        return ok();
                    });

                }
            });
            future.get();

            executorService.shutdown();

ExecutorService非同期処理にも使用します。この問題をどこでも検索しましたが、まだ解決策が見つかりません。

デバッグ中のエラー

デバッグ エラー

新しいデバッグ エラー

未完了エラー

4

1 に答える 1

0

ここでの問題は、WSClient が で閉じられていることcustomWSClient.close()です。それ以降のリクエストはできません。

于 2016-07-20T21:39:02.130 に答える