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/04/16 14:49:52 UTC
svn commit: r1326577 - in /openejb/trunk/openejb:
arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/httpheaders/
arquillian-tomee/arquillian-tomee-tests/src/test/resources/org/apache/openejb/arquillian/test...
Author: rmannibucau
Date: Mon Apr 16 12:49:52 2012
New Revision: 1326577
URL: http://svn.apache.org/viewvc?rev=1326577&view=rev
Log:
importing in trunk the new finder logic (enable meta annotation only if mandatory, linking finder for subclasses only if forced) and scanning @ApplicationPath to be able to ease the rest deployement when subclasses are not activated in the finder
Modified:
openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/httpheaders/Application.java
openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/resources/org/apache/openejb/arquillian/tests/jaxrs/basicapp/web.xml
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java
Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/httpheaders/Application.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/httpheaders/Application.java?rev=1326577&r1=1326576&r2=1326577&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/httpheaders/Application.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/jaxrs/httpheaders/Application.java Mon Apr 16 12:49:52 2012
@@ -21,10 +21,12 @@ package org.apache.openejb.arquillian.te
import java.util.HashSet;
import java.util.Set;
+import javax.ws.rs.ApplicationPath;
/**
* Application to test the HTTP headers
*/
+@ApplicationPath("/")
public class Application extends javax.ws.rs.core.Application {
@Override
Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/resources/org/apache/openejb/arquillian/tests/jaxrs/basicapp/web.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/resources/org/apache/openejb/arquillian/tests/jaxrs/basicapp/web.xml?rev=1326577&r1=1326576&r2=1326577&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/resources/org/apache/openejb/arquillian/tests/jaxrs/basicapp/web.xml (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/resources/org/apache/openejb/arquillian/tests/jaxrs/basicapp/web.xml Mon Apr 16 12:49:52 2012
@@ -20,14 +20,7 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
- <!--servlet>
- <servlet-name>org.apache.openejb.arquillian.tests.jaxrs.noservlet.BasicApplication</servlet-name>
- </servlet>
- <servlet-mapping>
- <servlet-name>org.apache.openejb.arquillian.tests.jaxrs.noservlet.BasicApplication</servlet-name>
- <url-pattern>/*</url-pattern>
- </servlet-mapping-->
- <servlet> <!-- RMB: was noservlet a typo? -->
+ <servlet>
<servlet-name>org.apache.openejb.arquillian.tests.jaxrs.basicapp.BasicApplication</servlet-name>
</servlet>
<servlet-mapping>
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1326577&r1=1326576&r2=1326577&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Mon Apr 16 12:49:52 2012
@@ -16,6 +16,7 @@
*/
package org.apache.openejb.config;
+import javax.ws.rs.ApplicationPath;
import org.apache.openejb.BeanContext;
import org.apache.openejb.OpenEJBException;
import org.apache.openejb.api.LocalClient;
@@ -1037,19 +1038,28 @@ public class AnnotationDeployer implemen
*/
// get by annotations
webModule.getRestClasses().addAll(findRestClasses(webModule, finder));
+
// Applications with a default constructor
+ // findSubclasses will not work by default to gain a lot of time
+ // look FinderFactory for the flag to activate it or
+ // use @ApplicationPath("/")
List<Class<? extends Application>> applications = finder.findSubclasses(Application.class);
for (Class<? extends Application> app : applications) {
- if (app.getConstructors().length == 0) {
- webModule.getRestApplications().add(app.getName());
- } else {
- for (Constructor<?> ctr : app.getConstructors()) {
- if (ctr.getParameterTypes().length == 0) {
- webModule.getRestApplications().add(app.getName());
- break;
- }
- }
+ addRestApplicationIfPossible(webModule, app);
+ }
+
+ // look for ApplicationPath, it will often return the same than the previous one
+ // but without finder.link() invocation it still works
+ // so it can save a lot of startup time
+ List<Annotated<Class<?>>> applicationsByAnnotation = finder.findMetaAnnotatedClasses(ApplicationPath.class);
+ for (Annotated<Class<?>> annotatedApp : applicationsByAnnotation) {
+ final Class<?> app = annotatedApp.get();
+ if (!Application.class.isAssignableFrom(app)) {
+ logger.error("class '" + app.getName() + "' is annotated with @ApplicationPath but doesn't implement " + Application.class.getName());
+ continue;
}
+
+ addRestApplicationIfPossible(webModule, (Class<? extends Application>) app);
}
/*
@@ -1092,6 +1102,19 @@ public class AnnotationDeployer implemen
return webModule;
}
+ private static void addRestApplicationIfPossible(final WebModule webModule, final Class<? extends Application> app) {
+ if (app.getConstructors().length == 0) {
+ webModule.getRestApplications().add(app.getName());
+ } else {
+ for (Constructor<?> ctr : app.getConstructors()) {
+ if (ctr.getParameterTypes().length == 0) {
+ webModule.getRestApplications().add(app.getName());
+ break;
+ }
+ }
+ }
+ }
+
public EjbModule deploy(EjbModule ejbModule) throws OpenEJBException {
if (ejbModule.getEjbJar() != null && ejbModule.getEjbJar().isMetadataComplete()) return ejbModule;
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java?rev=1326577&r1=1326576&r2=1326577&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java Mon Apr 16 12:49:52 2012
@@ -34,6 +34,7 @@ import org.apache.xbean.finder.archive.C
public class FinderFactory {
private static final FinderFactory factory = new FinderFactory();
+ public static final String TOMEE_JAXRS_DEPLOY_UNDECLARED_PROP = "tomee.jaxrs.deploy.undeclared";
private static FinderFactory get() {
FinderFactory factory = SystemInstance.get().getComponent(FinderFactory.class);
@@ -52,15 +53,17 @@ public class FinderFactory {
IAnnotationFinder finder;
if (module instanceof WebModule) {
WebModule webModule = (WebModule) module;
- AnnotationFinder annotationFinder = new AnnotationFinder(new WebappAggregatedArchive(webModule, webModule.getScannableUrls()));
-
- // always link otherwise the ModuleLimitedFinder will not be able to use getAnnotatedClassNames() method
- // and result will always be empty
- // moreover we call findSubclasses in annotation finder so that's mandatory
- finder = annotationFinder.link();
+ final AnnotationFinder annotationFinder = new AnnotationFinder(new WebappAggregatedArchive(webModule, webModule.getScannableUrls()));
+ if (annotationFinder.hasMetaAnnotations()) {
+ annotationFinder.enableMetaAnnotations();
+ }
+ if (enableFindSubclasses()) {
+ annotationFinder.enableFindSubclasses();
+ }
+ finder = annotationFinder;
} else if (module instanceof ConnectorModule) {
- ConnectorModule connectorModule = (ConnectorModule) module;
- finder = new AnnotationFinder(new ConfigurableClasspathArchive(connectorModule, connectorModule.getLibraries())).link();
+ ConnectorModule connectorModule = (ConnectorModule) module;
+ finder = new AnnotationFinder(new ConfigurableClasspathArchive(connectorModule, connectorModule.getLibraries())).link();
} else if (module.getJarLocation() != null) {
String location = module.getJarLocation();
File file = new File(location);
@@ -68,10 +71,10 @@ public class FinderFactory {
URL url;
if (file.exists()) {
url = file.toURI().toURL();
-
+
File webInfClassesFolder = new File(file, "WEB-INF/classes"); // is it possible?? normally no
- if (webInfClassesFolder.exists() && webInfClassesFolder.isDirectory()) {
- url = webInfClassesFolder.toURI().toURL();
+ if (webInfClassesFolder.exists() && webInfClassesFolder.isDirectory()) {
+ url = webInfClassesFolder.toURI().toURL();
}
} else {
url = new URL(location);
@@ -89,6 +92,19 @@ public class FinderFactory {
return new ModuleLimitedFinder(finder);
}
+ private static boolean enableFindSubclasses() {
+ return isJaxRsInstalled() && SystemInstance.get().getOptions().get(TOMEE_JAXRS_DEPLOY_UNDECLARED_PROP, false);
+ }
+
+ public static boolean isJaxRsInstalled() {
+ try {
+ FinderFactory.class.getClassLoader().loadClass("org.apache.openejb.server.rest.RsRegistry");
+ return true;
+ } catch (Throwable e) {
+ return false;
+ }
+ }
+
public static class ModuleLimitedFinder implements IAnnotationFinder {
private final IAnnotationFinder delegate;
Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java?rev=1326577&r1=1326576&r2=1326577&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/AnnotationDeployerTest.java Mon Apr 16 12:49:52 2012
@@ -16,27 +16,13 @@
*/
package org.apache.openejb.config;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
-import java.util.Locale;
import java.util.Set;
-
import javax.annotation.Resource;
import javax.ejb.ApplicationException;
import javax.ejb.Local;
@@ -68,7 +54,7 @@ import javax.resource.spi.endpoint.Messa
import javax.resource.spi.work.WorkContext;
import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;
-
+import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Path;
import javax.ws.rs.core.Application;
import org.apache.openejb.assembler.classic.AppInfo;
@@ -85,12 +71,17 @@ import org.apache.openejb.jee.WebApp;
import org.apache.xbean.finder.Annotated;
import org.apache.xbean.finder.AnnotationFinder;
import org.apache.xbean.finder.ClassFinder;
-import org.apache.xbean.finder.archive.Archive;
import org.apache.xbean.finder.archive.ClassesArchive;
-import org.apache.xbean.finder.archive.JarArchive;
import org.junit.Assert;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
/**
* @version $Rev$ $Date$
*/
@@ -526,6 +517,7 @@ public class AnnotationDeployerTest {
}
}
+ @ApplicationPath("/")
public static class RESTApp extends Application {
public java.util.Set<java.lang.Class<?>> getClasses() {
return new HashSet<Class<?>>() {{