Author: dkulp Date: Tue Sep 11 18:54:04 2012 New Revision: 1383541 URL: http://svn.apache.org/viewvc?rev=1383541&view=rev Log: Merged revisions 1383521 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
........ r1383521 | dkulp | 2012-09-11 14:38:49 -0400 (Tue, 11 Sep 2012) | 10 lines Merged revisions 1381673 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/trunk ........ r1381673 | dkulp | 2012-09-06 12:40:43 -0400 (Thu, 06 Sep 2012) | 2 lines Add a test that tests the basic HTTP proxy stuff ........ ........ Added: cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java Modified: cxf/branches/2.5.x-fixes/systests/transports/pom.xml cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java Modified: cxf/branches/2.5.x-fixes/systests/transports/pom.xml URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/transports/pom.xml?rev=1383541&r1=1383540&r2=1383541&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/systests/transports/pom.xml (original) +++ cxf/branches/2.5.x-fixes/systests/transports/pom.xml Tue Sep 11 18:54:04 2012 @@ -292,7 +292,11 @@ <artifactId>commons-httpclient</artifactId> <scope>test</scope> </dependency> - + <dependency> + <groupId>org.littleshoot</groupId> + <artifactId>littleproxy</artifactId> + <version>0.4</version> + </dependency> </dependencies> </project> Modified: cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java?rev=1383541&r1=1383540&r2=1383541&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java (original) +++ cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPConduitTest.java Tue Sep 11 18:54:04 2012 @@ -281,6 +281,16 @@ public class HTTPConduitTest extends Abs return fac.getTrustManagers(); } + //methods that a subclass can override to inject a Proxy into the flow + //and assert the proxy was appropriately called + public void configureProxy(Client c) { + } + public void resetProxyCount() { + } + public void assertProxyRequestCount(int i) { + } + + private Greeter getMortimerGreeter() throws MalformedURLException { URL wsdl = getClass().getResource("resources/greeting.wsdl"); assertNotNull("WSDL is null", wsdl); @@ -291,6 +301,8 @@ public class HTTPConduitTest extends Abs Greeter mortimer = service.getPort(mortimerQ, Greeter.class); assertNotNull("Port is null", mortimer); updateAddressPort(mortimer, PORT0); + + configureProxy(ClientProxy.getClient(mortimer)); return mortimer; } @@ -302,6 +314,7 @@ public class HTTPConduitTest extends Abs String answer = mortimer.sayHi(); assertTrue("Unexpected answer: " + answer, "Bonjour from Mortimer".equals(answer)); + assertProxyRequestCount(1); } @Test @@ -317,6 +330,7 @@ public class HTTPConduitTest extends Abs } finally { rootLogger.setLevel(oldLevel); } + assertProxyRequestCount(1); } /** @@ -342,7 +356,8 @@ public class HTTPConduitTest extends Abs Greeter rethwel = service.getPort(rethwelQ, Greeter.class); assertNotNull("Port is null", rethwel); - updateAddressPort(rethwel, PORT5); + updateAddressPort(rethwel, PORT4); + configureProxy(ClientProxy.getClient(rethwel)); String answer = null; try { @@ -351,6 +366,7 @@ public class HTTPConduitTest extends Abs } catch (Exception e) { //e.printStackTrace(); } + assertProxyRequestCount(1); } @@ -392,10 +408,12 @@ public class HTTPConduitTest extends Abs Greeter rethwel = service.getPort(rethwelQ, Greeter.class); updateAddressPort(rethwel, PORT4); assertNotNull("Port is null", rethwel); + configureProxy(ClientProxy.getClient(rethwel)); String answer = rethwel.sayHi(); assertTrue("Unexpected answer: " + answer, "Bonjour from Mortimer".equals(answer)); + assertProxyRequestCount(2); } /** @@ -425,6 +443,7 @@ public class HTTPConduitTest extends Abs Greeter hurlon = service.getPort(hurlonQ, Greeter.class); assertNotNull("Port is null", hurlon); updateAddressPort(hurlon, PORT6); + configureProxy(ClientProxy.getClient(hurlon)); String answer = null; try { @@ -435,7 +454,7 @@ public class HTTPConduitTest extends Abs // read from the StreamReader //e.printStackTrace(); } - + assertProxyRequestCount(2); } /** * This methods tests a basic https connection to Bethal. @@ -458,6 +477,7 @@ public class HTTPConduitTest extends Abs assertNotNull("Service is null", service); Greeter bethal = service.getPort(bethalQ, Greeter.class); + assertNotNull("Port is null", bethal); updateAddressPort(bethal, PORT2); verifyBethalClient(bethal); @@ -485,6 +505,7 @@ public class HTTPConduitTest extends Abs // we just verify the configurations are loaded successfully private void verifyBethalClient(Greeter bethal) { Client client = ClientProxy.getClient(bethal); + HTTPConduit http = (HTTPConduit) client.getConduit(); @@ -503,9 +524,16 @@ public class HTTPConduitTest extends Abs "Betty", authPolicy.getUserName()); assertEquals("Set the wrong pass word form the configuration", "password", authPolicy.getPassword()); + + configureProxy(ClientProxy.getClient(bethal)); + String answer = bethal.sayHi(); assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer)); + + //With HTTPS, it will just be a CONNECT to the proxy and all the + //data is encrypted. Thus, the proxy cannot distinquish the requests + assertProxyRequestCount(0); } /** @@ -547,9 +575,11 @@ public class HTTPConduitTest extends Abs http.setTlsClientParameters(tlsClientParameters); http.setAuthorization(authPolicy); + configureProxy(client); String answer = bethal.sayHi(); assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer)); + assertProxyRequestCount(0); } @@ -580,7 +610,11 @@ public class HTTPConduitTest extends Abs http.setClient(httpClientPolicy); http.setTlsClientParameters(tlsClientParameters); + configureProxy(client); poltim.sayHi(); + //client -> poltim is https and thus not recorded but then redirected to mortimer + //client -> mortimer is http and recoreded + assertProxyRequestCount(1); } class MyHttpsTrustDecider extends MessageTrustDecider { @@ -676,9 +710,12 @@ public class HTTPConduitTest extends Abs // Our expected server should be OU=Bethal http.setTrustDecider(new MyHttpsTrustDecider("Bethal")); + configureProxy(client); String answer = bethal.sayHi(); assertTrue("Unexpected answer: " + answer, "Bonjour from Bethal".equals(answer)); + assertProxyRequestCount(0); + // Nobody will not equal OU=Bethal MyHttpsTrustDecider trustDecider = @@ -692,6 +729,7 @@ public class HTTPConduitTest extends Abs //assertTrue("Trust Decider was not called", // 0 > trustDecider.wasCalled()); } + assertProxyRequestCount(0); } @Test @@ -738,7 +776,9 @@ public class HTTPConduitTest extends Abs // We actually get our answer from Bethal at the end of the // redirects. + configureProxy(ClientProxy.getClient(tarpin)); String answer = tarpin.sayHi(); + assertProxyRequestCount(0); assertTrue("Trust Decider wasn't called correctly", 3 == trustDecider.wasCalled()); @@ -754,6 +794,7 @@ public class HTTPConduitTest extends Abs } catch (Exception e) { //e.printStackTrace(); } + assertProxyRequestCount(0); // Set back to unlimited. http.getClient().setMaxRetransmits(-1); @@ -772,7 +813,7 @@ public class HTTPConduitTest extends Abs assertTrue("Trust Decider wasn't called correctly", 2 == trustDecider.wasCalled()); } - + assertProxyRequestCount(0); } public class MyBasicAuthSupplier implements HttpAuthSupplier { Added: cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java?rev=1383541&view=auto ============================================================================== --- cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java (added) +++ cxf/branches/2.5.x-fixes/systests/transports/src/test/java/org/apache/cxf/systest/http/HTTPProxyConduitTest.java Tue Sep 11 18:54:04 2012 @@ -0,0 +1,100 @@ +/** + * 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.cxf.systest.http; + +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.cxf.endpoint.Client; +import org.apache.cxf.transport.http.HTTPConduit; +import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; + +import org.jboss.netty.handler.codec.http.HttpRequest; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; + +import org.littleshoot.proxy.DefaultHttpProxyServer; +import org.littleshoot.proxy.HttpFilter; +import org.littleshoot.proxy.HttpRequestFilter; + + +/** + * + */ +public class HTTPProxyConduitTest extends HTTPConduitTest { + static final int PROXY_PORT = Integer.parseInt(allocatePort(HTTPProxyConduitTest.class)); + static DefaultHttpProxyServer proxy; + static CountingFilter requestFilter = new CountingFilter(); + + static class CountingFilter implements HttpRequestFilter { + AtomicInteger count = new AtomicInteger(); + public void filter(HttpRequest httpRequest) { + count.incrementAndGet(); + } + + public void reset() { + count.set(0); + } + public int getCount() { + return count.get(); + } + } + + public HTTPProxyConduitTest() { + } + + + @AfterClass + public static void stopProxy() { + proxy.stop(); + proxy = null; + } + + @BeforeClass + public static void startProxy() { + proxy = new DefaultHttpProxyServer(PROXY_PORT, requestFilter, new HashMap<String, HttpFilter>()); + proxy.start(); + } + @Before + public void resetCount() { + requestFilter.reset(); + } + + public void configureProxy(Client client) { + HTTPConduit cond = (HTTPConduit)client.getConduit(); + HTTPClientPolicy pol = cond.getClient(); + if (pol == null) { + pol = new HTTPClientPolicy(); + cond.setClient(pol); + } + pol.setProxyServer("localhost"); + pol.setProxyServerPort(PROXY_PORT); + } + + public void resetProxyCount() { + requestFilter.reset(); + } + public void assertProxyRequestCount(int i) { + assertEquals("Unexpected request count", i, requestFilter.getCount()); + } + +}
