| [4231] | 1 | package oauth.signpost.basic;
|
|---|
| 2 |
|
|---|
| 3 | import java.io.IOException;
|
|---|
| 4 | import java.io.InputStream;
|
|---|
| 5 | import java.net.HttpURLConnection;
|
|---|
| 6 | import java.util.HashMap;
|
|---|
| 7 | import java.util.List;
|
|---|
| 8 | import java.util.Map;
|
|---|
| 9 |
|
|---|
| 10 | import oauth.signpost.http.HttpRequest;
|
|---|
| 11 |
|
|---|
| 12 | public 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 | }
|
|---|