You are viewing a plain text version of this content. The canonical link for it is here.
Posted to portalapps-dev@portals.apache.org by wo...@apache.org on 2014/08/01 04:39:17 UTC
svn commit: r1615023 - in /portals/applications/webcontent/trunk:
portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/
reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/
reverse-proxy/src/main/ja...
Author: woonsan
Date: Fri Aug 1 02:39:16 2014
New Revision: 1615023
URL: http://svn.apache.org/r1615023
Log:
APA-65: replacing deprecated http-client api usages.
Removed:
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyHttpClient.java
Modified:
portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/RequestContext.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommand.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeaderToHttpRequestCommand.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/CleanupCommand.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ExecuteHttpClientCommand.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleNotModifiedCommand.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpClientCommand.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/SerializeHttpEntityContentCommand.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/HttpEntitySource.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyContext.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyProcessingChain.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ServletRequestContext.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java
portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java
portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/CommonsChainTest.java
Modified: portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java (original)
+++ portals/applications/webcontent/trunk/portlets/src/main/java/org/apache/portals/applications/webcontent2/portlet/proxy/SimpleReverseProxyPortlet.java Fri Aug 1 02:39:16 2014
@@ -21,16 +21,8 @@ import java.util.List;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
-import org.apache.commons.lang.math.NumberUtils;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.params.ConnManagerParamBean;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
import org.apache.portals.applications.webcontent2.proxy.command.AddCookiesToResponseCommand;
import org.apache.portals.applications.webcontent2.proxy.command.AddHeaderToHttpRequestCommand;
@@ -63,14 +55,6 @@ public class SimpleReverseProxyPortlet e
public static final String MAPPINGS_PARAM_NAME = "mappings";
- public static final String HTTP_MAX_TOTAL_CONNECTIONS_PARAM_NAME = "http.max.total.connections";
-
- public static final String HTTP_TIMEOUT_PARAM_NAME = "http.timeout";
-
- private int httpMaxTotalConnections = 400;
-
- private long httpTimeout = 10000L;
-
private ProxyProcessingChain proxyServiceCommand;
public SimpleReverseProxyPortlet()
@@ -83,11 +67,7 @@ public class SimpleReverseProxyPortlet e
{
super.init(portletConfig);
- httpMaxTotalConnections = NumberUtils.toInt(portletConfig.getInitParameter(HTTP_MAX_TOTAL_CONNECTIONS_PARAM_NAME), httpMaxTotalConnections);
-
- httpTimeout = NumberUtils.toLong(portletConfig.getInitParameter(HTTP_TIMEOUT_PARAM_NAME), httpTimeout);
-
- proxyServiceCommand = createProxyServiceCommand(portletConfig);
+ proxyServiceCommand = createProxyServiceCommand();
List<AbstractProxyCommand> allProxyCommands = proxyServiceCommand.getAllProxyCommands();
@@ -100,14 +80,27 @@ public class SimpleReverseProxyPortlet e
setProxyService(proxyService);
}
- protected ProxyProcessingChain createProxyServiceCommand(final PortletConfig portletConfig)
+ protected ProxyProcessingChain createProxyServiceCommand()
{
- ProxyProcessingChain preprocessingChain = new ProxyProcessingChain();
+ ProxyProcessingChain proxyServiceChain = new ProxyProcessingChain();
- InitializationCommand initializationCommand = new InitializationCommand();
+ proxyServiceChain.addCommand(createPreprocessingCommand());
+ proxyServiceChain.addCommand(createProcessingCommand());
+ proxyServiceChain.addCommand(createPostprocessingCommand());
+ return proxyServiceChain;
+ }
+
+ protected ProxyProcessingChain createPreprocessingCommand()
+ {
+ ProxyProcessingChain preprocessingChain = new ProxyProcessingChain();
+ InitializationCommand initializationCommand = new InitializationCommand();
preprocessingChain.addCommand(initializationCommand);
+ return preprocessingChain;
+ }
+ protected ProxyProcessingChain createProcessingCommand()
+ {
ProxyProcessingChain processingChain = new ProxyProcessingChain();
ResolveLocalPathCommand resolveLocalPathCommand = new ResolveLocalPathCommand();
@@ -119,16 +112,7 @@ public class SimpleReverseProxyPortlet e
ResolveContentRewriterCommand resolveContentRewriterCommand = new ResolveContentRewriterCommand();
InitHttpClientCommand initHttpClientCommand = new InitHttpClientCommand();
- SchemeRegistry schemeRegistry = new SchemeRegistry();
- schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
- schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
- HttpParams connManagerParams = new BasicHttpParams();
- ConnManagerParamBean connManagerParamBean = new ConnManagerParamBean(connManagerParams);
- connManagerParamBean.setMaxTotalConnections(httpMaxTotalConnections);
- connManagerParamBean.setTimeout(httpTimeout);
- ClientConnectionManager clientConnectionManager = new ThreadSafeClientConnManager(connManagerParams, schemeRegistry);
- initHttpClientCommand.setClientConnectionManager(clientConnectionManager);
- initHttpClientCommand.setHttpClientParams(new BasicHttpParams());
+ initHttpClientCommand.setHttpClientBuilder(createHttpClientBuilder());
InitHttpRequestCommand initHttpRequestCommand = new InitHttpRequestCommand();
AddHeaderToHttpRequestCommand addHeaderToHttpRequestCommand = new AddHeaderToHttpRequestCommand();
@@ -153,19 +137,20 @@ public class SimpleReverseProxyPortlet e
processingChain.addCommand(addCookiesToResponseCommand);
processingChain.addCommand(serializeHttpEntityContentCommand);
- ProxyProcessingChain postprocessingChain = new ProxyProcessingChain();
+ return processingChain;
+ }
+ protected ProxyProcessingChain createPostprocessingCommand()
+ {
+ ProxyProcessingChain postprocessingChain = new ProxyProcessingChain();
CleanupCommand cleanupCommand = new CleanupCommand();
-
postprocessingChain.addCommand(cleanupCommand);
+ return postprocessingChain;
+ }
- ProxyProcessingChain proxyServiceChain = new ProxyProcessingChain();
-
- proxyServiceChain.addCommand(preprocessingChain);
- proxyServiceChain.addCommand(processingChain);
- proxyServiceChain.addCommand(postprocessingChain);
-
- return proxyServiceChain;
+ protected HttpClientBuilder createHttpClientBuilder()
+ {
+ return HttpClients.custom();
}
protected ProxyMappingRegistry createProxyMappingRegistry()
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/RequestContext.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/RequestContext.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/RequestContext.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/RequestContext.java Fri Aug 1 02:39:16 2014
@@ -44,8 +44,10 @@ public interface RequestContext
public String getQueryString();
+ @SuppressWarnings("rawtypes")
public Enumeration getHeaderNames();
+ @SuppressWarnings("rawtypes")
public Enumeration getHeaders(String name);
public String getHeader(String name);
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommand.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddCookiesToResponseCommand.java Fri Aug 1 02:39:16 2014
@@ -24,11 +24,10 @@ import java.util.List;
import javax.servlet.http.Cookie;
import org.apache.commons.lang.StringUtils;
-import org.apache.http.client.HttpClient;
+import org.apache.http.client.CookieStore;
import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
import org.apache.portals.applications.webcontent2.proxy.impl.ProxyContext;
-import org.apache.portals.applications.webcontent2.proxy.impl.ProxyHttpClient;
public class AddCookiesToResponseCommand extends AbstractProxyCommand
@@ -37,40 +36,42 @@ public class AddCookiesToResponseCommand
@Override
protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
{
- HttpClient httpClient = context.getHttpClient();
+ List<org.apache.http.cookie.Cookie> responseCookies = null;
- if (httpClient instanceof ProxyHttpClient)
+ CookieStore cookieStore = context.getCookieStore();
+
+ if (cookieStore != null)
+ {
+ responseCookies = cookieStore.getCookies();
+ }
+
+ if (responseCookies != null && !responseCookies.isEmpty())
{
- List<org.apache.http.cookie.Cookie> responseCookies = ((ProxyHttpClient) httpClient).getResponseCookies();
+ final boolean isSecureRequest = context.getRequestContext().isSecure();
+ String reverseCookiePath = null;
- if (!responseCookies.isEmpty())
+ for (org.apache.http.cookie.Cookie cookie : responseCookies)
{
- final boolean isSecureRequest = context.getRequestContext().isSecure();
- String reverseCookiePath = null;
+ String cookieName = cookie.getName();
+ Cookie responseCookie = new Cookie(cookieName, cookie.getValue());
+ responseCookie.setSecure(isSecureRequest && cookie.isSecure());
+ responseCookie.setVersion(cookie.getVersion());
+ responseCookie.setComment(cookie.getComment());
+ Date expireDate = cookie.getExpiryDate();
- for (org.apache.http.cookie.Cookie cookie : responseCookies)
+ if (expireDate != null)
{
- String cookieName = cookie.getName();
- Cookie responseCookie = new Cookie(cookieName, cookie.getValue());
- responseCookie.setSecure(isSecureRequest && cookie.isSecure());
- responseCookie.setVersion(cookie.getVersion());
- responseCookie.setComment(cookie.getComment());
- Date expireDate = cookie.getExpiryDate();
-
- if (expireDate != null)
- {
- int maxAgeSeconds = (int) ((expireDate.getTime() - System.currentTimeMillis()) / 1000L);
- responseCookie.setMaxAge(maxAgeSeconds);
- }
-
- reverseCookiePath = getReverseCookiePath(context, cookie);
-
- if (reverseCookiePath != null) {
- responseCookie.setPath(reverseCookiePath);
- }
+ int maxAgeSeconds = (int) ((expireDate.getTime() - System.currentTimeMillis()) / 1000L);
+ responseCookie.setMaxAge(maxAgeSeconds);
+ }
+
+ reverseCookiePath = getReverseCookiePath(context, cookie);
- context.getRequestContext().addCookie(responseCookie);
+ if (reverseCookiePath != null) {
+ responseCookie.setPath(reverseCookiePath);
}
+
+ context.getRequestContext().addCookie(responseCookie);
}
}
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeaderToHttpRequestCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeaderToHttpRequestCommand.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeaderToHttpRequestCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/AddHeaderToHttpRequestCommand.java Fri Aug 1 02:39:16 2014
@@ -25,22 +25,19 @@ import org.apache.http.protocol.HTTP;
import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
import org.apache.portals.applications.webcontent2.proxy.impl.ProxyContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class AddHeaderToHttpRequestCommand extends AbstractProxyCommand
{
- private static Logger log = LoggerFactory.getLogger(AddHeaderToHttpRequestCommand.class);
-
@Override
protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
{
HttpRequestBase httpRequest = context.getHttpRequest();
// pass most headers to remote URI...
- for (Enumeration enumHeaderNames = context.getRequestContext().getHeaderNames(); enumHeaderNames.hasMoreElements(); )
+ for (@SuppressWarnings("rawtypes")
+ Enumeration enumHeaderNames = context.getRequestContext().getHeaderNames(); enumHeaderNames.hasMoreElements();)
{
String headerName = (String) enumHeaderNames.nextElement();
@@ -50,7 +47,8 @@ public class AddHeaderToHttpRequestComma
if (StringUtils.equalsIgnoreCase(headerName, HTTP.TARGET_HOST))
continue;
- for (Enumeration enumHeaderValues = context.getRequestContext().getHeaders(headerName); enumHeaderValues.hasMoreElements(); )
+ for (@SuppressWarnings("rawtypes")
+ Enumeration enumHeaderValues = context.getRequestContext().getHeaders(headerName); enumHeaderValues.hasMoreElements();)
{
String headerValue = (String) enumHeaderValues.nextElement();
httpRequest.addHeader(headerName, headerValue);
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/CleanupCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/CleanupCommand.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/CleanupCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/CleanupCommand.java Fri Aug 1 02:39:16 2014
@@ -20,7 +20,10 @@ import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.util.EntityUtils;
import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
import org.apache.portals.applications.webcontent2.proxy.impl.ProxyContext;
@@ -68,7 +71,7 @@ public class CleanupCommand extends Abst
{
try
{
- httpEntity.consumeContent();
+ EntityUtils.consume(httpEntity);
}
catch (Exception e)
{
@@ -84,6 +87,27 @@ public class CleanupCommand extends Abst
}
}
+ HttpClient httpClient = context.getHttpClient();
+
+ if (httpClient instanceof CloseableHttpClient)
+ {
+ try
+ {
+ ((CloseableHttpClient) httpClient).close();
+ }
+ catch (Exception e)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.warn("Failed to close http client.", e);
+ }
+ else
+ {
+ log.warn("Failed to close http client. " + e);
+ }
+ }
+ }
+
return false;
}
}
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ExecuteHttpClientCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ExecuteHttpClientCommand.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ExecuteHttpClientCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/ExecuteHttpClientCommand.java Fri Aug 1 02:39:16 2014
@@ -24,15 +24,11 @@ import org.apache.http.client.methods.Ht
import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
import org.apache.portals.applications.webcontent2.proxy.impl.ProxyContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class ExecuteHttpClientCommand extends AbstractProxyCommand
{
- private static Logger log = LoggerFactory.getLogger(ExecuteHttpClientCommand.class);
-
@Override
protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
{
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleNotModifiedCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleNotModifiedCommand.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleNotModifiedCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/HandleNotModifiedCommand.java Fri Aug 1 02:39:16 2014
@@ -25,15 +25,11 @@ import org.apache.http.protocol.HTTP;
import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
import org.apache.portals.applications.webcontent2.proxy.impl.ProxyContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class HandleNotModifiedCommand extends AbstractProxyCommand
{
- private static Logger log = LoggerFactory.getLogger(HandleNotModifiedCommand.class);
-
@Override
protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
{
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpClientCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpClientCommand.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpClientCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/InitHttpClientCommand.java Fri Aug 1 02:39:16 2014
@@ -18,95 +18,35 @@ package org.apache.portals.applications.
import java.io.IOException;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.routing.HttpRoutePlanner;
-import org.apache.http.params.HttpParams;
+import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
import org.apache.portals.applications.webcontent2.proxy.impl.ProxyContext;
-import org.apache.portals.applications.webcontent2.proxy.impl.ProxyHttpClient;
public class InitHttpClientCommand extends AbstractProxyCommand
{
- private ClientConnectionManager clientConnectionManager;
-
- private HttpParams httpClientParams;
-
- // Note: normally redirection should be adjusted with local host header...
- private Boolean handleRedirects = Boolean.FALSE;
-
- private HttpRoutePlanner httpRoutePlanner;
+ private HttpClientBuilder httpClientBuilder;
@Override
protected boolean executeInternal(final ProxyContext context) throws ReverseProxyException, IOException
{
- ProxyHttpClient httpClient = new ProxyHttpClient(clientConnectionManager, httpClientParams);
-
- if (handleRedirects != null)
- {
- httpClient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, handleRedirects.booleanValue());
- }
-
- if (httpRoutePlanner != null)
- {
- httpClient.setRoutePlanner(httpRoutePlanner);
- }
-
+ CloseableHttpClient httpClient = httpClientBuilder.build();
context.setHttpClient(httpClient);
-
+ context.setCookieStore(new BasicCookieStore());
return false;
}
- @Override
- public void destroy()
+ public HttpClientBuilder getHttpClientBuilder()
{
- if (clientConnectionManager != null)
- {
- clientConnectionManager.shutdown();
- }
+ return httpClientBuilder;
}
- public ClientConnectionManager getClientConnectionManager()
+ public void setHttpClientBuilder(HttpClientBuilder httpClientBuilder)
{
- return clientConnectionManager;
+ this.httpClientBuilder = httpClientBuilder;
}
-
- public void setClientConnectionManager(ClientConnectionManager clientConnectionManager)
- {
- this.clientConnectionManager = clientConnectionManager;
- }
-
- public HttpParams getHttpClientParams()
- {
- return httpClientParams;
- }
-
- public void setHttpClientParams(HttpParams httpClientParams)
- {
- this.httpClientParams = httpClientParams;
- }
-
- public Boolean getHandleRedirects()
- {
- return handleRedirects;
- }
-
- public void setHandleRedirects(Boolean handleRedirects)
- {
- this.handleRedirects = handleRedirects;
- }
-
- public HttpRoutePlanner getHttpRoutePlanner()
- {
- return httpRoutePlanner;
- }
-
- public void setHttpRoutePlanner(HttpRoutePlanner httpRoutePlanner)
- {
- this.httpRoutePlanner = httpRoutePlanner;
- }
-
}
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/SerializeHttpEntityContentCommand.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/SerializeHttpEntityContentCommand.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/SerializeHttpEntityContentCommand.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/command/SerializeHttpEntityContentCommand.java Fri Aug 1 02:39:16 2014
@@ -22,6 +22,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
+import java.nio.charset.Charset;
import java.util.zip.GZIPInputStream;
import org.apache.commons.io.IOUtils;
@@ -29,7 +30,7 @@ import org.apache.commons.lang.StringUti
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
-import org.apache.http.util.EntityUtils;
+import org.apache.http.entity.ContentType;
import org.apache.portals.applications.webcontent2.proxy.ReverseProxyException;
import org.apache.portals.applications.webcontent2.proxy.impl.AbstractProxyCommand;
import org.apache.portals.applications.webcontent2.proxy.impl.GzippedSource;
@@ -83,7 +84,6 @@ public class SerializeHttpEntityContentC
Source source = new HttpEntitySource(httpEntity);
Sink sink = context.getRequestContext().getSink();
- String contentCharset = StringUtils.defaultIfEmpty(EntityUtils.getContentCharSet(httpEntity), getDefaultCharacterEncoding());
boolean gzipEncoded = isGzipEncodedContent(httpEntity);
ContentRewriter contentRewriter = context.getContentRewriter();
@@ -120,11 +120,15 @@ public class SerializeHttpEntityContentC
}
else
{
+ ContentType contentType = ContentType.getOrDefault(httpEntity);
+ Charset charset = contentType.getCharset();
+ String charsetName = StringUtils.defaultIfEmpty((charset != null ? charset.name() : null), getDefaultCharacterEncoding());
+
ContentRewritingContext rewritingContext = createContentRewritingContext();
if (gzipEncoded)
{
- contentRewriter.rewrite(new GzippedSource(source, contentCharset), sink, rewritingContext);
+ contentRewriter.rewrite(new GzippedSource(source, charsetName), sink, rewritingContext);
}
else
{
@@ -138,7 +142,10 @@ public class SerializeHttpEntityContentC
Source source = new HttpEntitySource(httpEntity);
Sink sink = context.getRequestContext().getSink();
- String contentCharset = StringUtils.defaultIfEmpty(EntityUtils.getContentCharSet(httpEntity), getDefaultCharacterEncoding());
+ ContentType contentType = ContentType.getOrDefault(httpEntity);
+ Charset charset = contentType.getCharset();
+ String charsetName = StringUtils.defaultIfEmpty((charset != null ? charset.name() : null), getDefaultCharacterEncoding());
+
boolean gzipEncoded = isGzipEncodedContent(httpEntity);
ContentRewriter contentRewriter = context.getContentRewriter();
@@ -156,7 +163,7 @@ public class SerializeHttpEntityContentC
if (gzipEncoded)
{
- contentRewriter.rewrite(new GzippedSource(source, contentCharset), sink, rewritingContext);
+ contentRewriter.rewrite(new GzippedSource(source, charsetName), sink, rewritingContext);
}
else
{
@@ -187,9 +194,9 @@ public class SerializeHttpEntityContentC
}
else
{
- if (contentCharset != null)
+ if (charsetName != null)
{
- reader = new InputStreamReader(gzipEncoded ? new GZIPInputStream(in) : in, contentCharset);
+ reader = new InputStreamReader(gzipEncoded ? new GZIPInputStream(in) : in, charsetName);
}
else
{
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/HttpEntitySource.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/HttpEntitySource.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/HttpEntitySource.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/HttpEntitySource.java Fri Aug 1 02:39:16 2014
@@ -20,9 +20,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.nio.charset.Charset;
import org.apache.http.HttpEntity;
-import org.apache.http.util.EntityUtils;
+import org.apache.http.entity.ContentType;
import org.apache.portals.applications.webcontent2.rewriter.Source;
public class HttpEntitySource implements Source
@@ -49,11 +50,18 @@ public class HttpEntitySource implements
public Reader getReader() throws IOException
{
- String charset = (characterEncoding != null ? characterEncoding : EntityUtils.getContentCharSet(entity));
+ String charsetName = characterEncoding;
- if (charset != null)
+ if (charsetName == null)
{
- return new InputStreamReader(getInputStream(), charset);
+ ContentType contentType = ContentType.getOrDefault(entity);
+ Charset charset = contentType.getCharset();
+ charsetName = (charset != null ? charset.name() : null);
+ }
+
+ if (charsetName != null)
+ {
+ return new InputStreamReader(getInputStream(), charsetName);
}
else
{
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyContext.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyContext.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyContext.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyContext.java Fri Aug 1 02:39:16 2014
@@ -22,6 +22,7 @@ import java.util.Map;
import org.apache.commons.chain.impl.ContextBase;
import org.apache.http.HttpResponse;
+import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.portals.applications.webcontent2.proxy.ProxyMapping;
@@ -40,6 +41,7 @@ public class ProxyContext extends Contex
private String localPath;
private String remoteURI;
private HttpClient httpClient;
+ private CookieStore cookieStore;
private HttpRequestBase httpRequest;
private HttpResponse httpResponse;
private ContentRewriter contentRewriter;
@@ -52,7 +54,7 @@ public class ProxyContext extends Contex
this.requestContext = requestContext;
}
- public ProxyContext(final RequestContext requestContext, Map map)
+ public ProxyContext(final RequestContext requestContext, @SuppressWarnings("rawtypes") Map map)
{
super(map);
this.requestContext = requestContext;
@@ -113,6 +115,16 @@ public class ProxyContext extends Contex
this.httpClient = httpClient;
}
+ public CookieStore getCookieStore()
+ {
+ return cookieStore;
+ }
+
+ public void setCookieStore(CookieStore cookieStore)
+ {
+ this.cookieStore = cookieStore;
+ }
+
public HttpRequestBase getHttpRequest()
{
return httpRequest;
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyProcessingChain.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyProcessingChain.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyProcessingChain.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ProxyProcessingChain.java Fri Aug 1 02:39:16 2014
@@ -44,7 +44,7 @@ public class ProxyProcessingChain extend
super(commands);
}
- public ProxyProcessingChain(Collection commands)
+ public ProxyProcessingChain(@SuppressWarnings("rawtypes") Collection commands)
{
super(commands);
}
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ServletRequestContext.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ServletRequestContext.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ServletRequestContext.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/impl/ServletRequestContext.java Fri Aug 1 02:39:16 2014
@@ -134,11 +134,13 @@ public class ServletRequestContext imple
return request.getInputStream();
}
+ @SuppressWarnings("rawtypes")
public Enumeration getHeaderNames()
{
return request.getHeaderNames();
}
+ @SuppressWarnings("rawtypes")
public Enumeration getHeaders(String name)
{
return request.getHeaders(name);
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.java Fri Aug 1 02:39:16 2014
@@ -21,16 +21,8 @@ import java.util.List;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
-import org.apache.commons.lang.math.NumberUtils;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.params.ConnManagerParamBean;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpParams;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
import org.apache.portals.applications.webcontent2.proxy.command.AddCookiesToResponseCommand;
import org.apache.portals.applications.webcontent2.proxy.command.AddHeaderToHttpRequestCommand;
@@ -68,14 +60,6 @@ public class SimpleReverseProxyServlet e
public static final String MAPPINGS_PARAM_NAME = "mappings";
- public static final String HTTP_MAX_TOTAL_CONNECTIONS_PARAM_NAME = "http.max.total.connections";
-
- public static final String HTTP_TIMEOUT_PARAM_NAME = "http.timeout";
-
- private int httpMaxTotalConnections = 400;
-
- private long httpTimeout = 10000L;
-
private ProxyProcessingChain proxyServiceCommand;
public SimpleReverseProxyServlet()
@@ -88,11 +72,7 @@ public class SimpleReverseProxyServlet e
{
super.init(servletConfig);
- httpMaxTotalConnections = NumberUtils.toInt(servletConfig.getInitParameter(HTTP_MAX_TOTAL_CONNECTIONS_PARAM_NAME), httpMaxTotalConnections);
-
- httpTimeout = NumberUtils.toLong(servletConfig.getInitParameter(HTTP_TIMEOUT_PARAM_NAME), httpTimeout);
-
- proxyServiceCommand = createProxyServiceCommand(servletConfig);
+ proxyServiceCommand = createProxyServiceCommand();
List<AbstractProxyCommand> allProxyCommands = proxyServiceCommand.getAllProxyCommands();
@@ -105,14 +85,27 @@ public class SimpleReverseProxyServlet e
setProxyService(proxyService);
}
- protected ProxyProcessingChain createProxyServiceCommand(final ServletConfig servletConfig)
+ protected ProxyProcessingChain createProxyServiceCommand()
{
- ProxyProcessingChain preprocessingChain = new ProxyProcessingChain();
+ ProxyProcessingChain proxyServiceChain = new ProxyProcessingChain();
- InitializationCommand initializationCommand = new InitializationCommand();
+ proxyServiceChain.addCommand(createPreprocessingCommand());
+ proxyServiceChain.addCommand(createProcessingCommand());
+ proxyServiceChain.addCommand(createPostprocessingCommand());
+ return proxyServiceChain;
+ }
+
+ protected ProxyProcessingChain createPreprocessingCommand()
+ {
+ ProxyProcessingChain preprocessingChain = new ProxyProcessingChain();
+ InitializationCommand initializationCommand = new InitializationCommand();
preprocessingChain.addCommand(initializationCommand);
+ return preprocessingChain;
+ }
+ protected ProxyProcessingChain createProcessingCommand()
+ {
ProxyProcessingChain processingChain = new ProxyProcessingChain();
ResolveLocalPathCommand resolveLocalPathCommand = new ResolveLocalPathCommand();
@@ -124,16 +117,7 @@ public class SimpleReverseProxyServlet e
ResolveContentRewriterCommand resolveContentRewriterCommand = new ResolveContentRewriterCommand();
InitHttpClientCommand initHttpClientCommand = new InitHttpClientCommand();
- SchemeRegistry schemeRegistry = new SchemeRegistry();
- schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
- schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
- HttpParams connManagerParams = new BasicHttpParams();
- ConnManagerParamBean connManagerParamBean = new ConnManagerParamBean(connManagerParams);
- connManagerParamBean.setMaxTotalConnections(httpMaxTotalConnections);
- connManagerParamBean.setTimeout(httpTimeout);
- ClientConnectionManager clientConnectionManager = new ThreadSafeClientConnManager(connManagerParams, schemeRegistry);
- initHttpClientCommand.setClientConnectionManager(clientConnectionManager);
- initHttpClientCommand.setHttpClientParams(new BasicHttpParams());
+ initHttpClientCommand.setHttpClientBuilder(createHttpClientBuilder());
InitHttpRequestCommand initHttpRequestCommand = new InitHttpRequestCommand();
AddHeaderToHttpRequestCommand addHeaderToHttpRequestCommand = new AddHeaderToHttpRequestCommand();
@@ -158,19 +142,20 @@ public class SimpleReverseProxyServlet e
processingChain.addCommand(addCookiesToResponseCommand);
processingChain.addCommand(serializeHttpEntityContentCommand);
- ProxyProcessingChain postprocessingChain = new ProxyProcessingChain();
+ return processingChain;
+ }
+ protected ProxyProcessingChain createPostprocessingCommand()
+ {
+ ProxyProcessingChain postprocessingChain = new ProxyProcessingChain();
CleanupCommand cleanupCommand = new CleanupCommand();
-
postprocessingChain.addCommand(cleanupCommand);
+ return postprocessingChain;
+ }
- ProxyProcessingChain proxyServiceChain = new ProxyProcessingChain();
-
- proxyServiceChain.addCommand(preprocessingChain);
- proxyServiceChain.addCommand(processingChain);
- proxyServiceChain.addCommand(postprocessingChain);
-
- return proxyServiceChain;
+ protected HttpClientBuilder createHttpClientBuilder()
+ {
+ return HttpClients.custom().disableRedirectHandling();
}
protected ProxyMappingRegistry createProxyMappingRegistry()
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/util/YamlConfigUtils.java Fri Aug 1 02:39:16 2014
@@ -116,7 +116,7 @@ public class YamlConfigUtils
{
if (item instanceof Collection)
{
- for (Object mapping : (Collection) item)
+ for (Object mapping : (Collection<?>) item)
{
if (mapping instanceof ProxyMapping)
{
Modified: portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/CommonsChainTest.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/CommonsChainTest.java?rev=1615023&r1=1615022&r2=1615023&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/CommonsChainTest.java (original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/CommonsChainTest.java Fri Aug 1 02:39:16 2014
@@ -113,6 +113,7 @@ public class CommonsChainTest
catalog = new CatalogBase(commandsMap);
}
+ @SuppressWarnings("unchecked")
@Test
public void testDefaultChainWithoutAuthorization() throws Exception
{
@@ -138,6 +139,7 @@ public class CommonsChainTest
assertEquals("Hello, John!", sw.toString());
}
+ @SuppressWarnings("unchecked")
@Test
public void testDefaultChainWithAuthorization() throws Exception
{
@@ -165,6 +167,7 @@ public class CommonsChainTest
assertEquals("Hello, John!", sw.toString());
}
+ @SuppressWarnings("unchecked")
@Test
public void testDefaultChainWithAuthorizationFailure() throws Exception
{
@@ -194,6 +197,7 @@ public class CommonsChainTest
private abstract class AbstractLoggableCommand implements Command
{
+ @SuppressWarnings("unchecked")
public final boolean execute(Context context) throws Exception
{
List<String> logs = (List<String>) context.get("logs");
@@ -224,6 +228,7 @@ public class CommonsChainTest
private class AuthCommand extends AbstractLoggableCommand
{
+ @SuppressWarnings("unchecked")
protected boolean executeInternal(Context context) throws Exception
{
final String roleAllowed = (String) context.get("role.allowed");
@@ -262,6 +267,7 @@ public class CommonsChainTest
private class CleanupCommand extends AbstractLoggableCommand
{
+ @SuppressWarnings("unchecked")
protected boolean executeInternal(Context context) throws Exception
{
Collection<Closeable> closeables = (Collection<Closeable>) context.get("closeables");