View Javadoc
1   package ca.uhn.fhir.rest.client.api;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   * http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import ca.uhn.fhir.util.StopWatch;
24  
25  import java.io.IOException;
26  import java.io.InputStream;
27  import java.io.Reader;
28  import java.util.List;
29  import java.util.Map;
30  
31  /**
32   * An interface around the HTTP Response.
33   */
34  public interface IHttpResponse {
35  
36  	/**
37  	 * @deprecated This method was deprecated in HAPI FHIR 2.2 because its name has a typo. Use {@link #bufferEntity()} instead.
38  	 */
39  	@Deprecated
40  	void bufferEntitity() throws IOException;
41  
42  	/**
43  	 * Buffer the message entity data.
44  	 * <p>
45  	 * In case the message entity is backed by an unconsumed entity input stream,
46  	 * all the bytes of the original entity input stream are read and stored in a
47  	 * local buffer. The original entity input stream is consumed.
48  	 * </p>
49  	 * <p>
50  	 * In case the response entity instance is not backed by an unconsumed input stream
51  	 * an invocation of {@code bufferEntity} method is ignored and the method returns.
52  	 * </p>
53  	 * <p>
54  	 * This operation is idempotent, i.e. it can be invoked multiple times with
55  	 * the same effect which also means that calling the {@code bufferEntity()}
56  	 * method on an already buffered (and thus closed) message instance is legal
57  	 * and has no further effect.
58  	 * </p>
59  	 * <p>
60  	 * Buffering the message entity data allows for multiple invocations of
61  	 * {@code readEntity(...)} methods on the response instance.
62  	 *
63  	 * @since 2.2
64  	 */
65  	void bufferEntity() throws IOException;
66  
67  	/**
68  	 * Close the response
69  	 */
70  	void close();
71  
72  	/**
73  	 * Returna reader for the response entity
74  	 */
75  	Reader createReader() throws IOException;
76  
77  	/**
78  	 * Get map of the response headers and corresponding string values.
79  	 *
80  	 * @return response headers as a map header keys and they values.
81  	 */
82  	Map<String, List<String>> getAllHeaders();
83  
84  	/**
85  	 * Return all headers in the response with the given type
86  	 */
87  	List<String> getHeaders(String theName);
88  
89  	/**
90  	 * Extracts {@code Content-Type} value from the response exactly as
91  	 * specified by the {@code Content-Type} header. Returns {@code null}
92  	 * if not specified.
93  	 */
94  	String getMimeType();
95  
96  	/**
97  	 * @return Returns a StopWatch that was started right before
98  	 * the client request was started. The time returned by this
99  	 * client includes any time that was spent within the HTTP
100 	 * library (possibly including waiting for a connection, and
101 	 * any network activity)
102 	 */
103 	StopWatch getRequestStopWatch();
104 
105 	/**
106 	 * @return the native response, depending on the client library used
107 	 */
108 	Object getResponse();
109 
110 	/**
111 	 * Get the status code associated with the response.
112 	 *
113 	 * @return the response status code.
114 	 */
115 	int getStatus();
116 
117 	/**
118 	 * Get the response status information reason phrase associated with the response.
119 	 *
120 	 * @return the reason phrase.
121 	 */
122 	String getStatusInfo();
123 
124 	/**
125 	 * Read the message entity input stream as an InputStream.
126 	 */
127 	InputStream readEntity() throws IOException;
128 }