< prev index next >

src/java.httpclient/share/classes/java/net/http/HttpResponseImpl.java

Print this page




   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 java.net.http;
  27 
  28 import java.io.IOException;

  29 import java.net.URI;
  30 import java.nio.ByteBuffer;
  31 import java.security.AccessControlContext;
  32 import java.security.AccessController;
  33 import java.util.concurrent.CompletableFuture;
  34 import java.util.function.LongConsumer;
  35 import javax.net.ssl.SSLParameters;
  36 
  37 /**
  38  * The implementation class for HttpResponse
  39  */
  40 class HttpResponseImpl extends HttpResponse {
  41 
  42     int responseCode;
  43     Exchange exchange;
  44     HttpRequestImpl request;
  45     HttpHeaders1 headers;
  46     HttpHeaders1 trailers;
  47     SSLParameters sslParameters;
  48     URI uri;
  49     HttpClient.Version version;
  50     AccessControlContext acc;
  51     RawChannel rawchan;
  52     HttpConnection connection;

  53 
  54     public HttpResponseImpl(int responseCode, Exchange exch, HttpHeaders1 headers,
  55             HttpHeaders1 trailers, SSLParameters sslParameters,
  56             HttpClient.Version version, HttpConnection connection) {
  57         this.responseCode = responseCode;
  58         this.exchange = exch;
  59         this.request = exchange.request();
  60         this.headers = headers;
  61         this.trailers = trailers;
  62         this.sslParameters = sslParameters;
  63         this.uri = request.uri();
  64         this.version = version;
  65         this.connection = connection;

















  66     }
  67 
  68     @Override
  69     public int statusCode() {
  70         return responseCode;
  71     }
  72 
  73     @Override
  74     public HttpRequestImpl request() {
  75         return request;
  76     }
  77 
  78     @Override
  79     public HttpHeaders headers() {
  80         headers.makeUnmodifiable();
  81         return headers;
  82     }
  83 
  84     @Override
  85     public HttpHeaders trailers() {
  86         trailers.makeUnmodifiable();
  87         return trailers;
  88     }
  89 
  90 
  91     @Override
  92     public <T> T body(java.net.http.HttpResponse.BodyProcessor<T> processor) {


  93         return exchange.responseBody(processor);






  94     }
  95 
  96     @Override
  97     public <T> CompletableFuture<T> bodyAsync(java.net.http.HttpResponse.BodyProcessor<T> processor) {
  98         acc = AccessController.getContext();

  99         return exchange.responseBodyAsync(processor);


 100     }
 101 
 102     @Override
 103     public SSLParameters sslParameters() {
 104         return sslParameters;
 105     }
 106 
 107     public AccessControlContext getAccessControlContext() {
 108         return acc;
 109     }
 110 
 111     @Override
 112     public URI uri() {
 113         return uri;
 114     }
 115 
 116     @Override
 117     public HttpClient.Version version() {
 118         return version;
 119     }




   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 java.net.http;
  27 
  28 import java.io.IOException;
  29 import java.io.UncheckedIOException;
  30 import java.net.URI;
  31 import java.nio.ByteBuffer;
  32 import java.security.AccessControlContext;
  33 import java.security.AccessController;
  34 import java.util.concurrent.CompletableFuture;
  35 import java.util.function.LongConsumer;
  36 import javax.net.ssl.SSLParameters;
  37 
  38 /**
  39  * The implementation class for HttpResponse
  40  */
  41 class HttpResponseImpl extends HttpResponse {
  42 
  43     int responseCode;
  44     Exchange exchange;
  45     HttpRequestImpl request;
  46     HttpHeaders headers;
  47     HttpHeaders trailers;
  48     SSLParameters sslParameters;
  49     URI uri;
  50     HttpClient.Version version;
  51     AccessControlContext acc;
  52     RawChannel rawchan;
  53     HttpConnection connection;
  54     final Stream stream;
  55 
  56     public HttpResponseImpl(int responseCode, Exchange exch, HttpHeaders headers,
  57             HttpHeaders trailers, SSLParameters sslParameters,
  58             HttpClient.Version version, HttpConnection connection) {
  59         this.responseCode = responseCode;
  60         this.exchange = exch;
  61         this.request = exchange.request();
  62         this.headers = headers;
  63         this.trailers = trailers;
  64         this.sslParameters = sslParameters;
  65         this.uri = request.uri();
  66         this.version = version;
  67         this.connection = connection;
  68         this.stream = null;
  69     }
  70 
  71     // A response to a PUSH_PROMISE
  72     public HttpResponseImpl(int responseCode, HttpRequestImpl pushRequest,
  73             ImmutableHeaders headers,
  74             Stream stream, SSLParameters sslParameters) {
  75         this.responseCode = responseCode;
  76         this.exchange = null;
  77         this.request = pushRequest;
  78         this.headers = headers;
  79         this.trailers = null;
  80         this.sslParameters = sslParameters;
  81         this.uri = request.uri(); // TODO: take from headers
  82         this.version = HttpClient.Version.HTTP_2;
  83         this.connection = null;
  84         this.stream = stream;
  85     }
  86 
  87     @Override
  88     public int statusCode() {
  89         return responseCode;
  90     }
  91 
  92     @Override
  93     public HttpRequestImpl request() {
  94         return request;
  95     }
  96 
  97     @Override
  98     public HttpHeaders headers() {

  99         return headers;
 100     }
 101 
 102     @Override
 103     public HttpHeaders trailers() {

 104         return trailers;
 105     }
 106 
 107 
 108     @Override
 109     public <T> T body(java.net.http.HttpResponse.BodyProcessor<T> processor) {
 110         try {
 111             if (exchange != null) {
 112                 return exchange.responseBody(processor);
 113             } else {
 114                 return stream.responseBody(processor);
 115             }
 116         } catch (IOException e) {
 117             throw new UncheckedIOException(e);
 118         }
 119     }
 120 
 121     @Override
 122     public <T> CompletableFuture<T> bodyAsync(java.net.http.HttpResponse.BodyProcessor<T> processor) {
 123         acc = AccessController.getContext();
 124         if (exchange != null)
 125             return exchange.responseBodyAsync(processor);
 126         else
 127             return stream.responseBodyAsync(processor);
 128     }
 129 
 130     @Override
 131     public SSLParameters sslParameters() {
 132         return sslParameters;
 133     }
 134 
 135     public AccessControlContext getAccessControlContext() {
 136         return acc;
 137     }
 138 
 139     @Override
 140     public URI uri() {
 141         return uri;
 142     }
 143 
 144     @Override
 145     public HttpClient.Version version() {
 146         return version;
 147     }


< prev index next >