Author: alessio.soldano(a)jboss.com
Date: 2013-07-09 08:13:32 -0400 (Tue, 09 Jul 2013)
New Revision: 17764
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/EndpointOne.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/EndpointOneImpl.java
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/ServletCtxTestCase.java
Modified:
stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml
Log:
Adding test on http servlet context retrieval
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 2013-07-05
12:48:02 UTC (rev 17763)
+++ stack/cxf/trunk/modules/testsuite/cxf-tests/scripts/cxf-jars-jaxws.xml 2013-07-09
12:13:32 UTC (rev 17764)
@@ -481,6 +481,17 @@
</manifest>
</war>
+ <!-- jaxws-cxf-servletCtx -->
+ <war warfile="${tests.output.dir}/test-libs/jaxws-cxf-servletCtx.war"
needxmlfile='false'>
+ <classes dir="${tests.output.dir}/test-classes">
+ <include
name="org/jboss/test/ws/jaxws/cxf/servletCtx/EndpointOneImpl.class"/>
+ <include
name="org/jboss/test/ws/jaxws/cxf/servletCtx/EndpointOne.class"/>
+ </classes>
+ <manifest>
+ <attribute name="Dependencies"
value="org.jboss.logging"/>
+ </manifest>
+ </war>
+
<!-- jaxws-cxf-spring -->
<war warfile="${tests.output.dir}/test-libs/jaxws-cxf-spring.war"
needxmlfile='false'>
<classes dir="${tests.output.dir}/test-classes">
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/EndpointOne.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/EndpointOne.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/EndpointOne.java 2013-07-09
12:13:32 UTC (rev 17764)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, 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.servletCtx;
+
+import javax.jws.Oneway;
+import javax.jws.WebService;
+
+@WebService(name = "EndpointOne", targetNamespace =
"http://org.jboss.ws.jaxws.cxf/servletCtx", serviceName =
"ServiceOne")
+public interface EndpointOne
+{
+ String echo(String input);
+
+ @Oneway
+ void echoOneWay(String input);
+
+ int getCount1();
+
+ int getCount2();
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/EndpointOneImpl.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/EndpointOneImpl.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/EndpointOneImpl.java 2013-07-09
12:13:32 UTC (rev 17764)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, 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.servletCtx;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.annotation.Resource;
+import javax.jws.Oneway;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.soap.Addressing;
+
+import org.jboss.logging.Logger;
+
+@WebService(name = "EndpointOne", targetNamespace =
"http://org.jboss.ws.jaxws.cxf/servletCtx", serviceName =
"ServiceOne")
+@Addressing
+public class EndpointOneImpl implements EndpointOne
+{
+ private static AtomicInteger count1 = new AtomicInteger(0);
+ private static AtomicInteger count2 = new AtomicInteger(0);
+ @Resource
+ private WebServiceContext context;
+
+ @WebMethod
+ public String echo(String input)
+ {
+ count1.incrementAndGet();
+ MessageContext msgContext = context.getMessageContext();
+ HttpServletRequest request =
(HttpServletRequest)msgContext.get(MessageContext.SERVLET_REQUEST);
+ final String scheme = request.getScheme();
+ Logger.getLogger(this.getClass()).info("echo: " + input + ", scheme:
" + scheme);
+ if (scheme != null) {
+ count2.incrementAndGet();
+ }
+ return input;
+ }
+
+ @WebMethod
+ @Oneway
+ public void echoOneWay(String input)
+ {
+ count1.incrementAndGet();
+ MessageContext msgContext = context.getMessageContext();
+ HttpServletRequest request =
(HttpServletRequest)msgContext.get(MessageContext.SERVLET_REQUEST);
+ final String scheme = request.getScheme();
+ Logger.getLogger(this.getClass()).info("echoOneWay: " + input + ",
scheme: " + scheme);
+ if (scheme != null) {
+ count2.incrementAndGet();
+ }
+ }
+
+ @WebMethod
+ public int getCount1()
+ {
+ return count1.get();
+ }
+
+ @WebMethod
+ public int getCount2()
+ {
+ return count2.get();
+ }
+}
Added:
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/ServletCtxTestCase.java
===================================================================
---
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/ServletCtxTestCase.java
(rev 0)
+++
stack/cxf/trunk/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/servletCtx/ServletCtxTestCase.java 2013-07-09
12:13:32 UTC (rev 17764)
@@ -0,0 +1,146 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, 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.servletCtx;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import junit.framework.Test;
+
+import org.jboss.wsf.test.JBossWSCXFTestSetup;
+import org.jboss.wsf.test.JBossWSTest;
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 09-Jul-2013
+ */
+public class ServletCtxTestCase extends JBossWSTest
+{
+ private String endpointOneURL = "http://" + getServerHost() +
":8080/jaxws-cxf-servletCtx/ServiceOne";
+
+ public static Test suite()
+ {
+ return new JBossWSCXFTestSetup(ServletCtxTestCase.class,
"jaxws-cxf-servletCtx.war");
+ }
+
+ private String targetNS = "http://org.jboss.ws.jaxws.cxf/servletCtx";
+
+ private EndpointOne portOne;
+
+ protected int defaultSize = 30;
+
+ public void testAccess() throws Exception
+ {
+ initPort();
+ int count1 = portOne.getCount1();
+ int count2 = portOne.getCount2();
+ Object retObj = portOne.echo("Hello");
+ assertEquals("Hello", retObj);
+ assertEquals(1, portOne.getCount1() - count1);
+ assertEquals(1, portOne.getCount2() - count2);
+ }
+
+ public void testConcurrentInvocations() throws Exception
+ {
+ runConcurrentTests(false);
+ }
+
+ public void testConcurrentOneWayInvocations() throws Exception
+ {
+ runConcurrentTests(true);
+ }
+
+ private void runConcurrentTests(boolean oneway) throws Exception
+ {
+ initPort();
+ final int size = defaultSize;
+ int count1 = portOne.getCount1();
+ int count2 = portOne.getCount2();
+ ExecutorService es = Executors.newFixedThreadPool(size);
+ List<Callable<Boolean>> callables = new
ArrayList<Callable<Boolean>>(size);
+ for (int i = 0; i < size; i++)
+ {
+ callables.add(new CallableOne(portOne, oneway, i));
+ }
+ List<Future<Boolean>> futures = es.invokeAll(callables);
+ for (Future<Boolean> f : futures)
+ {
+ assertTrue(f.get());
+ }
+ if (oneway)
+ {
+ Thread.sleep(3000);
+ }
+ assertEquals(size, portOne.getCount1() - count1);
+ assertEquals(size, portOne.getCount2() - count2);
+ }
+
+ private void initPort() throws MalformedURLException
+ {
+ URL wsdlOneURL = new URL(endpointOneURL + "?wsdl");
+ QName serviceOneName = new QName(targetNS, "ServiceOne");
+ Service serviceOne = Service.create(wsdlOneURL, serviceOneName);
+ portOne = (EndpointOne) serviceOne.getPort(EndpointOne.class);
+ }
+
+ private static class CallableOne implements Callable<Boolean>
+ {
+ private EndpointOne port;
+
+ private boolean oneway;
+
+ private int seqNum;
+
+ public CallableOne(EndpointOne port, boolean oneway, int seqNum)
+ {
+ this.port = port;
+ this.oneway = oneway;
+ this.seqNum = seqNum;
+ }
+
+ public Boolean call() throws Exception
+ {
+ String arg = "Foo" + seqNum;
+ if (oneway)
+ {
+ port.echoOneWay(arg);
+ return true;
+ }
+ else
+ {
+ String result = port.echo(arg);
+ return arg.equals(result);
+ }
+ }
+ }
+
+}