test/jdk/java/net/httpclient/offline/DelegatingHttpClient.java
changeset 49765 ee6f7a61f3a5
child 51364 31d9e82b2e64
child 56451 9585061fdb04
equal deleted inserted replaced
49707:f7fd051519ac 49765:ee6f7a61f3a5
       
     1 /*
       
     2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import javax.net.ssl.SSLContext;
       
    25 import javax.net.ssl.SSLParameters;
       
    26 import java.io.IOException;
       
    27 import java.net.Authenticator;
       
    28 import java.net.CookieHandler;
       
    29 import java.net.ProxySelector;
       
    30 import java.util.Optional;
       
    31 import java.util.concurrent.CompletableFuture;
       
    32 import java.util.concurrent.Executor;
       
    33 import java.net.http.HttpClient;
       
    34 import java.net.http.HttpRequest;
       
    35 import java.net.http.HttpResponse;
       
    36 
       
    37 /**
       
    38  * An HttpClient that delegates all its operations to the given client.
       
    39  */
       
    40 public class DelegatingHttpClient extends HttpClient {
       
    41 
       
    42     private final HttpClient client;
       
    43 
       
    44     public DelegatingHttpClient(HttpClient client) {
       
    45         this.client = client;
       
    46     }
       
    47 
       
    48     @Override
       
    49     public Optional<CookieHandler> cookieHandler() {
       
    50         return client.cookieHandler();
       
    51     }
       
    52 
       
    53     @Override
       
    54     public Redirect followRedirects() {
       
    55         return client.followRedirects();
       
    56     }
       
    57 
       
    58     @Override
       
    59     public Optional<ProxySelector> proxy() {
       
    60         return client.proxy();
       
    61     }
       
    62 
       
    63     @Override
       
    64     public SSLContext sslContext() {
       
    65         return client.sslContext();
       
    66     }
       
    67 
       
    68     @Override
       
    69     public SSLParameters sslParameters() {
       
    70         return client.sslParameters();
       
    71     }
       
    72 
       
    73     @Override
       
    74     public Optional<Authenticator> authenticator() {
       
    75         return client.authenticator();
       
    76     }
       
    77 
       
    78     @Override
       
    79     public Version version() {
       
    80         return client.version();
       
    81     }
       
    82 
       
    83     @Override
       
    84     public Optional<Executor> executor() {
       
    85         return client.executor();
       
    86     }
       
    87 
       
    88     @Override
       
    89     public <T> HttpResponse<T> send(HttpRequest request,
       
    90                                     HttpResponse.BodyHandler<T> responseBodyHandler)
       
    91             throws IOException, InterruptedException {
       
    92         return client.send(request, responseBodyHandler);
       
    93     }
       
    94 
       
    95     @Override
       
    96     public <T> CompletableFuture<HttpResponse<T>>
       
    97     sendAsync(HttpRequest request,
       
    98               HttpResponse.BodyHandler<T> responseBodyHandler) {
       
    99         return client.sendAsync(request, responseBodyHandler);
       
   100     }
       
   101 
       
   102     @Override
       
   103     public <T> CompletableFuture<HttpResponse<T>>
       
   104     sendAsync(HttpRequest request,
       
   105               HttpResponse.BodyHandler<T> responseBodyHandler,
       
   106               HttpResponse.PushPromiseHandler<T> pushPromiseHandler) {
       
   107         return client.sendAsync(request, responseBodyHandler, pushPromiseHandler);
       
   108     }
       
   109 }