source: josm/trunk/src/oauth/signpost/basic/HttpURLConnectionRequestAdapter.java@ 4231

Last change on this file since 4231 was 4231, checked in by stoecker, 13 years ago

add signpost and metadata extractor code to repository directly

File size: 1.6 KB
Line 
1package oauth.signpost.basic;
2
3import java.io.IOException;
4import java.io.InputStream;
5import java.net.HttpURLConnection;
6import java.util.HashMap;
7import java.util.List;
8import java.util.Map;
9
10import oauth.signpost.http.HttpRequest;
11
12public class HttpURLConnectionRequestAdapter implements HttpRequest {
13
14 protected HttpURLConnection connection;
15
16 public HttpURLConnectionRequestAdapter(HttpURLConnection connection) {
17 this.connection = connection;
18 }
19
20 public String getMethod() {
21 return connection.getRequestMethod();
22 }
23
24 public String getRequestUrl() {
25 return connection.getURL().toExternalForm();
26 }
27
28 public void setRequestUrl(String url) {
29 // can't do
30 }
31
32 public void setHeader(String name, String value) {
33 connection.setRequestProperty(name, value);
34 }
35
36 public String getHeader(String name) {
37 return connection.getRequestProperty(name);
38 }
39
40 public Map<String, String> getAllHeaders() {
41 Map<String, List<String>> origHeaders = connection.getRequestProperties();
42 Map<String, String> headers = new HashMap<String, String>(origHeaders.size());
43 for (String name : origHeaders.keySet()) {
44 List<String> values = origHeaders.get(name);
45 if (!values.isEmpty()) {
46 headers.put(name, values.get(0));
47 }
48 }
49 return headers;
50 }
51
52 public InputStream getMessagePayload() throws IOException {
53 return null;
54 }
55
56 public String getContentType() {
57 return connection.getRequestProperty("Content-Type");
58 }
59
60 public HttpURLConnection unwrap() {
61 return connection;
62 }
63}
Note: See TracBrowser for help on using the repository browser.