portals-portalapps-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r1721443 - 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/builder/ reverse-proxy/src...
Date Tue, 22 Dec 2015 18:30:18 GMT
Author: woonsan
Date: Tue Dec 22 18:30:18 2015
New Revision: 1721443

URL: http://svn.apache.org/viewvc?rev=1721443&view=rev
Log:
APA-72 setting default httpClientContextBuilder

Added:
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultHttpClientContextBuilder.java
  (with props)
    portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/command/HttpClientContextCommandsTest.java
  (with props)
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/command/ExecuteHttpClientCommand.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/SimpleReverseProxyFilter.java
    portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/servlet/SimpleReverseProxyServlet.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=1721443&r1=1721442&r2=1721443&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
Tue Dec 22 18:30:18 2015
@@ -36,6 +36,7 @@ import org.apache.http.impl.client.HttpC
 import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
 import org.apache.portals.applications.webcontent2.proxy.ProxyMapping;
 import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
+import org.apache.portals.applications.webcontent2.proxy.builder.DefaultHttpClientContextBuilder;
 import org.apache.portals.applications.webcontent2.proxy.builder.ProxyServices;
 import org.apache.portals.applications.webcontent2.proxy.impl.DefaultProxyMappingRegistry;
 import org.apache.portals.applications.webcontent2.proxy.impl.DefaultReverseProxyService;
@@ -96,7 +97,7 @@ public class SimpleReverseProxyPortlet e
     /**
      * Internal {@link HttpClientContextBuilder} instance.
      */
-    private HttpClientContextBuilder httpClientContextBuilder;
+    private HttpClientContextBuilder httpClientContextBuilder = new DefaultHttpClientContextBuilder();
 
     /**
      * SSL Socket Connection Factory.

Added: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultHttpClientContextBuilder.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultHttpClientContextBuilder.java?rev=1721443&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultHttpClientContextBuilder.java
(added)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultHttpClientContextBuilder.java
Tue Dec 22 18:30:18 2015
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.proxy.builder;
+
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
+
+public class DefaultHttpClientContextBuilder implements HttpClientContextBuilder {
+
+    public DefaultHttpClientContextBuilder()
+    {
+    }
+
+    @Override
+    public HttpClientContext build()
+    {
+        final HttpClientContext httpClientContext = HttpClientContext.create();
+        return httpClientContext;
+    }
+
+}

Propchange: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/builder/DefaultHttpClientContextBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1721443&r1=1721442&r2=1721443&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
Tue Dec 22 18:30:18 2015
@@ -22,6 +22,7 @@ import org.apache.commons.chain.Command;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.protocol.HttpContext;
 import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
 import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
@@ -64,7 +65,24 @@ public class ExecuteHttpClientCommand ex
         }
         else
         {
-            httpResponse = httpClient.execute(httpRequest, getHttpClientContextBuilder().build());
+            final HttpClientContext httpClientContext = getHttpClientContextBuilder().build();
+
+            // if cookie store is not provided by httpClientContext, then use the default
one in proxy context
+            if (httpClientContext.getCookieStore() == null)
+            {
+                if (context.getCookieStore() != null)
+                {
+                    httpClientContext.setCookieStore(context.getCookieStore());
+                }
+            }
+            // if cookie store is provided by httpClientContext, then replace that of proxy
context as well
+            // to use the same cookie store onward
+            else
+            {
+                context.setCookieStore(httpClientContext.getCookieStore());
+            }
+
+            httpResponse = httpClient.execute(httpRequest, httpClientContext);
         }
 
         context.setHttpResponse(httpResponse);

Modified: portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/SimpleReverseProxyFilter.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/SimpleReverseProxyFilter.java?rev=1721443&r1=1721442&r2=1721443&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/SimpleReverseProxyFilter.java
(original)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/main/java/org/apache/portals/applications/webcontent2/proxy/filter/SimpleReverseProxyFilter.java
Tue Dec 22 18:30:18 2015
@@ -30,6 +30,7 @@ import org.apache.http.impl.client.HttpC
 import org.apache.http.impl.client.HttpClients;
 import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
 import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
+import org.apache.portals.applications.webcontent2.proxy.builder.DefaultHttpClientContextBuilder;
 import org.apache.portals.applications.webcontent2.proxy.builder.ProxyServices;
 import org.apache.portals.applications.webcontent2.proxy.impl.DefaultProxyMappingRegistry;
 import org.apache.portals.applications.webcontent2.proxy.impl.DefaultReverseProxyService;
@@ -62,7 +63,7 @@ public class SimpleReverseProxyFilter ex
     /**
      * Internal {@link HttpClientContextBuilder} instance.
      */
-    private HttpClientContextBuilder httpClientContextBuilder;
+    private HttpClientContextBuilder httpClientContextBuilder = new DefaultHttpClientContextBuilder();
 
     /**
      * SSL Socket Connection Factory.

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=1721443&r1=1721442&r2=1721443&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
Tue Dec 22 18:30:18 2015
@@ -29,6 +29,7 @@ import org.apache.http.impl.client.HttpC
 import org.apache.http.impl.client.HttpClients;
 import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
 import org.apache.portals.applications.webcontent2.proxy.ProxyMappingRegistry;
+import org.apache.portals.applications.webcontent2.proxy.builder.DefaultHttpClientContextBuilder;
 import org.apache.portals.applications.webcontent2.proxy.builder.ProxyServices;
 import org.apache.portals.applications.webcontent2.proxy.impl.DefaultProxyMappingRegistry;
 import org.apache.portals.applications.webcontent2.proxy.impl.DefaultReverseProxyService;
@@ -62,7 +63,7 @@ public class SimpleReverseProxyServlet e
     /**
      * Internal {@link HttpClientContextBuilder} instance.
      */
-    private HttpClientContextBuilder httpClientContextBuilder;
+    private HttpClientContextBuilder httpClientContextBuilder = new DefaultHttpClientContextBuilder();
 
     /**
      * SSL Socket Connection Factory.

Added: portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/command/HttpClientContextCommandsTest.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/command/HttpClientContextCommandsTest.java?rev=1721443&view=auto
==============================================================================
--- portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/command/HttpClientContextCommandsTest.java
(added)
+++ portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/command/HttpClientContextCommandsTest.java
Tue Dec 22 18:30:18 2015
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.applications.webcontent2.proxy.command;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.portals.applications.webcontent2.proxy.HttpClientContextBuilder;
+import org.apache.portals.applications.webcontent2.proxy.ProxyContext;
+import org.apache.portals.applications.webcontent2.proxy.builder.DefaultHttpClientContextBuilder;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class HttpClientContextCommandsTest
+{
+
+    private HttpClient httpClient;
+
+    private HttpClientContextBuilder httpClientContextBuilder;
+    private HttpClientContext currentHttpClientContext;
+
+    private CookieStore httpClientContextCookieStore;
+
+    private InitHttpClientCommand initCommand;
+    private ExecuteHttpClientCommand execCommand;
+    private AddCookiesToResponseCommand cookiesRespondCommand;
+
+    @Before
+    public void before() throws Exception
+    {
+        httpClient = EasyMock.createNiceMock(HttpClient.class);
+        EasyMock.replay(httpClient);
+
+        httpClientContextBuilder = new DefaultHttpClientContextBuilder()
+        {
+            @Override
+            public HttpClientContext build()
+            {
+                currentHttpClientContext = super.build();
+
+                if (httpClientContextCookieStore != null) {
+                    currentHttpClientContext.setCookieStore(httpClientContextCookieStore);
+                }
+
+                return currentHttpClientContext;
+            }
+        };
+
+        initCommand = new InitHttpClientCommand();
+        initCommand.setHttpClientBuilder(HttpClientBuilder.create());
+        execCommand = new ExecuteHttpClientCommand();
+        execCommand.setHttpClientContextBuilder(httpClientContextBuilder);
+        cookiesRespondCommand = new AddCookiesToResponseCommand();
+    }
+
+    @Test
+    public void test_whenCookieStoreNotSetInHttpClientContext() throws Exception
+    {
+        ProxyContext proxyContext = new ProxyContext(null);
+
+        assertNull(proxyContext.getCookieStore());
+        initCommand.execute(proxyContext);
+        final CookieStore proxyContextCookieStore = proxyContext.getCookieStore();
+        assertNotNull(proxyContextCookieStore);
+
+        assertNull(currentHttpClientContext);
+        proxyContext.setHttpClient(httpClient);
+        execCommand.execute(proxyContext);
+        assertNotNull(currentHttpClientContext);
+
+        assertSame(proxyContextCookieStore, proxyContext.getCookieStore());
+        assertSame(proxyContextCookieStore, currentHttpClientContext.getCookieStore());
+    }
+
+    @Test
+    public void test_whenCookieStoreSetInHttpClientContext() throws Exception
+    {
+        httpClientContextCookieStore = new BasicCookieStore();
+
+        ProxyContext proxyContext = new ProxyContext(null);
+
+        assertNull(proxyContext.getCookieStore());
+        initCommand.execute(proxyContext);
+        final CookieStore proxyContextCookieStore = proxyContext.getCookieStore();
+        assertNotNull(proxyContextCookieStore);
+        assertNotSame(httpClientContextCookieStore, proxyContextCookieStore);
+
+        assertNull(currentHttpClientContext);
+        proxyContext.setHttpClient(httpClient);
+        execCommand.execute(proxyContext);
+        assertNotNull(currentHttpClientContext);
+
+        assertSame(httpClientContextCookieStore, proxyContext.getCookieStore());
+        assertSame(httpClientContextCookieStore, currentHttpClientContext.getCookieStore());
+    }
+
+}

Propchange: portals/applications/webcontent/trunk/reverse-proxy/src/test/java/org/apache/portals/applications/webcontent2/proxy/command/HttpClientContextCommandsTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message