You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2010/08/09 21:33:09 UTC
svn commit: r983790 [1/2] - in /openejb/trunk/openejb3:
assembly/openejb-jetty/openejb-jetty-common/
assembly/openejb-jetty/openejb-jetty-common/etc/
assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/
assembly/openejb-jetty/openejb-jetty-co...
Author: jgallimore
Date: Mon Aug 9 19:33:08 2010
New Revision: 983790
URL: http://svn.apache.org/viewvc?rev=983790&view=rev
Log:
OPENEJB-1325 initial commit of Jetty Integration work
Added:
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/etc/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/etc/realm.properties
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/EJBHelper.java
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/JettyJndiBuilder.java
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/JettySecurityService.java
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/OpenEJBConfiguration.java
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/OpenEJBLifecycle.java
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/resources/META-INF/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/resources/META-INF/org.apache.openejb.jetty/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/resources/META-INF/org.apache.openejb.jetty/service-jar.xml
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/BootstrapTest.java
openejb/trunk/openejb3/examples/webapps/ejb-examples/src/main/webapp/WEB-INF/jetty-web.xml
Modified:
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/ (props changed)
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/pom.xml
openejb/trunk/openejb3/examples/webapps/ejb-examples/src/main/webapp/WEB-INF/web.xml
Propchange: openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Aug 9 19:33:08 2010
@@ -6,4 +6,5 @@
.project
.classpath
target
+data
Added: openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/etc/realm.properties
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/etc/realm.properties?rev=983790&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/etc/realm.properties (added)
+++ openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/etc/realm.properties Mon Aug 9 19:33:08 2010
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+
+
+manager: manager,manager,user
+user: user,user
Modified: openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/pom.xml?rev=983790&r1=983789&r2=983790&view=diff
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/pom.xml (original)
+++ openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/pom.xml Mon Aug 9 19:33:08 2010
@@ -19,28 +19,126 @@
<!-- $Rev: 600338 $ $Date: 2007-12-02 09:08:04 -0800 (Sun, 02 Dec 2007) $ -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <artifactId>openejb-jetty</artifactId>
- <groupId>org.apache.openejb</groupId>
- <version>3.2-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>openejb-jetty-common</artifactId>
- <packaging>jar</packaging>
- <name>OpenEJB :: Assembly :: Jetty :: Common</name>
- <dependencies>
- <dependency>
- <groupId>org.apache.openejb</groupId>
- <artifactId>openejb-webapp-common</artifactId>
- <version>${version}</version>
- </dependency>
-<!--
- <dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty</artifactId>
- </dependency>
--->
- </dependencies>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>openejb-jetty</artifactId>
+ <groupId>org.apache.openejb</groupId>
+ <version>3.2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>openejb-jetty-common</artifactId>
+ <packaging>jar</packaging>
+ <name>OpenEJB :: Assembly :: Jetty :: Common</name>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>target/test</outputDirectory>
+ <overWriteSnapshots>
+ true
+ </overWriteSnapshots>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.superbiz</groupId>
+ <artifactId>ejb-examples</artifactId>
+ <version>1.1-SNAPSHOT</version>
+ <type>war</type>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-webapp-common</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <!--
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ </dependency>
+ -->
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-core</artifactId>
+ <version>3.2-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>javaee-api</artifactId>
+ <version>6.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-server</artifactId>
+ <version>7.0.2.v20100331</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <version>7.0.2.v20100331</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-plus</artifactId>
+ <version>7.0.2.v20100331</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-jndi</artifactId>
+ <version>7.0.2.v20100331</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-jsp-2.1</artifactId>
+ <version>7.0.2.v20100331</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.1</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jsp-2.1-glassfish</artifactId>
+ <version>2.1.v20091210</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.htmlunit</groupId>
+ <artifactId>htmlunit</artifactId>
+ <version>2.7</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
Added: openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/EJBHelper.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/EJBHelper.java?rev=983790&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/EJBHelper.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/EJBHelper.java Mon Aug 9 19:33:08 2010
@@ -0,0 +1,190 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openejb.jetty.common;
+
+import org.apache.openejb.assembler.classic.*;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.jee.EjbRef;
+import org.apache.openejb.jee.EjbReference;
+import org.apache.openejb.jee.EjbLocalRef;
+
+import java.util.Collection;
+import java.util.List;
+
+public class EJBHelper {
+ public EnterpriseBeanInfo getEJBInfo(EjbReference ejbReference) {
+ Collection<AppInfo> deployedApplications = getDeployedApps();
+ for (AppInfo app : deployedApplications) {
+ List<EjbJarInfo> ejbJars = app.ejbJars;
+ for (EjbJarInfo ejbJar : ejbJars) {
+ List<EnterpriseBeanInfo> enterpriseBeans = ejbJar.enterpriseBeans;
+ for (EnterpriseBeanInfo enterpriseBean : enterpriseBeans) {
+ if (enterpriseBean.ejbDeploymentId.equals(ejbReference.getEjbLink())) {
+ return enterpriseBean;
+ }
+
+ if (ejbReference instanceof EjbRef) {
+ EjbRef ejbRef = (EjbRef) ejbReference;
+
+ if (enterpriseBean.remote != null && enterpriseBean.remote.equals(ejbRef.getRemote())) {
+ return enterpriseBean;
+ }
+
+ if (enterpriseBean.businessRemote != null && enterpriseBean.businessRemote.contains(ejbRef.getRemote())) {
+ return enterpriseBean;
+ }
+ }
+
+ if (ejbReference instanceof EjbLocalRef) {
+ EjbLocalRef ejbLocalRef = (EjbLocalRef) ejbReference;
+ if (enterpriseBean.local != null && enterpriseBean.local.equals(ejbLocalRef.getLocal())) {
+ return enterpriseBean;
+ }
+
+ if (enterpriseBean.businessLocal != null && enterpriseBean.businessLocal.contains(ejbLocalRef.getLocal())) {
+ return enterpriseBean;
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public EnterpriseBeanInfo getBeanInfo(Class<?> fieldType) {
+ Collection<AppInfo> deployedApplications = getDeployedApps();
+
+ for (AppInfo deployedApplication : deployedApplications) {
+ List<EjbJarInfo> ejbJars = deployedApplication.ejbJars;
+
+ for (EjbJarInfo ejbJar : ejbJars) {
+ List<EnterpriseBeanInfo> enterpriseBeans = ejbJar.enterpriseBeans;
+
+ for (EnterpriseBeanInfo enterpriseBean : enterpriseBeans) {
+ List<String> remoteInterfaces = enterpriseBean.businessRemote;
+ List<String> localInterfaces = enterpriseBean.businessLocal;
+ if (remoteInterfaces.contains(fieldType.getCanonicalName()) || localInterfaces.contains(fieldType.getCanonicalName())) {
+ return enterpriseBean;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private Collection<AppInfo> getDeployedApps() {
+ Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
+ return assembler.getDeployedApplications();
+ }
+
+ public String getJndiName(EjbReference ref, EnterpriseBeanInfo beanInfo) {
+ for (JndiNameInfo jndiNameInfo : beanInfo.jndiNamess) {
+ if (ref instanceof EjbRef) {
+ EjbRef ejbRef = (EjbRef) ref;
+ if (jndiNameInfo.intrface.equals(ejbRef.getRemote())) {
+ return "java:openejb/remote/" + jndiNameInfo.name;
+ }
+ }
+ if (ref instanceof EjbLocalRef) {
+ EjbLocalRef ejbRef = (EjbLocalRef) ref;
+ if (jndiNameInfo.intrface.equals(ejbRef.getLocal())) {
+ return "java:openejb/local/" + jndiNameInfo.name;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public String getJndiName(EjbReference ref) {
+ EnterpriseBeanInfo beanInfo = getEJBInfo(ref);
+ if (beanInfo == null) return null;
+ return getJndiName(ref, beanInfo);
+ }
+
+ public String getJndiName(Class<?> iface) {
+ EnterpriseBeanInfo beanInfo = getBeanInfo(iface);
+ if (beanInfo == null) return null;
+
+ List<JndiNameInfo> jndiNameInfoList = beanInfo.jndiNamess;
+ for (JndiNameInfo jndiNameInfo : jndiNameInfoList) {
+ if (jndiNameInfo.intrface.equals(iface.getCanonicalName()) && beanInfo.businessRemote.contains(iface.getCanonicalName())) {
+ return "java:openejb/remote/" + jndiNameInfo.name;
+ }
+ if (jndiNameInfo.intrface.equals(iface.getCanonicalName()) && beanInfo.businessLocal.contains(iface.getCanonicalName())) {
+ return "java:openejb/local/" + jndiNameInfo.name;
+ }
+ }
+
+ return null;
+ }
+
+ public String getJndiName(EjbReferenceInfo ref) {
+ EnterpriseBeanInfo beanInfo = getEJBInfo(ref);
+
+ if (beanInfo == null) return null;
+ return getJndiName(ref, beanInfo);
+ }
+
+ private String getJndiName(EjbReferenceInfo ref, EnterpriseBeanInfo beanInfo) {
+ for (JndiNameInfo jndiNameInfo : beanInfo.jndiNamess) {
+ if (jndiNameInfo.intrface.equals(ref.interfaceClassName) && beanInfo.businessRemote.contains(ref.interfaceClassName)) {
+ return "java:openejb/remote/" + jndiNameInfo.name;
+ }
+ if (jndiNameInfo.intrface.equals(ref.interfaceClassName) && beanInfo.businessLocal.contains(ref.interfaceClassName)) {
+ return "java:openejb/local/" + jndiNameInfo.name;
+ }
+ }
+
+ return null;
+ }
+
+ private EnterpriseBeanInfo getEJBInfo(EjbReferenceInfo ref) {
+ Collection<AppInfo> deployedApplications = getDeployedApps();
+ for (AppInfo app : deployedApplications) {
+ List<EjbJarInfo> ejbJars = app.ejbJars;
+ for (EjbJarInfo ejbJar : ejbJars) {
+ List<EnterpriseBeanInfo> enterpriseBeans = ejbJar.enterpriseBeans;
+ for (EnterpriseBeanInfo enterpriseBean : enterpriseBeans) {
+ if (enterpriseBean.ejbDeploymentId.equals(ref.ejbDeploymentId)) {
+ return enterpriseBean;
+ }
+
+ if (enterpriseBean.remote != null && enterpriseBean.remote.equals(ref.interfaceClassName)) {
+ return enterpriseBean;
+ }
+
+ if (enterpriseBean.businessRemote != null && enterpriseBean.businessRemote.contains(ref.interfaceClassName)) {
+ return enterpriseBean;
+ }
+
+ if (enterpriseBean.local != null && enterpriseBean.local.equals(ref.interfaceClassName)) {
+ return enterpriseBean;
+ }
+
+ if (enterpriseBean.businessLocal != null && enterpriseBean.businessLocal.contains(ref.interfaceClassName)) {
+ return enterpriseBean;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+}
Added: openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/JettyJndiBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/JettyJndiBuilder.java?rev=983790&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/JettyJndiBuilder.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/JettyJndiBuilder.java Mon Aug 9 19:33:08 2010
@@ -0,0 +1,160 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openejb.jetty.common;
+
+import org.apache.log4j.Logger;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.classic.*;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.persistence.JtaEntityManager;
+import org.apache.openejb.persistence.JtaEntityManagerRegistry;
+import org.apache.openejb.spi.ContainerSystem;
+import org.eclipse.jetty.plus.jndi.EnvEntry;
+import org.eclipse.jetty.plus.jndi.NamingEntryUtil;
+import org.eclipse.jetty.plus.jndi.Resource;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+import javax.naming.Context;
+import javax.naming.LinkRef;
+import javax.naming.NamingException;
+import javax.persistence.EntityManagerFactory;
+
+public class JettyJndiBuilder {
+ private WebAppContext webAppContext;
+ private WebAppInfo webApp;
+ private Logger log = Logger.getLogger(JettyJndiBuilder.class);
+
+ public JettyJndiBuilder(WebAppContext webAppContext, WebAppInfo webApp) {
+
+ this.webAppContext = webAppContext;
+ this.webApp = webApp;
+ }
+
+ public void mergeJndi() throws OpenEJBException {
+ for (EnvEntryInfo ref : webApp.jndiEnc.envEntries) {
+ mergeRef(ref);
+ }
+ for (EjbReferenceInfo ref : webApp.jndiEnc.ejbReferences) {
+ mergeRef(ref);
+ }
+ for (EjbLocalReferenceInfo ref : webApp.jndiEnc.ejbLocalReferences) {
+ mergeRef(ref);
+ }
+ for (PersistenceContextReferenceInfo ref : webApp.jndiEnc.persistenceContextRefs) {
+ mergeRef(ref);
+ }
+ for (PersistenceUnitReferenceInfo ref : webApp.jndiEnc.persistenceUnitRefs) {
+ mergeRef(ref);
+ }
+ for (ResourceReferenceInfo ref : webApp.jndiEnc.resourceRefs) {
+ mergeRef(ref);
+ }
+ for (ResourceEnvReferenceInfo ref : webApp.jndiEnc.resourceEnvRefs) {
+ mergeRef(ref);
+ }
+// for (ServiceReferenceInfo ref : webApp.jndiEnc.serviceRefs) {
+// mergeRef(ref);
+// }
+ }
+
+ private void mergeRef(ResourceEnvReferenceInfo ref) {
+ try {
+ new Resource(webAppContext, cleanup(ref.referenceName), new LinkRef("java:openejb/Resource/" + ref.resourceID));
+ setupEnv(cleanup(ref.referenceName));
+ } catch (Exception e) {
+ log.error("Error adding EJB ref" + cleanup(ref.referenceName), e);
+ }
+ }
+
+ private void mergeRef(ResourceReferenceInfo ref) {
+ try {
+ new Resource(webAppContext, cleanup(ref.referenceName), new LinkRef("java:openejb/Resource/" + ref.resourceID));
+ setupEnv(cleanup(ref.referenceName));
+ } catch (Exception e) {
+ log.error("Error adding EJB ref" + cleanup(ref.referenceName), e);
+ }
+ }
+
+ private void mergeRef(PersistenceUnitReferenceInfo ref) {
+ try {
+ Context context = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext();
+ EntityManagerFactory factory;
+ try {
+ factory = (EntityManagerFactory) context.lookup("openejb/PersistenceUnit/" + ref.unitId);
+ } catch (NamingException e) {
+ throw new IllegalStateException("PersistenceUnit '" + ref.unitId + "' not found for EXTENDED ref '" + ref.referenceName + "'");
+ }
+
+ new Resource(webAppContext, cleanup(ref.referenceName), factory);
+ setupEnv(cleanup(ref.referenceName));
+ } catch (Exception e) {
+ log.error("Error adding EJB ref" + cleanup(ref.referenceName), e);
+ }
+ }
+
+ private void mergeRef(PersistenceContextReferenceInfo ref) {
+ try {
+ Context context = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext();
+ EntityManagerFactory factory;
+ try {
+ factory = (EntityManagerFactory) context.lookup("openejb/PersistenceUnit/" + ref.unitId);
+ } catch (NamingException e) {
+ throw new IllegalStateException("PersistenceUnit '" + ref.unitId + "' not found for EXTENDED ref '" + ref.referenceName + "'");
+ }
+
+ JtaEntityManagerRegistry jtaEntityManagerRegistry = SystemInstance.get().getComponent(JtaEntityManagerRegistry.class);
+ JtaEntityManager jtaEntityManager = new JtaEntityManager(ref.persistenceUnitName, jtaEntityManagerRegistry, factory, ref.properties, ref.extended);
+
+ new Resource(webAppContext, cleanup(ref.referenceName), jtaEntityManager);
+ setupEnv(cleanup(ref.referenceName));
+ } catch (Exception e) {
+ log.error("Error adding EJB ref" + cleanup(ref.referenceName), e);
+ }
+ }
+
+ private void mergeRef(EjbReferenceInfo ref) {
+ try {
+ String jndiName = new EJBHelper().getJndiName(ref);
+ new Resource(webAppContext, cleanup(ref.referenceName), new LinkRef(jndiName));
+ setupEnv(cleanup(ref.referenceName));
+ } catch (Exception e) {
+ log.error("Error adding EJB ref" + cleanup(ref.referenceName), e);
+ }
+ }
+
+ private void setupEnv(String referenceName) throws NamingException {
+ NamingEntryUtil.bindToENC(webAppContext, referenceName, referenceName);
+ }
+
+ private void mergeRef(EnvEntryInfo ref) {
+ try {
+ new EnvEntry(webAppContext, cleanup(ref.referenceName), ref.value, true);
+ setupEnv(cleanup(ref.referenceName));
+ } catch (Exception e) {
+ log.error("Error adding env entry: " + cleanup(ref.referenceName), e);
+ }
+ }
+
+ private String cleanup(String referenceName) {
+ if (referenceName.startsWith("comp/env/")) {
+ return referenceName.substring(9);
+ }
+
+ return referenceName;
+ }
+
+}
Added: openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/JettySecurityService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/JettySecurityService.java?rev=983790&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/JettySecurityService.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/JettySecurityService.java Mon Aug 9 19:33:08 2010
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openejb.jetty.common;
+
+import org.apache.openejb.core.security.SecurityServiceImpl;
+import org.apache.openejb.core.CoreDeploymentInfo;
+import org.apache.openejb.DeploymentInfo;
+import org.eclipse.jetty.plus.jaas.JAASUserPrincipal;
+import org.eclipse.jetty.server.Authentication;
+
+import javax.security.auth.Subject;
+import java.security.Principal;
+import java.util.LinkedList;
+
+public class JettySecurityService extends SecurityServiceImpl {
+
+ static protected final ThreadLocal<LinkedList<Subject>> runAsStack = new ThreadLocal<LinkedList<Subject>>() {
+ protected LinkedList<Subject> initialValue() {
+ return new LinkedList<Subject>();
+ }
+ };
+
+ public Object enterWebApp(Authentication.User principal, String runAs) {
+ Identity oldIdentity = clientIdentity.get();
+ Subject subject = principal.getUserIdentity().getSubject();
+
+ Identity newIdentity = new Identity(subject, null);
+ WebAppState webAppState = new WebAppState(oldIdentity, runAs != null);
+ clientIdentity.set(newIdentity);
+
+ if (runAs != null) {
+ Subject runAsSubject = createRunAsSubject(runAs);
+ runAsStack.get().addFirst(runAsSubject);
+ }
+
+ return webAppState;
+ }
+
+ public void exitWebApp(Object state) {
+ if (state instanceof WebAppState) {
+ WebAppState webAppState = (WebAppState) state;
+ clientIdentity.set(webAppState.oldIdentity);
+ if (webAppState.hadRunAs) {
+ runAsStack.get().removeFirst();
+ }
+ }
+ }
+
+ protected Subject getRunAsSubject(DeploymentInfo callingDeploymentInfo) {
+ Subject runAsSubject = super.getRunAsSubject(callingDeploymentInfo);
+ if (runAsSubject != null) return runAsSubject;
+
+ LinkedList<Subject> stack = runAsStack.get();
+ if (stack.isEmpty()) {
+ return null;
+ }
+ return stack.getFirst();
+ }
+
+ private static class WebAppState {
+ private final Identity oldIdentity;
+ private final boolean hadRunAs;
+
+
+ public WebAppState(Identity oldIdentity, boolean hadRunAs) {
+ this.oldIdentity = oldIdentity;
+ this.hadRunAs = hadRunAs;
+ }
+ }
+
+
+}
Added: openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/OpenEJBConfiguration.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/OpenEJBConfiguration.java?rev=983790&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/OpenEJBConfiguration.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/OpenEJBConfiguration.java Mon Aug 9 19:33:08 2010
@@ -0,0 +1,276 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openejb.jetty.common;
+
+import org.apache.openejb.Injection;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.InjectionBuilder;
+import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.config.*;
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.URLs;
+import org.apache.xbean.finder.ResourceFinder;
+import org.apache.xbean.finder.UrlSet;
+import org.eclipse.jetty.webapp.Configuration;
+import org.eclipse.jetty.webapp.WebAppContext;
+import org.eclipse.jetty.plus.annotation.InjectionCollection;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletContext;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+public class OpenEJBConfiguration implements Configuration {
+ private ConfigurationFactory configurationFactory;
+ private Assembler assembler;
+ private static final org.apache.openejb.util.Logger logger = org.apache.openejb.util.Logger.getInstance(LogCategory.OPENEJB.createChild("jetty"), "org.apache.openejb.util.resources");
+
+ public OpenEJBConfiguration() {
+ configurationFactory = new ConfigurationFactory();
+ assembler = (Assembler) SystemInstance.get().getComponent(org.apache.openejb.spi.Assembler.class);
+ }
+
+ public void preConfigure(WebAppContext context) throws Exception {
+ }
+
+ public void configure(WebAppContext webAppContext) throws Exception {
+ try {
+ AppModule appModule = loadApplication(webAppContext);
+
+ AppInfo appInfo = configurationFactory.configureApplication(appModule);
+ assembler.createApplication(appInfo, webAppContext.getClassLoader());
+
+ InitialContext context = new InitialContext();
+
+ // add java:openejb to InitialContext
+ Context openejbContext = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext();
+ openejbContext = (Context) openejbContext.lookup("openejb");
+
+ context.bind("java:openejb", openejbContext);
+
+ List<WebAppInfo> webApps = appInfo.webApps;
+ for (WebAppInfo webApp : webApps) {
+ InjectionBuilder injectionBuilder = new InjectionBuilder(webAppContext.getClassLoader());
+ List<Injection> injections = injectionBuilder.buildInjections(webApp.jndiEnc);
+
+ JettyJndiBuilder jndiBuilder = new JettyJndiBuilder(webAppContext, webApp);
+ jndiBuilder.mergeJndi();
+
+ for (Injection injection : injections) {
+
+ Class clazz = injection.getTarget();
+ String jndiName = injection.getJndiName();
+ String targetName = injection.getName();
+
+ InjectionCollection injectionCollection = (InjectionCollection) webAppContext.getAttribute(InjectionCollection.INJECTION_COLLECTION);
+ if (injectionCollection == null) {
+ injectionCollection = new InjectionCollection();
+ webAppContext.setAttribute(InjectionCollection.INJECTION_COLLECTION, injectionCollection);
+ }
+ Class valueClass = getValueClass(clazz, targetName);
+ if (valueClass != null) {
+ org.eclipse.jetty.plus.annotation.Injection inj = new org.eclipse.jetty.plus.annotation.Injection();
+ if (jndiName.startsWith("comp/env/")) {
+ inj.setJndiName(jndiName.substring(9));
+ } else {
+ inj.setJndiName(jndiName);
+ }
+
+ inj.setTarget(clazz, targetName, valueClass);
+ injectionCollection.add(inj);
+ }
+ }
+
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private Class getValueClass(Class clazz, String targetName) {
+ try {
+ Field field = clazz.getDeclaredField(targetName);
+ if (field != null) {
+ return field.getType();
+ }
+ } catch (Exception e) {
+ // field not found, try and find a setter method instead
+ }
+
+ String setter = "set" + targetName.substring(0, 1).toUpperCase() + targetName.substring(1);
+ Method[] methods = clazz.getDeclaredMethods();
+ for (Method method : methods) {
+ if (setter.equals(method.getName())) {
+ Class<?>[] paramTypes = method.getParameterTypes();
+ if (paramTypes != null && paramTypes.length == 1) {
+ return paramTypes[0];
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public void postConfigure(WebAppContext context) throws Exception {
+ }
+
+ public void deconfigure(WebAppContext context) throws Exception {
+ }
+
+ /**
+ * Creates an openejb {@link AppModule} instance
+ * from given tomcat context.
+ *
+ * @param application tomcat context instance
+ * @return a openejb application module
+ */
+ private AppModule loadApplication(WebAppContext application) {
+ // create the web module
+ WebModule webModule = createWebModule(application);
+
+ // create the app module
+ AppModule appModule = new AppModule(webModule.getClassLoader(), webModule.getJarLocation());
+
+ // add the web module itself
+ appModule.getWebModules().add(webModule);
+
+ // check each url to determine if it is an ejb jar
+ for (URL url : getUrls(application)) {
+ try {
+ Class moduleType = new DeploymentLoader().discoverModuleType(url, application.getClassLoader(), true);
+ if (EjbModule.class.isAssignableFrom(moduleType)) {
+ File file;
+ if (url.getProtocol().equals("jar")) {
+ url = new URL(url.getFile().replaceFirst("!.*$", ""));
+ file = URLs.toFile(url);
+ } else if (url.getProtocol().equals("file")) {
+ file = URLs.toFile(url);
+ } else {
+ logger.warning("Not loading " + moduleType.getSimpleName() + ". Unknown protocol " + url.getProtocol());
+ continue;
+ }
+
+ logger.info("Found ejb module " + moduleType.getSimpleName() + " in war " + application.getWar());
+
+ // create the ejb module and set its moduleId to the webapp context root name
+ EjbModule ejbModule = new EjbModule(webModule.getClassLoader(), getEjbModuleId(application), file.getAbsolutePath(), null, null);
+ ejbModule.setClientModule(new ClientModule(null, ejbModule.getClassLoader(), ejbModule.getJarLocation(), null, ejbModule.getModuleId()));
+
+ // EJB deployment descriptors
+ try {
+ ResourceFinder ejbResourceFinder = new ResourceFinder("", application.getClassLoader(), file.toURI().toURL());
+ Map<String, URL> descriptors = ejbResourceFinder.getResourcesMap("META-INF/");
+ descriptors = DeploymentLoader.altDDSources(descriptors, true);
+ ejbModule.getAltDDs().putAll(descriptors);
+ ejbModule.getClientModule().getAltDDs().putAll(descriptors);
+ } catch (IOException e) {
+ logger.error("Unable to determine descriptors in jar.", e);
+ }
+
+ // add module to app
+ appModule.getEjbModules().add(ejbModule);
+ }
+ } catch (IOException e) {
+ logger.warning("Unable to determine the module type of " + url.toExternalForm() + ": Exception: " + e.getMessage(), e);
+ } catch (UnknownModuleTypeException ignore) {
+ ignore.printStackTrace();
+ }
+
+ }
+
+ // Persistence Units via META-INF/persistence.xml
+ try {
+ ResourceFinder finder = new ResourceFinder("", application.getClassLoader());
+ List<URL> persistenceUrls = finder.findAll("META-INF/persistence.xml");
+ appModule.getAltDDs().put("persistence.xml", persistenceUrls);
+ } catch (IOException e) {
+ logger.warning("Cannot load persistence-units from 'META-INF/persistence.xml' : " + e.getMessage(), e);
+ }
+
+ return appModule;
+ }
+
+ private String getEjbModuleId(WebAppContext application) {
+ String ejbModuleId = application.getServletContext().getContextPath();
+ if (ejbModuleId.startsWith("/")) ejbModuleId = ejbModuleId.substring(1);
+ return ejbModuleId;
+ }
+
+ private WebModule createWebModule(WebAppContext application) {
+ // todo replace this code with DeploymentLoader
+ ServletContext servletContext = application.getServletContext();
+
+ // read the web.xml
+ WebApp webApp = new WebApp();
+ try {
+ URL webXmlUrl = servletContext.getResource("/WEB-INF/web.xml");
+ if (webXmlUrl != null) {
+ webApp = ReadDescriptors.readWebApp(webXmlUrl);
+ }
+ } catch (Exception e) {
+ logger.error("Unable to load web.xml in war " + application.getWar() + ": Exception: " + e.getMessage(), e);
+ }
+
+ // create the web module
+ String basePath = new File(servletContext.getRealPath(".")).getParentFile().getAbsolutePath();
+ ClassLoader classLoader = application.getClassLoader();//ClassLoaderUtil.createTempClassLoader(application.getClassLoader());
+ System.out.println("context path = " + application);
+
+ WebModule webModule = new WebModule(webApp, application.getWar(), classLoader, basePath, getId(application));
+
+ // process the annotations
+ try {
+ AnnotationDeployer annotationDeployer = new AnnotationDeployer();
+ annotationDeployer.deploy(webModule);
+ } catch (OpenEJBException e) {
+ logger.error("Unable to process annotation in " + application.getWar() + ": Exception: " + e.getMessage(), e);
+ }
+
+
+ return webModule;
+ }
+
+ private String getId(WebAppContext application) {
+ return application.getServletContext().getContextPath();
+ }
+
+ private List<URL> getUrls(WebAppContext standardContext) {
+ List<URL> urls = null;
+ try {
+ ClassLoader classLoader = standardContext.getClassLoader();
+ UrlSet urlSet = new UrlSet(classLoader);
+ urlSet = urlSet.exclude(classLoader.getParent());
+ urls = urlSet.getUrls();
+ } catch (IOException e) {
+ logger.warning("Unable to determine URLs in web application " + standardContext.getWar(), e);
+ }
+ return urls;
+ }
+
+}
Added: openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/OpenEJBLifecycle.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/OpenEJBLifecycle.java?rev=983790&view=auto
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/OpenEJBLifecycle.java (added)
+++ openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/main/java/org/apache/openejb/jetty/common/OpenEJBLifecycle.java Mon Aug 9 19:33:08 2010
@@ -0,0 +1,227 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.openejb.jetty.common;
+
+import org.apache.openejb.OpenEJB;
+import org.apache.openejb.core.ServerFederation;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.SecurityService;
+import org.apache.openejb.util.OptionsLog;
+import org.eclipse.jetty.server.Authentication;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.servlet.FilterHolder;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.util.component.AbstractLifeCycle;
+import org.eclipse.jetty.webapp.WebAppClassLoader;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.servlet.*;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+public class OpenEJBLifecycle extends AbstractLifeCycle {
+ private List<String> applications = new ArrayList<String>();
+ private Server server;
+
+ public Server getServer() {
+ return server;
+ }
+
+ public void setServer(Server server) {
+ this.server = server;
+ }
+
+ protected void doStart() throws Exception {
+ for (String application : applications) {
+ deploy(application);
+ }
+
+ super.doStart();
+ }
+
+ private void deploy(String application) throws Exception {
+ if (server == null) {
+ throw new IllegalStateException("Server is null");
+ }
+
+ WebAppContext webAppContext = new WebAppContext();
+ webAppContext.setWar(application);
+ webAppContext.setTempDirectory(getTempDir(application));
+ webAppContext.setClassLoader(new WebAppClassLoader(webAppContext));
+ webAppContext.setServer(server);
+
+ webAppContext.setConfigurationClasses(new String[] {
+ "org.eclipse.jetty.webapp.WebInfConfiguration",
+ "org.eclipse.jetty.webapp.WebXmlConfiguration",
+ "org.eclipse.jetty.webapp.MetaInfConfiguration",
+ "org.eclipse.jetty.webapp.FragmentConfiguration",
+ "org.apache.openejb.jetty.common.OpenEJBConfiguration",
+ "org.eclipse.jetty.plus.webapp.EnvConfiguration",
+ "org.eclipse.jetty.plus.webapp.Configuration",
+ "org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
+ "org.eclipse.jetty.webapp.TagLibConfiguration"
+ });
+
+ // intercept all requests and wire up to the security service
+ FilterHolder filterHolder = new FilterHolder();
+ filterHolder.setFilter(new Filter() {
+
+ private ThreadLocal<Object> oldState = new ThreadLocal<Object>();
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ enter(servletRequest);
+ filterChain.doFilter(servletRequest, servletResponse);
+ exit();
+ }
+
+ private void exit() {
+ JettySecurityService securityService = getSecurityService();
+ if (securityService != null) {
+ securityService.exitWebApp(oldState.get());
+ }
+
+ oldState.set(null);
+ }
+
+ private void enter(ServletRequest servletRequest) {
+ JettySecurityService securityService = getSecurityService();
+ Request request = (Request) servletRequest;
+
+ String runAsRole = null;
+ if (request.getUserIdentityScope() != null && (request.getUserIdentityScope() instanceof ServletHolder)) {
+ runAsRole = ((ServletHolder)request.getUserIdentityScope()).getRunAsRole();
+ }
+
+ if (securityService != null) {
+ Authentication auth = request.getAuthentication();
+
+ if (auth != null && (auth instanceof Authentication.User)) {
+ Authentication.User user = (Authentication.User) auth;
+ oldState.set(securityService.enterWebApp(user, runAsRole));
+ }
+ }
+ }
+
+ public void destroy() {
+ }
+ });
+
+ webAppContext.addFilter(filterHolder, "*", 0);
+ try {
+ webAppContext.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+
+ server.setHandler(webAppContext);
+ }
+
+ private File getTempDir(String application) {
+ try {
+ File tempDir = new File(System.getProperty("java.io.tmpdir"));
+ if (tempDir.getAbsolutePath().startsWith("/var/folders")) {
+ tempDir = new File("/tmp");
+ }
+
+ File dir = File.createTempFile("Jetty_" + application.substring(application.lastIndexOf("/") + 1), "", tempDir);
+ if (dir.exists()) {
+ dir.delete();
+ }
+
+ dir.mkdirs();
+ return dir;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ protected void doStop() throws Exception {
+ super.doStop();
+ }
+
+ public OpenEJBLifecycle() {
+ try {
+ init();
+ } catch (Exception e) {
+ e.printStackTrace(); // TODO: something better than this
+ }
+ }
+
+
+ public void addApplication(String application) {
+ applications.add(application);
+ }
+
+ private void init() throws Exception {
+ System.setProperty("openejb.provider.default", "org.apache.openejb.jetty");
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.eclipse.jetty.jndi.InitialContextFactory");
+ System.setProperty(Context.URL_PKG_PREFIXES, "org.eclipse.jetty.jndi");
+ new InitialContext();
+
+ Properties properties = new Properties();
+ properties.setProperty("openejb.deployments.classpath", "false");
+ properties.setProperty("openejb.deployments.classpath.filter.systemapps", "false");
+
+ // Loader maybe the first thing executed in a new classloader
+ // so we must attempt to initialize the system instance.
+ SystemInstance.init(properties);
+ OptionsLog.install();
+
+ // Read in and apply the conf/system.properties
+ try {
+ File conf = SystemInstance.get().getBase().getDirectory("conf");
+ File file = new File(conf, "system.properties");
+ if (file.exists()) {
+ Properties systemProperties = new Properties();
+ FileInputStream fin = new FileInputStream(file);
+ InputStream in = new BufferedInputStream(fin);
+ systemProperties.load(in);
+ System.getProperties().putAll(systemProperties);
+ // store the system properties inside SystemInstance otherwise we will lose these properties.
+ // i.e. any piece of code which is trying to look for properties inside SystemInstance will not be able to find it.
+ SystemInstance.get().getProperties().putAll(systemProperties);
+ }
+ } catch (IOException e) {
+ System.out.println("Processing conf/system.properties failed: " + e.getMessage());
+ }
+
+ System.setProperty("openejb.home", SystemInstance.get().getHome().getDirectory().getAbsolutePath());
+ System.setProperty("openejb.base", SystemInstance.get().getBase().getDirectory().getAbsolutePath());
+
+ OpenEJB.init(properties, new ServerFederation());
+ }
+
+ private JettySecurityService getSecurityService() {
+ SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class);
+ if (securityService instanceof JettySecurityService) {
+ return (JettySecurityService) securityService;
+ }
+ return null;
+ }
+
+}