Porting test webapps from codehaus to jetty-9
This commit is contained in:
parent
949996931a
commit
94c05e6c2e
|
@ -364,6 +364,12 @@
|
|||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-jaas</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-annotations</artifactId>
|
||||
|
@ -381,11 +387,6 @@
|
|||
<artifactId>jetty-jndi</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-plus</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-client</artifactId>
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
|
@ -63,7 +62,6 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
-->
|
||||
<!-- always include the sources to be able to prepare the eclipse-jetty-SDK feature
|
||||
with a snapshot. -->
|
||||
<plugin>
|
||||
|
|
|
@ -14,17 +14,4 @@
|
|||
<Arg><SystemProperty name="jetty.home" default="." />/etc/login.conf</Arg>
|
||||
</Call>
|
||||
|
||||
|
||||
<!-- ======================================================== -->
|
||||
<!-- An example JAAS realm setup -->
|
||||
<!-- ======================================================== -->
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.jaas.JAASLoginService">
|
||||
<Set name="Name">Test JAAS Realm</Set>
|
||||
<Set name="LoginModuleName">xyz</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
</Configure>
|
|
@ -40,9 +40,13 @@
|
|||
</plugins>
|
||||
</build>
|
||||
<modules>
|
||||
<!--
|
||||
<module>test-integration</module>
|
||||
-->
|
||||
<module>test-webapps</module>
|
||||
<module>test-sessions</module>
|
||||
<!--
|
||||
<module>test-loginservice</module>
|
||||
-->
|
||||
</modules>
|
||||
</project>
|
||||
|
|
|
@ -40,5 +40,8 @@
|
|||
</build>
|
||||
<modules>
|
||||
<module>test-webapp-rfc2616</module>
|
||||
<module>test-mock-resources</module>
|
||||
<module>test-servlet-spec</module>
|
||||
<module>test-jaas-webapp</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<directory>src/main/config</directory>
|
||||
<outputDirectory></outputDirectory>
|
||||
<includes>
|
||||
<include>contexts/**</include>
|
||||
<include>webapps/test-jaas.xml</include>
|
||||
<include>etc/**</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
|
||||
<Set name="contextPath">/test-jaas</Set>
|
||||
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test-jaas</Set>
|
||||
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test-jaas.war</Set>
|
||||
<Set name="extractWAR">true</Set>
|
||||
|
||||
<Set name="securityHandler">
|
||||
<New class="org.eclipse.jetty.security.ConstraintSecurityHandler">
|
|
@ -1,4 +1,15 @@
|
|||
<HTML><HEAD><TITLE>Welcome to the JAAS Authentication and Authorization Test</TITLE></HEAD>
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>JAAS Authentication and Authorization Test</TITLE>
|
||||
<META http-equiv="Pragma" content="no-cache">
|
||||
<META http-equiv="Cache-Control" content="no-cache,no-store">
|
||||
<style>
|
||||
body {color: #2E2E2E; font-family:sans-serif; font-size:90%;}
|
||||
h1 {font-variant: small-caps; font-size:130%; letter-spacing: 0.1em;}
|
||||
h2 {font-variant: small-caps; font-size:100%; letter-spacing: 0.1em;}
|
||||
</style>
|
||||
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<A HREF="http://www.eclipse.org/jetty"><IMG SRC="images/jetty_banner.gif"></A>
|
||||
|
||||
|
@ -6,6 +17,7 @@
|
|||
<a href="http://localhost:8080/">Home</a>
|
||||
<center>
|
||||
<hr/>
|
||||
<span style="color:red; font-variant:small-caps; font-weight:bold">Test Web Application Only - Do NOT Deploy in Production</span>
|
||||
</center>
|
||||
|
||||
<H1>JAAS Authentication and Authorization Demo </H1>
|
||||
|
@ -20,7 +32,6 @@
|
|||
|
||||
<li>Unjar the test-jaas-webapp-<version>-config.jar inside $JETTY_HOME. The following files will be added:
|
||||
<pre>
|
||||
etc/jetty-jaas.xml
|
||||
etc/login.conf
|
||||
etc/login.properties
|
||||
contexts/test-jaas.xml
|
||||
|
@ -37,7 +48,7 @@
|
|||
Click on the following link to test JAAS <i>authentication</i> and role-based web security constraint <i>authorization</i>.
|
||||
</P>
|
||||
<p>
|
||||
This demo uses a simple login module that stores its configuration in a properties file. There are other types of login module provided with the jetty distro. For full information, please refer to the jetty documentation: <a href="http://www.eclipse.org/jetty/documentation/current/">http://www.eclipse.org/jetty/documentation/current/</a>.
|
||||
This demo uses a simple login module that stores its configuration in a properties file. There are other types of login module provided with the jetty distro. For full information, please refer to the <a href="http://www.eclipse.org/jetty/documentation/current/">Jetty 9 documentation</a>.
|
||||
</p>
|
||||
<P>
|
||||
To authenticate successfully with this demonstration, you must use username="me" with password="me". All other usernames, passwords should result in authentication failure.
|
||||
|
|
|
@ -0,0 +1,153 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-webapps-parent</artifactId>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-jndi-webapp</artifactId>
|
||||
<name>Jetty Tests :: WebApp :: JNDI</name>
|
||||
<packaging>war</packaging>
|
||||
<build>
|
||||
<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>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-xml-files</id>
|
||||
<phase>process-resources</phase>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<concat destfile="${project.build.directory}/plugin-context.xml">
|
||||
<filelist dir="src/main/templates/" files="plugin-context-header.xml,env-definitions.xml" />
|
||||
</concat>
|
||||
<concat destfile="${project.build.directory}/test-jndi.xml">
|
||||
<filelist dir="src/main/templates/" files="jetty-test-jndi-header.xml,env-definitions.xml" />
|
||||
</concat>
|
||||
</tasks>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-mock-resources</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<includes>**</includes>
|
||||
<overWrite>true</overWrite>
|
||||
<outputDirectory>${project.build.directory}/lib/jndi</outputDirectory>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-transaction-properties</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/resources</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/config/resources</directory>
|
||||
<includes>
|
||||
<include>**/transactions.properties</include>
|
||||
</includes>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2-beta-3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/main/assembly/config.xml</descriptor>
|
||||
</descriptors>
|
||||
<!-- filters> <filter>src/filters/filter.properties</filter>
|
||||
</filters -->
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<configuration>
|
||||
<webAppXml>${project.build.directory}/plugin-context.xml</webAppXml>
|
||||
<webAppConfig>
|
||||
<war>src/main/webapp</war>
|
||||
<descriptor>src/main/webapp/WEB-INF/web.xml</descriptor>
|
||||
<contextPath>/test-jndi</contextPath>
|
||||
</webAppConfig>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.transaction</artifactId>
|
||||
<version>1.1.1.v201105210645</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.servlet</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.mail.glassfish</artifactId>
|
||||
<scope>provided</scope>
|
||||
<version>1.4.1.v201005082020</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<assembly>
|
||||
<id>config</id>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>src/main/config</directory>
|
||||
<outputDirectory></outputDirectory>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/resources/**</exclude>
|
||||
</excludes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>target</directory>
|
||||
<outputDirectory>webapps</outputDirectory>
|
||||
<includes>
|
||||
<include>test-jndi.xml</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>target</directory>
|
||||
<outputDirectory></outputDirectory>
|
||||
<includes>
|
||||
<include>lib/jndi/**</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
|
@ -0,0 +1,161 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 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 com.acme;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.mail.Session;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.sql.DataSource;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
/**
|
||||
* JNDITest
|
||||
*
|
||||
* Use JNDI from within Jetty.
|
||||
*
|
||||
* Also, use servlet spec 2.5 resource injection and lifecycle callbacks from within the web.xml
|
||||
* to set up some of the JNDI resources.
|
||||
*
|
||||
*/
|
||||
public class JNDITest extends HttpServlet
|
||||
{
|
||||
private DataSource myDS;
|
||||
|
||||
private Session myMailSession;
|
||||
private Double wiggle;
|
||||
private Integer woggle;
|
||||
private Double gargle;
|
||||
|
||||
private String resourceNameMappingInjectionResult;
|
||||
private String envEntryOverrideResult;
|
||||
private String postConstructResult = "PostConstruct method called: FALSE";
|
||||
private String preDestroyResult = "PreDestroy method called: NOT YET";
|
||||
private String envEntryGlobalScopeResult;
|
||||
private String envEntryWebAppScopeResult;
|
||||
private String userTransactionResult;
|
||||
private String mailSessionResult;
|
||||
|
||||
|
||||
public void setMyDatasource(DataSource ds)
|
||||
{
|
||||
myDS=ds;
|
||||
}
|
||||
|
||||
|
||||
private void postConstruct ()
|
||||
{
|
||||
String tmp = (myDS == null?"":myDS.toString());
|
||||
resourceNameMappingInjectionResult= "Injection of resource to locally mapped name (java:comp/env/mydatasource as java:comp/env/mydatasource1): "+String.valueOf(myDS);
|
||||
envEntryOverrideResult = "Override of EnvEntry in jetty-env.xml (java:comp/env/wiggle): "+(wiggle==55.0?"PASS":"FAIL(expected 55.0, got "+wiggle+")");
|
||||
postConstructResult = "PostConstruct method called: PASS";
|
||||
}
|
||||
|
||||
private void preDestroy()
|
||||
{
|
||||
preDestroyResult = "PreDestroy method called: PASS";
|
||||
}
|
||||
|
||||
|
||||
public void init(ServletConfig config) throws ServletException
|
||||
{
|
||||
super.init(config);
|
||||
try
|
||||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
woggle = (Integer)ic.lookup("java:comp/env/woggle");
|
||||
envEntryGlobalScopeResult = "EnvEntry defined in context xml lookup result (java:comp/env/woggle): "+(woggle==4000?"PASS":"FAIL(expected 4000, got "+woggle+")");
|
||||
gargle = (Double)ic.lookup("java:comp/env/gargle");
|
||||
envEntryWebAppScopeResult = "EnvEntry defined in jetty-env.xml lookup result (java:comp/env/gargle): "+(gargle==100.0?"PASS":"FAIL(expected 100, got "+gargle+")");
|
||||
UserTransaction utx = (UserTransaction)ic.lookup("java:comp/UserTransaction");
|
||||
userTransactionResult = "UserTransaction lookup result (java:comp/UserTransaction): "+(utx!=null?"PASS":"FAIL");
|
||||
myMailSession = (Session)ic.lookup("java:comp/env/mail/Session");
|
||||
mailSessionResult = "Mail Session lookup result (java:comp/env/mail/Session): "+(myMailSession!=null?"PASS": "FAIL");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
String mailTo = request.getParameter("mailto");
|
||||
String mailFrom = request.getParameter("mailfrom");
|
||||
|
||||
if (mailTo != null)
|
||||
mailTo = mailTo.trim();
|
||||
|
||||
if (mailFrom != null)
|
||||
mailFrom = mailFrom.trim();
|
||||
|
||||
try
|
||||
{
|
||||
response.setContentType("text/html");
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
out.println("<html>");
|
||||
out.println("<h1>Jetty JNDI Tests</h1>");
|
||||
out.println("<body>");
|
||||
|
||||
out.println("<h2>Injection and JNDI Lookup Results</h2>");
|
||||
out.println("<p>"+resourceNameMappingInjectionResult+"</p>");
|
||||
out.println("<p>"+envEntryOverrideResult+"</p>");
|
||||
out.println("<p>"+postConstructResult+"</p>");
|
||||
out.println("<p>"+preDestroyResult+"</p>");
|
||||
out.println("<p>"+envEntryGlobalScopeResult+"</p>");
|
||||
out.println("<p>"+envEntryWebAppScopeResult+"</p>");
|
||||
out.println("<p>"+userTransactionResult+"</p>");
|
||||
out.println("<p>"+mailSessionResult+"</p>");
|
||||
|
||||
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
out.flush();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void destroy ()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
<!-- Define an env entry with Server scope for java:comp/env -->
|
||||
<New id="woggle" class="org.eclipse.jetty.plus.jndi.EnvEntry">
|
||||
<Arg><Property name='server'/></Arg>
|
||||
<Arg>woggle</Arg>
|
||||
<Arg type="java.lang.Integer">4000</Arg>
|
||||
<Arg type="boolean">false</Arg>
|
||||
</New>
|
||||
|
||||
<!-- Define an env entry with webapp scope for java:comp/env -->
|
||||
<New id="wiggle" class="org.eclipse.jetty.plus.jndi.EnvEntry">
|
||||
<Arg><Ref id='wac'/></Arg>
|
||||
<Arg>wiggle</Arg>
|
||||
<Arg type="java.lang.Double">100</Arg>
|
||||
<Arg type="boolean">true</Arg>
|
||||
</New>
|
||||
|
||||
<!-- Mail Session setup -->
|
||||
<New id="xxxmail" class="org.eclipse.jetty.plus.jndi.Resource">
|
||||
<Arg><Ref id='wac'/></Arg>
|
||||
<Arg>mail/Session</Arg>
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.jndi.factories.MailSessionReference">
|
||||
<Set name="user">CHANGE-ME</Set>
|
||||
<Set name="password">CHANGE-ME</Set>
|
||||
<Set name="properties">
|
||||
<New class="java.util.Properties">
|
||||
<Put name="mail.smtp.auth">false</Put> <!-- change to true if you want to authenticate -->
|
||||
<Put name="mail.smtp.host">CHANGE-ME</Put>
|
||||
<Put name="mail.from">CHANGE-ME</Put>
|
||||
<Put name="mail.debug">false</Put>
|
||||
</New>
|
||||
</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</New>
|
||||
|
||||
<!-- A mock DataSource -->
|
||||
<New id="mydatasource" class="org.eclipse.jetty.plus.jndi.Resource">
|
||||
<Arg><Ref id='wac'/></Arg>
|
||||
<Arg>jdbc/mydatasource</Arg>
|
||||
<Arg>
|
||||
<New class="com.acme.MockDataSource"/>
|
||||
</Arg>
|
||||
</New>
|
||||
|
||||
</Configure>
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configure the test-jndi webapp -->
|
||||
<!-- =============================================================== -->
|
||||
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
|
||||
<New id="tx" class="org.eclipse.jetty.plus.jndi.Transaction">
|
||||
<Arg>
|
||||
<New class="com.acme.MockUserTransaction"/>
|
||||
</Arg>
|
||||
</New>
|
||||
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configure the webapp -->
|
||||
<!-- =============================================================== -->
|
||||
<Set name="configurationClasses">
|
||||
<Array type="java.lang.String">
|
||||
<Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.TagLibConfiguration</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
|
||||
|
||||
<Set name="contextPath">/test-jndi</Set>
|
||||
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test-jndi.war</Set>
|
||||
<Set name="extractWAR">true</Set>
|
||||
<Set name="copyWebDir">false</Set>
|
||||
<Set name="configurationDiscovered">true</Set>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configure the test-jndi webapp -->
|
||||
<!-- =============================================================== -->
|
||||
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
|
||||
|
||||
<!-- only necessary for mvn jetty:run -->
|
||||
<New id="tx" class="org.eclipse.jetty.plus.jndi.Transaction">
|
||||
<Arg>
|
||||
<New class="com.atomikos.icatch.jta.UserTransactionImp"/>
|
||||
</Arg>
|
||||
</New>
|
||||
|
||||
<Call class="java.lang.System" name="setProperty">
|
||||
<Arg>derby.system.home</Arg>
|
||||
<Arg><SystemProperty name="java.io.tmpdir"/></Arg>
|
||||
</Call>
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
|
||||
<!-- Add an EnvEntry only valid for this webapp -->
|
||||
<New id="gargle" class="org.eclipse.jetty.plus.jndi.EnvEntry">
|
||||
<Arg><Ref id='wac'/></Arg>
|
||||
<Arg>gargle</Arg>
|
||||
<Arg type="java.lang.Double">100</Arg>
|
||||
<Arg type="boolean">true</Arg>
|
||||
</New>
|
||||
|
||||
<!-- Add an override for a global EnvEntry -->
|
||||
<New id="wiggle" class="org.eclipse.jetty.plus.jndi.EnvEntry">
|
||||
<Arg><Ref id='wac'/></Arg>
|
||||
<Arg>wiggle</Arg>
|
||||
<Arg type="java.lang.Double">55.0</Arg>
|
||||
<Arg type="boolean">true</Arg>
|
||||
</New>
|
||||
|
||||
<!-- Add a mapping from name in web.xml to the environment -->
|
||||
<New id="map1" class="org.eclipse.jetty.plus.jndi.Link">
|
||||
<Arg><Ref id='wac'/></Arg>
|
||||
<Arg>jdbc/mydatasource1</Arg> <!-- name in web.xml -->
|
||||
<Arg>jdbc/mydatasource</Arg> <!-- name in environment -->
|
||||
</New>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</Configure>
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<web-app
|
||||
xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
|
||||
metadata-complete="true"
|
||||
version="2.5">
|
||||
|
||||
<display-name>Test JNDI WebApp</display-name>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>JNDITest</servlet-name>
|
||||
<servlet-class>com.acme.JNDITest</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>JNDITest</servlet-name>
|
||||
<url-pattern>/test/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<env-entry>
|
||||
<env-entry-name>wiggle</env-entry-name>
|
||||
<env-entry-value>99.99</env-entry-value>
|
||||
<env-entry-type>java.lang.Double</env-entry-type>
|
||||
<injection-target>
|
||||
<injection-target-class>com.acme.JNDITest</injection-target-class>
|
||||
<injection-target-name>wiggle</injection-target-name>
|
||||
</injection-target>
|
||||
</env-entry>
|
||||
|
||||
<resource-ref>
|
||||
<res-ref-name>mail/Session</res-ref-name>
|
||||
<res-type>javax.mail.Session</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
</resource-ref>
|
||||
|
||||
<resource-ref>
|
||||
<res-ref-name>jdbc/mydatasource1</res-ref-name>
|
||||
<res-type>javax.sql.DataSource</res-type>
|
||||
<res-auth>Container</res-auth>
|
||||
<injection-target>
|
||||
<injection-target-class>com.acme.JNDITest</injection-target-class>
|
||||
<injection-target-name>myDatasource</injection-target-name>
|
||||
</injection-target>
|
||||
</resource-ref>
|
||||
|
||||
|
||||
<post-construct>
|
||||
<lifecycle-callback-class>com.acme.JNDITest</lifecycle-callback-class>
|
||||
<lifecycle-callback-method>postConstruct</lifecycle-callback-method>
|
||||
</post-construct>
|
||||
|
||||
<pre-destroy>
|
||||
<lifecycle-callback-class>com.acme.JNDITest</lifecycle-callback-class>
|
||||
<lifecycle-callback-method>preDestroy</lifecycle-callback-method>
|
||||
</pre-destroy>
|
||||
|
||||
</web-app>
|
||||
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
|
@ -0,0 +1,62 @@
|
|||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>JNDI Test WebApp</TITLE>
|
||||
<META http-equiv="Pragma" content="no-cache">
|
||||
<META http-equiv="Cache-Control" content="no-cache,no-store">
|
||||
<style>
|
||||
body {color: #2E2E2E; font-family:sans-serif; font-size:90%;}
|
||||
h1 {font-variant: small-caps; font-size:130%; letter-spacing: 0.1em;}
|
||||
h2 {font-variant: small-caps; font-size:100%; letter-spacing: 0.1em;}
|
||||
h3 {font-size:100%; letter-spacing: 0.1em;}
|
||||
</style>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
<A HREF="http://www.eclipse.org/jetty"><IMG SRC="images/jetty_banner.gif"></A>
|
||||
|
||||
<p> </p>
|
||||
<a href="http://localhost:8080/">Home</a>
|
||||
<center>
|
||||
<hr/>
|
||||
<span style="color:red; font-variant:small-caps; font-weight:bold">Test Web Application Only - Do NOT Deploy in Production</span>
|
||||
</center>
|
||||
|
||||
<P>
|
||||
<h1>JNDI Test WebApp</h1>
|
||||
|
||||
<p>
|
||||
This example shows how to configure and lookup resources such as DataSources, a JTA transaction manager and a java.mail.Session in JNDI.
|
||||
</p>
|
||||
|
||||
<h2>Preparation</h2>
|
||||
<p>
|
||||
<ol>
|
||||
<li>Ensure that you have downloaded and unpacked the test-jndi-webapp-<version>-config.jar, where <version> is replaced by the desired version number. The following files will be created:
|
||||
<pre>
|
||||
lib/jndi/test-mock-resources-<version>.jar (where <version> is replaced by the particular version number)
|
||||
webapps/test-jndi.xml
|
||||
</pre>
|
||||
</li>
|
||||
<li>Edit your $JETTY_HOME/start.ini file and add the following line:
|
||||
<pre>
|
||||
OPTIONS=plus
|
||||
</pre>
|
||||
</li>
|
||||
</ol>
|
||||
</p>
|
||||
|
||||
<h2>Execution</h2>
|
||||
<p>
|
||||
Click <code>Test</code> to check the runtime lookup of the JNDI resources.
|
||||
</p>
|
||||
<form action="test" method="post">
|
||||
<button type="submit">Test</button>
|
||||
</form>
|
||||
|
||||
|
||||
<center>
|
||||
<hr/>
|
||||
<a href="http://www.eclipse.org/jetty"><img style="border:0" src="images/small_powered_by.gif"/></a>
|
||||
</center>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
|
@ -0,0 +1,35 @@
|
|||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-webapps-parent</artifactId>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<name>Jetty Tests :: WebApp :: Mock Resources</name>
|
||||
<artifactId>test-mock-resources</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<verbose>false</verbose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.transaction</artifactId>
|
||||
<version>1.1.1.v201105210645</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.servlet</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,101 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 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 com.acme;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* MockDataSource
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MockDataSource implements DataSource
|
||||
{
|
||||
|
||||
/**
|
||||
* NOTE: JDK7+ new feature
|
||||
*/
|
||||
public Logger getParentLogger()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#getConnection()
|
||||
*/
|
||||
public Connection getConnection() throws SQLException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public Connection getConnection(String username, String password)
|
||||
throws SQLException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#getLogWriter()
|
||||
*/
|
||||
public PrintWriter getLogWriter() throws SQLException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#getLoginTimeout()
|
||||
*/
|
||||
public int getLoginTimeout() throws SQLException
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
|
||||
*/
|
||||
public void setLogWriter(PrintWriter out) throws SQLException
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#setLoginTimeout(int)
|
||||
*/
|
||||
public void setLoginTimeout(int seconds) throws SQLException
|
||||
{
|
||||
}
|
||||
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 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 com.acme;
|
||||
|
||||
import javax.transaction.HeuristicMixedException;
|
||||
import javax.transaction.HeuristicRollbackException;
|
||||
import javax.transaction.NotSupportedException;
|
||||
import javax.transaction.RollbackException;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
/**
|
||||
* MockUserTransaction
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MockUserTransaction implements UserTransaction
|
||||
{
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#begin()
|
||||
*/
|
||||
public void begin() throws NotSupportedException, SystemException
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#commit()
|
||||
*/
|
||||
public void commit() throws HeuristicMixedException,
|
||||
HeuristicRollbackException, IllegalStateException,
|
||||
RollbackException, SecurityException, SystemException
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#getStatus()
|
||||
*/
|
||||
public int getStatus() throws SystemException
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#rollback()
|
||||
*/
|
||||
public void rollback() throws IllegalStateException, SecurityException,
|
||||
SystemException
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#setRollbackOnly()
|
||||
*/
|
||||
public void setRollbackOnly() throws IllegalStateException, SystemException
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#setTransactionTimeout(int)
|
||||
*/
|
||||
public void setTransactionTimeout(int arg0) throws SystemException
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-webapps-parent</artifactId>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-servlet-spec-parent</artifactId>
|
||||
<name>Jetty Tests :: Spec Test WebApp :: Parent</name>
|
||||
<packaging>pom</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- DO NOT DEPLOY (or Release) -->
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<modules>
|
||||
<module>test-web-fragment</module>
|
||||
<module>test-container-initializer</module>
|
||||
<module>test-spec-webapp</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,30 @@
|
|||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-servlet-spec-parent</artifactId>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>test-container-initializer</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Jetty Tests :: WebApp :: Servlet Spec :: ServletContainerInitializer Test Jar</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<verbose>false</verbose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.servlet</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,15 @@
|
|||
package com.acme;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
|
||||
public @interface Foo
|
||||
{
|
||||
int value();
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.acme;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import javax.servlet.ServletRegistration;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.annotation.HandlesTypes;
|
||||
import javax.servlet.ServletContainerInitializer;
|
||||
|
||||
@HandlesTypes ({javax.servlet.Servlet.class, Foo.class})
|
||||
public class FooInitializer implements ServletContainerInitializer
|
||||
{
|
||||
|
||||
public void onStartup(Set<Class<?>> classes, ServletContext context)
|
||||
{
|
||||
context.setAttribute("com.acme.Foo", new ArrayList<Class>(classes));
|
||||
ServletRegistration.Dynamic reg = context.addServlet("AnnotationTest", "com.acme.AnnotationTest");
|
||||
context.setAttribute("com.acme.AnnotationTest.complete", (reg == null));
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
com.acme.FooInitializer
|
|
@ -0,0 +1,165 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-servlet-spec-parent</artifactId>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<name>Jetty Tests :: Webapps :: Spec Webapp</name>
|
||||
<artifactId>test-spec-webapp</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-xml-files</id>
|
||||
<phase>process-resources</phase>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<concat destfile="${project.build.directory}/plugin-context.xml">
|
||||
<filelist dir="src/main/templates/" files="plugin-context-header.xml,env-definitions.xml" />
|
||||
</concat>
|
||||
<concat destfile="${project.build.directory}/test-annotations.xml">
|
||||
<filelist dir="src/main/templates/" files="annotations-context-header.xml,env-definitions.xml" />
|
||||
</concat>
|
||||
</tasks>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-mock-resources</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<includes>**</includes>
|
||||
<overWrite>true</overWrite>
|
||||
<outputDirectory>${project.build.directory}/lib/jndi</outputDirectory>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2-beta-3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>${basedir}/src/main/assembly/config.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>10</scanIntervalSeconds>
|
||||
<useTestClasspath>true</useTestClasspath>
|
||||
<webAppXml>${project.build.directory}/plugin-context.xml</webAppXml>
|
||||
<webAppConfig>
|
||||
<war>src/main/webapp</war>
|
||||
<descriptor>src/main/webapp/WEB-INF/web.xml</descriptor>
|
||||
<contextPath>/test-annotations</contextPath>
|
||||
<containerIncludeJarPattern>.*/javax.servlet-[^/]*\.jar$</containerIncludeJarPattern>
|
||||
<configurationDiscovered>true</configurationDiscovered>
|
||||
<jettyEnvXml>${basedir}/src/main/webapp/WEB-INF/jetty-env.xml</jettyEnvXml>
|
||||
</webAppConfig>
|
||||
<loginServices>
|
||||
<loginService implementation="org.eclipse.jetty.security.HashLoginService">
|
||||
<name>Test Realm</name>
|
||||
<config>src/etc/realm.properties</config>
|
||||
</loginService>
|
||||
</loginServices>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-mock-resources</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.transaction</artifactId>
|
||||
<version>1.1.1.v201105210645</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.mail.glassfish</artifactId>
|
||||
<version>1.4.1.v201005082020</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.servlet</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.annotation</artifactId>
|
||||
<version>1.1.0.v201108011116</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-web-fragment</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-container-initializer</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,8 @@
|
|||
jetty: MD5:164c88b302622e17050af52c89945d44,user
|
||||
admin: CRYPT:adpexzg3FUZAk,server-administrator,content-administrator,admin
|
||||
other: OBF:1xmk1w261u9r1w1c1xmq,user
|
||||
plain: plain,user
|
||||
user: password,user
|
||||
|
||||
# This entry is for digest auth. The credential is a MD5 hash of username:realmname:password
|
||||
digest: MD5:6e120743ad67abfbc385bc2bb754e297,user
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<assembly>
|
||||
<id>config</id>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>src/main/config</directory>
|
||||
<outputDirectory></outputDirectory>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/resources/**</exclude>
|
||||
</excludes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>target</directory>
|
||||
<outputDirectory>webapps</outputDirectory>
|
||||
<includes>
|
||||
<include>test-annotations.xml</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>target</directory>
|
||||
<outputDirectory></outputDirectory>
|
||||
<includes>
|
||||
<include>lib/jndi/**</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
|
@ -0,0 +1,319 @@
|
|||
//========================================================================
|
||||
//Copyright 2004-2009 Mort Bay Consulting Pty. Ltd.
|
||||
//------------------------------------------------------------------------
|
||||
//Licensed 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 com.acme;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.naming.InitialContext;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.sql.DataSource;
|
||||
import javax.transaction.UserTransaction;
|
||||
import javax.annotation.Resource;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.annotation.security.RunAs;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.annotation.WebInitParam;
|
||||
import javax.annotation.security.DeclareRoles;
|
||||
|
||||
/**
|
||||
* AnnotationTest
|
||||
*
|
||||
* Use Annotations from within Jetty.
|
||||
*
|
||||
* Also, use servlet spec 2.5 resource injection and lifecycle callbacks from within the web.xml
|
||||
* to set up some of the JNDI resources.
|
||||
*
|
||||
*/
|
||||
|
||||
@RunAs("special")
|
||||
@WebServlet(urlPatterns = {"/","/test/*"}, name="AnnotationTest", initParams={@WebInitParam(name="fromAnnotation", value="xyz")})
|
||||
@DeclareRoles({"user","client"})
|
||||
public class AnnotationTest extends HttpServlet
|
||||
{
|
||||
static List<String> __HandlesTypes;
|
||||
private String postConstructResult = "";
|
||||
private String dsResult = "";
|
||||
private String envResult = "";
|
||||
private String envLookupResult = "";
|
||||
private String envResult2 ="";
|
||||
private String envLookupResult2 = "";
|
||||
private String envResult3 = "";
|
||||
private String envLookupResult3 = "";
|
||||
private String dsLookupResult = "";
|
||||
private String txResult = "";
|
||||
private String txLookupResult = "";
|
||||
private DataSource myDS;
|
||||
private ServletConfig config;
|
||||
|
||||
@Resource(mappedName="UserTransaction")
|
||||
private UserTransaction myUserTransaction;
|
||||
|
||||
|
||||
@Resource(mappedName="maxAmount")
|
||||
private Double maxAmount;
|
||||
|
||||
@Resource(name="someAmount")
|
||||
private Double minAmount;
|
||||
|
||||
@Resource
|
||||
private Double avgAmount;
|
||||
|
||||
|
||||
@Resource(mappedName="jdbc/mydatasource")
|
||||
public void setMyDatasource(DataSource ds)
|
||||
{
|
||||
myDS=ds;
|
||||
}
|
||||
|
||||
|
||||
@PostConstruct
|
||||
private void myPostConstructMethod ()
|
||||
{
|
||||
postConstructResult = "Called";
|
||||
try
|
||||
{
|
||||
dsResult = (myDS==null?"FAIL":"myDS="+myDS.toString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dsResult = "FAIL: "+e;
|
||||
}
|
||||
|
||||
|
||||
envResult = (maxAmount==null?"FAIL":"maxAmount="+maxAmount.toString());
|
||||
|
||||
try
|
||||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
envLookupResult = "java:comp/env/com.acme.AnnotationTest/maxAmount="+ic.lookup("java:comp/env/com.acme.AnnotationTest/maxAmount");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
envLookupResult = "FAIL: "+e;
|
||||
}
|
||||
|
||||
envResult2 = (minAmount==null?"FAIL":"minAmount="+minAmount.toString());
|
||||
try
|
||||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
envLookupResult2 = "java:comp/env/someAmount="+ic.lookup("java:comp/env/someAmount");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
envLookupResult2 = "FAIL: "+e;
|
||||
}
|
||||
envResult3 = (minAmount==null?"FAIL":"avgAmount="+avgAmount.toString());
|
||||
try
|
||||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
envLookupResult3 = "java:comp/env/com.acme.AnnotationTest/avgAmount="+ic.lookup("java:comp/env/com.acme.AnnotationTest/avgAmount");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
envLookupResult3 = "FAIL: "+e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
dsLookupResult = "java:comp/env/com.acme.AnnotationTest/myDatasource="+ic.lookup("java:comp/env/com.acme.AnnotationTest/myDatasource");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
dsLookupResult = "FAIL: "+e;
|
||||
}
|
||||
|
||||
txResult = (myUserTransaction==null?"FAIL":"myUserTransaction="+myUserTransaction);
|
||||
try
|
||||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
txLookupResult = "java:comp/env/com.acme.AnnotationTest/myUserTransaction="+ic.lookup("java:comp/env/com.acme.AnnotationTest/myUserTransaction");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
txLookupResult = "FAIL: "+e;
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
private void myPreDestroyMethod()
|
||||
{
|
||||
}
|
||||
|
||||
public void init(ServletConfig config) throws ServletException
|
||||
{
|
||||
super.init(config);
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
response.setContentType("text/html");
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
out.println("<html>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>Results</h1>");
|
||||
|
||||
out.println("<h2>Init Params from Annotation</h2>");
|
||||
out.println("<pre>");
|
||||
out.println("initParams={@WebInitParam(name=\"fromAnnotation\", value=\"xyz\")}");
|
||||
out.println("</pre>");
|
||||
out.println("<br/><b>Result: "+("xyz".equals(config.getInitParameter("fromAnnotation"))? "PASS": "FAIL"));
|
||||
|
||||
out.println("<h2>Init Params from web-fragment</h2>");
|
||||
out.println("<pre>");
|
||||
out.println("extra1=123, extra2=345");
|
||||
out.println("</pre>");
|
||||
boolean fragInitParamResult = "123".equals(config.getInitParameter("extra1")) && "345".equals(config.getInitParameter("extra2"));
|
||||
out.println("<br/><b>Result: "+(fragInitParamResult? "PASS": "FAIL"));
|
||||
|
||||
|
||||
__HandlesTypes = Arrays.asList( "javax.servlet.GenericServlet",
|
||||
"javax.servlet.http.HttpServlet",
|
||||
"com.acme.AnnotationTest",
|
||||
"com.acme.RoleAnnotationTest",
|
||||
"com.acme.MultiPartTest",
|
||||
"com.acme.FragmentServlet",
|
||||
"com.acme.TestListener",
|
||||
"com.acme.SecuredServlet",
|
||||
"com.acme.Bar");
|
||||
out.println("<h2>@ContainerInitializer</h2>");
|
||||
out.println("<pre>");
|
||||
out.println("@HandlesTypes({javax.servlet.Servlet.class, Foo.class})");
|
||||
out.println("</pre>");
|
||||
out.print("<br/><b>Result: ");
|
||||
List<Class> classes = (List<Class>)config.getServletContext().getAttribute("com.acme.Foo");
|
||||
List<String> classNames = new ArrayList<String>();
|
||||
if (classes != null)
|
||||
{
|
||||
for (Class c: classes)
|
||||
{
|
||||
classNames.add(c.getName());
|
||||
out.print(c.getName()+" ");
|
||||
}
|
||||
|
||||
if (classNames.size() != __HandlesTypes.size())
|
||||
out.println("<br/>FAIL");
|
||||
else if (!classNames.containsAll(__HandlesTypes))
|
||||
out.println("<br/>FAIL");
|
||||
else
|
||||
out.println("<br/>PASS");
|
||||
}
|
||||
else
|
||||
out.print("<br/>FAIL (No such attribute com.acme.Foo)");
|
||||
out.println("</b>");
|
||||
|
||||
out.println("<h2>Complete Servlet Registration</h2>");
|
||||
Boolean complete = (Boolean)config.getServletContext().getAttribute("com.acme.AnnotationTest.complete");
|
||||
out.println("<br/><b>Result: "+(complete.booleanValue()?"PASS":"FAIL")+"</b>");
|
||||
|
||||
out.println("<h2>@PostConstruct Callback</h2>");
|
||||
out.println("<pre>");
|
||||
out.println("@PostConstruct");
|
||||
out.println("private void myPostConstructMethod ()");
|
||||
out.println("{}");
|
||||
out.println("</pre>");
|
||||
out.println("<br/><b>Result: "+postConstructResult+"</b>");
|
||||
|
||||
|
||||
out.println("<h2>@Resource Injection for DataSource</h2>");
|
||||
out.println("<pre>");
|
||||
out.println("@Resource(mappedName=\"jdbc/mydatasource\");");
|
||||
out.println("public void setMyDatasource(DataSource ds)");
|
||||
out.println("{");
|
||||
out.println("myDS=ds;");
|
||||
out.println("}");
|
||||
out.println("</pre>");
|
||||
out.println("<br/><b>Result: "+dsResult+"</b>");
|
||||
out.println("<br/><b>JNDI Lookup Result: "+dsLookupResult+"</b>");
|
||||
|
||||
|
||||
out.println("<h2>@Resource Injection for env-entry </h2>");
|
||||
out.println("<pre>");
|
||||
out.println("@Resource(mappedName=\"maxAmount\")");
|
||||
out.println("private Double maxAmount;");
|
||||
out.println("@Resource(name=\"minAmount\")");
|
||||
out.println("private Double minAmount;");
|
||||
out.println("</pre>");
|
||||
out.println("<br/><b>Result: "+envResult+": "+(maxAmount.compareTo(new Double(55))==0?" PASS":" FAIL")+"</b>");
|
||||
out.println("<br/><b>JNDI Lookup Result: "+envLookupResult+"</b>");
|
||||
out.println("<br/><b>Result: "+envResult2+": "+(minAmount.compareTo(new Double("0.99"))==0?" PASS":" FAIL")+"</b>");
|
||||
out.println("<br/><b>JNDI Lookup Result: "+envLookupResult2+"</b>");
|
||||
out.println("<br/><b>Result: "+envResult3+": "+(avgAmount.compareTo(new Double("1.25"))==0?" PASS":" FAIL")+"</b>");
|
||||
out.println("<br/><b>JNDI Lookup Result: "+envLookupResult3+"</b>");
|
||||
out.println("<h2>@Resource Injection for UserTransaction </h2>");
|
||||
out.println("<pre>");
|
||||
out.println("@Resource(mappedName=\"UserTransaction\")");
|
||||
out.println("private UserTransaction myUserTransaction;");
|
||||
out.println("</pre>");
|
||||
out.println("<br/><b>Result: "+txResult+"</b>");
|
||||
out.println("<br/><b>JNDI Lookup Result: "+txLookupResult+"</b>");
|
||||
out.println("<h2>DeclaresRoles</h2>");
|
||||
out.println("<p>Login as user \"admin\" with password \"admin\" when prompted after clicking the button below to test @DeclareRoles annotation</p>");
|
||||
String context = request.getContextPath();
|
||||
if (!context.endsWith("/"))
|
||||
context += "/";
|
||||
context += "role/";
|
||||
out.println("<form action="+context+" method=\"post\"><button type=\"submit\">Test Role Annotations</button></form>");
|
||||
|
||||
out.println("<h2>ServletSecurity</h2>");
|
||||
out.println("<p>Login as user \"admin\" with password \"admin\" when prompted after clicking the button below to test @ServletSecurity annotation</p>");
|
||||
context = request.getContextPath();
|
||||
if (!context.endsWith("/"))
|
||||
context += "/";
|
||||
context += "sec/foo";
|
||||
out.println("<form action="+context+" method=\"post\"><button type=\"submit\">Test ServletSecurity Annotation</button></form>");
|
||||
|
||||
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
out.flush();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
//========================================================================
|
||||
//Copyright 2010 Mort Bay Consulting Pty. Ltd.
|
||||
//------------------------------------------------------------------------
|
||||
//Licensed 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 com.acme;
|
||||
|
||||
import com.acme.Foo;
|
||||
|
||||
public class Bar {
|
||||
|
||||
@Foo(2)
|
||||
public void someMethod () {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
//========================================================================
|
||||
//$Id: MockDataSource.java 3317 2008-07-19 08:08:24Z gregw $
|
||||
//Copyright 2006 Mort Bay Consulting Pty. Ltd.
|
||||
//------------------------------------------------------------------------
|
||||
//Licensed 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 com.acme;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* MockDataSource
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MockDataSource implements DataSource
|
||||
{
|
||||
|
||||
/**
|
||||
* NOTE: JDK7+ new feature
|
||||
*/
|
||||
public Logger getParentLogger()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#getConnection()
|
||||
*/
|
||||
public Connection getConnection() throws SQLException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public Connection getConnection(String username, String password)
|
||||
throws SQLException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#getLogWriter()
|
||||
*/
|
||||
public PrintWriter getLogWriter() throws SQLException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#getLoginTimeout()
|
||||
*/
|
||||
public int getLoginTimeout() throws SQLException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
|
||||
*/
|
||||
public void setLogWriter(PrintWriter out) throws SQLException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.sql.DataSource#setLoginTimeout(int)
|
||||
*/
|
||||
public void setLoginTimeout(int seconds) throws SQLException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
//========================================================================
|
||||
//$Id: MockUserTransaction.java 1692 2007-03-23 04:33:07Z janb $
|
||||
//Copyright 2006 Mort Bay Consulting Pty. Ltd.
|
||||
//------------------------------------------------------------------------
|
||||
//Licensed 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 com.acme;
|
||||
|
||||
import javax.transaction.HeuristicMixedException;
|
||||
import javax.transaction.HeuristicRollbackException;
|
||||
import javax.transaction.NotSupportedException;
|
||||
import javax.transaction.RollbackException;
|
||||
import javax.transaction.SystemException;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
/**
|
||||
* MockUserTransaction
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MockUserTransaction implements UserTransaction
|
||||
{
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#begin()
|
||||
*/
|
||||
public void begin() throws NotSupportedException, SystemException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#commit()
|
||||
*/
|
||||
public void commit() throws HeuristicMixedException,
|
||||
HeuristicRollbackException, IllegalStateException,
|
||||
RollbackException, SecurityException, SystemException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#getStatus()
|
||||
*/
|
||||
public int getStatus() throws SystemException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#rollback()
|
||||
*/
|
||||
public void rollback() throws IllegalStateException, SecurityException,
|
||||
SystemException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#setRollbackOnly()
|
||||
*/
|
||||
public void setRollbackOnly() throws IllegalStateException, SystemException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.transaction.UserTransaction#setTransactionTimeout(int)
|
||||
*/
|
||||
public void setTransactionTimeout(int arg0) throws SystemException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
//========================================================================
|
||||
//Copyright 2010 Mort Bay Consulting Pty. Ltd.
|
||||
//------------------------------------------------------------------------
|
||||
//Licensed 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 com.acme;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.Part;
|
||||
import javax.servlet.annotation.MultipartConfig;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
/**
|
||||
* MultiPartTest
|
||||
*
|
||||
* Test Servlet 3.0 MultiPart Mime handling.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
@MultipartConfig(location="foo/bar", maxFileSize=10240, maxRequestSize=-1, fileSizeThreshold=2048)
|
||||
public class MultiPartTest extends HttpServlet
|
||||
{
|
||||
private ServletConfig config;
|
||||
|
||||
|
||||
public void init(ServletConfig config) throws ServletException
|
||||
{
|
||||
super.init(config);
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
response.setContentType("text/html");
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
out.println("<html>");
|
||||
out.println("<h1>Results</h1>");
|
||||
out.println("<body>");
|
||||
out.println("<p>");
|
||||
|
||||
Collection<Part> parts = request.getParts();
|
||||
out.println("<b>Parts:</b> "+parts.size());
|
||||
for (Part p: parts)
|
||||
{
|
||||
out.println("<h3>"+p.getName()+"</h3>");
|
||||
out.println("<b>Size:</b> "+p.getSize());
|
||||
if (p.getContentType() == null || p.getContentType().startsWith("text/plain"))
|
||||
{
|
||||
out.println("<p>");
|
||||
IO.copy(p.getInputStream(),out);
|
||||
out.println("</p>");
|
||||
}
|
||||
}
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
out.flush();
|
||||
}
|
||||
catch (ServletException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
response.setContentType("text/html");
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
out.println("<html>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>Use a POST Instead</h1>");
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
out.flush();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,93 @@
|
|||
//========================================================================
|
||||
//Copyright 2010 Mort Bay Consulting Pty. Ltd.
|
||||
//------------------------------------------------------------------------
|
||||
//Licensed 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 com.acme;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.annotation.security.DeclareRoles;
|
||||
|
||||
/**
|
||||
* RoleAnnotationTest
|
||||
*
|
||||
* Use DeclareRolesAnnotations from within Jetty.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@DeclareRoles({"server-administrator","user"})
|
||||
public class RoleAnnotationTest extends HttpServlet
|
||||
{
|
||||
private ServletConfig _config;
|
||||
|
||||
public void init(ServletConfig config) throws ServletException
|
||||
{
|
||||
super.init(config);
|
||||
_config = config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
response.setContentType("text/html");
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
out.println("<html>");
|
||||
out.println("<h1>Jetty DeclareRoles Annotation Results</h1>");
|
||||
out.println("<body>");
|
||||
|
||||
out.println("<h2>Roles</h2>");
|
||||
boolean result = request.isUserInRole("other");
|
||||
out.println("<br/><b>Result: isUserInRole(\"other\")="+result+":"+ (result==false?" PASS":" FAIL")+"</b>");
|
||||
|
||||
result = request.isUserInRole("manager");
|
||||
out.println("<br/><b>Result: isUserInRole(\"manager\")="+result+":"+ (result?" PASS":" FAIL")+"</b>");
|
||||
result = request.isUserInRole("user");
|
||||
out.println("<br/><b>Result: isUserInRole(\"user\")="+result+":"+ (result==false?" PASS":" FAIL")+"</b>");
|
||||
String context = _config.getServletContext().getContextPath();
|
||||
if (!context.endsWith("/"))
|
||||
context += "/";
|
||||
|
||||
out.println("<p><A HREF=\""+context+"logout.jsp\">Logout</A></p>");
|
||||
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
out.flush();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.acme;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.HttpConstraint;
|
||||
import javax.servlet.annotation.ServletSecurity;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@WebServlet(urlPatterns="/sec/*")
|
||||
@ServletSecurity(@HttpConstraint(rolesAllowed="admin"))
|
||||
public class SecuredServlet extends HttpServlet
|
||||
{
|
||||
|
||||
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
PrintWriter writer = resp.getWriter();
|
||||
writer.println( "<html>");
|
||||
writer.println( "<body>");
|
||||
writer.println("<h1>@ServletSecurity</h2>");
|
||||
writer.println("<pre>");
|
||||
writer.println("@ServletSecurity");
|
||||
writer.println("public class SecuredServlet");
|
||||
writer.println("</pre>");
|
||||
writer.println("<br/><b>Result: "+true+"</b>");
|
||||
String context = getServletConfig().getServletContext().getContextPath();
|
||||
if (!context.endsWith("/"))
|
||||
context += "/";
|
||||
writer.println("<p><A HREF=\""+context+"logout.jsp\">Logout</A></p>");
|
||||
writer.println( "</body>");
|
||||
writer.println( "</html>");
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
//========================================================================
|
||||
//$Id: TestListener.java 3363 2008-07-22 13:40:59Z janb $
|
||||
//Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
|
||||
//------------------------------------------------------------------------
|
||||
//Licensed 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 com.acme;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.annotation.WebListener;
|
||||
import javax.servlet.ServletContextAttributeEvent;
|
||||
import javax.servlet.ServletContextAttributeListener;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.ServletRequestAttributeEvent;
|
||||
import javax.servlet.ServletRequestAttributeListener;
|
||||
import javax.servlet.ServletRequestEvent;
|
||||
import javax.servlet.ServletRequestListener;
|
||||
import javax.servlet.http.HttpSessionActivationListener;
|
||||
import javax.servlet.http.HttpSessionAttributeListener;
|
||||
import javax.servlet.http.HttpSessionBindingEvent;
|
||||
import javax.servlet.http.HttpSessionEvent;
|
||||
import javax.servlet.http.HttpSessionListener;
|
||||
import com.acme.Foo;
|
||||
|
||||
|
||||
@Foo(1)
|
||||
@WebListener
|
||||
public class TestListener implements HttpSessionListener, HttpSessionAttributeListener, HttpSessionActivationListener, ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener
|
||||
{
|
||||
|
||||
@Resource(mappedName="maxAmount")
|
||||
private Double maxAmount;
|
||||
|
||||
public void attributeAdded(HttpSessionBindingEvent se)
|
||||
{
|
||||
// System.err.println("attributedAdded "+se);
|
||||
}
|
||||
|
||||
public void attributeRemoved(HttpSessionBindingEvent se)
|
||||
{
|
||||
// System.err.println("attributeRemoved "+se);
|
||||
}
|
||||
|
||||
public void attributeReplaced(HttpSessionBindingEvent se)
|
||||
{
|
||||
// System.err.println("attributeReplaced "+se);
|
||||
}
|
||||
|
||||
public void sessionWillPassivate(HttpSessionEvent se)
|
||||
{
|
||||
// System.err.println("sessionWillPassivate "+se);
|
||||
}
|
||||
|
||||
public void sessionDidActivate(HttpSessionEvent se)
|
||||
{
|
||||
// System.err.println("sessionDidActivate "+se);
|
||||
}
|
||||
|
||||
public void contextInitialized(ServletContextEvent sce)
|
||||
{
|
||||
//System.err.println("contextInitialized, maxAmount injected as "+maxAmount);
|
||||
}
|
||||
|
||||
public void contextDestroyed(ServletContextEvent sce)
|
||||
{
|
||||
// System.err.println("contextDestroyed "+sce);
|
||||
}
|
||||
|
||||
public void attributeAdded(ServletContextAttributeEvent scab)
|
||||
{
|
||||
// System.err.println("attributeAdded "+scab);
|
||||
}
|
||||
|
||||
public void attributeRemoved(ServletContextAttributeEvent scab)
|
||||
{
|
||||
// System.err.println("attributeRemoved "+scab);
|
||||
}
|
||||
|
||||
public void attributeReplaced(ServletContextAttributeEvent scab)
|
||||
{
|
||||
// System.err.println("attributeReplaced "+scab);
|
||||
}
|
||||
|
||||
public void requestDestroyed(ServletRequestEvent sre)
|
||||
{
|
||||
// System.err.println("requestDestroyed "+sre);
|
||||
}
|
||||
|
||||
public void requestInitialized(ServletRequestEvent sre)
|
||||
{
|
||||
// System.err.println("requestInitialized "+sre);
|
||||
}
|
||||
|
||||
public void attributeAdded(ServletRequestAttributeEvent srae)
|
||||
{
|
||||
// System.err.println("attributeAdded "+srae);
|
||||
}
|
||||
|
||||
public void attributeRemoved(ServletRequestAttributeEvent srae)
|
||||
{
|
||||
// System.err.println("attributeRemoved "+srae);
|
||||
}
|
||||
|
||||
public void attributeReplaced(ServletRequestAttributeEvent srae)
|
||||
{
|
||||
// System.err.println("attributeReplaced "+srae);
|
||||
}
|
||||
|
||||
public void sessionCreated(HttpSessionEvent se)
|
||||
{
|
||||
// System.err.println("sessionCreated "+se);
|
||||
}
|
||||
|
||||
public void sessionDestroyed(HttpSessionEvent se)
|
||||
{
|
||||
// System.err.println("sessionDestroyed "+se);
|
||||
}
|
||||
|
||||
public void requestCompleted(ServletRequestEvent rre)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void requestResumed(ServletRequestEvent rre)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void requestSuspended(ServletRequestEvent rre)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configure the test-annotations webapp -->
|
||||
<!-- =============================================================== -->
|
||||
|
||||
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
|
||||
<New id="tx" class="org.eclipse.jetty.plus.jndi.Transaction">
|
||||
<Arg>
|
||||
<New class="com.acme.MockUserTransaction"/>
|
||||
</Arg>
|
||||
</New>
|
||||
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configure the webapp -->
|
||||
<!-- =============================================================== -->
|
||||
<Set name="configurationClasses">
|
||||
<Array type="java.lang.String">
|
||||
<Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.TagLibConfiguration</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
|
||||
<Set name="contextPath">/test-annotations</Set>
|
||||
<Set name="war"><SystemProperty name="jetty.home"/>/webapps/test-annotations</Set>
|
||||
<Set name="configurationDiscovered">true</Set>
|
||||
|
||||
<Get name="securityHandler">
|
||||
<Set name="loginService">
|
||||
<New class="org.eclipse.jetty.security.HashLoginService">
|
||||
<Set name="name">Test Realm</Set>
|
||||
<Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
|
||||
</New>
|
||||
</Set>
|
||||
</Get>
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
<New id="maxAmount" class="org.eclipse.jetty.plus.jndi.EnvEntry">
|
||||
<Arg><Ref id='wac'/></Arg>
|
||||
<Arg>maxAmount</Arg>
|
||||
<Arg type="java.lang.Double">100</Arg>
|
||||
<Arg type="boolean">true</Arg>
|
||||
</New>
|
||||
|
||||
|
||||
<New id="mydatasource" class="org.eclipse.jetty.plus.jndi.Resource">
|
||||
<Arg><Ref id='wac'/></Arg>
|
||||
<Arg>jdbc/mydatasource</Arg>
|
||||
<Arg>
|
||||
<New class="com.acme.MockDataSource">
|
||||
</New>
|
||||
</Arg>
|
||||
</New>
|
||||
|
||||
</Configure>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configure the test-annotations webapp -->
|
||||
<!-- =============================================================== -->
|
||||
|
||||
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
|
||||
|
||||
<!-- Configure the tx mgr (only needed for mvn jetty:run -->
|
||||
<New id="tx" class="org.eclipse.jetty.plus.jndi.Transaction">
|
||||
<Arg>
|
||||
<New class="com.atomikos.icatch.jta.UserTransactionImp"/>
|
||||
</Arg>
|
||||
</New>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
|
||||
|
||||
<!-- Add an override for a global EnvEntry -->
|
||||
<New id="maxAmount" class="org.eclipse.jetty.plus.jndi.EnvEntry">
|
||||
<Arg><Ref id='wac'/></Arg>
|
||||
<Arg>maxAmount</Arg>
|
||||
<Arg type="java.lang.Double">55.0</Arg>
|
||||
<Arg type="boolean">true</Arg>
|
||||
</New>
|
||||
|
||||
|
||||
</Configure>
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<web-app
|
||||
xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
|
||||
metadata-complete="false"
|
||||
version="2.5">
|
||||
|
||||
<display-name>Test Annotations WebApp</display-name>
|
||||
|
||||
<listener>
|
||||
<listener-class>com.acme.TestListener</listener-class>
|
||||
</listener>
|
||||
|
||||
|
||||
<servlet>
|
||||
<servlet-name>AnnotationTest</servlet-name>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>AnnotationTest</servlet-name>
|
||||
<url-pattern>/test/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>RoleAnnotationTest</servlet-name>
|
||||
<servlet-class>com.acme.RoleAnnotationTest</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
<security-role-ref>
|
||||
<role-name>manager</role-name>
|
||||
<role-link>server-administrator</role-link>
|
||||
</security-role-ref>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>RoleAnnotationTest</servlet-name>
|
||||
<url-pattern>/role/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Multi</servlet-name>
|
||||
<servlet-class>com.acme.MultiPartTest</servlet-class>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>Multi</servlet-name>
|
||||
<url-pattern>/multi/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<env-entry>
|
||||
<env-entry-name>com.acme.AnnotationTest/avgAmount</env-entry-name>
|
||||
<env-entry-value>1.25</env-entry-value>
|
||||
<env-entry-type>java.lang.Double</env-entry-type>
|
||||
</env-entry>
|
||||
|
||||
<env-entry>
|
||||
<env-entry-name>someAmount</env-entry-name>
|
||||
<env-entry-value>0.99</env-entry-value>
|
||||
<env-entry-type>java.lang.Double</env-entry-type>
|
||||
</env-entry>
|
||||
|
||||
<security-constraint>
|
||||
<web-resource-collection>
|
||||
<web-resource-name>Admin Role</web-resource-name>
|
||||
<url-pattern>/role/*</url-pattern>
|
||||
</web-resource-collection>
|
||||
<auth-constraint>
|
||||
<role-name>admin</role-name>
|
||||
</auth-constraint>
|
||||
</security-constraint>
|
||||
|
||||
<security-role>
|
||||
<role-name>admin</role-name>
|
||||
</security-role>
|
||||
|
||||
|
||||
<!--
|
||||
<login-config>
|
||||
<auth-method>BASIC</auth-method>
|
||||
<realm-name>Test Realm</realm-name>
|
||||
</login-config>
|
||||
-->
|
||||
|
||||
<login-config>
|
||||
<auth-method>FORM</auth-method>
|
||||
<realm-name>Test Realm</realm-name>
|
||||
<form-login-config>
|
||||
<form-login-page>
|
||||
/login.html
|
||||
</form-login-page>
|
||||
<form-error-page>
|
||||
/authfail.html
|
||||
</form-error-page>
|
||||
</form-login-config>
|
||||
</login-config>
|
||||
|
||||
|
||||
</web-app>
|
|
@ -0,0 +1,6 @@
|
|||
<html>
|
||||
<head><title>Authentication Failure</title</head>
|
||||
<body>
|
||||
<h1>Authentication Failure</h1>
|
||||
<p>Sorry, either your login or password were incorrect, please try again.</p>
|
||||
</html>
|
Binary file not shown.
After Width: | Height: | Size: 71 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
|
@ -0,0 +1,69 @@
|
|||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>Test Specification WebApp</TITLE>
|
||||
<META http-equiv="Pragma" content="no-cache">
|
||||
<META http-equiv="Cache-Control" content="no-cache,no-store">
|
||||
<style>
|
||||
body {color: #2E2E2E; font-family:sans-serif; font-size:90%;}
|
||||
h1 {font-variant: small-caps; font-size:130%; letter-spacing: 0.1em;}
|
||||
h2 {font-variant: small-caps; font-size:100%; letter-spacing: 0.1em;}
|
||||
h3 {font-size:100%; letter-spacing: 0.1em;}
|
||||
</style>
|
||||
|
||||
</HEAD>
|
||||
<BODY >
|
||||
<A HREF="http://www.eclipse.org/jetty"><IMG SRC="images/jetty_banner.gif"></A>
|
||||
|
||||
<p> </p>
|
||||
<a href="http://localhost:8080/">Home</a>
|
||||
<center>
|
||||
<hr/>
|
||||
<span style="color:red; font-variant:small-caps; font-weight:bold">Test Web Application Only - Do NOT Deploy in Production</span>
|
||||
</center>
|
||||
<P>
|
||||
<h1>Advanced Servlet Specification Test WebApp</h1>
|
||||
|
||||
<p>
|
||||
This example uses and tests newer aspects of the servlet specification such as annotations, web-fragments and servlet container initializers.
|
||||
</p>
|
||||
|
||||
<h2>Preparation</h2>
|
||||
<p>
|
||||
<ol>
|
||||
<li>Ensure that you have downloaded and unpacked the test-spec-webapp-<version>-config.jar, where <version> is replaced by the desired version number. The following files will be created:
|
||||
<pre>
|
||||
lib/jndi/test-mock-resources-<version>.jar (where <version> is replaced by the particular version number)
|
||||
webapps/test-annotations.xml
|
||||
</pre>
|
||||
</li>
|
||||
<li>Edit your $JETTY_HOME/start.ini file and add the following lines:
|
||||
<pre>
|
||||
OPTIONS=plus
|
||||
OPTIONS=annotations
|
||||
</pre>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
</p>
|
||||
|
||||
<h2>The Tests</h2>
|
||||
|
||||
<h3>Test Servlet 2.5/3.0 Annotations, Fragments and Initializers</h3>
|
||||
<form action="test" method="post">
|
||||
<button type="submit">Test</button>
|
||||
</form>
|
||||
|
||||
<h3>Test Servlet 3.0 Multipart Mime</h3>
|
||||
<form ENCTYPE="multipart/form-data" ACTION="multi" METHOD=POST>
|
||||
File to upload: <INPUT NAME="userfile1" TYPE="file">
|
||||
<input TYPE="submit" VALUE="Test Upload">
|
||||
</form>
|
||||
|
||||
|
||||
<center>
|
||||
<hr/>
|
||||
<a href="http://www.eclipse.org/jetty"><img style="border:0" src="images/small_powered_by.gif"/></a>
|
||||
</center>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
<HTML><HEAD><TITLE>Annotation Test</TITLE></HEAD>
|
||||
<BODY>
|
||||
<H1> Enter your username and password to login </H1>
|
||||
<I> Enter login=admin and password=admin in order to authenticate successfully</I>
|
||||
<form method="POST" action="j_security_check">
|
||||
<B>Login: </B><input type="text" name="j_username">
|
||||
<P>
|
||||
<B>Password: </B><input type="password" name="j_password">
|
||||
<P>
|
||||
<input type="submit" value="Login"/>
|
||||
</form>
|
||||
<p>
|
||||
</BODY>
|
||||
</HTML>
|
|
@ -0,0 +1,21 @@
|
|||
<%@ page contentType="text/html; charset=UTF-8" %>
|
||||
<%@ page import="java.util.*"%>
|
||||
<%@ page import="javax.servlet.*" %>
|
||||
<%@ page import="javax.servlet.http.*" %>
|
||||
<html>
|
||||
<head>
|
||||
<title>Logout</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%
|
||||
HttpSession s = request.getSession(false);
|
||||
s.invalidate();
|
||||
%>
|
||||
<h1>Logout</h1>
|
||||
|
||||
<p>You are now logged out.</p>
|
||||
<a href="/"/>Home</a>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
|
||||
|
||||
<!-- Add an override for a global EnvEntry -->
|
||||
<New id="maxAmount" class="org.eclipse.jetty.plus.jndi.EnvEntry">
|
||||
<Arg><Ref id='wac'/></Arg>
|
||||
<Arg>maxAmount</Arg>
|
||||
<Arg type="java.lang.Double">55.0</Arg>
|
||||
<Arg type="boolean">true</Arg>
|
||||
</New>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configuring Transactions and XA Datasources -->
|
||||
<!-- =============================================================== -->
|
||||
|
||||
|
||||
<New id="tx" class="org.eclipse.jetty.plus.jndi.Transaction">
|
||||
<Arg>
|
||||
<New class="com.acme.MockUserTransaction"/>
|
||||
</Arg>
|
||||
</New>
|
||||
|
||||
|
||||
|
||||
<New id="mydatasource" class="org.eclipse.jetty.plus.jndi.Resource">
|
||||
<Arg><Ref id='wac'/></Arg>
|
||||
<Arg>jdbc/mydatasource</Arg>
|
||||
<Arg>
|
||||
<New class="com.acme.MockDataSource"/>
|
||||
</Arg>
|
||||
</New>
|
||||
|
||||
|
||||
</Configure>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-servlet-spec-parent</artifactId>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<name>Jetty Tests :: WebApp :: Servlet Spec :: Fragment Jar</name>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>test-web-fragment</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<verbose>false</verbose>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.orbit</groupId>
|
||||
<artifactId>javax.servlet</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,82 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 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 com.acme;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* FragmentServlet
|
||||
*
|
||||
* A web fragment jar.
|
||||
*/
|
||||
|
||||
public class FragmentServlet extends HttpServlet
|
||||
{
|
||||
private ServletConfig config;
|
||||
|
||||
|
||||
public void init(ServletConfig config) throws ServletException
|
||||
{
|
||||
super.init(config);
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||
{
|
||||
try
|
||||
{
|
||||
response.setContentType("text/html");
|
||||
ServletOutputStream out = response.getOutputStream();
|
||||
out.println("<html>");
|
||||
out.println("<h1>Jetty Fragment Servlet</h1>");
|
||||
out.println("<body>");
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
out.flush();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<h1>Welcome to a Fragment</h1>
|
||||
|
||||
<p>
|
||||
This index.html file was included in a fragment's META-INF/resources directory.
|
||||
</p>
|
||||
|
||||
<a href="../fragment/">Now hit a servlet added by a fragment</a>
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<web-fragment
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd"
|
||||
version="3.0">
|
||||
|
||||
<name>FragmentA</name>
|
||||
|
||||
<ordering>
|
||||
<after><others/></after>
|
||||
</ordering>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>AnnotationTest</servlet-name>
|
||||
<servlet-class>com.acme.AnnotationTest</servlet-class>
|
||||
<init-param>
|
||||
<param-name>extra1</param-name><param-value>123</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>extra2</param-name><param-value>345</param-value>
|
||||
</init-param>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>Fragment</servlet-name>
|
||||
<servlet-class>com.acme.FragmentServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>Fragment</servlet-name>
|
||||
<url-pattern>/fragment/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
||||
</web-fragment>
|
||||
|
||||
|
Loading…
Reference in New Issue