diff options
author | Jan Bartel | 2013-06-06 22:48:38 +0000 |
---|---|---|
committer | Jan Bartel | 2013-06-06 22:49:28 +0000 |
commit | b86344e2693dd18ac086fb837a26fdda1e303946 (patch) | |
tree | 9c73ced5ab9692104ed53fe111bc0d3fd0171e72 /examples | |
parent | bf9a4dd0c05f7c56c82138c5f5c492a825a8238a (diff) | |
download | org.eclipse.jetty.project-b86344e2693dd18ac086fb837a26fdda1e303946.tar.gz org.eclipse.jetty.project-b86344e2693dd18ac086fb837a26fdda1e303946.tar.xz org.eclipse.jetty.project-b86344e2693dd18ac086fb837a26fdda1e303946.zip |
Added new examples of embedding JNDI,annotations and updated realm.properties to match distro
Diffstat (limited to 'examples')
4 files changed, 194 insertions, 3 deletions
diff --git a/examples/embedded/pom.xml b/examples/embedded/pom.xml index 7b70eb0461..d549d781be 100644 --- a/examples/embedded/pom.xml +++ b/examples/embedded/pom.xml @@ -58,6 +58,16 @@ </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-annotations</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty.tests</groupId> + <artifactId>test-mock-resources</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-proxy</artifactId> <version>${project.version}</version> </dependency> diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java new file mode 100644 index 0000000000..9b56916b5a --- /dev/null +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java @@ -0,0 +1,71 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.embedded; + +import org.eclipse.jetty.security.HashLoginService; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.webapp.WebAppContext; + +/** + * ServerWithAnnotations + * + * + */ +public class ServerWithAnnotations +{ + public static final void main(String args[]) throws Exception + { + //Create the server + Server server = new Server(8080); + + //Enable parsing of jndi-related parts of web.xml and jetty-env.xml + org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server); + classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration"); + classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration"); + + //Create a WebApp + WebAppContext webapp = new WebAppContext(); + webapp.setContextPath("/"); + webapp.setWar("../../tests/test-webapps/test-servlet-spec/test-spec-webapp/target/test-spec-webapp-9.0.4-SNAPSHOT.war"); + server.setHandler(webapp); + + //Register new transaction manager in JNDI + //At runtime, the webapp accesses this as java:comp/UserTransaction + org.eclipse.jetty.plus.jndi.Transaction transactionMgr = new org.eclipse.jetty.plus.jndi.Transaction(new com.acme.MockUserTransaction()); + + //Define an env entry with webapp scope. + org.eclipse.jetty.plus.jndi.EnvEntry maxAmount = new org.eclipse.jetty.plus.jndi.EnvEntry (webapp, "maxAmount", new Double(100), true); + + + // Register a mock DataSource scoped to the webapp + org.eclipse.jetty.plus.jndi.Resource mydatasource = new org.eclipse.jetty.plus.jndi.Resource(webapp, "jdbc/mydatasource", new com.acme.MockDataSource()); + + // Configure a LoginService + HashLoginService loginService = new HashLoginService(); + loginService.setName("Test Realm"); + loginService.setConfig("src/test/resources/realm.properties"); + server.addBean(loginService); + + + server.start(); + server.join(); + } + +} diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithJNDI.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithJNDI.java new file mode 100644 index 0000000000..dd27587f24 --- /dev/null +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithJNDI.java @@ -0,0 +1,111 @@ +// +// ======================================================================== +// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. +// ------------------------------------------------------------------------ +// All rights reserved. This program and the accompanying materials +// are made available under the terms of the Eclipse Public License v1.0 +// and Apache License v2.0 which accompanies this distribution. +// +// The Eclipse Public License is available at +// http://www.eclipse.org/legal/epl-v10.html +// +// The Apache License v2.0 is available at +// http://www.opensource.org/licenses/apache2.0.php +// +// You may elect to redistribute this code under either of these licenses. +// ======================================================================== +// + + +package org.eclipse.jetty.embedded; + + +import java.util.Properties; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.webapp.WebAppContext; + +/** + * ServerWithJNDI + * + * + */ +public class ServerWithJNDI +{ + public static void main(String[] args) throws Exception + { + + //Create the server + Server server = new Server(8080); + + //Enable parsing of jndi-related parts of web.xml and jetty-env.xml + org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server); + classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration"); + + //Create a WebApp + WebAppContext webapp = new WebAppContext(); + webapp.setContextPath("/"); + webapp.setWar("../../tests/test-webapps/test-jndi-webapp/target/test-jndi-webapp-9.0.4-SNAPSHOT.war"); + server.setHandler(webapp); + + //Register new transaction manager in JNDI + //At runtime, the webapp accesses this as java:comp/UserTransaction + org.eclipse.jetty.plus.jndi.Transaction transactionMgr = new org.eclipse.jetty.plus.jndi.Transaction(new com.acme.MockUserTransaction()); + + //Define an env entry with Server scope. + //At runtime, the webapp accesses this as java:comp/env/woggle + //This is equivalent to putting an env-entry in web.xml: + //<env-entry> + // <env-entry-name>woggle</env-entry-name> + // <env-entry-type>java.lang.Integer</env-entry-type> + // <env-entry-value>4000</env-entry-value> + //</env-entry> + org.eclipse.jetty.plus.jndi.EnvEntry woggle = new org.eclipse.jetty.plus.jndi.EnvEntry(server, "woggle", new Integer(4000), false); + + + //Define an env entry with webapp scope. + //At runtime, the webapp accesses this as java:comp/env/wiggle + //This is equivalent to putting a web.xml entry in web.xml: + //<env-entry> + // <env-entry-name>wiggle</env-entry-name> + // <env-entry-value>100</env-entry-value> + // <env-entry-type>java.lang.Double</env-entry-type> + //</env-entry> + //Note that the last arg of "true" means that this definition for "wiggle" would override an entry of the + //same name in web.xml + org.eclipse.jetty.plus.jndi.EnvEntry wiggle = new org.eclipse.jetty.plus.jndi.EnvEntry(webapp, "wiggle", new Double(100), true); + + //Register a reference to a mail service scoped to the webapp. + //This must be linked to the webapp by an entry in web.xml: + // <resource-ref> + // <res-ref-name>mail/Session</res-ref-name> + // <res-type>javax.mail.Session</res-type> + // <res-auth>Container</res-auth> + // </resource-ref> + //At runtime the webapp accesses this as java:comp/env/mail/Session + org.eclipse.jetty.jndi.factories.MailSessionReference mailref = new org.eclipse.jetty.jndi.factories.MailSessionReference(); + mailref.setUser("CHANGE-ME"); + mailref.setPassword("CHANGE-ME"); + Properties props = new Properties(); + props.put("mail.smtp.auth", "false"); + props.put("mail.smtp.host","CHANGE-ME"); + props.put("mail.from","CHANGE-ME"); + props.put("mail.debug", "false"); + mailref.setProperties(props); + org.eclipse.jetty.plus.jndi.Resource xxxmail = new org.eclipse.jetty.plus.jndi.Resource(webapp, "mail/Session", mailref); + + + // Register a mock DataSource scoped to the webapp + //This must be linked to the webapp via an entry in web.xml: + //<resource-ref> + // <res-ref-name>jdbc/mydatasource</res-ref-name> + // <res-type>javax.sql.DataSource</res-type> + // <res-auth>Container</res-auth> + //</resource-ref> + //At runtime the webapp accesses this as java:comp/env/jdbc/mydatasource + org.eclipse.jetty.plus.jndi.Resource mydatasource = new org.eclipse.jetty.plus.jndi.Resource(webapp, "jdbc/mydatasource", + new com.acme.MockDataSource()); + + server.start(); + server.join(); + } +} diff --git a/examples/embedded/src/test/resources/realm.properties b/examples/embedded/src/test/resources/realm.properties index 6cd8ffa401..9d88b852b7 100644 --- a/examples/embedded/src/test/resources/realm.properties +++ b/examples/embedded/src/test/resources/realm.properties @@ -11,9 +11,8 @@ # If DIGEST Authentication is used, the password must be in a recoverable # format, either plain text or OBF:. # -# if using digest authentication, do not MD5-hash the password -jetty: jetty,user -admin: CRYPT:ad1ks..kc.1Ug,server-administrator,content-administrator,admin,user +jetty: MD5:164c88b302622e17050af52c89945d44,user +admin: CRYPT:adpexzg3FUZAk,server-administrator,content-administrator,admin,user other: OBF:1xmk1w261u9r1w1c1xmq,user plain: plain,user user: password,user |