Author: rmannibucau
Date: Sun Sep 21 11:30:15 2014
New Revision: 1626577
URL: http://svn.apache.org/r1626577
Log:
TOMEE-1355 basic skeleton to be able to configure an app in tomee-embedded
dynamically from a java description of the app
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/
tomee/tomee/trunk/tomee/tomee-application-composer/pom.xml
tomee/tomee/trunk/tomee/tomee-application-composer/src/
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/TomEEApplicationComposer.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/AutoDiscovery.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Libraries.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Library.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Web.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/WebComponent.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/Bundler.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/ClasspathBuilder.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/LazyDeployer.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/StandardContextCustomizer.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/resources/
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/AutoDiscoveryServletTest.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualFilterTest.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualListenerTest.java
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualServletTest.java
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/registration/
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/registration/Registrations.java
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
tomee/tomee/trunk/tomee/pom.xml
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/GlobalListenerSupport.java
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ServerListener.java
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
tomee/tomee/trunk/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1626577&r1=1626576&r2=1626577&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
Sun Sep 21 11:30:15 2014
@@ -1218,22 +1218,7 @@ public class AnnotationDeployer implemen
}
if (urlByClasses == null) { // try to reuse scanning info,
maybe some better indexing can be a nice idea
- if (finder instanceof FinderFactory.ModuleLimitedFinder) {
- final IAnnotationFinder limitedFinder =
((FinderFactory.ModuleLimitedFinder) finder).getDelegate();
- if (limitedFinder instanceof AnnotationFinder) {
- final Archive archive = ((AnnotationFinder)
limitedFinder).getArchive();
- if (archive instanceof WebappAggregatedArchive) {
- final Map<URL, List<String>> index =
((WebappAggregatedArchive) archive).getClassesMap();
- urlByClasses = new HashMap<String, String>();
- for (final Map.Entry<URL, List<String>> entry
: index.entrySet()) {
- final String url =
entry.getKey().toExternalForm();
- for (final String current :
entry.getValue()) {
- urlByClasses.put(current, url);
- }
- }
- }
- }
- }
+ urlByClasses = FinderFactory.urlByClass(finder);
}
final List<Annotated<Class<?>>> found =
finder.findMetaAnnotatedClasses(clazz);
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=1626577&r1=1626576&r2=1626577&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
Sun Sep 21 11:30:15 2014
@@ -1064,7 +1064,7 @@ public class DeploymentLoader implements
return urls.getUrls();
}
- private void addBeansXmls(final WebModule webModule) {
+ public static void addBeansXmls(final WebModule webModule) {
final List<URL> urls = webModule.getScannableUrls();
// parent returns nothing when calling getresources because we don't
want here to be fooled by maven classloader
final URLClassLoader loader = new URLClassLoader(urls.toArray(new
URL[urls.size()]), new EmptyResourcesClassLoader());
@@ -1093,7 +1093,7 @@ public class DeploymentLoader implements
}
}
- private Beans mergeBeansXml(final CompositeBeans current, final URL url) {
+ private static Beans mergeBeansXml(final CompositeBeans current, final URL
url) {
try {
final Beans beans;
try {
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java?rev=1626577&r1=1626576&r2=1626577&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
Sun Sep 21 11:30:15 2014
@@ -213,7 +213,8 @@ public class DeploymentsResolver impleme
* 2- Loading the resource is the default behaviour in case of not
defining a value for any class-path pattern
* This appears in step 3 of the above algorithm.
*/
- public static void loadFromClasspath(final FileUtils ignored, final
List<URL> jarList, final ClassLoader classLoader) {
+ public static List<URL> loadFromClasspath(final ClassLoader classLoader) {
+ final List<URL> jarList = new ArrayList<>(16);
final Options options = SystemInstance.get().getOptions();
final String include = options.get(CLASSPATH_INCLUDE, ".*");
final String exclude = options.get(CLASSPATH_EXCLUDE, "");
@@ -271,9 +272,9 @@ public class DeploymentsResolver impleme
final int size = urls.size();
if (size == 0 && include.length() > 0) {
logger.warning("No classpath URLs matched. Current settings:
" + CLASSPATH_EXCLUDE + "='" + exclude + "', " + CLASSPATH_INCLUDE + "='" +
include + "'");
- return;
+ return jarList;
} else if (size == 0 && !filterDescriptors &&
prefiltered.getUrls().size() == 0) {
- return;
+ return jarList;
} else if (size < 20) {
logger.debug("Inspecting classpath for applications: " +
urls.size() + " urls.");
} else {
@@ -299,7 +300,7 @@ public class DeploymentsResolver impleme
}
final long begin = System.currentTimeMillis();
- processUrls("DeploymentsResolver1", urls, classLoader,
requireDescriptors, ignored, jarList);
+ processUrls("DeploymentsResolver1", urls, classLoader,
requireDescriptors, jarList);
final long end = System.currentTimeMillis();
final long time = end - begin;
@@ -310,7 +311,7 @@ public class DeploymentsResolver impleme
if (filterSystemApps) {
unchecked =
unchecked.exclude(".*/openejb-[^/]+(.(jar|ear|war)(./)?|/target/classes/?)");
}
- processUrls("DeploymentsResolver2", unchecked.getUrls(),
classLoader, EnumSet.allOf(RequireDescriptors.class), ignored, jarList);
+ processUrls("DeploymentsResolver2", unchecked.getUrls(),
classLoader, EnumSet.allOf(RequireDescriptors.class), jarList);
}
if (logger.isDebugEnabled()) {
@@ -325,7 +326,7 @@ public class DeploymentsResolver impleme
}
if (urls.size() == 0) {
- return;
+ return jarList;
}
if (time < 1000) {
@@ -360,14 +361,29 @@ public class DeploymentsResolver impleme
logger.warning("Unable to search classpath for modules: Received
Exception: " + e1.getClass().getName() + " " + e1.getMessage(), e1);
}
+ return jarList;
+ }
+
+ @Deprecated
+ public static void loadFromClasspath(final FileUtils ignored, final
List<URL> jarList, final ClassLoader classLoader) {
+ jarList.addAll(loadFromClasspath(classLoader));
}
+ @Deprecated
public static void processUrls(final String caller,
final List<URL> urls,
final ClassLoader classLoader,
final Set<RequireDescriptors>
requireDescriptors,
final FileUtils ignored, // don't use it,
it will be removed since we already suppose it is null in several places
final List<URL> jarList) {
+ processUrls(caller, urls, classLoader, requireDescriptors, jarList);
+ }
+
+ public static void processUrls(final String caller,
+ final List<URL> urls,
+ final ClassLoader classLoader,
+ final Set<RequireDescriptors>
requireDescriptors,
+ final List<URL> jarList) {
for (final URL url : urls) {
final String urlProtocol = url.getProtocol();
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java?rev=1626577&r1=1626576&r2=1626577&view=diff
==============================================================================
---
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
(original)
+++
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
Sun Sep 21 11:30:15 2014
@@ -45,9 +45,12 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import static org.apache.openejb.util.Classes.ancestors;
@@ -261,6 +264,30 @@ public class FinderFactory {
return new OpenEJBAnnotationFinder(archive);
}
+ public static Map<String, String> urlByClass(final IAnnotationFinder
finder) {
+ final IAnnotationFinder limitedFinder;
+ if (finder instanceof FinderFactory.ModuleLimitedFinder) {
+ limitedFinder = ((FinderFactory.ModuleLimitedFinder)
finder).getDelegate();
+ } else {
+ limitedFinder = finder;
+ }
+ if (limitedFinder instanceof AnnotationFinder) {
+ final Archive archive = ((AnnotationFinder)
limitedFinder).getArchive();
+ if (archive instanceof WebappAggregatedArchive) {
+ final Map<URL, List<String>> index =
((WebappAggregatedArchive) archive).getClassesMap();
+ final Map<String, String> urlByClasses = new HashMap<String,
String>();
+ for (final Map.Entry<URL, List<String>> entry :
index.entrySet()) {
+ final String url = entry.getKey().toExternalForm();
+ for (final String current : entry.getValue()) {
+ urlByClasses.put(current, url);
+ }
+ }
+ return urlByClasses;
+ }
+ }
+ return Collections.emptyMap();
+ }
+
public static final class DebugArchive implements Archive {
private final Archive archive;
Modified: tomee/tomee/trunk/tomee/pom.xml
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/pom.xml?rev=1626577&r1=1626576&r2=1626577&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/pom.xml (original)
+++ tomee/tomee/trunk/tomee/pom.xml Sun Sep 21 11:30:15 2014
@@ -55,6 +55,7 @@
<module>tomee-util</module>
<module>tomee-juli</module>
<module>tomee-overlay-runner</module>
+ <module>tomee-application-composer</module>
<!--<module>tomee-deb</module>-->
</modules>
Added: tomee/tomee/trunk/tomee/tomee-application-composer/pom.xml
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/pom.xml?rev=1626577&view=auto
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-application-composer/pom.xml (added)
+++ tomee/tomee/trunk/tomee/tomee-application-composer/pom.xml Sun Sep 21
11:30:15 2014
@@ -0,0 +1,28 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>tomee</artifactId>
+ <groupId>org.apache.openejb</groupId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>tomee-application-composer</artifactId>
+ <name>OpenEJB :: TomEE :: Application Composer</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>javaee-api</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>tomee-embedded</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/TomEEApplicationComposer.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/TomEEApplicationComposer.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/TomEEApplicationComposer.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/TomEEApplicationComposer.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,133 @@
+/*
+ * 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.tomee.application.composer;
+
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.config.AppModule;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.config.WebModule;
+import org.apache.openejb.loader.Files;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.tomee.application.composer.component.Web;
+import org.apache.tomee.application.composer.internal.Bundler;
+import org.apache.tomee.application.composer.internal.ClasspathBuilder;
+import org.apache.tomee.application.composer.internal.LazyDeployer;
+import
org.apache.tomee.application.composer.internal.StandardContextCustomizer;
+import org.apache.tomee.embedded.Configuration;
+import org.apache.tomee.embedded.Container;
+import org.apache.xbean.finder.MetaAnnotatedClass;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import static java.util.Arrays.asList;
+
+public class TomEEApplicationComposer implements AutoCloseable {
+ private static final String[] EMPTY_ARGS = new String[0];
+
+ private final Container closable;
+
+ public TomEEApplicationComposer(final Class<?> application, final String[]
args) {
+ final MetaAnnotatedClass<?> meta = new
MetaAnnotatedClass<>(application);
+ final ClassLoader loader =
Thread.currentThread().getContextClassLoader();
+ final List<URL> jars = ClasspathBuilder.buildClasspath(meta, loader);
+
+ final File root = fakeRootDir();
+
+ // ATM we only support web module so we use it directly but if we
support ejb module or even ear we'll have to do it here
+ final Web web = meta.getAnnotation(Web.class);
+ final WebModule webModule = Bundler.createWebModule(web, loader, jars,
root.getAbsolutePath());
+ final AppModule app = new AppModule(webModule);
+ app.setStandloneWebModule();
+
+ try {
+ final Configuration configuration = new Configuration();
+ configuration.property("openejb.system.apps", "false");
+ configuration.setHttpPort(4589); // just to avoid 8080 while
config part is not done
+ // TODO: take config from args
+
+ final Container container = new Container(configuration);
+ final SystemInstance systemInstance = SystemInstance.get();
+ systemInstance.addObserver(new
StandardContextCustomizer(webModule));
+ systemInstance.addObserver(new LazyDeployer(webModule, meta));
+
+ try {
+ final AppInfo appInfo = new
ConfigurationFactory().configureApplication(app);
+
systemInstance.getComponent(Assembler.class).createApplication(appInfo);
+ } catch (final Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ closable = container;
+ } catch (final Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public TomEEApplicationComposer(final Class<?> application) {
+ this(application, EMPTY_ARGS);
+ }
+
+ public int getPort() {
+ return closable.getTomcat().getConnector().getPort();
+ }
+
+ @Override
+ public void close() throws Exception {
+ closable.close();
+ }
+
+ public static AutoCloseable run(final Class<?> application, final String[]
args) {
+ return new TomEEApplicationComposer(application, args);
+ }
+
+ // TODO: config it from args
+ private static File fakeRootDir() {
+ final File root = new File(System.getProperty("java.io.tmpdir"),
"tomee-application-composer-" + TomEEApplicationComposer.class.hashCode() + "_"
+ new Date());
+ Files.mkdirs(root);
+ Files.deleteOnExit(root);
+ return root;
+ }
+
+ public static void main(final String[] args) {
+ if (args == null || args.length < 1) {
+ System.err.println("First parameter should be the application
class");
+ return;
+ }
+
+ try {
+ final Collection<String> newArgs = new ArrayList<>(asList(args));
+ final Iterator<String> iterator = newArgs.iterator();
+ iterator.next();
+ iterator.remove();
+
+
run(Thread.currentThread().getContextClassLoader().loadClass(args[0]),
newArgs.toArray(new String[newArgs.size()]));
+ } catch (final ClassNotFoundException e) {
+ System.err.println("Can't find application class, it should be the
first parameter: " + e.getMessage());
+ }
+ }
+
+ public static AutoCloseable run(final Class<?> application) {
+ return run(application, EMPTY_ARGS);
+ }
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/AutoDiscovery.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/AutoDiscovery.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/AutoDiscovery.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/AutoDiscovery.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,42 @@
+/*
+ * 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.tomee.application.composer.component;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Mark the application class with it to let the container handle scanning
itself.
+ */
+@Target(TYPE)
+@Retention(RUNTIME)
+public @interface AutoDiscovery {
+ /**
+ * @return true if the jar containing the application contains EE
components to scan
+ */
+ boolean application() default true;
+
+ /**
+ * @return true if the classpath should be scanned as well
+ */
+ boolean classpath() default false;
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Libraries.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Libraries.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Libraries.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Libraries.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,32 @@
+/*
+ * 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.tomee.application.composer.component;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+// @Repeatable
+@Target(TYPE)
+@Retention(RUNTIME)
+public @interface Libraries {
+ Library[] value();
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Library.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Library.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Library.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Library.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,41 @@
+/*
+ * 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.tomee.application.composer.component;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Add a library in the application.
+ * It doesn't have to be present in the classpath if resolvable
+ * by TomEE provisioning.
+ */
+@Target(TYPE)
+@Retention(RUNTIME)
+public @interface Library {
+ String value();
+
+ /**
+ * @return true if this is an application dependency, false if that's just
a needed dependency
+ */
+ boolean isApplicative() default true;
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Web.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Web.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Web.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/Web.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,37 @@
+/*
+ * 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.tomee.application.composer.component;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Mark the application as being a "war"
+ */
+@Target(TYPE)
+@Retention(RUNTIME)
+public @interface Web {
+ /**
+ * @return the context name
+ */
+ String value() default "";
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/WebComponent.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/WebComponent.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/WebComponent.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/component/WebComponent.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,39 @@
+/*
+ * 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.tomee.application.composer.component;
+
+import javax.servlet.annotation.WebInitParam;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Mark a Servlet to deploy
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+public @interface WebComponent {
+ String name() default "";
+ String[] urlPatterns() default {};
+ int loadOnStartup() default -1;
+ WebInitParam[] initParams() default {};
+ boolean asyncSupported() default false;
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/Bundler.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/Bundler.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/Bundler.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/Bundler.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,61 @@
+/*
+ * 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.tomee.application.composer.internal;
+
+import org.apache.openejb.config.DeploymentLoader;
+import org.apache.openejb.config.FinderFactory;
+import org.apache.openejb.config.WebModule;
+import org.apache.openejb.jee.WebApp;
+import org.apache.tomee.application.composer.component.Web;
+
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+
+public final class Bundler {
+ public static WebModule createWebModule(final Web web, final ClassLoader
loader,
+ final List<URL> jarList,
+ final String path) {
+ final String contextRoot = web == null ? "" : web.value();
+ final WebModule webModule = new WebModule(
+ new WebApp(),
+ contextRoot,
+ loader,
+ path,
+ contextRoot);
+
+ webModule.setUrls(jarList);
+ webModule.setAddedUrls(Collections.<URL>emptyList());
+ webModule.setRarUrls(Collections.<URL>emptyList());
+ webModule.setScannableUrls(jarList);
+ try {
+ webModule.setFinder(FinderFactory.createFinder(webModule));
+ } catch (final Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ DeploymentLoader.addBeansXmls(webModule);
+
+ return webModule;
+ }
+
+ private Bundler() {
+ // no-op
+ }
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/ClasspathBuilder.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/ClasspathBuilder.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/ClasspathBuilder.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/ClasspathBuilder.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,131 @@
+/*
+ * 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.tomee.application.composer.internal;
+
+import org.apache.openejb.config.DeploymentsResolver;
+import org.apache.openejb.loader.JarLocation;
+import org.apache.openejb.loader.provisining.ProvisioningResolver;
+import org.apache.openejb.util.URLs;
+import org.apache.tomee.application.composer.component.AutoDiscovery;
+import org.apache.tomee.application.composer.component.Libraries;
+import org.apache.tomee.application.composer.component.Library;
+import org.apache.xbean.finder.MetaAnnotatedClass;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import static java.util.Arrays.asList;
+
+public final class ClasspathBuilder {
+ public static List<URL> buildClasspath(final MetaAnnotatedClass<?> meta,
final ClassLoader loader) {
+ final List<URL> jarList = handleAutoDiscovery(meta, loader);
+ handleLibraries(meta, jarList, loader);
+ return jarList;
+ }
+
+ private static void handleLibraries(final MetaAnnotatedClass<?> meta,
final List<URL> jarList, final ClassLoader loader) {
+ // @Library/@Libraries
+ final ProvisioningResolver resolver = new ProvisioningResolver();
+
+ final Libraries libs = meta.getAnnotation(Libraries.class);
+ if (libs != null) {
+ for (final Library lib : libs.value()) {
+ resolve(jarList, resolver, lib, loader);
+ }
+ }
+ final Library lib = meta.getAnnotation(Library.class);
+ if (lib != null) {
+ resolve(jarList, resolver, lib, loader);
+ }
+ }
+
+ private static List<URL> handleAutoDiscovery(final MetaAnnotatedClass<?>
meta, final ClassLoader loader) {
+ final AutoDiscovery autoDiscovery =
meta.getAnnotation(AutoDiscovery.class);
+ if (autoDiscovery != null) {
+ final File appJar = JarLocation.jarLocation(meta.get());
+ if (autoDiscovery.classpath()) {
+ final List<URL> jarList =
DeploymentsResolver.loadFromClasspath(loader);
+ if (!autoDiscovery.application()) {
+ final Iterator<URL> urls = jarList.iterator();
+ while (urls.hasNext()) {
+ if (URLs.toFile(urls.next()).equals(appJar)) {
+ urls.remove();
+ break;
+ }
+ }
+ }
+ return jarList;
+ } else if (autoDiscovery.application()) {
+ try {
+ return new ArrayList<>(asList(appJar.toURI().toURL()));
+ } catch (final MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ }
+ } else {
+ logger().warning("You set @AutoDiscovery on " + meta.getName()
+ " but you asked to scan nothing");
+ return new LinkedList<>();
+ }
+ }
+ return new LinkedList<>();
+ }
+
+ private static void resolve(final List<URL> jarList, final
ProvisioningResolver resolver, final Library lib, final ClassLoader loader) {
+ for (final String location : resolver.realLocation(lib.value())) {
+ try {
+ final URL url = new File(location).toURI().toURL();
+ if (lib.isApplicative()) {
+ jarList.add(url);
+ } else {
+ if (URLClassLoader.class.isInstance(loader)) {
+ try {
+ final Method m =
URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
+ if (!m.isAccessible()) {
+ m.setAccessible(true);
+ }
+ m.invoke(loader, url);
+ } catch (final Exception e) {
+ throw new IllegalStateException(e);
+ }
+ } else {
+ logger().severe("Can't add (yet) " + lib.value() + "
since the classloader is not an URLClassloader");
+ }
+ }
+ } catch (final MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ }
+
+ // don't initialize logger system before we boot if there is no issue
+ private static Logger logger() {
+ return Logger.getLogger(ClasspathBuilder.class.getName());
+ }
+
+ private ClasspathBuilder() {
+ // no-op
+ }
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/LazyDeployer.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/LazyDeployer.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/LazyDeployer.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/LazyDeployer.java
Sun Sep 21 11:30:15 2014
@@ -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.tomee.application.composer.internal;
+
+import org.apache.catalina.Wrapper;
+import org.apache.catalina.core.StandardContext;
+import org.apache.openejb.config.WebModule;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.observer.Observes;
+import org.apache.tomcat.util.descriptor.web.FilterDef;
+import org.apache.tomcat.util.descriptor.web.FilterMap;
+import org.apache.tomee.application.composer.component.WebComponent;
+import org.apache.tomee.catalina.TomcatWebAppBuilder;
+import org.apache.tomee.catalina.event.AfterApplicationCreated;
+import org.apache.tomee.catalina.registration.Registrations;
+import org.apache.xbean.finder.MetaAnnotatedClass;
+import org.apache.xbean.finder.MetaAnnotatedMethod;
+
+import javax.servlet.Filter;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRegistration;
+import javax.servlet.annotation.WebInitParam;
+import java.util.Collection;
+import java.util.LinkedList;
+
+// deploys all which was not possible without having an instance of class
+public class LazyDeployer {
+ private final WebModule module;
+ private final MetaAnnotatedClass<?> app;
+
+ public LazyDeployer(final WebModule webModule, final MetaAnnotatedClass<?>
app) {
+ this.module = webModule;
+ this.app = app;
+ }
+
+ public void afterApplicationCreated(@Observes final
AfterApplicationCreated event) {
+ Object instance = null;
+
+ final Collection<MetaAnnotatedMethod> servlets = new LinkedList<>();
+ final Collection<MetaAnnotatedMethod> filters = new LinkedList<>();
+ final Collection<MetaAnnotatedMethod> listeners = new LinkedList<>();
+
+ for (final MetaAnnotatedMethod m : app.getMethods()) {
+ if (m.getParameterTypes().length > 0) {
+ continue;
+ }
+
+ final WebComponent webComponent =
m.getAnnotation(WebComponent.class);
+ if (webComponent != null) {
+
+
+ final Class<?> returnType = m.get().getReturnType();
+ if (Servlet.class.isAssignableFrom(returnType)) {
+ servlets.add(m);
+ } else if (Filter.class.isAssignableFrom(returnType)) {
+ filters.add(m);
+ } else if
(ServletContextListener.class.isAssignableFrom(returnType)) {
+ listeners.add(m);
+ } else {
+ throw new IllegalArgumentException("Unsupported type: " +
returnType);
+ }
+ }
+ }
+ if (servlets.size() + listeners.size() + filters.size() > 0) {
+ instance = createInstance();
+
+ final StandardContext context = tomcatContext();
+ final Thread thread = Thread.currentThread();
+ final ClassLoader oldLoader = thread.getContextClassLoader();
+ thread.setContextClassLoader(context.getLoader().getClassLoader());
+ try {
+ for (final MetaAnnotatedMethod m : listeners) {
+ deployListener(instance, m,
m.getAnnotation(WebComponent.class), context);
+ }
+ for (final MetaAnnotatedMethod m : filters) {
+ deployFilter(instance, m,
m.getAnnotation(WebComponent.class), context);
+ }
+ for (final MetaAnnotatedMethod m : servlets) {
+ deployServlet(instance, m,
m.getAnnotation(WebComponent.class), context);
+ }
+ } finally {
+ thread.setContextClassLoader(oldLoader);
+ }
+ }
+ }
+
+ // side note: while we do it the listener will be initialized here which
means after StandardContext is started
+ // which is later than usually
+ private void deployListener(final Object instance, final
MetaAnnotatedMethod m, final WebComponent webComponent, final StandardContext
context) {
+ final Object listener;
+ try {
+ listener = m.get().invoke(instance);
+ } catch (final Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ context.addApplicationLifecycleListener(listener);
+ if (ServletContextListener.class.isInstance(listener)) {
+ ServletContextListener.class.cast(listener).contextInitialized(new
ServletContextEvent(context.getServletContext()));
+ }
+ }
+
+ private void deployFilter(final Object instance, final MetaAnnotatedMethod
m, final WebComponent webComponent, final StandardContext context) {
+ final Filter filter;
+ try {
+ filter = Filter.class.cast(m.get().invoke(instance));
+ } catch (final Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ final FilterDef filterDef = new FilterDef();
+ filterDef.setFilterName(webComponent.name().isEmpty() ?
filter.getClass().getName() : webComponent.name());
+
filterDef.setAsyncSupported(String.valueOf(webComponent.asyncSupported()));
+ filterDef.setFilter(filter);
+ filterDef.setFilterClass(filter.getClass().getName());
+ context.addFilterDef(filterDef);
+
+ final FilterMap filterMap = new FilterMap();
+ for (final String pattern : webComponent.urlPatterns()) {
+ filterMap.addURLPattern(pattern);
+ }
+ filterMap.setFilterName(filterDef.getFilterName());
+ context.addFilterMap(filterMap);
+
+ Registrations.addFilterConfig(context, filterDef);
+ }
+
+ // TODO: cdi etc
+ private Object createInstance() {
+ try {
+ return app.get().newInstance();
+ } catch (final Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private void deployServlet(final Object instance, final
MetaAnnotatedMethod m, final WebComponent webComponent, final StandardContext
context) {
+ final Servlet servlet;
+ try {
+ servlet = Servlet.class.cast(m.get().invoke(instance));
+ } catch (final Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ final Wrapper wrapper = context.createWrapper();
+ wrapper.setName(webComponent.name().isEmpty() ?
servlet.getClass().getName() : webComponent.name());
+ wrapper.setServletClass(servlet.getClass().getName());
+ wrapper.setAsyncSupported(webComponent.asyncSupported());
+ context.addChild(wrapper);
+ wrapper.setServlet(servlet);
+ final ServletRegistration.Dynamic registration =
context.dynamicServletAdded(wrapper);
+ registration.addMapping(webComponent.urlPatterns());
+ for (final WebInitParam param : webComponent.initParams()) {
+ registration.setInitParameter(param.name(), param.value());
+ }
+
+ if (webComponent.loadOnStartup() >= 0) {
+ try {
+ wrapper.load();
+ } catch (final ServletException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ private StandardContext tomcatContext() {
+ final StandardContext context =
SystemInstance.get().getComponent(TomcatWebAppBuilder.class).getContextInfo(module.getModuleId()).standardContext;
+ if (context == null) {
+ throw new IllegalStateException("Can't find the app");
+ }
+ return context;
+ }
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/StandardContextCustomizer.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/StandardContextCustomizer.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/StandardContextCustomizer.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/main/java/org/apache/tomee/application/composer/internal/StandardContextCustomizer.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,69 @@
+/*
+ * 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.tomee.application.composer.internal;
+
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.WebResourceRoot;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.webresources.StandardRoot;
+import org.apache.openejb.config.WebModule;
+import org.apache.openejb.observer.Observes;
+import org.apache.openejb.util.URLs;
+
+import java.io.File;
+import java.net.URL;
+
+public class StandardContextCustomizer {
+ private final WebModule module;
+ private boolean enriched = false;
+
+ public StandardContextCustomizer(final WebModule webModule) {
+ module = webModule;
+ }
+
+ public void customize(final @Observes LifecycleEvent event) {
+ if (enriched) {
+ return;
+ }
+
+ final Object data = event.getSource();
+ if (!StandardContext.class.isInstance(data) ||
!Lifecycle.BEFORE_START_EVENT.equals(event.getType())) {
+ return;
+ }
+
+ final StandardContext context = StandardContext.class.cast(data);
+ if (!module.getContextRoot().equals(context.getPath())) {
+ return;
+ }
+ context.setResources(new StandardRoot(context));
+
+ final WebResourceRoot resources = context.getResources();
+ for (final URL url : module.getScannableUrls()) {
+ final File file = URLs.toFile(url);
+ if (file.isDirectory()) {
+
resources.createWebResourceSet(WebResourceRoot.ResourceSetType.RESOURCE_JAR,
"/WEB-INF/classes", file.getAbsolutePath(), "", "/");
+ } else {
+
resources.createWebResourceSet(WebResourceRoot.ResourceSetType.RESOURCE_JAR,
"/WEB-INF/lib", file.getAbsolutePath(), "", "/");
+ }
+ }
+
+ enriched = true;
+ }
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/AutoDiscoveryServletTest.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/AutoDiscoveryServletTest.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/AutoDiscoveryServletTest.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/AutoDiscoveryServletTest.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,56 @@
+/*
+ * 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.tomee.application.composer;
+
+import org.apache.openejb.loader.IO;
+import org.apache.tomee.application.composer.component.AutoDiscovery;
+import org.junit.Test;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+@AutoDiscovery
+public class AutoDiscoveryServletTest {
+ @WebServlet(urlPatterns = "/ServletTest")
+ public static class TheServlet extends HttpServlet {
+ private boolean init;
+
+ @Override
+ protected void service(final HttpServletRequest req, final
HttpServletResponse resp) throws ServletException, IOException {
+ resp.getWriter().write("Init = " + init);
+ }
+
+ @Override
+ public void init() throws ServletException {
+ init = true;
+ }
+ }
+
+ @Test
+ public void checkItIsDeployed() throws Exception {
+ try (final TomEEApplicationComposer runner = new
TomEEApplicationComposer(AutoDiscoveryServletTest.class)) {
+ assertEquals("Init = true", IO.slurp(new URL("http://localhost:" +
runner.getPort() + "/ServletTest")));
+ }
+ }
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualFilterTest.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualFilterTest.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualFilterTest.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualFilterTest.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,66 @@
+/*
+ * 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.tomee.application.composer;
+
+import org.apache.openejb.loader.IO;
+import org.apache.tomee.application.composer.component.WebComponent;
+import org.junit.Test;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+public class ManualFilterTest {
+ @WebComponent(urlPatterns = "/ManualFilterTest", loadOnStartup = 1)
+ public Filter simpleServlet() {
+ return new Filter() {
+ public boolean init;
+
+ @Override
+ public void init(final FilterConfig filterConfig) throws
ServletException {
+ init = true;
+ }
+
+ @Override
+ public void doFilter(final ServletRequest servletRequest, final
ServletResponse servletResponse, final FilterChain filterChain) throws
IOException, ServletException {
+ servletResponse.getWriter().write("Filter = " + init);
+ }
+
+ @Override
+ public void destroy() {
+ // no-op
+ }
+ };
+ }
+
+ @Test
+ public void checkItIsDeployed() throws Exception {
+ try (final TomEEApplicationComposer runner = new
TomEEApplicationComposer(ManualFilterTest.class)) {
+ assertEquals("Filter = true", IO.slurp(new URL("http://localhost:"
+ runner.getPort() + "/ManualFilterTest")));
+ }
+ }
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualListenerTest.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualListenerTest.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualListenerTest.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualListenerTest.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,55 @@
+/*
+ * 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.tomee.application.composer;
+
+import org.apache.tomee.application.composer.component.WebComponent;
+import org.junit.Test;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import static org.junit.Assert.assertTrue;
+
+public class ManualListenerTest {
+ public static boolean init;
+ public static boolean destroy;
+
+ @WebComponent(urlPatterns = "/ManualFilterTest", loadOnStartup = 1)
+ public ServletContextListener simpleServlet() {
+ return new ServletContextListener() {
+ @Override
+ public void contextInitialized(final ServletContextEvent
servletContextEvent) {
+ init = servletContextEvent != null;
+ }
+
+ @Override
+ public void contextDestroyed(final ServletContextEvent
servletContextEvent) {
+ destroy = servletContextEvent != null;
+ }
+ };
+ }
+
+ @Test
+ public void checkItIsDeployed() throws Exception {
+ init = false;
+ destroy = false;
+ try (final TomEEApplicationComposer runner = new
TomEEApplicationComposer(ManualListenerTest.class)) {
+ assertTrue(init);
+ }
+ assertTrue(destroy);
+ }
+}
Added:
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualServletTest.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualServletTest.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualServletTest.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-application-composer/src/test/java/org/apache/tomee/application/composer/ManualServletTest.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,56 @@
+/*
+ * 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.tomee.application.composer;
+
+import org.apache.openejb.loader.IO;
+import org.apache.tomee.application.composer.component.WebComponent;
+import org.junit.Test;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+public class ManualServletTest {
+ @WebComponent(urlPatterns = "/ManualServletTest", loadOnStartup = 1)
+ public HttpServlet simpleServlet() {
+ return new HttpServlet() {
+ private boolean init;
+
+ @Override
+ protected void service(final HttpServletRequest req, final
HttpServletResponse resp) throws ServletException, IOException {
+ resp.getWriter().write("TheServlet = " + init);
+ }
+
+ @Override
+ public void init() throws ServletException {
+ init = true;
+ }
+ };
+ }
+
+ @Test
+ public void checkItIsDeployed() throws Exception {
+ try (final TomEEApplicationComposer runner = new
TomEEApplicationComposer(ManualServletTest.class)) {
+ assertEquals("TheServlet = true", IO.slurp(new
URL("http://localhost:" + runner.getPort() + "/ManualServletTest")));
+ }
+ }
+}
Modified:
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/GlobalListenerSupport.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/GlobalListenerSupport.java?rev=1626577&r1=1626576&r2=1626577&view=diff
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/GlobalListenerSupport.java
(original)
+++
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/GlobalListenerSupport.java
Sun Sep 21 11:30:15 2014
@@ -100,28 +100,39 @@ public class GlobalListenerSupport imple
final String type = event.getType();
- if (INIT_EVENT.equals(type) ||
Lifecycle.BEFORE_INIT_EVENT.equals(type)) {
- contextListener.init(standardContext);
- } else if (Lifecycle.BEFORE_START_EVENT.equals(type)) {
- contextListener.beforeStart(standardContext);
- } else if (Lifecycle.BEFORE_START_EVENT.equals(type)) {
- contextListener.beforeStart(standardContext);
- } else if (Lifecycle.START_EVENT.equals(type)) {
- standardContext.addParameter("openejb.start.late", "true");
- contextListener.start(standardContext);
- } else if (Lifecycle.AFTER_START_EVENT.equals(type)) {
- contextListener.afterStart(standardContext);
- standardContext.removeParameter("openejb.start.late");
- } else if (Lifecycle.BEFORE_STOP_EVENT.equals(type)) {
- contextListener.beforeStop(standardContext);
- } else if (Lifecycle.STOP_EVENT.equals(type)) {
- contextListener.stop(standardContext);
- } else if (Lifecycle.AFTER_STOP_EVENT.equals(type)) {
- contextListener.afterStop(standardContext);
- } else if (DESTROY_EVENT.equals(type) ||
Lifecycle.AFTER_DESTROY_EVENT.equals(type)) {
- contextListener.destroy(standardContext);
- } else if (Lifecycle.CONFIGURE_START_EVENT.equals(type)) {
- contextListener.configureStart(standardContext);
+ switch (type) { // better than if cause it prevent duplicates
+ case INIT_EVENT:
+ case Lifecycle.BEFORE_INIT_EVENT:
+ contextListener.init(standardContext);
+ break;
+ case Lifecycle.BEFORE_START_EVENT:
+ contextListener.beforeStart(standardContext);
+ break;
+ case Lifecycle.START_EVENT:
+ standardContext.addParameter("openejb.start.late", "true");
+ contextListener.start(standardContext);
+ break;
+ case Lifecycle.AFTER_START_EVENT:
+ contextListener.afterStart(standardContext);
+ standardContext.removeParameter("openejb.start.late");
+ break;
+ case Lifecycle.BEFORE_STOP_EVENT:
+ contextListener.beforeStop(standardContext);
+ break;
+ case Lifecycle.STOP_EVENT:
+ contextListener.stop(standardContext);
+ break;
+ case Lifecycle.AFTER_STOP_EVENT:
+ contextListener.afterStop(standardContext);
+ break;
+ case DESTROY_EVENT:
+ case Lifecycle.AFTER_DESTROY_EVENT:
+ contextListener.destroy(standardContext);
+ break;
+ case Lifecycle.CONFIGURE_START_EVENT:
+ contextListener.configureStart(standardContext);
+ break;
+ default:
}
} else if (StandardHost.class.isInstance(source)) {
final StandardHost standardHost = (StandardHost) source;
@@ -151,6 +162,9 @@ public class GlobalListenerSupport imple
contextListener.afterStop(standardServer);
}
}
+
+ // Notify
+ SystemInstance.get().fireEvent(event); // here this way we are sure we
get it even in embedded mode. TODO: we miss then few boot events, is it an
issue.
}
private static boolean hasChild(final StandardHost host, final String
name) {
Modified:
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ServerListener.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ServerListener.java?rev=1626577&r1=1626576&r2=1626577&view=diff
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ServerListener.java
(original)
+++
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ServerListener.java
Sun Sep 21 11:30:15 2014
@@ -50,15 +50,6 @@ public class ServerListener implements L
private static final AtomicBoolean listenerInstalled = new
AtomicBoolean(false);
public void lifecycleEvent(final LifecycleEvent event) {
-
- // Bootstrap
- install(event);
-
- // Notify
- SystemInstance.get().fireEvent(event);
- }
-
- private void install(final LifecycleEvent event) {
if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType()) &&
StandardServer.class.isInstance(event.getSource())) {
installServerInfo();
}
Modified:
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java?rev=1626577&r1=1626576&r2=1626577&view=diff
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
(original)
+++
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatJndiBuilder.java
Sun Sep 21 11:30:15 2014
@@ -158,7 +158,7 @@ public class TomcatJndiBuilder {
ContextAccessController.setWritable(name, namingToken);
Context root = null;
try {
- root = (Context) ContextBindings.getClassLoader();
+ root = ContextBindings.getClassLoader();
} catch (final NamingException ignored) { // shouldn't occur
// no-op
}
Modified:
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java?rev=1626577&r1=1626576&r2=1626577&view=diff
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
(original)
+++
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
Sun Sep 21 11:30:15 2014
@@ -2233,7 +2233,7 @@ public class TomcatWebAppBuilder impleme
* @param standardContext context
* @return context info
*/
- private ContextInfo addContextInfo(final String host, final
StandardContext standardContext) {
+ public ContextInfo addContextInfo(final String host, final StandardContext
standardContext) {
String contextRoot = standardContext.getName();
if (!contextRoot.startsWith("/")) {
contextRoot = "/" + contextRoot;
Added:
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/registration/Registrations.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/registration/Registrations.java?rev=1626577&view=auto
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/registration/Registrations.java
(added)
+++
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/registration/Registrations.java
Sun Sep 21 11:30:15 2014
@@ -0,0 +1,45 @@
+/*
+ * 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.tomee.catalina.registration;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.core.ApplicationFilterConfig;
+import org.apache.openejb.util.reflection.Reflections;
+import org.apache.tomcat.util.descriptor.web.FilterDef;
+
+import java.lang.reflect.Constructor;
+import java.util.Map;
+
+public class Registrations {
+ private Registrations() {
+ // no-op
+ }
+
+ // hack to force filter to get a config otherwise it is ignored in the
http routing
+ public static void addFilterConfig(final Context context, final FilterDef
filterDef) {
+ try {
+ final Constructor<ApplicationFilterConfig> cons =
ApplicationFilterConfig.class.getDeclaredConstructor(Context.class,
FilterDef.class);
+ if (!cons.isAccessible()) {
+ cons.setAccessible(true);
+ }
+ final ApplicationFilterConfig config = cons.newInstance(context,
filterDef);
+ ((Map<String, ApplicationFilterConfig>) Reflections.get(context,
"filterConfigs")).put(filterDef.getFilterName(), config);
+ } catch (final Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+}
Modified:
tomee/tomee/trunk/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java?rev=1626577&r1=1626576&r2=1626577&view=diff
==============================================================================
---
tomee/tomee/trunk/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java
(original)
+++
tomee/tomee/trunk/tomee/tomee-jaxrs/src/main/java/org/apache/tomee/webservices/TomcatRsRegistry.java
Sun Sep 21 11:30:15 2014
@@ -34,6 +34,7 @@ import org.apache.openejb.util.reflectio
import org.apache.tomcat.util.descriptor.web.FilterDef;
import org.apache.tomcat.util.descriptor.web.FilterMap;
import org.apache.tomee.catalina.environment.Hosts;
+import org.apache.tomee.catalina.registration.Registrations;
import org.apache.tomee.loader.TomcatHelper;
import java.lang.reflect.Constructor;
@@ -131,7 +132,7 @@ public class TomcatRsRegistry implements
filterMap.setFilterName(filterDef.getFilterName());
context.addFilterMap(filterMap);
- addFilterConfig(context, filterDef);
+ Registrations.addFilterConfig(context, filterDef);
path = address(connectors, host.getName(), webContext);
final String key = address(connectors, host.getName(), completePath);
@@ -140,20 +141,6 @@ public class TomcatRsRegistry implements
return new AddressInfo(path, key);
}
- private void addFilterConfig(final Context context, final FilterDef
filterDef) {
- // hack to force filter to get a config otherwise it is ignored in the
http routing
- try {
- final Constructor<ApplicationFilterConfig> cons =
ApplicationFilterConfig.class.getDeclaredConstructor(Context.class,
FilterDef.class);
- if (!cons.isAccessible()) {
- cons.setAccessible(true);
- }
- final ApplicationFilterConfig config = cons.newInstance(context,
filterDef);
- ((Map<String, ApplicationFilterConfig>) Reflections.get(context,
"filterConfigs")).put(filterDef.getFilterName(), config);
- } catch (final Exception e) {
- throw new IllegalStateException(e);
- }
- }
-
private CxfRsHttpListener findCxfRsHttpListener(final HttpListener
listener) {
// can we have some unwrapping to do here? normally no
return CxfRsHttpListener.class.cast(listener);