Search in sources :

Example 1 with Transaction

use of org.eclipse.jetty.plus.jndi.Transaction in project jetty.project by eclipse.

the class ServerWithAnnotations method main.

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
    Configuration.ClassList classlist = 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("/");
    File warFile = new File("../../jetty-distribution/target/distribution/demo-base/webapps/test.war");
    webapp.setWar(warFile.getAbsolutePath());
    webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/javax.servlet-[^/]*\\.jar$|.*/servlet-api-[^/]*\\.jar$");
    server.setHandler(webapp);
    // Register new transaction manager in JNDI
    // At runtime, the webapp accesses this as java:comp/UserTransaction
    new Transaction(new com.acme.MockUserTransaction());
    // Define an env entry with webapp scope.
    new EnvEntry(webapp, "maxAmount", new Double(100), true);
    // Register a mock DataSource scoped to the webapp
    new 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();
}
Also used : Server(org.eclipse.jetty.server.Server) Configuration(org.eclipse.jetty.webapp.Configuration) Resource(org.eclipse.jetty.plus.jndi.Resource) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) HashLoginService(org.eclipse.jetty.security.HashLoginService) Transaction(org.eclipse.jetty.plus.jndi.Transaction) File(java.io.File) EnvEntry(org.eclipse.jetty.plus.jndi.EnvEntry)

Aggregations

File (java.io.File)1 EnvEntry (org.eclipse.jetty.plus.jndi.EnvEntry)1 Resource (org.eclipse.jetty.plus.jndi.Resource)1 Transaction (org.eclipse.jetty.plus.jndi.Transaction)1 HashLoginService (org.eclipse.jetty.security.HashLoginService)1 Server (org.eclipse.jetty.server.Server)1 Configuration (org.eclipse.jetty.webapp.Configuration)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1