Subversion Repositories javautils

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
package de.viathinksoft.utils.http;
2
 
3
import java.io.IOException;
4
 
19 daniel-mar 5
import org.apache.http.Header;
2 daniel-mar 6
import org.apache.http.HttpEntity;
7
import org.apache.http.HttpResponse;
8
import org.apache.http.ParseException;
9
import org.apache.http.util.EntityUtils;
10
 
11
public class MyHttpResponse {
12
 
13
        private String content;
14
        private HttpResponse response;
15
        private int statusCode;
16
 
17
        public MyHttpResponse(HttpResponse response) throws ParseException, IOException {
18
                super();
19
 
20
                this.response = response;
21
 
22
                HttpEntity ent = response.getEntity();
23
                if (ent != null) {
24
                        this.content = EntityUtils.toString(ent);
25
                        ent.consumeContent();
26
                }
27
 
28
                this.statusCode = response.getStatusLine().getStatusCode();
29
        }
30
 
31
        public HttpResponse getResponse() {
32
                return response;
33
        }
34
 
35
        public String getContent() {
36
                return content;
37
        }
38
 
39
        public int getStatusCode() {
40
                return statusCode;
41
        }
19 daniel-mar 42
 
43
        public String getHeader(String name) {
44
                Header[] h = response.getHeaders(name);
45
                if (h.length != 1) return null;
46
                return h[0].getValue();
47
        }
2 daniel-mar 48
}