Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2015-03-26 00:23:23 +0000
committerJoakim Erdfelt2015-03-26 00:23:23 +0000
commitea8a0f0e9affc53098031aa23547a1515d98d038 (patch)
tree75f5014077548db30ba7a414d4b0684ac117dcd5 /jetty-cdi/test-cdi-webapp
parent739b6c9556ee736638d7c876519800284ff6d764 (diff)
downloadorg.eclipse.jetty.project-ea8a0f0e9affc53098031aa23547a1515d98d038.tar.gz
org.eclipse.jetty.project-ea8a0f0e9affc53098031aa23547a1515d98d038.tar.xz
org.eclipse.jetty.project-ea8a0f0e9affc53098031aa23547a1515d98d038.zip
Moving CDI tests into /jetty-cdi/ tree
Diffstat (limited to 'jetty-cdi/test-cdi-webapp')
-rw-r--r--jetty-cdi/test-cdi-webapp/pom.xml91
-rw-r--r--jetty-cdi/test-cdi-webapp/src/assembly/with-weld.xml31
-rw-r--r--jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/HelloServlet.java42
-rw-r--r--jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ServerInfoServlet.java54
-rw-r--r--jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULog.java47
-rw-r--r--jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULogFactory.java31
-rw-r--r--jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ws/SessionInfoSocket.java98
-rw-r--r--jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/beans.xml0
-rw-r--r--jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/web.xml18
9 files changed, 412 insertions, 0 deletions
diff --git a/jetty-cdi/test-cdi-webapp/pom.xml b/jetty-cdi/test-cdi-webapp/pom.xml
new file mode 100644
index 0000000000..15ca5299f3
--- /dev/null
+++ b/jetty-cdi/test-cdi-webapp/pom.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ // ========================================================================
+ // Copyright (c) Webtide LLC
+ //
+ // All rights reserved. This program and the accompanying materials
+ // are made available under the terms of the Eclipse Public License v1.0
+ // and Apache License v2.0 which accompanies this distribution.
+ //
+ // The Eclipse Public License is available at
+ // http://www.eclipse.org/legal/epl-v10.html
+ //
+ // The Apache License v2.0 is available at
+ // http://www.apache.org/licenses/LICENSE-2.0.txt
+ //
+ // You may elect to redistribute this code under either of these licenses.
+ // ========================================================================
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.eclipse.jetty.cdi</groupId>
+ <artifactId>jetty-cdi-parent</artifactId>
+ <version>9.3.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>test-cdi-webapp</artifactId>
+ <packaging>war</packaging>
+ <name>Jetty :: CDI :: Test :: WebApp</name>
+ <url>http://www.eclipse.org/jetty</url>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <bundle-symbolic-name>${project.groupId}.cdi.webapp.noweld</bundle-symbolic-name>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.websocket</groupId>
+ <artifactId>javax.websocket-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>1.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld.servlet</groupId>
+ <artifactId>weld-servlet</artifactId>
+ <version>${weld.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>cdi-webapp</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <!-- DO NOT DEPLOY (or Release) -->
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.5.3</version>
+ <executions>
+ <execution>
+ <id>with-weld</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>src/assembly/with-weld.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/jetty-cdi/test-cdi-webapp/src/assembly/with-weld.xml b/jetty-cdi/test-cdi-webapp/src/assembly/with-weld.xml
new file mode 100644
index 0000000000..ca1747115d
--- /dev/null
+++ b/jetty-cdi/test-cdi-webapp/src/assembly/with-weld.xml
@@ -0,0 +1,31 @@
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
+ <id>with-weld</id>
+ <formats>
+ <format>war</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <fileSets>
+ <fileSet>
+ <directory>${project.basedir}/src/main/webapp</directory>
+ <outputDirectory>/</outputDirectory>
+ </fileSet>
+ <fileSet>
+ <directory>${project.build.outputDirectory}</directory>
+ <outputDirectory>/WEB-INF/classes</outputDirectory>
+ </fileSet>
+ </fileSets>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>/WEB-INF/lib</outputDirectory>
+ <useProjectArtifact>true</useProjectArtifact>
+ <unpack>false</unpack>
+ <scope>test</scope>
+ <includes>
+ <include>*:cdi-api</include>
+ <include>*:weld-servlet</include>
+ </includes>
+ </dependencySet>
+ </dependencySets>
+</assembly>
diff --git a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/HelloServlet.java b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/HelloServlet.java
new file mode 100644
index 0000000000..489d7ce9e6
--- /dev/null
+++ b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/HelloServlet.java
@@ -0,0 +1,42 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.tests;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * The most basic servlet here, no CDI use.
+ */
+@SuppressWarnings("serial")
+@WebServlet("/hello")
+public class HelloServlet extends HttpServlet
+{
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ resp.setContentType("text/plain");
+ resp.getWriter().println("Hello World");
+ }
+}
diff --git a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ServerInfoServlet.java b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ServerInfoServlet.java
new file mode 100644
index 0000000000..fe4dd1c567
--- /dev/null
+++ b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ServerInfoServlet.java
@@ -0,0 +1,54 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.tests;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@SuppressWarnings("serial")
+@WebServlet("/serverinfo")
+public class ServerInfoServlet extends HttpServlet
+{
+ @Inject
+ private ServletContext context;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ resp.setContentType("text/plain");
+
+ PrintWriter out = resp.getWriter();
+ if (context == null)
+ {
+ out.println("context = null");
+ return;
+ }
+ out.printf("context = %s%n",context);
+ out.printf("context.contextPath = %s%n",context.getContextPath());
+ out.printf("context.effective-version = %d.%d%n",context.getEffectiveMajorVersion(),context.getEffectiveMinorVersion());
+ }
+}
diff --git a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULog.java b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULog.java
new file mode 100644
index 0000000000..8f7d02f41e
--- /dev/null
+++ b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULog.java
@@ -0,0 +1,47 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.tests.logging;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class JULog
+{
+ private final Logger log;
+
+ public JULog(Class<?> clazz)
+ {
+ this.log = Logger.getLogger(clazz.getName());
+ }
+
+ public void info(String msg)
+ {
+ log.log(Level.INFO, msg);
+ }
+
+ public void info(String msg, Object ... args)
+ {
+ log.log(Level.INFO, msg, args);
+ }
+
+ public void warn(Throwable t)
+ {
+ log.log(Level.WARNING, "", t);
+ }
+}
diff --git a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULogFactory.java b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULogFactory.java
new file mode 100644
index 0000000000..6a6a1f8f2a
--- /dev/null
+++ b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/logging/JULogFactory.java
@@ -0,0 +1,31 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.tests.logging;
+
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+public class JULogFactory
+{
+ @Produces
+ public JULog createJULog(InjectionPoint injectionPoint)
+ {
+ return new JULog(injectionPoint.getMember().getDeclaringClass());
+ }
+}
diff --git a/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ws/SessionInfoSocket.java b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ws/SessionInfoSocket.java
new file mode 100644
index 0000000000..53d15fe5f1
--- /dev/null
+++ b/jetty-cdi/test-cdi-webapp/src/main/java/org/eclipse/jetty/tests/ws/SessionInfoSocket.java
@@ -0,0 +1,98 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.tests.ws;
+
+import javax.inject.Inject;
+import javax.servlet.http.HttpSession;
+import javax.websocket.OnMessage;
+import javax.websocket.OnOpen;
+import javax.websocket.RemoteEndpoint;
+import javax.websocket.Session;
+import javax.websocket.server.ServerEndpoint;
+
+import org.eclipse.jetty.tests.logging.JULog;
+
+@ServerEndpoint(value = "/sessioninfo")
+public class SessionInfoSocket
+{
+ @Inject
+ private JULog LOG;
+
+ @Inject
+ private HttpSession httpSession;
+
+ private Session wsSession;
+
+ @OnOpen
+ public void onOpen(Session session)
+ {
+ LOG.info("onOpen({0})",asClassId(session));
+ this.wsSession = session;
+ }
+
+ @OnMessage
+ public void onMessage(String message)
+ {
+ LOG.info("onMessage({0})",quoted(message));
+
+ try
+ {
+ RemoteEndpoint.Basic remote = wsSession.getBasicRemote();
+ LOG.info("Remote.Basic: {0}", remote);
+
+ if ("info".equalsIgnoreCase(message))
+ {
+ LOG.info("returning 'info' details");
+ remote.sendText("HttpSession = " + httpSession);
+ }
+ else if ("close".equalsIgnoreCase(message))
+ {
+ LOG.info("closing session");
+ wsSession.close();
+ }
+ else
+ {
+ LOG.info("echoing message as-is");
+ remote.sendText(message);
+ }
+ }
+ catch (Throwable t)
+ {
+ LOG.warn(t);
+ }
+ }
+
+ private String asClassId(Object obj)
+ {
+ if (obj == null)
+ {
+ return "<null>";
+ }
+ return String.format("%s@%X",obj.getClass().getName(),obj.hashCode());
+ }
+
+ private String quoted(String str)
+ {
+ if (str == null)
+ {
+ return "<null>";
+ }
+ return '"' + str + '"';
+ }
+}
diff --git a/jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/beans.xml b/jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/beans.xml
diff --git a/jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/web.xml b/jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000000..fe2940c4f8
--- /dev/null
+++ b/jetty-cdi/test-cdi-webapp/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
+ version="3.1">
+ <display-name>CDI Integration Test WebApp</display-name>
+
+ <listener>
+ <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
+ </listener>
+
+ <resource-env-ref>
+ <description>Object factory for the CDI Bean Manager</description>
+ <resource-env-ref-name>BeanManager</resource-env-ref-name>
+ <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
+ </resource-env-ref>
+
+</web-app>

Back to the top