You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oltu.apache.org by si...@apache.org on 2017/10/25 13:32:54 UTC

svn commit: r1813290 - /oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java

Author: simonetripodi
Date: Wed Oct 25 13:32:54 2017
New Revision: 1813290

URL: http://svn.apache.org/viewvc?rev=1813290&view=rev
Log:
OLTU-202 - Add possibility to use OAuthClient behind proxy - applied patch kindly provided by Petr Novicky, thanks

Modified:
    oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java

Modified: oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java
URL: http://svn.apache.org/viewvc/oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java?rev=1813290&r1=1813289&r2=1813290&view=diff
==============================================================================
--- oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java (original)
+++ oltu/trunk/oauth-2.0/client/src/main/java/org/apache/oltu/oauth2/client/URLConnectionClient.java Wed Oct 25 13:32:54 2017
@@ -21,27 +21,28 @@
 
 package org.apache.oltu.oauth2.client;
 
-import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
-import org.apache.oltu.oauth2.client.response.OAuthClientResponse;
-import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory;
-import org.apache.oltu.oauth2.common.OAuth;
-import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
-import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
-import org.apache.oltu.oauth2.common.utils.OAuthUtils;
+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 static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
-import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED;
+import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
+import org.apache.oltu.oauth2.client.response.OAuthClientResponse;
+import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory;
+import org.apache.oltu.oauth2.common.OAuth;
+import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
+import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
+import org.apache.oltu.oauth2.common.utils.OAuthUtils;
 
 
 /**
@@ -53,11 +54,18 @@ import static javax.servlet.http.HttpSer
  */
 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 @@ public class URLConnectionClient impleme
         try {
             URL url = new URL(request.getLocationUri());
 
-            c = url.openConnection();
+            c = url.openConnection(proxy);
             responseCode = -1;
             if (c instanceof HttpURLConnection) {
                 HttpURLConnection httpURLConnection = (HttpURLConnection) c;