You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/11/05 10:33:04 UTC
svn commit: r1405724 - in /openejb/trunk/openejb:
container/openejb-core/src/main/java/org/apache/openejb/web/
container/openejb-core/src/test/java/org/apache/openejb/
container/openejb-core/src/test/java/org/apache/openejb/web/ server/
server/openejb-...
Author: rmannibucau
Date: Mon Nov 5 09:33:02 2012
New Revision: 1405724
URL: http://svn.apache.org/viewvc?rev=1405724&view=rev
Log:
moving openejb-lightweight-web in core since there is no reason to keep it separated
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/web/
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/web/WebInitialContext.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/web/
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/web/LightweightWebAppBuilderTest.java
Removed:
openejb/trunk/openejb/server/openejb-lightweight-web/
Modified:
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java
openejb/trunk/openejb/server/openejb-cxf-rs/pom.xml
openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimpleApplicationTest.java
openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimplePojoTest.java
openejb/trunk/openejb/server/pom.xml
Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java?rev=1405724&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/web/LightweightWebAppBuilder.java Mon Nov 5 09:33:02 2012
@@ -0,0 +1,77 @@
+/*
+ * 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.web;
+
+import org.apache.openejb.AppContext;
+import org.apache.openejb.Injection;
+import org.apache.openejb.OpenEJBRuntimeException;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.InjectionBuilder;
+import org.apache.openejb.assembler.classic.JndiEncBuilder;
+import org.apache.openejb.assembler.classic.WebAppBuilder;
+import org.apache.openejb.assembler.classic.WebAppInfo;
+import org.apache.openejb.core.CoreContainerSystem;
+import org.apache.openejb.core.WebContext;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class LightweightWebAppBuilder implements WebAppBuilder {
+ @Override
+ public void deployWebApps(final AppInfo appInfo, final ClassLoader classLoader) throws Exception {
+ final CoreContainerSystem cs = (CoreContainerSystem) SystemInstance.get().getComponent(ContainerSystem.class);
+ final AppContext appContext = cs.getAppContext(appInfo.appId);
+ if (appContext == null) {
+ throw new OpenEJBRuntimeException("Can't find app context for " + appInfo.appId);
+ }
+
+ for (WebAppInfo webAppInfo : appInfo.webApps) {
+ final Collection<Injection> injections = appContext.getInjections();
+ injections.addAll(new InjectionBuilder(classLoader).buildInjections(webAppInfo.jndiEnc));
+
+ final Map<String, Object> bindings = new HashMap<String, Object>();
+ bindings.putAll(appContext.getBindings());
+ bindings.putAll(new JndiEncBuilder(webAppInfo.jndiEnc, injections, webAppInfo.moduleId, "Bean", null, webAppInfo.uniqueId, classLoader).buildBindings(JndiEncBuilder.JndiScope.comp));
+
+ final WebContext webContext = new WebContext(appContext);
+ webContext.setBindings(bindings);
+ webContext.setJndiEnc(WebInitialContext.create(bindings, appContext.getGlobalJndiContext()));
+ webContext.setClassLoader(classLoader);
+ webContext.setId(webAppInfo.moduleId);
+ webContext.setContextRoot(webAppInfo.contextRoot);
+ webContext.getInjections().addAll(injections);
+
+ appContext.getWebContexts().add(webContext);
+ cs.addWebContext(webContext);
+ }
+ }
+
+ @Override
+ public void undeployWebApps(final AppInfo appInfo) throws Exception {
+ // no-op
+ }
+
+ @Override
+ public Map<ClassLoader, Map<String, Set<String>>> getJsfClasses() {
+ return Collections.emptyMap(); // while we don't manage servlet in embedded mode we don't need it
+ }
+}
Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/web/WebInitialContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/web/WebInitialContext.java?rev=1405724&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/web/WebInitialContext.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/web/WebInitialContext.java Mon Nov 5 09:33:02 2012
@@ -0,0 +1,64 @@
+/*
+ * 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.web;
+
+import org.apache.openejb.core.ivm.naming.Reference;
+
+import javax.naming.Context;
+import javax.naming.LinkRef;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Map;
+
+public class WebInitialContext implements InvocationHandler {
+ private static final Class<?>[] INTERFACES = new Class<?>[]{ Context.class };
+
+ private final Map<String, Object> bindings;
+ private final Context delegate;
+
+ public WebInitialContext(final Map<String, Object> bindings, final Context ctx) {
+ this.bindings = bindings;
+ delegate = ctx;
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if ("lookup".equals(method.getName()) && method.getParameterTypes().length == 1 && String.class.equals(method.getParameterTypes()[0])) {
+ final Object lookedUp = bindings.get(normalize((String) args[0]));
+ if (lookedUp != null) {
+ if (lookedUp instanceof Reference) {
+ return ((Reference) lookedUp).getObject();
+ } else if (lookedUp instanceof LinkRef) {
+ return ((Context) proxy).lookup(((LinkRef) lookedUp).getLinkName());
+ }
+ }
+ }
+ return method.invoke(delegate, args);
+ }
+
+ private static String normalize(final String arg) {
+ if (arg.startsWith("java:")) {
+ return arg.substring("java:".length());
+ }
+ return arg;
+ }
+
+ public static Context create(final Map<String, Object> bindings, final Context fallback) {
+ return (Context) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), INTERFACES, new WebInitialContext(bindings, fallback));
+ }
+}
Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java?rev=1405724&r1=1405723&r2=1405724&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java Mon Nov 5 09:33:02 2012
@@ -55,7 +55,7 @@ public class DependenceValidationTest ex
// Nothing may depend on the Assembler except the config code and events
String dynamicAssembler = "org.apache.openejb.assembler.dynamic";
- assertNotDependentOn("org.apache.openejb", "org.apache.openejb.assembler.classic", "org.apache.openejb.config.typed.util", "org.apache.openejb.assembler", "org.apache.openejb.assembler.classic.util", "org.apache.openejb.config", "org.apache.openejb.assembler.dynamic", "org.apache.openejb.assembler.classic.cmd", "org.apache.openejb.assembler.monitoring", "org.apache.openejb.cdi", "org.apache.openejb.junit", "org.apache.openejb.assembler.classic.event");
+ assertNotDependentOn("org.apache.openejb", "org.apache.openejb.assembler.classic", "org.apache.openejb.config.typed.util", "org.apache.openejb.assembler", "org.apache.openejb.assembler.classic.util", "org.apache.openejb.config", "org.apache.openejb.assembler.dynamic", "org.apache.openejb.assembler.classic.cmd", "org.apache.openejb.assembler.monitoring", "org.apache.openejb.cdi", "org.apache.openejb.junit", "org.apache.openejb.assembler.classic.event", "org.apache.openejb.web");
// Nothing may depend on the Dynamic Assembler
assertNotDependentOn("org.apache.openejb", dynamicAssembler);
Added: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/web/LightweightWebAppBuilderTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/web/LightweightWebAppBuilderTest.java?rev=1405724&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/web/LightweightWebAppBuilderTest.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/web/LightweightWebAppBuilderTest.java Mon Nov 5 09:33:02 2012
@@ -0,0 +1,52 @@
+/*
+ * 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.web;
+
+import org.apache.openejb.assembler.classic.WebAppBuilder;
+import org.apache.openejb.config.WebModule;
+import org.apache.openejb.core.WebContext;
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Component;
+import org.apache.openejb.junit.Module;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(ApplicationComposer.class)
+public class LightweightWebAppBuilderTest {
+ @Component
+ public WebAppBuilder webAppBuilder() {
+ return new LightweightWebAppBuilder();
+ }
+
+ @Module
+ public WebModule war() {
+ return new WebModule(new WebApp(), "/foo", Thread.currentThread().getContextClassLoader(), "", "web");
+ }
+
+ @Test
+ public void checkWebContextExists() {
+ final WebContext wc = SystemInstance.get().getComponent(ContainerSystem.class).getWebContext("web");
+ assertNotNull(wc);
+ assertEquals("web", wc.getId());
+ }
+}
Modified: openejb/trunk/openejb/server/openejb-cxf-rs/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf-rs/pom.xml?rev=1405724&r1=1405723&r2=1405724&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-cxf-rs/pom.xml (original)
+++ openejb/trunk/openejb/server/openejb-cxf-rs/pom.xml Mon Nov 5 09:33:02 2012
@@ -118,12 +118,6 @@
<artifactId>jettison</artifactId>
<version>1.3</version>
</dependency>
- <dependency>
- <groupId>org.apache.openejb</groupId>
- <artifactId>openejb-lightweight-web</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
Modified: openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimpleApplicationTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimpleApplicationTest.java?rev=1405724&r1=1405723&r2=1405724&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimpleApplicationTest.java (original)
+++ openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimpleApplicationTest.java Mon Nov 5 09:33:02 2012
@@ -28,7 +28,7 @@ import org.apache.openejb.junit.Module;
import org.apache.openejb.server.cxf.rs.beans.MyRESTApplication;
import org.apache.openejb.server.cxf.rs.beans.RestWithInjections;
import org.apache.openejb.server.cxf.rs.beans.SimpleEJB;
-import org.apache.openejb.server.web.LightweightWebAppBuilder;
+import org.apache.openejb.web.LightweightWebAppBuilder;
import org.apache.xbean.finder.AnnotationFinder;
import org.apache.xbean.finder.archive.ClassesArchive;
import org.junit.Test;
Modified: openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimplePojoTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimplePojoTest.java?rev=1405724&r1=1405723&r2=1405724&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimplePojoTest.java (original)
+++ openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimplePojoTest.java Mon Nov 5 09:33:02 2012
@@ -28,7 +28,7 @@ import org.apache.openejb.junit.Configur
import org.apache.openejb.junit.Module;
import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.server.cxf.rs.beans.MyFirstRestClass;
-import org.apache.openejb.server.web.LightweightWebAppBuilder;
+import org.apache.openejb.web.LightweightWebAppBuilder;
import org.apache.openejb.spi.ContainerSystem;
import org.junit.Test;
import org.junit.runner.RunWith;
Modified: openejb/trunk/openejb/server/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/pom.xml?rev=1405724&r1=1405723&r2=1405724&view=diff
==============================================================================
--- openejb/trunk/openejb/server/pom.xml (original)
+++ openejb/trunk/openejb/server/pom.xml Mon Nov 5 09:33:02 2012
@@ -45,7 +45,6 @@
<module>openejb-ssh</module>
<module>openejb-common-cli</module>
<module>openejb-bonecp</module>
- <module>openejb-lightweight-web</module>
</modules>
</project>