Author: alessio.soldano(a)jboss.com
Date: 2011-04-01 12:19:57 -0400 (Fri, 01 Apr 2011)
New Revision: 13987
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/main/java/org/jboss/wsf/test/ClientHelper.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/main/java/org/jboss/wsf/test/TestServlet.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPEnforcingInInterceptor.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPServletTestCase.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/Helper.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/gzip/META-INF/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/gzip/META-INF/MANIFEST.MF
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPTestCase.java
Log:
Adding an in-container servlet-client-based version of gzip testcase, refactoring the test
a bit and fixing an issue with erroneusly re-using HTTPConduit
Modified: stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml
===================================================================
--- stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml 2011-04-01
09:03:29 UTC (rev 13986)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml 2011-04-01
16:19:57 UTC (rev 13987)
@@ -85,6 +85,19 @@
<include
name="org/jboss/test/ws/jaxws/cxf/gzip/HelloWorld*.class"/>
</classes>
</war>
+ <war warfile="${tests.output.dir}/test-libs/jaxws-cxf-gzip-client.war"
+
manifest="${tests.output.dir}/test-resources/jaxws/cxf/gzip/META-INF/MANIFEST.MF"
+ needxmlfile='false'>
+ <classes dir="${tests.output.dir}/test-classes">
+ <include name="org/jboss/test/ws/jaxws/cxf/gzip/Helper.class"/>
+ <include
name="org/jboss/test/ws/jaxws/cxf/gzip/GZIPEnforcingInInterceptor.class"/>
+ <include
name="org/jboss/test/ws/jaxws/cxf/gzip/HelloWorld.class"/>
+ </classes>
+ <classes dir="${tests.output.dir}/classes">
+ <include name="org/jboss/wsf/test/TestServlet.class"/>
+ <include name="org/jboss/wsf/test/ClientHelper.class"/>
+ </classes>
+ </war>
<!-- jaxws-cxf-jaxbintros -->
<jar
destfile="${tests.output.dir}/test-libs/jaxws-cxf-jaxbintros.jar">
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/main/java/org/jboss/wsf/test/ClientHelper.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/main/java/org/jboss/wsf/test/ClientHelper.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/main/java/org/jboss/wsf/test/ClientHelper.java 2011-04-01
16:19:57 UTC (rev 13987)
@@ -0,0 +1,27 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.wsf.test;
+
+public interface ClientHelper
+{
+ public void setTargetEndpoint(String address);
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/main/java/org/jboss/wsf/test/TestServlet.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/main/java/org/jboss/wsf/test/TestServlet.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/main/java/org/jboss/wsf/test/TestServlet.java 2011-04-01
16:19:57 UTC (rev 13987)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.wsf.test;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 01-Apr-2011
+ *
+ */
+@WebServlet(name = "TestServlet", urlPatterns = "/*")
+public class TestServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
+ {
+ String helperClassName = req.getParameter("helper");
+ if (helperClassName == null || helperClassName.length() == 0)
+ throw new ServletException("helper not specified!");
+ String path = req.getParameter("path");
+ if (path == null || path.length() == 0)
+ throw new ServletException("path not specified!");
+ try
+ {
+ ClientHelper helper = (ClientHelper)
Class.forName(helperClassName).newInstance();
+ helper.setTargetEndpoint("http://" +
System.getProperty("jboss.bind.address", "localhost") +
":8080" + path);
+ List<String> failedTests = new LinkedList<String>();
+ List<String> errorTests = new LinkedList<String>();
+ Method[] methods = helper.getClass().getMethods();
+ String methodName = req.getParameter("method");
+ int testsRun = 0;
+ if (methodName != null && methodName.length() > 0)
+ {
+ Method m = null;
+ m = helper.getClass().getMethod(methodName);
+ testsRun++;
+ invokeMethod(m, helper, failedTests, errorTests);
+ }
+ else
+ {
+ for (Method m : methods)
+ {
+ if (m.getName().startsWith("test") &&
m.getParameterTypes().length == 0
+ && m.getReturnType().equals(boolean.class))
+ {
+ testsRun++;
+ invokeMethod(m, helper, failedTests, errorTests);
+ }
+ }
+ }
+ if (failedTests.isEmpty() && errorTests.isEmpty())
+ {
+ res.getWriter().print(testsRun);
+ }
+ else
+ {
+ PrintWriter w = res.getWriter();
+ w.print("# Failed tests: ");
+ for (Iterator<String> it = failedTests.iterator(); it.hasNext();)
+ {
+ w.print(it.next());
+ if (it.hasNext())
+ w.print(", ");
+ }
+ res.getWriter().print(" # Error tests: ");
+ for (Iterator<String> it = errorTests.iterator(); it.hasNext();)
+ {
+ w.print(it.next());
+ if (it.hasNext())
+ w.print(", ");
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new ServletException(e);
+ }
+ }
+
+ private void invokeMethod(Method m, ClientHelper helper, List<String>
failedTests, List<String> errorTests) throws ServletException
+ {
+ try
+ {
+ if (!(Boolean)m.invoke(helper))
+ {
+ failedTests.add(m.getName());
+ }
+ }
+ catch (InvocationTargetException e)
+ {
+ Throwable thrownException = e.getTargetException();
+ errorTests.add(m.getName() + ": " +
thrownException.getClass().getName() + " " + thrownException.getMessage());
+ thrownException.printStackTrace();
+ }
+ catch (Exception e)
+ {
+ throw new ServletException(e);
+ }
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPEnforcingInInterceptor.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPEnforcingInInterceptor.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPEnforcingInInterceptor.java 2011-04-01
16:19:57 UTC (rev 13987)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.gzip;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.HttpHeaderHelper;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.transport.http.gzip.GZIPInInterceptor;
+
+public class GZIPEnforcingInInterceptor extends GZIPInInterceptor
+{
+ @Override
+ public void handleMessage(Message message) throws Fault
+ {
+ Map<String, List<String>> protocolHeaders = CastUtils.cast((Map<?,
?>) message.get(Message.PROTOCOL_HEADERS));
+ if (protocolHeaders != null)
+ {
+ List<String> contentEncoding =
HttpHeaderHelper.getHeader(protocolHeaders,
+ HttpHeaderHelper.CONTENT_ENCODING);
+ if (contentEncoding != null &&
(contentEncoding.contains("gzip") ||
contentEncoding.contains("x-gzip")))
+ {
+ super.handleMessage(message);
+ return;
+ }
+ }
+ throw new RuntimeException("Content-Encoding gzip not found!");
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPServletTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPServletTestCase.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPServletTestCase.java 2011-04-01
16:19:57 UTC (rev 13987)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.gzip;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import junit.framework.Test;
+
+import org.jboss.wsf.test.JBossWSCXFTestSetup;
+import org.jboss.wsf.test.JBossWSTest;
+
+/**
+ * This covers the same tests of GZIPTestCase but runs them via a Servlet client
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 01-Apr-2011
+ *
+ */
+public class GZIPServletTestCase extends JBossWSTest
+{
+ public static Test suite()
+ {
+ return new JBossWSCXFTestSetup(GZIPServletTestCase.class, "jaxws-cxf-gzip.war,
jaxws-cxf-gzip-client.war");
+ }
+
+ public void testGZIPUsingFeatureOnBus() throws Exception
+ {
+ assertEquals("1",
runTestInContainer("testGZIPUsingFeatureOnBus"));
+ }
+
+ public void testGZIPUsingFeatureOnClient() throws Exception
+ {
+ assertEquals("1",
runTestInContainer("testGZIPUsingFeatureOnClient"));
+ }
+
+ public void testGZIPServerSideOnlyInterceptorOnClient() throws Exception
+ {
+ assertEquals("1",
runTestInContainer("testGZIPServerSideOnlyInterceptorOnClient"));
+ }
+
+ public void testFailureGZIPServerSideOnlyInterceptorOnClient() throws Exception
+ {
+ assertEquals("1",
runTestInContainer("testFailureGZIPServerSideOnlyInterceptorOnClient"));
+ }
+
+ public void testGZIPServerSideOnlyInterceptorsOnBus() throws Exception
+ {
+ assertEquals("1",
runTestInContainer("testGZIPServerSideOnlyInterceptorsOnBus"));
+ }
+
+ public void testFailureGZIPServerSideOnlyInterceptorsOnBus() throws Exception
+ {
+ assertEquals("1",
runTestInContainer("testFailureGZIPServerSideOnlyInterceptorsOnBus"));
+ }
+
+ private String runTestInContainer(String test) throws Exception
+ {
+ URL url = new URL("http://" + getServerHost()
+ +
":8080/jaxws-cxf-gzip-client?path=/jaxws-cxf-gzip/HelloWorldService/HelloWorldImpl&method="
+ test
+ + "&helper=" + Helper.class.getName());
+ BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
+ return br.readLine();
+ }
+}
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPTestCase.java 2011-04-01
09:03:29 UTC (rev 13986)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/GZIPTestCase.java 2011-04-01
16:19:57 UTC (rev 13987)
@@ -21,29 +21,8 @@
*/
package org.jboss.test.ws.jaxws.cxf.gzip;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-import javax.xml.ws.Service;
-
import junit.framework.Test;
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.endpoint.Client;
-import org.apache.cxf.frontend.ClientProxy;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.helpers.HttpHeaderHelper;
-import org.apache.cxf.interceptor.Fault;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.transport.http.HTTPConduit;
-import org.apache.cxf.transport.http.gzip.GZIPFeature;
-import org.apache.cxf.transport.http.gzip.GZIPInInterceptor;
-import org.apache.cxf.transport.http.gzip.GZIPOutInterceptor;
-import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.jboss.wsf.test.JBossWSCXFTestSetup;
import org.jboss.wsf.test.JBossWSTest;
@@ -56,158 +35,50 @@
public class GZIPTestCase extends JBossWSTest
{
private String gzipFeatureEndpointURL = "http://" + getServerHost() +
":8080/jaxws-cxf-gzip/HelloWorldService/HelloWorldImpl";
+
+ private Helper helper;
- private HelloWorld port;
-
public static Test suite()
{
return new JBossWSCXFTestSetup(GZIPTestCase.class,
"jaxws-cxf-gzip.war");
}
- public void testGZIPUsingFeatureOnBus() throws Exception
+ private Helper getHelper()
{
- Bus bus = BusFactory.newInstance().createBus();
- try
+ if (helper == null)
{
- BusFactory.setThreadDefaultBus(bus);
-
- GZIPFeature gzipFeature = new GZIPFeature();
- gzipFeature.setThreshold(0);
- gzipFeature.initialize(bus);
-
- HelloWorld port = getPort();
- assertEquals("foo", port.echo("foo"));
+ helper = new Helper(gzipFeatureEndpointURL);
}
- finally
- {
- bus.shutdown(true);
- }
+ return helper;
}
+ public void testGZIPUsingFeatureOnBus() throws Exception
+ {
+ assertTrue(getHelper().testGZIPUsingFeatureOnBus());
+ }
+
public void testGZIPUsingFeatureOnClient() throws Exception
{
- HelloWorld port = getPort();
- Client client = ClientProxy.getClient(port);
- GZIPFeature gzipFeature = new GZIPFeature();
- gzipFeature.setThreshold(0);
- gzipFeature.initialize(client, BusFactory.getThreadDefaultBus());
- assertEquals("foo", port.echo("foo"));
+ assertTrue(getHelper().testGZIPUsingFeatureOnClient());
}
public void testGZIPServerSideOnlyInterceptorOnClient() throws Exception
{
- HelloWorld port = getPort();
- Client client = ClientProxy.getClient(port);
- HTTPConduit conduit = (HTTPConduit)client.getConduit();
- HTTPClientPolicy policy = conduit.getClient();
- //enable Accept gzip, otherwise the server will not try to reply using gzip
- policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
- //add interceptor for decoding gzip message
- client.getInInterceptors().add(new GZIPEnforcingInInterceptor());
- assertEquals("foo", port.echo("foo"));
+ assertTrue(getHelper().testGZIPServerSideOnlyInterceptorOnClient());
}
public void testFailureGZIPServerSideOnlyInterceptorOnClient() throws Exception
{
- HelloWorld port = getPort();
- Client client = ClientProxy.getClient(port);
- HTTPConduit conduit = (HTTPConduit)client.getConduit();
- HTTPClientPolicy policy = conduit.getClient();
- //enable Accept gzip, otherwise the server will not try to reply using gzip
- policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
- try
- {
- port.echo("foo");
- fail();
- }
- catch (Exception e)
- {
- //expected exception, as the client is not able to decode gzip message
- }
+ assertTrue(getHelper().testFailureGZIPServerSideOnlyInterceptorOnClient());
}
public void testGZIPServerSideOnlyInterceptorsOnBus() throws Exception
{
- Bus bus = BusFactory.newInstance().createBus();
- try
- {
- //enable Accept gzip, otherwise the server will not try to reply using gzip
- GZIPOutInterceptor outInterceptor = new GZIPOutInterceptor();
- outInterceptor.setThreshold(1024*1024); // 1MB -> no gzip on request
- bus.getOutInterceptors().add(outInterceptor);
- //add interceptor for decoding gzip message
- bus.getInInterceptors().add(new GZIPEnforcingInInterceptor());
- BusFactory.setThreadDefaultBus(bus);
- HelloWorld port = getPort();
- assertEquals("foo", port.echo("foo"));
- }
- finally
- {
- bus.shutdown(true);
- }
+ assertTrue(getHelper().testGZIPServerSideOnlyInterceptorsOnBus());
}
public void testFailureGZIPServerSideOnlyInterceptorsOnBus() throws Exception
{
- Bus bus = BusFactory.newInstance().createBus();
- try
- {
- //enable Accept gzip, otherwise the server will not try to reply using gzip
- GZIPOutInterceptor outInterceptor = new GZIPOutInterceptor();
- outInterceptor.setThreshold(1024*1024); // 1MB -> no gzip on request
- bus.getOutInterceptors().add(outInterceptor);
- BusFactory.setThreadDefaultBus(bus);
- HelloWorld port = getPort();
- try
- {
- port.echo("foo");
- fail();
- }
- catch (Exception e)
- {
- //expected exception, as the client is not able to decode gzip message
- }
- }
- finally
- {
- bus.shutdown(true);
- }
+ assertTrue(getHelper().testFailureGZIPServerSideOnlyInterceptorsOnBus());
}
-
- private HelloWorld getPort() throws MalformedURLException
- {
- if (port == null)
- {
- URL wsdlURL = new URL(gzipFeatureEndpointURL + "?wsdl");
- QName serviceName = new QName("http://org.jboss.ws/jaxws/cxf/gzip",
"HelloWorldService");
- Service service = Service.create(wsdlURL, serviceName);
- QName portQName = new QName("http://org.jboss.ws/jaxws/cxf/gzip",
"HelloWorldImplPort");
- port = (HelloWorld) service.getPort(portQName, HelloWorld.class);
- }
- return port;
- }
-
- /**
- * A test extension of the GZIPInInterceptor that requires all received messages to be
gzip encoded
- *
- */
- private class GZIPEnforcingInInterceptor extends GZIPInInterceptor
- {
- @Override
- public void handleMessage(Message message) throws Fault
- {
- Map<String, List<String>> protocolHeaders =
CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
- if (protocolHeaders != null)
- {
- List<String> contentEncoding =
HttpHeaderHelper.getHeader(protocolHeaders,
- HttpHeaderHelper.CONTENT_ENCODING);
- if (contentEncoding != null &&
(contentEncoding.contains("gzip") ||
contentEncoding.contains("x-gzip")))
- {
- super.handleMessage(message);
- return;
- }
- }
- throw new RuntimeException("Content-Encoding gzip not found!");
- }
- }
}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/Helper.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/Helper.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/gzip/Helper.java 2011-04-01
16:19:57 UTC (rev 13987)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, 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.gzip;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transport.http.gzip.GZIPFeature;
+import org.apache.cxf.transport.http.gzip.GZIPOutInterceptor;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.jboss.wsf.test.ClientHelper;
+
+public class Helper implements ClientHelper
+{
+ private String gzipFeatureEndpointURL;
+
+ public Helper()
+ {
+
+ }
+
+ public Helper(String endpointURL)
+ {
+ setTargetEndpoint(endpointURL);
+ }
+
+ public boolean testGZIPUsingFeatureOnBus() throws Exception
+ {
+ Bus bus = BusFactory.newInstance().createBus();
+ try
+ {
+ BusFactory.setThreadDefaultBus(bus);
+
+ GZIPFeature gzipFeature = new GZIPFeature();
+ gzipFeature.setThreshold(0);
+ gzipFeature.initialize(bus);
+
+ HelloWorld port = getPort();
+ return ("foo".equals(port.echo("foo")));
+ }
+ finally
+ {
+ bus.shutdown(true);
+ }
+ }
+
+ public boolean testGZIPUsingFeatureOnClient() throws Exception
+ {
+ HelloWorld port = getPort();
+ Client client = ClientProxy.getClient(port);
+ GZIPFeature gzipFeature = new GZIPFeature();
+ gzipFeature.setThreshold(0);
+ gzipFeature.initialize(client, BusFactory.getThreadDefaultBus());
+ return ("foo".equals(port.echo("foo")));
+ }
+
+ public boolean testGZIPServerSideOnlyInterceptorOnClient() throws Exception
+ {
+ HelloWorld port = getPort();
+ Client client = ClientProxy.getClient(port);
+ HTTPConduit conduit = (HTTPConduit)client.getConduit();
+ HTTPClientPolicy policy = conduit.getClient();
+ //enable Accept gzip, otherwise the server will not try to reply using gzip
+ policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
+ //add interceptor for decoding gzip message
+ client.getInInterceptors().add(new GZIPEnforcingInInterceptor());
+ return ("foo".equals(port.echo("foo")));
+ }
+
+ public boolean testFailureGZIPServerSideOnlyInterceptorOnClient() throws Exception
+ {
+ HelloWorld port = getPort();
+ Client client = ClientProxy.getClient(port);
+ HTTPConduit conduit = (HTTPConduit)client.getConduit();
+ HTTPClientPolicy policy = conduit.getClient();
+ //enable Accept gzip, otherwise the server will not try to reply using gzip
+ policy.setAcceptEncoding("gzip;q=1.0, identity; q=0.5, *;q=0");
+ try
+ {
+ port.echo("foo");
+ return false;
+ }
+ catch (Exception e)
+ {
+ //expected exception, as the client is not able to decode gzip message
+ return true;
+ }
+ }
+
+ public boolean testGZIPServerSideOnlyInterceptorsOnBus() throws Exception
+ {
+ Bus bus = BusFactory.newInstance().createBus();
+ try
+ {
+ //enable Accept gzip, otherwise the server will not try to reply using gzip
+ GZIPOutInterceptor outInterceptor = new GZIPOutInterceptor();
+ outInterceptor.setThreshold(1024*1024); // 1MB -> no gzip on request
+ bus.getOutInterceptors().add(outInterceptor);
+ //add interceptor for decoding gzip message
+ bus.getInInterceptors().add(new GZIPEnforcingInInterceptor());
+ BusFactory.setThreadDefaultBus(bus);
+ HelloWorld port = getPort();
+ return ("foo".equals(port.echo("foo")));
+ }
+ finally
+ {
+ bus.shutdown(true);
+ }
+ }
+
+ public boolean testFailureGZIPServerSideOnlyInterceptorsOnBus() throws Exception
+ {
+ Bus bus = BusFactory.newInstance().createBus();
+ try
+ {
+ //enable Accept gzip, otherwise the server will not try to reply using gzip
+ GZIPOutInterceptor outInterceptor = new GZIPOutInterceptor();
+ outInterceptor.setThreshold(1024*1024); // 1MB -> no gzip on request
+ bus.getOutInterceptors().add(outInterceptor);
+ BusFactory.setThreadDefaultBus(bus);
+ HelloWorld port = getPort();
+ try
+ {
+ port.echo("foo");
+ return false;
+ }
+ catch (Exception e)
+ {
+ //expected exception, as the client is not able to decode gzip message
+ return true;
+ }
+ }
+ finally
+ {
+ bus.shutdown(true);
+ }
+ }
+
+ private HelloWorld getPort() throws MalformedURLException
+ {
+ URL wsdlURL = new URL(gzipFeatureEndpointURL + "?wsdl");
+ QName serviceName = new QName("http://org.jboss.ws/jaxws/cxf/gzip",
"HelloWorldService");
+ Service service = Service.create(wsdlURL, serviceName);
+ QName portQName = new QName("http://org.jboss.ws/jaxws/cxf/gzip",
"HelloWorldImplPort");
+ return (HelloWorld) service.getPort(portQName, HelloWorld.class);
+ }
+
+ @Override
+ public void setTargetEndpoint(String address)
+ {
+ this.gzipFeatureEndpointURL = address;
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/gzip/META-INF/MANIFEST.MF
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/gzip/META-INF/MANIFEST.MF
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/resources/jaxws/cxf/gzip/META-INF/MANIFEST.MF 2011-04-01
16:19:57 UTC (rev 13987)
@@ -0,0 +1,2 @@
+Manifest-Version: 1.0
+Dependencies: org.jboss.ws.cxf.jbossws-cxf-client services
\ No newline at end of file