cdi-webapp
Directory actions
More options
Directory actions
More options
cdi-webapp
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 2 only ("GPL") or the Common Development
and Distribution License("CDDL") (collectively, the "License"). You
may not use this file except in compliance with the License. You can
obtain a copy of the License at
http://glassfish.java.net/public/CDDL+GPL_1_1.html
or packager/legal/LICENSE.txt. See the License for the specific
language governing permissions and limitations under the License.
When distributing the software, include this License Header Notice in each
file and include the License file at packager/legal/LICENSE.txt.
GPL Classpath Exception:
Oracle designates this particular file as subject to the "Classpath"
exception as provided by Oracle in the GPL Version 2 section of the License
file that accompanied this code.
Modifications:
If applicable, add the following below the License Header, with the fields
enclosed by brackets [] replaced by your own identifying information:
"Portions Copyright [year] [name of copyright owner]"
Contributor(s):
If you wish your version of this file to be governed by only the CDDL or
only the GPL Version 2, indicate your decision by adding "[Contributor]
elects to include this software in this distribution under the [CDDL or GPL
Version 2] license." If you don't indicate a single choice of license, a
recipient has the option to distribute your version of this file under
either the CDDL, the GPL Version 2 or to extend the choice of license to
its licensees as provided above. However, if you add GPL Version 2 code
and therefore, elected the GPL Version 2 license, then the option applies
only if the new code is made subject to such option by the copyright
holder.
-->
<html><head><title>CDI Beans WebApp Example</title></head>
<body>
<h1>Jersey CDI Example</h1>
<p>This example demonstrates how to develop RESTful web service with
CDI managed beans and a Servlet 3.0 Web container.</p>
<h2>Running the Example</h2>
<p>This example should work on any Java EE 7 compliant application server.
It has been tested on a standalone GlassFish 4 instance.
The easiest way to get the application running there is to build it and deploy as follows:
<pre>
mvn clean package
$AS_HOME/asadmin deploy target/cdi-webapp.war
</pre>
</p>
<p>Another option, introduced in Jersey 2.15, is to run this example in Grizzly HTTP server.
To get the application running there you just invoke the following command:
<pre>
mvn clean compile exec:java
</pre>
<p>Since Weld Servlet support is provided also for Apache Tomcat server, there is yet
another way how to deploy the application. Use the <code>tomcat-packaging</code> maven profile
to get the WAR archive packaged in a way that makes it ready for Tomcat 7+ deployment:
<pre>
mvn -Ptomcat-packaging clean package
cp target/cdi-webapp.war $CATALINA_HOME/webapps
</pre>
<p>After you successfully deploy the application, visit the following URLs:</p>
<blockquote>
<table border="1">
<tr>
<th>Description</th>
<th>URL</th>
<th>Expected Results</th>
</tr>
<tr>
<td>A managed bean with no use of injection whatsoever</td>
<td><code><a href="proxy.php?url=http%3A%2F%2Flocalhost%3A8080%2Fcdi-webapp%2Fhelloworld">http://localhost:8080/cdi-webapp/helloworld</a></code></td>
<td><code>Hello World</code></td>
</tr>
<tr>
<td>Shows injection of context objects into the fields of a managed bean.</td>
<td><code><a href="proxy.php?url=http%3A%2F%2Flocalhost%3A8080%2Fcdi-webapp%2Fsingleton">http://localhost:8080/cdi-webapp/singleton</a></code></td>
<td><code>OK GET http://localhost:8080/cdi-webapp/singleton</code></td>
</tr>
<tr>
<td>Shows injection of context objects into the fields of a managed bean.</td>
<td><code><a href="proxy.php?url=http%3A%2F%2Flocalhost%3A8080%2Fcdi-webapp%2Fsingleton%2Fcounter">http://localhost:8080/cdi-webapp/singleton/counter</a></code></td>
<td>
<table>
<tr>
<td>
<table>
<tr><td><code>0</code>:</td><td>standalone Grizzly (no resource injection support)</td></tr>
</table>
</td>
<td rowspan="2">initial value, that gets incremented with each other request</td>
<td>
</tr>
<tr>
<td>
<table>
<tr><td><code>42</code>:</td><td>Java EE compliant AS</td></tr>
</table>
</td>
</tr>
</table></td>
</tr>
<tr>
<td>Shows injection of context objects and path parameters into the fields of a managed bean.</td>
<td><code><a href="proxy.php?url=http%3A%2F%2Flocalhost%3A8080%2Fcdi-webapp%2Fother%2FC%2FD">http://localhost:8080/cdi-webapp/other/C/D</a></code></td>
<td><code>INTERCEPTED: OK GET http://localhost:8080/cdi-webapp/other, c=C, d=D</code></td>
</tr>
<!--tr>
<td>Shows constructor injection of a path parameter in a managed bean.</td>
<td><code><a href="proxy.php?url=http%3A%2F%2Flocalhost%3A8080%2Fcdi-webapp%2Fechoconstructor%2Fa">http://localhost:8080/cdi-webapp/echoconstructor/a</a></code></td>
<td><code>not available yet!</code></td>
</tr-->
<tr>
<td>Shows injection of path and query parameters into the fields of a managed bean.</td>
<td><code><a href="proxy.php?url=http%3A%2F%2Flocalhost%3A8080%2Fcdi-webapp%2Fechofield%2Fb%3Fa%3Da">http://localhost:8080/cdi-webapp/echofield/b?a=a</a></code></td>
<td><code>ECHO a b</code></td>
</tr>
<tr>
<td>A managed bean that uses (but does not inject) a path parameter.</td>
<td><code><a href="proxy.php?url=http%3A%2F%2Flocalhost%3A8080%2Fcdi-webapp%2Fecho%2Fa">http://localhost:8080/cdi-webapp/echo/a</a></code></td>
<td><code>ECHO a</code></td>
</tr>
</table>
</blockquote>
</body>
</html>