test/jdk/java/net/httpclient/offline/FixedHttpResponse.java
branchhttp-client-branch
changeset 56023 fa36a61f4cbf
child 56089 42208b2f224e
equal deleted inserted replaced
56020:ae3a51bc5b9f 56023:fa36a61f4cbf
       
     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.SSLParameters;
       
    25 import java.net.URI;
       
    26 import java.util.Optional;
       
    27 import jdk.incubator.http.HttpClient;
       
    28 import jdk.incubator.http.HttpHeaders;
       
    29 import jdk.incubator.http.HttpRequest;
       
    30 import jdk.incubator.http.HttpResponse;
       
    31 
       
    32 /**
       
    33  * An HttpResponse consisting of the given state.
       
    34  */
       
    35 public class FixedHttpResponse<T> extends HttpResponse<T> {
       
    36 
       
    37     private final int statusCode;
       
    38     private final HttpRequest request;
       
    39     private final HttpHeaders headers;
       
    40     private final T body;
       
    41     private final SSLParameters sslParameters;
       
    42     private final URI uri;
       
    43     private final HttpClient.Version version;
       
    44 
       
    45     public FixedHttpResponse(int statusCode,
       
    46                              HttpRequest request,
       
    47                              HttpHeaders headers,
       
    48                              T body,
       
    49                              SSLParameters sslParameters,
       
    50                              URI uri,
       
    51                              HttpClient.Version version) {
       
    52         this.statusCode = statusCode;
       
    53         this.request = request;
       
    54         this.headers = headers;
       
    55         this.body = body;
       
    56         this.sslParameters = sslParameters;
       
    57         this.uri = uri;
       
    58         this.version = version;
       
    59     }
       
    60 
       
    61     @Override
       
    62     public int statusCode() {
       
    63         return statusCode;
       
    64     }
       
    65 
       
    66     @Override
       
    67     public HttpRequest request() {
       
    68         return request;
       
    69     }
       
    70 
       
    71     @Override
       
    72     public Optional<HttpResponse<T>> previousResponse() {
       
    73         return Optional.empty();
       
    74     }
       
    75 
       
    76     @Override
       
    77     public HttpHeaders headers() {
       
    78         return headers;
       
    79     }
       
    80 
       
    81     @Override
       
    82     public T body() {
       
    83         return body;
       
    84     }
       
    85 
       
    86     @Override
       
    87     public SSLParameters sslParameters() {
       
    88         return sslParameters;
       
    89     }
       
    90 
       
    91     @Override
       
    92     public URI uri() {
       
    93         return uri;
       
    94     }
       
    95 
       
    96     @Override
       
    97     public HttpClient.Version version() {
       
    98         return version;
       
    99     }
       
   100 
       
   101     @Override
       
   102     public String toString() {
       
   103         StringBuilder sb = new StringBuilder();
       
   104         return sb.append(super.toString()).append(" [ ")
       
   105                 .append("status code: ").append(statusCode)
       
   106                 .append(", request: ").append(request)
       
   107                 .append(", headers: ").append(headers)
       
   108                 .append(" ]")
       
   109                 .toString();
       
   110     }
       
   111 }