OLTU-202 - Add possibility to use OAuthClient behind proxy - applied patch kindly provided by Petr Novicky, thanks
git-svn-id: https://svn.apache.org/repos/asf/oltu/trunk@1813290 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java
index 4c5b01d..70af5f2 100644
--- a/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java
+++ b/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java
@@ -21,6 +21,21 @@
package org.apache.oltu.oauth2.client;
+import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
+import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.net.HttpURLConnection;
+import java.net.Proxy;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
import org.apache.oltu.oauth2.client.response.OAuthClientResponse;
import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory;
@@ -29,20 +44,6 @@
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
import org.apache.oltu.oauth2.common.utils.OAuthUtils;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
-import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
-
/**
* Implementation of the Oltu OAuth HttpClient using URL Connection
@@ -53,11 +54,18 @@
*/
public class URLConnectionClient implements HttpClient {
+ private Proxy proxy = Proxy.NO_PROXY;
+
public URLConnectionClient() {
}
- public <T extends OAuthClientResponse> T execute(OAuthClientRequest request, Map<String, String> headers,
- String requestMethod, Class<T> responseClass)
+ public URLConnectionClient(final Proxy proxy) {
+ this.proxy = proxy;
+ }
+
+ @Override
+ public <T extends OAuthClientResponse> T execute(final OAuthClientRequest request, final Map<String, String> headers,
+ final String requestMethod, final Class<T> responseClass)
throws OAuthSystemException, OAuthProblemException {
InputStream responseBody = null;
@@ -67,7 +75,7 @@
try {
URL url = new URL(request.getLocationUri());
- c = url.openConnection();
+ c = url.openConnection(proxy);
responseCode = -1;
if (c instanceof HttpURLConnection) {
HttpURLConnection httpURLConnection = (HttpURLConnection) c;