src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/HttpClientFacade.java
branchhttp-client-branch
changeset 56089 42208b2f224e
parent 56088 38fac6d0521d
child 56090 5c7fb702948a
equal deleted inserted replaced
56088:38fac6d0521d 56089:42208b2f224e
     1 /*
       
     2  * Copyright (c) 2017, 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.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package jdk.incubator.http.internal;
       
    27 
       
    28 import java.io.IOException;
       
    29 import java.lang.ref.Reference;
       
    30 import java.net.Authenticator;
       
    31 import java.net.CookieHandler;
       
    32 import java.net.ProxySelector;
       
    33 import java.util.Optional;
       
    34 import java.util.concurrent.CompletableFuture;
       
    35 import java.util.concurrent.Executor;
       
    36 import javax.net.ssl.SSLContext;
       
    37 import javax.net.ssl.SSLParameters;
       
    38 import jdk.incubator.http.HttpClient;
       
    39 import jdk.incubator.http.HttpRequest;
       
    40 import jdk.incubator.http.HttpResponse;
       
    41 import jdk.incubator.http.HttpResponse.BodyHandler;
       
    42 import jdk.incubator.http.HttpResponse.PushPromiseHandler;
       
    43 import jdk.incubator.http.WebSocket;
       
    44 
       
    45 /**
       
    46  * An HttpClientFacade is a simple class that wraps an HttpClient implementation
       
    47  * and delegates everything to its implementation delegate.
       
    48  */
       
    49 final class HttpClientFacade extends HttpClient {
       
    50 
       
    51     final HttpClientImpl impl;
       
    52 
       
    53     /**
       
    54      * Creates an HttpClientFacade.
       
    55      */
       
    56     HttpClientFacade(HttpClientImpl impl) {
       
    57         this.impl = impl;
       
    58     }
       
    59 
       
    60     @Override
       
    61     public Optional<CookieHandler> cookieHandler() {
       
    62         return impl.cookieHandler();
       
    63     }
       
    64 
       
    65     @Override
       
    66     public Redirect followRedirects() {
       
    67         return impl.followRedirects();
       
    68     }
       
    69 
       
    70     @Override
       
    71     public Optional<ProxySelector> proxy() {
       
    72         return impl.proxy();
       
    73     }
       
    74 
       
    75     @Override
       
    76     public SSLContext sslContext() {
       
    77         return impl.sslContext();
       
    78     }
       
    79 
       
    80     @Override
       
    81     public SSLParameters sslParameters() {
       
    82         return impl.sslParameters();
       
    83     }
       
    84 
       
    85     @Override
       
    86     public Optional<Authenticator> authenticator() {
       
    87         return impl.authenticator();
       
    88     }
       
    89 
       
    90     @Override
       
    91     public HttpClient.Version version() {
       
    92         return impl.version();
       
    93     }
       
    94 
       
    95     @Override
       
    96     public Optional<Executor> executor() {
       
    97         return impl.executor();
       
    98     }
       
    99 
       
   100     @Override
       
   101     public <T> HttpResponse<T>
       
   102     send(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler)
       
   103         throws IOException, InterruptedException
       
   104     {
       
   105         try {
       
   106             return impl.send(req, responseBodyHandler);
       
   107         } finally {
       
   108             Reference.reachabilityFence(this);
       
   109         }
       
   110     }
       
   111 
       
   112     @Override
       
   113     public <T> CompletableFuture<HttpResponse<T>>
       
   114     sendAsync(HttpRequest req, HttpResponse.BodyHandler<T> responseBodyHandler) {
       
   115         try {
       
   116             return impl.sendAsync(req, responseBodyHandler);
       
   117         } finally {
       
   118             Reference.reachabilityFence(this);
       
   119         }
       
   120     }
       
   121 
       
   122     @Override
       
   123     public <T> CompletableFuture<HttpResponse<T>>
       
   124     sendAsync(HttpRequest req,
       
   125               BodyHandler<T> responseBodyHandler,
       
   126               PushPromiseHandler<T> pushPromiseHandler){
       
   127         try {
       
   128             return impl.sendAsync(req, responseBodyHandler, pushPromiseHandler);
       
   129         } finally {
       
   130             Reference.reachabilityFence(this);
       
   131         }
       
   132     }
       
   133 
       
   134     @Override
       
   135     public WebSocket.Builder newWebSocketBuilder() {
       
   136         try {
       
   137             return impl.newWebSocketBuilder();
       
   138         } finally {
       
   139             Reference.reachabilityFence(this);
       
   140         }
       
   141     }
       
   142 
       
   143     @Override
       
   144     public String toString() {
       
   145         // Used by tests to get the client's id.
       
   146         return impl.toString();
       
   147     }
       
   148 }