Author: alessio.soldano(a)jboss.com
Date: 2012-09-12 12:06:05 -0400 (Wed, 12 Sep 2012)
New Revision: 16716
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpproxy/HTTPProxyTestCaseForked.java
Removed:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpproxy/HTTPProxyTestCase.java
Modified:
stack/cxf/trunk/modules/testsuite/pom.xml
Log:
Moving http proxy testcase to forked VM execution as playing with client system properties
does not fit multithread execution...
Deleted:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpproxy/HTTPProxyTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpproxy/HTTPProxyTestCase.java 2012-09-12
16:03:29 UTC (rev 16715)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpproxy/HTTPProxyTestCase.java 2012-09-12
16:06:05 UTC (rev 16716)
@@ -1,283 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2012, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.test.ws.jaxws.cxf.httpproxy;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
-import java.net.Authenticator;
-import java.net.MalformedURLException;
-import java.net.PasswordAuthentication;
-import java.net.URL;
-import java.util.HashMap;
-
-import javax.xml.namespace.QName;
-import javax.xml.ws.BindingProvider;
-import javax.xml.ws.Service;
-
-import junit.framework.Test;
-
-import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy;
-import org.apache.cxf.endpoint.Client;
-import org.apache.cxf.frontend.ClientProxy;
-import org.apache.cxf.transport.http.HTTPConduit;
-import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
-import org.apache.cxf.transports.http.configuration.ProxyServerType;
-import org.jboss.wsf.test.JBossWSCXFTestSetup;
-import org.jboss.wsf.test.JBossWSTest;
-import org.littleshoot.proxy.DefaultHttpProxyServer;
-import org.littleshoot.proxy.HttpFilter;
-import org.littleshoot.proxy.HttpProxyServer;
-import org.littleshoot.proxy.ProxyAuthorizationHandler;
-
-/**
- * Tests / samples for WS client using HTTP Proxy
- *
- * @author alessio.soldano(a)jboss.com
- * @since 24-May-2011
- */
-public class HTTPProxyTestCase extends JBossWSTest
-{
- private static int proxyPort = 19387;
- private static final String PROXY_USER = "foo";
- private static final String PROXY_PWD = "bar";
- private static final String ENDPOINT_PATH =
"/jaxws-cxf-httpproxy/HelloWorldService/HelloWorldImpl";
- private HttpProxyServer proxyServer;
-
- public static Test suite()
- {
- return new JBossWSCXFTestSetup(HTTPProxyTestCase.class,
"jaxws-cxf-httpproxy.war");
- }
-
- public void testHttpProxy() throws Exception
- {
- final String testHost = "unreachable-testHttpProxy";
- HelloWorld port =
getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"),
testHost);
- final String hi = "Hi!";
- //first try without setting up the proxy -> request fails because the host is
not known/reachable
- try
- {
- port.echo(hi);
- fail("Exception expected");
- }
- catch (Exception e)
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- e.printStackTrace(new PrintStream(baos));
- assertTrue(baos.toString().contains(testHost));
- }
-
- //then setup the proxy, but provide no authentication/authorization info ->
request fails because of HTTP 407
- setProxySystemProperties();
- try
- {
- port.echo(hi);
- fail("Exception expected");
- }
- catch (Exception e)
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- e.printStackTrace(new PrintStream(baos));
- assertTrue(baos.toString().contains("407: Proxy Authentication
Required"));
- }
-
- //finally setup everything
- Client client = ClientProxy.getClient(port);
- HTTPConduit conduit = (HTTPConduit)client.getConduit();
- ProxyAuthorizationPolicy policy = new ProxyAuthorizationPolicy();
- policy.setAuthorizationType("Basic");
- policy.setUserName(PROXY_USER);
- policy.setPassword(PROXY_PWD);
- conduit.setProxyAuthorization(policy);
-
- assertEquals(hi, port.echo(hi));
- }
-
- public void testHttpProxyUsingHTTPClientPolicy() throws Exception
- {
- final String testHost =
"unreachable-testHttpProxyUsingHTTPClientPolicy";
- HelloWorld port =
getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"),
testHost);
- final String hi = "Hi!";
- //first try without setting up the proxy -> request fails because the host is
not known/reachable
- try
- {
- port.echo(hi);
- fail("Exception expected");
- }
- catch (Exception e)
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- e.printStackTrace(new PrintStream(baos));
- assertTrue(baos.toString().contains(testHost));
- }
-
- //then setup the proxy, but provide no authentication/authorization info ->
request fails because of HTTP 407
- Client client = ClientProxy.getClient(port);
- HTTPConduit conduit = (HTTPConduit)client.getConduit();
- HTTPClientPolicy clientPolicy = conduit.getClient();
- clientPolicy.setProxyServerType(ProxyServerType.HTTP);
- clientPolicy.setProxyServer(getServerHost());
- clientPolicy.setProxyServerPort(proxyPort);
- try
- {
- port.echo(hi);
- fail("Exception expected");
- }
- catch (Exception e)
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- e.printStackTrace(new PrintStream(baos));
- assertTrue(baos.toString().contains("407: Proxy Authentication
Required"));
- }
-
- //finally setup authorization info too
- ProxyAuthorizationPolicy authPolicy = new ProxyAuthorizationPolicy();
- authPolicy.setAuthorizationType("Basic");
- authPolicy.setUserName(PROXY_USER);
- authPolicy.setPassword(PROXY_PWD);
- conduit.setProxyAuthorization(authPolicy);
-
- assertEquals(hi, port.echo(hi));
- }
-
- @Override
- protected void setUp() throws Exception
- {
- proxyServer = new DefaultHttpProxyServer(++proxyPort, new HashMap<String,
HttpFilter>(),
- getServerHost() + ":8080", null, null);
- ProxyAuthorizationHandler authorizationHandler = new ProxyAuthorizationHandler()
- {
-
- @Override
- public boolean authenticate(String user, String pwd)
- {
- return (PROXY_USER.equals(user) && PROXY_PWD.equals(pwd));
- }
- };
- proxyServer.addProxyAuthenticationHandler(authorizationHandler);
- proxyServer.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- if (proxyServer != null)
- {
- proxyServer.stop();
- }
- clearProxySystemProperties();
- }
-
- private HelloWorld getPort(URL wsdlURL, String endpointAddressHost) throws
MalformedURLException
- {
- QName serviceName = new QName("http://org.jboss.ws/jaxws/cxf/httpproxy",
"HelloWorldService");
- Service service = Service.create(wsdlURL, serviceName);
- QName portQName = new QName("http://org.jboss.ws/jaxws/cxf/httpproxy",
"HelloWorldImplPort");
- HelloWorld port = (HelloWorld) service.getPort(portQName, HelloWorld.class);
- BindingProvider provider = (BindingProvider)port;
- provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://" + endpointAddressHost +
"/jaxws-cxf-httpproxy/HelloWorldService/HelloWorldImpl");
- return port;
- }
-
- private static void setProxySystemProperties()
- {
- System.getProperties().setProperty("http.proxyHost", getServerHost());
- System.getProperties().setProperty("http.proxyPort",
String.valueOf(proxyPort));
- }
-
- private static void clearProxySystemProperties()
- {
- System.clearProperty("http.proxyHost");
- System.clearProperty("http.proxyPort");
- }
-
- public void testWSDLHttpProxy() throws Exception
- {
- setProxySystemProperties();
- try
- {
- Authenticator.setDefault(new ProxyAuthenticator(PROXY_USER, PROXY_PWD));
- String endpointAddress = "http://unreachable-testWSDLHttpProxy" +
ENDPOINT_PATH;
- StringBuffer sb = readContent(new URL(endpointAddress + "?wsdl"));
- assertTrue(sb.toString().contains("wsdl:definitions
name=\"HelloWorldService\""));
- }
- finally
- {
- Authenticator.setDefault(null);
- }
- }
-
- public void testWSDLNoHttpProxy() throws Exception
- {
- clearProxySystemProperties();
- String endpointAddress = "http://unreachable-testWSDLNoHttpProxy" +
ENDPOINT_PATH;
- try
- {
- readContent(new URL(endpointAddress + "?wsdl"));
- fail("Request expected to fail without http proxy");
- }
- catch (Exception e)
- {
-
assertTrue(e.getMessage().contains("unreachable-testWSDLNoHttpProxy"));
- }
- }
-
- private static StringBuffer readContent(URL url) throws Exception
- {
- StringBuffer sb = new StringBuffer();
- InputStream is = null;
- try
- {
- is = url.openConnection().getInputStream();
- BufferedReader in = new BufferedReader(new InputStreamReader(is));
- String line;
- while ((line = in.readLine()) != null)
- {
- sb.append(line);
- sb.append("\n");
- }
- }
- finally
- {
- if (is != null) is.close();
- }
- return sb;
- }
-
- private static class ProxyAuthenticator extends Authenticator
- {
- private String user, password;
-
- public ProxyAuthenticator(String user, String password)
- {
- this.user = user;
- this.password = password;
- }
-
- protected PasswordAuthentication getPasswordAuthentication()
- {
- return new PasswordAuthentication(user, password.toCharArray());
- }
- }
-}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpproxy/HTTPProxyTestCaseForked.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpproxy/HTTPProxyTestCaseForked.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/httpproxy/HTTPProxyTestCaseForked.java 2012-09-12
16:06:05 UTC (rev 16716)
@@ -0,0 +1,283 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.cxf.httpproxy;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.net.Authenticator;
+import java.net.MalformedURLException;
+import java.net.PasswordAuthentication;
+import java.net.URL;
+import java.util.HashMap;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Service;
+
+import junit.framework.Test;
+
+import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.apache.cxf.transports.http.configuration.ProxyServerType;
+import org.jboss.wsf.test.JBossWSCXFTestSetup;
+import org.jboss.wsf.test.JBossWSTest;
+import org.littleshoot.proxy.DefaultHttpProxyServer;
+import org.littleshoot.proxy.HttpFilter;
+import org.littleshoot.proxy.HttpProxyServer;
+import org.littleshoot.proxy.ProxyAuthorizationHandler;
+
+/**
+ * Tests / samples for WS client using HTTP Proxy
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 24-May-2011
+ */
+public class HTTPProxyTestCaseForked extends JBossWSTest
+{
+ private static int proxyPort = 19387;
+ private static final String PROXY_USER = "foo";
+ private static final String PROXY_PWD = "bar";
+ private static final String ENDPOINT_PATH =
"/jaxws-cxf-httpproxy/HelloWorldService/HelloWorldImpl";
+ private HttpProxyServer proxyServer;
+
+ public static Test suite()
+ {
+ return new JBossWSCXFTestSetup(HTTPProxyTestCaseForked.class,
"jaxws-cxf-httpproxy.war");
+ }
+
+ public void testHttpProxy() throws Exception
+ {
+ final String testHost = "unreachable-testHttpProxy";
+ HelloWorld port =
getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"),
testHost);
+ final String hi = "Hi!";
+ //first try without setting up the proxy -> request fails because the host is
not known/reachable
+ try
+ {
+ port.echo(hi);
+ fail("Exception expected");
+ }
+ catch (Exception e)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ e.printStackTrace(new PrintStream(baos));
+ assertTrue(baos.toString().contains(testHost));
+ }
+
+ //then setup the proxy, but provide no authentication/authorization info ->
request fails because of HTTP 407
+ setProxySystemProperties();
+ try
+ {
+ port.echo(hi);
+ fail("Exception expected");
+ }
+ catch (Exception e)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ e.printStackTrace(new PrintStream(baos));
+ assertTrue(baos.toString().contains("407: Proxy Authentication
Required"));
+ }
+
+ //finally setup everything
+ Client client = ClientProxy.getClient(port);
+ HTTPConduit conduit = (HTTPConduit)client.getConduit();
+ ProxyAuthorizationPolicy policy = new ProxyAuthorizationPolicy();
+ policy.setAuthorizationType("Basic");
+ policy.setUserName(PROXY_USER);
+ policy.setPassword(PROXY_PWD);
+ conduit.setProxyAuthorization(policy);
+
+ assertEquals(hi, port.echo(hi));
+ }
+
+ public void testHttpProxyUsingHTTPClientPolicy() throws Exception
+ {
+ final String testHost =
"unreachable-testHttpProxyUsingHTTPClientPolicy";
+ HelloWorld port =
getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"),
testHost);
+ final String hi = "Hi!";
+ //first try without setting up the proxy -> request fails because the host is
not known/reachable
+ try
+ {
+ port.echo(hi);
+ fail("Exception expected");
+ }
+ catch (Exception e)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ e.printStackTrace(new PrintStream(baos));
+ assertTrue(baos.toString().contains(testHost));
+ }
+
+ //then setup the proxy, but provide no authentication/authorization info ->
request fails because of HTTP 407
+ Client client = ClientProxy.getClient(port);
+ HTTPConduit conduit = (HTTPConduit)client.getConduit();
+ HTTPClientPolicy clientPolicy = conduit.getClient();
+ clientPolicy.setProxyServerType(ProxyServerType.HTTP);
+ clientPolicy.setProxyServer(getServerHost());
+ clientPolicy.setProxyServerPort(proxyPort);
+ try
+ {
+ port.echo(hi);
+ fail("Exception expected");
+ }
+ catch (Exception e)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ e.printStackTrace(new PrintStream(baos));
+ assertTrue(baos.toString().contains("407: Proxy Authentication
Required"));
+ }
+
+ //finally setup authorization info too
+ ProxyAuthorizationPolicy authPolicy = new ProxyAuthorizationPolicy();
+ authPolicy.setAuthorizationType("Basic");
+ authPolicy.setUserName(PROXY_USER);
+ authPolicy.setPassword(PROXY_PWD);
+ conduit.setProxyAuthorization(authPolicy);
+
+ assertEquals(hi, port.echo(hi));
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ proxyServer = new DefaultHttpProxyServer(++proxyPort, new HashMap<String,
HttpFilter>(),
+ getServerHost() + ":8080", null, null);
+ ProxyAuthorizationHandler authorizationHandler = new ProxyAuthorizationHandler()
+ {
+
+ @Override
+ public boolean authenticate(String user, String pwd)
+ {
+ return (PROXY_USER.equals(user) && PROXY_PWD.equals(pwd));
+ }
+ };
+ proxyServer.addProxyAuthenticationHandler(authorizationHandler);
+ proxyServer.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ clearProxySystemProperties();
+ if (proxyServer != null)
+ {
+ proxyServer.stop();
+ }
+ }
+
+ private HelloWorld getPort(URL wsdlURL, String endpointAddressHost) throws
MalformedURLException
+ {
+ QName serviceName = new QName("http://org.jboss.ws/jaxws/cxf/httpproxy",
"HelloWorldService");
+ Service service = Service.create(wsdlURL, serviceName);
+ QName portQName = new QName("http://org.jboss.ws/jaxws/cxf/httpproxy",
"HelloWorldImplPort");
+ HelloWorld port = (HelloWorld) service.getPort(portQName, HelloWorld.class);
+ BindingProvider provider = (BindingProvider)port;
+ provider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://" + endpointAddressHost +
"/jaxws-cxf-httpproxy/HelloWorldService/HelloWorldImpl");
+ return port;
+ }
+
+ private static void setProxySystemProperties()
+ {
+ System.getProperties().setProperty("http.proxyHost", getServerHost());
+ System.getProperties().setProperty("http.proxyPort",
String.valueOf(proxyPort));
+ }
+
+ private static void clearProxySystemProperties()
+ {
+ System.clearProperty("http.proxyHost");
+ System.clearProperty("http.proxyPort");
+ }
+
+ public void testWSDLHttpProxy() throws Exception
+ {
+ setProxySystemProperties();
+ try
+ {
+ Authenticator.setDefault(new ProxyAuthenticator(PROXY_USER, PROXY_PWD));
+ String endpointAddress = "http://unreachable-testWSDLHttpProxy" +
ENDPOINT_PATH;
+ StringBuffer sb = readContent(new URL(endpointAddress + "?wsdl"));
+ assertTrue(sb.toString().contains("wsdl:definitions
name=\"HelloWorldService\""));
+ }
+ finally
+ {
+ Authenticator.setDefault(null);
+ }
+ }
+
+ public void testWSDLNoHttpProxy() throws Exception
+ {
+ clearProxySystemProperties();
+ String endpointAddress = "http://unreachable-testWSDLNoHttpProxy" +
ENDPOINT_PATH;
+ try
+ {
+ readContent(new URL(endpointAddress + "?wsdl"));
+ fail("Request expected to fail without http proxy");
+ }
+ catch (Exception e)
+ {
+
assertTrue(e.getMessage().contains("unreachable-testWSDLNoHttpProxy"));
+ }
+ }
+
+ private static StringBuffer readContent(URL url) throws Exception
+ {
+ StringBuffer sb = new StringBuffer();
+ InputStream is = null;
+ try
+ {
+ is = url.openConnection().getInputStream();
+ BufferedReader in = new BufferedReader(new InputStreamReader(is));
+ String line;
+ while ((line = in.readLine()) != null)
+ {
+ sb.append(line);
+ sb.append("\n");
+ }
+ }
+ finally
+ {
+ if (is != null) is.close();
+ }
+ return sb;
+ }
+
+ private static class ProxyAuthenticator extends Authenticator
+ {
+ private String user, password;
+
+ public ProxyAuthenticator(String user, String password)
+ {
+ this.user = user;
+ this.password = password;
+ }
+
+ protected PasswordAuthentication getPasswordAuthentication()
+ {
+ return new PasswordAuthentication(user, password.toCharArray());
+ }
+ }
+}
Modified: stack/cxf/trunk/modules/testsuite/pom.xml
===================================================================
--- stack/cxf/trunk/modules/testsuite/pom.xml 2012-09-12 16:03:29 UTC (rev 16715)
+++ stack/cxf/trunk/modules/testsuite/pom.xml 2012-09-12 16:06:05 UTC (rev 16716)
@@ -379,11 +379,12 @@
<forkMode>pertest</forkMode>
<skip>false</skip>
<includes>
+
<include>**/jaxws/cxf/httpproxy/*TestCaseForked.java</include>
+
<include>**/jaxws/samples/schemavalidation/*TestCaseForked.java</include>
+ <include>**/jbws2150/**/*TestCaseForked.java</include>
+ <include>**/jms*/**/*TestCaseForked.java</include>
<include>**/smoke/tools/**/*TestForked.java</include>
<include>**/smoke/tools/**/*TestCaseForked.java</include>
- <include>**/jbws2150/**/*TestCaseForked.java</include>
- <include>**/jms*/**/*TestCaseForked.java</include>
-
<include>**/jaxws/samples/schemavalidation/*TestCaseForked.java</include>
</includes>
<systemProperties>
<property>