Repository: cxf Updated Branches: refs/heads/master a6d41f6c0 -> 10570db97
CXF-5576: Initital support for CDI integration. Added Tomcat-based test cases for WAR-based deployments Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/72287e27 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/72287e27 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/72287e27 Branch: refs/heads/master Commit: 72287e2764a309412025fba0a27ce4acbfe96203 Parents: 7778876 Author: Andriy Redko <[email protected]> Authored: Mon Mar 10 13:21:55 2014 -0400 Committer: Andriy Redko <[email protected]> Committed: Mon Mar 10 13:21:55 2014 -0400 ---------------------------------------------------------------------- parent/pom.xml | 1 + systests/cdi/pom.xml | 10 ++ .../systest/jaxrs/cdi/AbstractJettyServer.java | 99 ------------------ .../systest/jaxrs/cdi/JettyEmbeddedTest.java | 48 --------- .../cxf/systest/jaxrs/cdi/JettyWarTest.java | 48 --------- .../jaxrs/cdi/WeldDiscoverableContainer.java | 55 ++++++++++ .../jaxrs/cdi/jetty/AbstractJettyServer.java | 102 +++++++++++++++++++ .../jaxrs/cdi/jetty/JettyEmbeddedTest.java | 49 +++++++++ .../systest/jaxrs/cdi/jetty/JettyWarTest.java | 49 +++++++++ .../jaxrs/cdi/tomcat/AbstractTomcatServer.java | 96 +++++++++++++++++ .../systest/jaxrs/cdi/tomcat/TomcatWarTest.java | 49 +++++++++ .../org.jboss.weld.environment.Container | 1 + 12 files changed, 412 insertions(+), 195 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index b250214..f1cf90d 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -117,6 +117,7 @@ <cxf.jdom.version>1.0</cxf.jdom.version> <cxf.jettison.version>1.3.5</cxf.jettison.version> <cxf.jetty.version>8.1.14.v20131031</cxf.jetty.version> + <cxf.tomcat.version>8.0.3</cxf.tomcat.version> <cxf.jetty.osgi.version>[7.6,8.2)</cxf.jetty.osgi.version> <cxf.jibx.version>1.2.5</cxf.jibx.version> <cxf.junit.version>4.11</cxf.junit.version> http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/systests/cdi/pom.xml ---------------------------------------------------------------------- diff --git a/systests/cdi/pom.xml b/systests/cdi/pom.xml index f9a69ff..14850c3 100644 --- a/systests/cdi/pom.xml +++ b/systests/cdi/pom.xml @@ -150,6 +150,16 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.tomcat.embed</groupId> + <artifactId>tomcat-embed-core</artifactId> + <version>${cxf.tomcat.version}</version> + </dependency> + <dependency> + <groupId>org.apache.tomcat.embed</groupId> + <artifactId>tomcat-embed-logging-juli</artifactId> + <version>${cxf.tomcat.version}</version> + </dependency> + <dependency> <groupId>com.ning</groupId> <artifactId>async-http-client</artifactId> <version>${cxf.ahc.version}</version> http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/AbstractJettyServer.java ---------------------------------------------------------------------- diff --git a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/AbstractJettyServer.java b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/AbstractJettyServer.java deleted file mode 100644 index 1f1bf70..0000000 --- a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/AbstractJettyServer.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * 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.jaxrs.cdi; - - -import org.apache.cxf.cdi.CXFCdiServlet; -import org.apache.cxf.testutil.common.AbstractBusTestServerBase; -import org.eclipse.jetty.server.Handler; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.DefaultHandler; -import org.eclipse.jetty.server.handler.HandlerCollection; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.webapp.WebAppContext; -import org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener; -import org.jboss.weld.environment.servlet.Listener; - -public abstract class AbstractJettyServer extends AbstractBusTestServerBase { - - private org.eclipse.jetty.server.Server server; - private final String resourcePath; - private final String contextPath; - private final int port; - - protected AbstractJettyServer(final String contextPath, int portNumber) { - this(null, contextPath, portNumber); - } - - protected AbstractJettyServer(final String resourcePath, final String contextPath, int portNumber) { - this.resourcePath = resourcePath; - this.contextPath = contextPath; - this.port = portNumber; - } - - protected void run() { - System.setProperty("java.naming.factory.url", "org.eclipse.jetty.jndi"); - System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory"); - - server = new Server(port); - - try { - if (resourcePath == null) { - // Register and map the dispatcher servlet - final ServletHolder servletHolder = new ServletHolder(new CXFCdiServlet()); - final ServletContextHandler context = new ServletContextHandler(); - context.setContextPath(contextPath); - context.addEventListener(new Listener()); - context.addEventListener(new BeanManagerResourceBindingListener()); - context.addServlet(servletHolder, "/rest/*"); - server.setHandler(context); - } else { - final WebAppContext context = new WebAppContext(); - context.setContextPath(contextPath); - context.setWar(getClass().getResource(resourcePath).toURI().getPath()); - - HandlerCollection handlers = new HandlerCollection(); - handlers.setHandlers(new Handler[] {context, new DefaultHandler()}); - server.setHandler(handlers); - } - - configureServer(server); - server.start(); - } catch (final Exception ex) { - ex.printStackTrace(); - fail(ex.getMessage()); - } - } - - protected void configureServer(org.eclipse.jetty.server.Server theserver) throws Exception { - - } - - public void tearDown() throws Exception { - super.tearDown(); - - if (server != null) { - server.stop(); - server.destroy(); - server = null; - } - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/JettyEmbeddedTest.java ---------------------------------------------------------------------- diff --git a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/JettyEmbeddedTest.java b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/JettyEmbeddedTest.java deleted file mode 100644 index 03efeb9..0000000 --- a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/JettyEmbeddedTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.jaxrs.cdi; - -import org.apache.cxf.jaxrs.model.AbstractResourceInfo; -import org.junit.BeforeClass; -import org.junit.Ignore; - -public class JettyEmbeddedTest extends AbstractCDITest { - @Ignore - public static class EmbeddedJettyServer extends AbstractJettyServer { - public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class); - - public EmbeddedJettyServer() { - super("/", PORT); - } - } - - @BeforeClass - public static void startServers() throws Exception { - AbstractResourceInfo.clearAllMaps(); - //keep out of process due to stack traces testing failures - assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true)); - createStaticBus(); - } - - @Override - protected int getPort() { - return EmbeddedJettyServer.PORT; - } -} http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/JettyWarTest.java ---------------------------------------------------------------------- diff --git a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/JettyWarTest.java b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/JettyWarTest.java deleted file mode 100644 index 100cbb1..0000000 --- a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/JettyWarTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.jaxrs.cdi; - -import org.apache.cxf.jaxrs.model.AbstractResourceInfo; -import org.junit.BeforeClass; -import org.junit.Ignore; - -public class JettyWarTest extends AbstractCDITest { - @Ignore - public static class EmbeddedJettyServer extends AbstractJettyServer { - public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class); - - public EmbeddedJettyServer() { - super("/jaxrs_cdi", "/", PORT); - } - } - - @BeforeClass - public static void startServers() throws Exception { - AbstractResourceInfo.clearAllMaps(); - assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true)); - createStaticBus(); - } - - @Override - protected int getPort() { - return EmbeddedJettyServer.PORT; - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/WeldDiscoverableContainer.java ---------------------------------------------------------------------- diff --git a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/WeldDiscoverableContainer.java b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/WeldDiscoverableContainer.java new file mode 100644 index 0000000..db726d8 --- /dev/null +++ b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/WeldDiscoverableContainer.java @@ -0,0 +1,55 @@ +/** + * 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.jaxrs.cdi; + +import org.jboss.weld.environment.Container; +import org.jboss.weld.environment.ContainerContext; +import org.jboss.weld.environment.jetty.JettyContainer; +import org.jboss.weld.environment.tomcat7.Tomcat7Container; + +/** + * Because we are mixing several Servlet Containers in the same project, JBoss Weld + * needs some help to figure out the correct one we are running right now. + */ +public class WeldDiscoverableContainer implements Container { + private final Container delegate; + + public WeldDiscoverableContainer() { + if (JettyContainer.class.getName().equals(System.getProperty(Container.class.getName()))) { + delegate = JettyContainer.INSTANCE; + } else { + delegate = Tomcat7Container.INSTANCE; + } + } + + @Override + public boolean touch(ContainerContext context) throws Exception { + return delegate.touch(context); + } + + @Override + public void initialize(ContainerContext context) { + delegate.initialize(context); + } + + @Override + public void destroy(ContainerContext context) { + delegate.destroy(context); + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/AbstractJettyServer.java ---------------------------------------------------------------------- diff --git a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/AbstractJettyServer.java b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/AbstractJettyServer.java new file mode 100644 index 0000000..0023934 --- /dev/null +++ b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/AbstractJettyServer.java @@ -0,0 +1,102 @@ +/** + * 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.jaxrs.cdi.jetty; + + +import org.apache.cxf.cdi.CXFCdiServlet; +import org.apache.cxf.testutil.common.AbstractBusTestServerBase; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.DefaultHandler; +import org.eclipse.jetty.server.handler.HandlerCollection; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.webapp.WebAppContext; +import org.jboss.weld.environment.Container; +import org.jboss.weld.environment.jetty.JettyContainer; +import org.jboss.weld.environment.servlet.BeanManagerResourceBindingListener; +import org.jboss.weld.environment.servlet.Listener; + +public abstract class AbstractJettyServer extends AbstractBusTestServerBase { + + private org.eclipse.jetty.server.Server server; + private final String resourcePath; + private final String contextPath; + private final int port; + + protected AbstractJettyServer(final String contextPath, int portNumber) { + this(null, contextPath, portNumber); + } + + protected AbstractJettyServer(final String resourcePath, final String contextPath, int portNumber) { + this.resourcePath = resourcePath; + this.contextPath = contextPath; + this.port = portNumber; + } + + protected void run() { + System.setProperty("java.naming.factory.url", "org.eclipse.jetty.jndi"); + System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory"); + System.setProperty(Container.class.getName(), JettyContainer.class.getName()); + + server = new Server(port); + + try { + if (resourcePath == null) { + // Register and map the dispatcher servlet + final ServletHolder servletHolder = new ServletHolder(new CXFCdiServlet()); + final ServletContextHandler context = new ServletContextHandler(); + context.setContextPath(contextPath); + context.addEventListener(new Listener()); + context.addEventListener(new BeanManagerResourceBindingListener()); + context.addServlet(servletHolder, "/rest/*"); + server.setHandler(context); + } else { + final WebAppContext context = new WebAppContext(); + context.setContextPath(contextPath); + context.setWar(getClass().getResource(resourcePath).toURI().getPath()); + + HandlerCollection handlers = new HandlerCollection(); + handlers.setHandlers(new Handler[] {context, new DefaultHandler()}); + server.setHandler(handlers); + } + + configureServer(server); + server.start(); + } catch (final Exception ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } + } + + protected void configureServer(org.eclipse.jetty.server.Server theserver) throws Exception { + + } + + public void tearDown() throws Exception { + super.tearDown(); + + if (server != null) { + server.stop(); + server.destroy(); + server = null; + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/JettyEmbeddedTest.java ---------------------------------------------------------------------- diff --git a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/JettyEmbeddedTest.java b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/JettyEmbeddedTest.java new file mode 100644 index 0000000..3d8ef7b --- /dev/null +++ b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/JettyEmbeddedTest.java @@ -0,0 +1,49 @@ +/** + * 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.jaxrs.cdi.jetty; + +import org.apache.cxf.jaxrs.model.AbstractResourceInfo; +import org.apache.cxf.systest.jaxrs.cdi.AbstractCDITest; +import org.junit.BeforeClass; +import org.junit.Ignore; + +public class JettyEmbeddedTest extends AbstractCDITest { + @Ignore + public static class EmbeddedJettyServer extends AbstractJettyServer { + public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class); + + public EmbeddedJettyServer() { + super("/", PORT); + } + } + + @BeforeClass + public static void startServers() throws Exception { + AbstractResourceInfo.clearAllMaps(); + //keep out of process due to stack traces testing failures + assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true)); + createStaticBus(); + } + + @Override + protected int getPort() { + return EmbeddedJettyServer.PORT; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/JettyWarTest.java ---------------------------------------------------------------------- diff --git a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/JettyWarTest.java b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/JettyWarTest.java new file mode 100644 index 0000000..1b62a46 --- /dev/null +++ b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/jetty/JettyWarTest.java @@ -0,0 +1,49 @@ +/** + * 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.jaxrs.cdi.jetty; + +import org.apache.cxf.jaxrs.model.AbstractResourceInfo; +import org.apache.cxf.systest.jaxrs.cdi.AbstractCDITest; +import org.junit.BeforeClass; +import org.junit.Ignore; + +public class JettyWarTest extends AbstractCDITest { + @Ignore + public static class EmbeddedJettyServer extends AbstractJettyServer { + public static final int PORT = allocatePortAsInt(EmbeddedJettyServer.class); + + public EmbeddedJettyServer() { + super("/jaxrs_cdi", "/", PORT); + } + } + + @BeforeClass + public static void startServers() throws Exception { + AbstractResourceInfo.clearAllMaps(); + assertTrue("server did not launch correctly", launchServer(EmbeddedJettyServer.class, true)); + createStaticBus(); + } + + @Override + protected int getPort() { + return EmbeddedJettyServer.PORT; + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/tomcat/AbstractTomcatServer.java ---------------------------------------------------------------------- diff --git a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/tomcat/AbstractTomcatServer.java b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/tomcat/AbstractTomcatServer.java new file mode 100644 index 0000000..a28cff3 --- /dev/null +++ b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/tomcat/AbstractTomcatServer.java @@ -0,0 +1,96 @@ +/** + * 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.jaxrs.cdi.tomcat; + + +import java.io.File; +import java.io.IOException; + +import org.apache.catalina.startup.Tomcat; +import org.apache.cxf.testutil.common.AbstractBusTestServerBase; +import org.jboss.weld.environment.Container; +import org.jboss.weld.environment.tomcat7.Tomcat7Container; + +public abstract class AbstractTomcatServer extends AbstractBusTestServerBase { + + private Tomcat server; + private final String resourcePath; + private final String contextPath; + private final int port; + + protected AbstractTomcatServer(final String resourcePath, final String contextPath, int portNumber) { + this.resourcePath = resourcePath; + this.contextPath = contextPath; + this.port = portNumber; + } + + protected void run() { + System.setProperty("java.naming.factory.url", "org.eclipse.jetty.jndi"); + System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory"); + System.setProperty(Container.class.getName(), Tomcat7Container.class.getName()); + + server = new Tomcat(); + server.setPort(port); + + try { + final File base = createTemporaryDirectory(); + server.setBaseDir(base.getAbsolutePath()); + + server.getHost().setAppBase(base.getAbsolutePath()); + server.getHost().setAutoDeploy(true); + server.getHost().setDeployOnStartup(true); + + server.addWebapp(contextPath, getClass().getResource(resourcePath).toURI().getPath().toString()); + server.start(); + } catch (final Exception ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } + } + + protected void configureServer(org.eclipse.jetty.server.Server theserver) throws Exception { + + } + + private static File createTemporaryDirectory() throws IOException { + final File base = File.createTempFile("tmp-", ""); + + if (!base.delete()) { + throw new IOException("Cannot (re)create base folder: " + base.getAbsolutePath()); + } + + if (!base.mkdir()) { + throw new IOException("Cannot create base folder: " + base.getAbsolutePath()); + } + + base.deleteOnExit(); + return base; + } + + public void tearDown() throws Exception { + super.tearDown(); + + if (server != null) { + server.stop(); + server.destroy(); + server = null; + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/tomcat/TomcatWarTest.java ---------------------------------------------------------------------- diff --git a/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/tomcat/TomcatWarTest.java b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/tomcat/TomcatWarTest.java new file mode 100644 index 0000000..2ebe1c4 --- /dev/null +++ b/systests/cdi/src/test/java/org/apache/cxf/systest/jaxrs/cdi/tomcat/TomcatWarTest.java @@ -0,0 +1,49 @@ +/** + * 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.jaxrs.cdi.tomcat; + +import org.apache.cxf.jaxrs.model.AbstractResourceInfo; +import org.apache.cxf.systest.jaxrs.cdi.AbstractCDITest; +import org.junit.BeforeClass; +import org.junit.Ignore; + +public class TomcatWarTest extends AbstractCDITest { + @Ignore + public static class EmbeddedTomcatServer extends AbstractTomcatServer { + public static final int PORT = allocatePortAsInt(EmbeddedTomcatServer.class); + + public EmbeddedTomcatServer() { + super("/jaxrs_cdi", "/", PORT); + } + } + + @BeforeClass + public static void startServers() throws Exception { + AbstractResourceInfo.clearAllMaps(); + assertTrue("server did not launch correctly", launchServer(EmbeddedTomcatServer.class, true)); + createStaticBus(); + } + + @Override + protected int getPort() { + return EmbeddedTomcatServer.PORT; + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/72287e27/systests/cdi/src/test/resources/META-INF/services/org.jboss.weld.environment.Container ---------------------------------------------------------------------- diff --git a/systests/cdi/src/test/resources/META-INF/services/org.jboss.weld.environment.Container b/systests/cdi/src/test/resources/META-INF/services/org.jboss.weld.environment.Container new file mode 100644 index 0000000..df31f74 --- /dev/null +++ b/systests/cdi/src/test/resources/META-INF/services/org.jboss.weld.environment.Container @@ -0,0 +1 @@ +org.apache.cxf.systest.jaxrs.cdi.WeldDiscoverableContainer \ No newline at end of file
