mirror of https://github.com/apache/activemq.git
Adds support of HTTP proxy auth using HttpClient 4.1.2 APIs git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1182931 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f33f32e892
commit
8a3bdd9f71
|
@ -30,6 +30,8 @@ import org.apache.activemq.util.ServiceStopper;
|
|||
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 HttpTransportSupport {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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 extends TransportFactory {
|
|||
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);
|
||||
|
|
|
@ -23,14 +23,16 @@ import org.apache.activemq.transport.util.TextWireFormat;
|
|||
|
||||
/**
|
||||
* 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 HttpTransportSupport extends TransportThreadSupport {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 HttpServlet {
|
|||
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 HttpServlet {
|
|||
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 HttpServlet {
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue