~s-friedemann/tomdroid/sshfs

« back to all changes in this revision

Viewing changes to lib/signpost/signpost-commonshttp4/src/main/java/oauth/signpost/commonshttp/HttpRequestAdapter.java

  • Committer: Benoit Garret
  • Date: 2010-03-06 20:39:56 UTC
  • mto: (185.4.1 sync-ui)
  • mto: This revision was merged to the branch mainline in revision 186.
  • Revision ID: benoit.garret_launchpad@gadz.org-20100306203956-k6vlss6hk2d91j4n
Put the signpost and commons-codec libraries in lib/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package oauth.signpost.commonshttp;
 
2
 
 
3
import java.io.IOException;
 
4
import java.io.InputStream;
 
5
 
 
6
import org.apache.http.Header;
 
7
import org.apache.http.HttpEntity;
 
8
import org.apache.http.HttpEntityEnclosingRequest;
 
9
import org.apache.http.client.methods.HttpUriRequest;
 
10
 
 
11
public class HttpRequestAdapter implements oauth.signpost.http.HttpRequest {
 
12
 
 
13
    private HttpUriRequest request;
 
14
 
 
15
    private HttpEntity entity;
 
16
 
 
17
    public HttpRequestAdapter(HttpUriRequest request) {
 
18
        this.request = request;
 
19
        if (request instanceof HttpEntityEnclosingRequest) {
 
20
            entity = ((HttpEntityEnclosingRequest) request).getEntity();
 
21
        }
 
22
    }
 
23
 
 
24
    public String getHeader(String name) {
 
25
        Header header = request.getFirstHeader(name);
 
26
        if (header == null) {
 
27
            return null;
 
28
        }
 
29
        return header.getValue();
 
30
    }
 
31
 
 
32
    public String getMethod() {
 
33
        return request.getRequestLine().getMethod();
 
34
    }
 
35
 
 
36
    public String getRequestUrl() {
 
37
        return request.getURI().toString();
 
38
    }
 
39
 
 
40
    public void setHeader(String name, String value) {
 
41
        request.setHeader(name, value);
 
42
    }
 
43
 
 
44
    public String getContentType() {
 
45
        if (entity == null) {
 
46
            return null;
 
47
        }
 
48
        Header header = entity.getContentType();
 
49
        if (header == null) {
 
50
            return null;
 
51
        }
 
52
        return header.getValue();
 
53
    }
 
54
 
 
55
    public InputStream getMessagePayload() throws IOException {
 
56
        if (entity == null) {
 
57
            return null;
 
58
        }
 
59
        return entity.getContent();
 
60
    }
 
61
}