[CXF-6655] Adding testcase

Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/0ac4ffd4
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0ac4ffd4
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0ac4ffd4

Branch: refs/heads/3.0.x-fixes
Commit: 0ac4ffd4ca8da307a53d50fbceedb55c53fe01f8
Parents: c9b4c04
Author: Alessio Soldano <asold...@redhat.com>
Authored: Fri Oct 30 00:15:20 2015 +0100
Committer: Alessio Soldano <asold...@redhat.com>
Committed: Fri Oct 30 15:27:47 2015 +0100

----------------------------------------------------------------------
 systests/jaxws/pom.xml                          |  15 +++
 .../apache/cxf/systest/jaxws/CXF6655Test.java   | 109 +++++++++++++++++++
 2 files changed, 124 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0ac4ffd4/systests/jaxws/pom.xml
----------------------------------------------------------------------
diff --git a/systests/jaxws/pom.xml b/systests/jaxws/pom.xml
index 372c2b7..3cf699a 100644
--- a/systests/jaxws/pom.xml
+++ b/systests/jaxws/pom.xml
@@ -249,6 +249,21 @@
             <version>${cxf.netty3.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.littleshoot</groupId>
+            <artifactId>littleproxy</artifactId>
+            <version>0.4</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>log4j</groupId>
+                    <artifactId>log4j</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-log4j12</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
     </dependencies>
     <profiles>
         <profile>

http://git-wip-us.apache.org/repos/asf/cxf/blob/0ac4ffd4/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/CXF6655Test.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/CXF6655Test.java 
b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/CXF6655Test.java
new file mode 100644
index 0000000..d8eca96
--- /dev/null
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/CXF6655Test.java
@@ -0,0 +1,109 @@
+/**
+ * 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.jaxws;
+
+import java.util.HashMap;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.testutil.common.AbstractClientServerTestBase;
+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.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.littleshoot.proxy.DefaultHttpProxyServer;
+import org.littleshoot.proxy.HttpFilter;
+import org.littleshoot.proxy.ProxyUtils;
+
+public class CXF6655Test extends AbstractClientServerTestBase {
+    static final String PORT = allocatePort(Server.class);
+    static final int PROXY_PORT = 
Integer.parseInt(allocatePort(CXF6655Test.class));
+    static DefaultHttpProxyServer proxy;
+
+    public static class Server extends AbstractBusTestServerBase {
+
+        protected void run() {
+            Object implementor = new HelloImpl();
+            String address = "http://localhost:"; + PORT + "/hello";
+            Endpoint.publish(address, implementor);
+        }
+
+        public static void main(String[] args) {
+            try {
+                Server s = new Server();
+                s.start();
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                System.exit(-1);
+            } finally {
+                System.out.println("done!");
+            }
+        }
+    }
+
+    @AfterClass
+    public static void stopProxy() {
+        proxy.stop();
+        proxy = null;
+    }
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", 
launchServer(Server.class, true));
+        proxy = new DefaultHttpProxyServer(PROXY_PORT, 
ProxyUtils.PASS_THROUGH_REQUEST_FILTER,
+                                           new HashMap<String, HttpFilter>());
+        proxy.start();
+    }
+
+    @Test
+    public void testConnectionWithProxy() throws Exception {
+        QName serviceName = new QName("http://cxf.apache.org/systest/jaxws/";, 
"HelloService");
+        HelloService service = new 
HelloService(getClass().getResource("/wsdl/others/hello.wsdl"),
+                                                serviceName);
+        assertNotNull(service);
+        Hello hello = service.getHelloPort();
+
+        Client client = ClientProxy.getClient(hello);
+        client.getInInterceptors().add(new LoggingInInterceptor());
+        client.getOutInterceptors().add(new LoggingOutInterceptor());
+        HTTPConduit http = (HTTPConduit)client.getConduit();
+        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
+        httpClientPolicy.setAllowChunking(false);
+        httpClientPolicy.setReceiveTimeout(0);
+        httpClientPolicy.setProxyServerType(ProxyServerType.HTTP);
+        httpClientPolicy.setProxyServer("localhost");
+        httpClientPolicy.setProxyServerPort(PROXY_PORT);
+        http.setClient(httpClientPolicy);
+
+        
((BindingProvider)hello).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+                                                         "http://localhost:"; + 
PORT + "/hello");
+        assertEquals("getSayHi", hello.sayHi("SayHi"));
+
+    }
+}

Reply via email to