1 /*
2  * Copyright 2002-2012 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package org.springframework.http.client;
18 
19 import java.io.IOException;
20 import java.io.InputStream;
21 
22 import org.apache.commons.httpclient.Header;
23 import org.apache.commons.httpclient.HttpMethod;
24 
25 import org.springframework.http.HttpHeaders;
26 
27 /**
28  * {@link org.springframework.http.client.ClientHttpResponse} implementation that uses
29  * Apache Commons HttpClient to execute requests.
30  *
31  * <p>Created via the {@link CommonsClientHttpRequest}.
32  *
33  * @author Arjen Poutsma
34  * @since 3.0
35  * @see CommonsClientHttpRequest#execute()
36  * @deprecated In favor of {@link HttpComponentsClientHttpResponse}
37  */
38 @Deprecated
39 final class CommonsClientHttpResponse extends AbstractClientHttpResponse {
40 
41 	private final HttpMethod httpMethod;
42 
43 	private HttpHeaders headers;
44 
45 
CommonsClientHttpResponse(HttpMethod httpMethod)46 	CommonsClientHttpResponse(HttpMethod httpMethod) {
47 		this.httpMethod = httpMethod;
48 	}
49 
50 
getRawStatusCode()51 	public int getRawStatusCode() {
52 		return this.httpMethod.getStatusCode();
53 	}
54 
getStatusText()55 	public String getStatusText() {
56 		return this.httpMethod.getStatusText();
57 	}
58 
getHeaders()59 	public HttpHeaders getHeaders() {
60 		if (this.headers == null) {
61 			this.headers = new HttpHeaders();
62 			for (Header header : this.httpMethod.getResponseHeaders()) {
63 				this.headers.add(header.getName(), header.getValue());
64 			}
65 		}
66 		return this.headers;
67 	}
68 
getBody()69 	public InputStream getBody() throws IOException {
70 		return this.httpMethod.getResponseBodyAsStream();
71 	}
72 
close()73 	public void close() {
74 		this.httpMethod.releaseConnection();
75 	}
76 
77 }