예제 #1
0
파일: HttpUtil.java 프로젝트: nookio/pay
  static {
    // 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(120, TimeUnit.SECONDS), // connectionTimeout
            Duration.apply(120, TimeUnit.SECONDS), // idleTimeout
            Duration.apply(120, TimeUnit.SECONDS), // requestTimeout
            true, // followRedirects
            false, // useProxyProperties
            noneString, // userAgent
            true, // compressionEnabled / enforced
            SSLConfigFactory.defaultConfig());

    NingWSClientConfig clientConfig = NingWSClientConfigFactory.forClientConfig(wsClientConfig);

    // Build a secure config out of the client config:
    NingAsyncHttpClientConfigBuilder secureBuilder =
        new NingAsyncHttpClientConfigBuilder(clientConfig);
    AsyncHttpClientConfig secureDefaults = secureBuilder.build();

    // You can directly use the builder for specific options once you have secure TLS defaults...
    AsyncHttpClientConfig customConfig =
        new AsyncHttpClientConfig.Builder(secureDefaults).setCompressionEnforced(true).build();
    ws = new NingWSClient(customConfig);
  }
예제 #2
0
    public void clientExamples() {
      // #ws-client
      WSClient client = WS.client();
      // #ws-client

      // #ws-custom-client
      // 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(120, TimeUnit.SECONDS), // connectionTimeout
              Duration.apply(120, TimeUnit.SECONDS), // idleTimeout
              Duration.apply(120, TimeUnit.SECONDS), // requestTimeout
              true, // followRedirects
              true, // useProxyProperties
              noneString, // userAgent
              true, // compressionEnabled / enforced
              SSLConfigFactory.defaultConfig());

      NingWSClientConfig clientConfig = NingWSClientConfigFactory.forClientConfig(wsClientConfig);

      // Build a secure config out of the client config:
      NingAsyncHttpClientConfigBuilder secureBuilder =
          new NingAsyncHttpClientConfigBuilder(clientConfig);
      AsyncHttpClientConfig secureDefaults = secureBuilder.build();

      // You can directly use the builder for specific options once you have secure TLS defaults...
      AsyncHttpClientConfig customConfig =
          new AsyncHttpClientConfig.Builder(secureDefaults)
              .setProxyServer(new org.asynchttpclient.proxy.ProxyServer("127.0.0.1", 38080))
              .setCompressionEnforced(true)
              .build();

      WSClient customClient = new play.libs.ws.ning.NingWSClient(customConfig, materializer);

      CompletionStage<WSResponse> responsePromise =
          customClient.url("http://example.com/feed").get();
      // #ws-custom-client

      // #ws-underlying-client
      org.asynchttpclient.AsyncHttpClient underlyingClient =
          (org.asynchttpclient.AsyncHttpClient) ws.getUnderlying();
      // #ws-underlying-client

    }