activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1182931 - in /activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http: HttpClientTransport.java HttpTransportFactory.java HttpTransportSupport.java HttpTunnelServlet.java
Date Thu, 13 Oct 2011 16:01:29 GMT
Author: tabish
Date: Thu Oct 13 16:01:28 2011
New Revision: 1182931

URL: http://svn.apache.org/viewvc?rev=1182931&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-1514

Adds support of HTTP proxy auth using HttpClient 4.1.2 APIs

Modified:
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportFactory.java
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportSupport.java
    activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java

Modified: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java?rev=1182931&r1=1182930&r2=1182931&view=diff
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java
(original)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpClientTransport.java
Thu Oct 13 16:01:28 2011
@@ -30,6 +30,8 @@ import org.apache.activemq.util.ServiceS
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.ResponseHandler;
 import org.apache.http.client.methods.HttpGet;
@@ -222,10 +224,16 @@ public class HttpClientTransport extends
     }
 
     protected HttpClient createHttpClient() {
-        HttpClient client = new DefaultHttpClient();
+        DefaultHttpClient client = new DefaultHttpClient();
         if (getProxyHost() != null) {
             HttpHost proxy = new HttpHost(getProxyHost(), getProxyPort());
             client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
+
+            if(getProxyUser() != null && getProxyPassword() != null) {
+                client.getCredentialsProvider().setCredentials(
+                    new AuthScope(getProxyHost(), getProxyPort()),
+                    new UsernamePasswordCredentials(getProxyUser(), getProxyPassword()));
+            }
         }
         return client;
     }

Modified: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportFactory.java?rev=1182931&r1=1182930&r2=1182931&view=diff
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportFactory.java
(original)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportFactory.java
Thu Oct 13 16:01:28 2011
@@ -23,8 +23,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.activemq.transport.InactivityMonitor;
-import org.apache.activemq.transport.MutexTransport;
-import org.apache.activemq.transport.ThreadNameFilter;
 import org.apache.activemq.transport.Transport;
 import org.apache.activemq.transport.TransportFactory;
 import org.apache.activemq.transport.TransportLoggerFactory;
@@ -40,10 +38,9 @@ import org.slf4j.LoggerFactory;
 
 /**
  * @author David Martin Clavo david(dot)martin(dot)clavo(at)gmail.com (logging improvement
modifications)
- * 
  */
 public class HttpTransportFactory extends TransportFactory {
-    
+
     private static final Logger LOG = LoggerFactory.getLogger(HttpTransportFactory.class);
 
     public TransportServer doBind(URI location) throws IOException {
@@ -75,10 +72,12 @@ public class HttpTransportFactory extend
         return new HttpClientTransport(textWireFormat, location);
     }
 
+    @SuppressWarnings("rawtypes")
     public Transport serverConfigure(Transport transport, WireFormat format, HashMap options)
throws Exception {
         return compositeConfigure(transport, format, options);
     }
 
+    @SuppressWarnings("rawtypes")
     public Transport compositeConfigure(Transport transport, WireFormat format, Map options)
{
         transport = super.compositeConfigure(transport, format, options);
         HttpClientTransport httpTransport = (HttpClientTransport)transport.narrow(HttpClientTransport.class);

Modified: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportSupport.java?rev=1182931&r1=1182930&r2=1182931&view=diff
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportSupport.java
(original)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTransportSupport.java
Thu Oct 13 16:01:28 2011
@@ -23,14 +23,16 @@ import org.apache.activemq.transport.uti
 
 /**
  * A useful base class for HTTP Transport implementations.
- * 
- * 
+ *
+ *
  */
 public abstract class HttpTransportSupport extends TransportThreadSupport {
     private TextWireFormat textWireFormat;
     private URI remoteUrl;
     private String proxyHost;
     private int proxyPort = 8080;
+    private String proxyUser;
+    private String proxyPassword;
 
     public HttpTransportSupport(TextWireFormat textWireFormat, URI remoteUrl) {
         this.textWireFormat = textWireFormat;
@@ -74,4 +76,20 @@ public abstract class HttpTransportSuppo
     public void setProxyPort(int proxyPort) {
         this.proxyPort = proxyPort;
     }
+
+    public String getProxyUser() {
+       return proxyUser;
+    }
+
+    public void setProxyUser(String proxyUser) {
+       this.proxyUser = proxyUser;
+    }
+
+    public String getProxyPassword() {
+       return proxyPassword;
+    }
+
+    public void setProxyPassword(String proxyPassword) {
+       this.proxyPassword = proxyPassword;
+    }
 }

Modified: activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java?rev=1182931&r1=1182930&r2=1182931&view=diff
==============================================================================
--- activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
(original)
+++ activemq/trunk/activemq-optional/src/main/java/org/apache/activemq/transport/http/HttpTunnelServlet.java
Thu Oct 13 16:01:28 2011
@@ -46,8 +46,6 @@ import org.slf4j.LoggerFactory;
  * A servlet which handles server side HTTP transport, delegating to the
  * ActiveMQ broker. This servlet is designed for being embedded inside an
  * ActiveMQ Broker using an embedded Jetty or Tomcat instance.
- *
- *
  */
 public class HttpTunnelServlet extends HttpServlet {
     private static final long serialVersionUID = -3826714430767484333L;
@@ -58,8 +56,9 @@ public class HttpTunnelServlet extends H
     private TextWireFormat wireFormat;
     private ConcurrentMap<String, BlockingQueueTransport> clients = new ConcurrentHashMap<String,
BlockingQueueTransport>();
     private final long requestTimeout = 30000L;
-    private HashMap transportOptions;
+    private HashMap<String, Object> transportOptions;
 
+    @SuppressWarnings("unchecked")
     @Override
     public void init() throws ServletException {
         super.init();
@@ -71,7 +70,7 @@ public class HttpTunnelServlet extends H
         if (transportFactory == null) {
             throw new ServletException("No such attribute 'transportFactory' available in
the ServletContext");
         }
-        transportOptions = (HashMap)getServletContext().getAttribute("transportOptions");
+        transportOptions = (HashMap<String, Object>)getServletContext().getAttribute("transportOptions");
         wireFormat = (TextWireFormat)getServletContext().getAttribute("wireFormat");
         if (wireFormat == null) {
             wireFormat = createWireFormat();
@@ -210,7 +209,7 @@ public class HttpTunnelServlet extends H
         Transport transport = answer;
         try {
             // Preserve the transportOptions for future use by making a copy before applying
(they are removed when applied).
-            HashMap options = new HashMap(transportOptions);
+            HashMap<String, Object> options = new HashMap<String, Object>(transportOptions);
             transport = transportFactory.serverConfigure(answer, null, options);
         } catch (Exception e) {
             throw IOExceptionSupport.create(e);



Mime
View raw message