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 2014/04/01 07:30:33 UTC
svn commit: r1583538 - in /tomee/tomee/trunk:
container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEClassLoaderEnricher.java
Author: rmannibucau
Date: Tue Apr 1 05:30:33 2014
New Revision: 1583538
URL: http://svn.apache.org/r1583538
Log:
TOMEE-1159 support jaxrs in webapp
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEClassLoaderEnricher.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=1583538&r1=1583537&r2=1583538&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 Tue Apr 1 05:30:33 2014
@@ -1111,31 +1111,40 @@ public class AnnotationDeployer implemen
/*
* REST
*/
- // get by annotations
- webModule.getRestClasses().addAll(findRestClasses(webModule, finder));
- addJaxRsProviders(finder, webModule.getJaxrsProviders(), Provider.class);
-
- // 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("/")
- final List<Class<? extends Application>> applications = finder.findSubclasses(Application.class);
- for (final Class<? extends Application> app : applications) {
- 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
- final List<Annotated<Class<?>>> applicationsByAnnotation = finder.findMetaAnnotatedClasses(ApplicationPath.class);
- for (final 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;
- }
+ boolean restHandledByTheWebApp;
+ try {
+ restHandledByTheWebApp = webModule.getClassLoader().loadClass(Application.class.getName()) != Application.class;
+ } catch (final Throwable e) { // ClassNotFoundException or NoClassDefFoundError
+ restHandledByTheWebApp = false;
+ }
+
+ if (!restHandledByTheWebApp) {
+ // get by annotations
+ webModule.getRestClasses().addAll(findRestClasses(webModule, finder));
+ addJaxRsProviders(finder, webModule.getJaxrsProviders(), Provider.class);
+
+ // 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("/")
+ final List<Class<? extends Application>> applications = finder.findSubclasses(Application.class);
+ for (final Class<? extends Application> app : applications) {
+ 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
+ final List<Annotated<Class<?>>> applicationsByAnnotation = finder.findMetaAnnotatedClasses(ApplicationPath.class);
+ for (final 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);
+ addRestApplicationIfPossible(webModule, (Class<? extends Application>) app);
+ }
}
/*
Modified: tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEClassLoaderEnricher.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEClassLoaderEnricher.java?rev=1583538&r1=1583537&r2=1583538&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEClassLoaderEnricher.java (original)
+++ tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEClassLoaderEnricher.java Tue Apr 1 05:30:33 2014
@@ -49,7 +49,7 @@ public final class TomEEClassLoaderEnric
private static final String[] JAR_TO_ADD_CLASS_HELPERS;
- private static final String[] DEFAULT_PREFIXES_TO_ADD = new String[] {
+ private static final String[] DEFAULT_PREFIXES_TO_ADD = new String[]{
"openwebbeans-jsf", // to be able to provide jsf impl
"tomee-mojarra",
"tomee-myfaces", // to be able to embedded myfaces in the webapp
@@ -136,17 +136,17 @@ public final class TomEEClassLoaderEnric
/**
* Validation part
*/
- private static final String[] FORBIDDEN_CLASSES = new String[]{
- "javax.persistence.Entity", // JPA
- "javax.transaction.Transaction", // JTA
- "javax.jws.WebService", // JAXWS
- "javax.validation.Validation", // BVal
- "javax.jms.Queue", // JMS
- "javax.enterprise.context.ApplicationScoped", // CDI
- "javax.inject.Inject", // CDI
- "javax.ws.rs.Path", // JAXRS - commented since we manage to find why jersey-core brings the api!
- "javax.ejb.EJB", // EJB
- "javax.annotation.PostConstruct" // javax.annotation
+ private static final String[][] FORBIDDEN_CLASSES = new String[][]{
+ {"javax.persistence.Entity", null}, // JPA
+ {"javax.transaction.Transaction", null}, // JTA
+ {"javax.jws.WebService", null}, // JAXWS
+ {"javax.validation.Validation", null}, // BVal
+ {"javax.jms.Queue", null}, // JMS
+ {"javax.enterprise.context.ApplicationScoped", null}, // CDI
+ {"javax.inject.Inject", null}, // CDI
+ {"javax.ws.rs.Path", "You provide JAXRS API in the webapp, we tolerate it to support some advanced feature but if you expect TomEE to provide it you should remove it"}, // JAXRS - commented since we manage to find why jersey-core brings the api!
+ {"javax.ejb.EJB", null}, // EJB
+ {"javax.annotation.PostConstruct", null} // javax.annotation
};
public static boolean validateJarFile(final File file) throws IOException {
@@ -156,13 +156,13 @@ public final class TomEEClassLoaderEnric
try {
jarFile = new JarFile(file);
- for (String name : FORBIDDEN_CLASSES) {
+ for (final String[] name : FORBIDDEN_CLASSES) {
// if we can't load if from our classLoader we'll not impose anything on this class
boolean found = false;
for (int i = 0; i < 2; i++) {
try {
try {
- parent.loadClass(name);
+ parent.loadClass(name[0]);
found = true;
break;
} catch (Exception e) {
@@ -178,12 +178,17 @@ public final class TomEEClassLoaderEnric
}
// we found it so let's check it is or not in the file (potential conflict)
- final String entry = name.replace('.', '/') + ".class";
+ final String entry = name[0].replace('.', '/') + ".class";
final JarEntry jarEntry = jarFile.getJarEntry(entry);
if (jarEntry != null) {
- LOGGER.warning("jar '" + file.getAbsolutePath() + "' contains offending class: " + name
- + ". It will be ignored.");
- return false;
+ if (name[1] == null) {
+ LOGGER.warning("jar '" + file.getAbsolutePath() + "' contains offending class: " + name[0]
+ + ". It will be ignored.");
+ return false;
+ }
+ LOGGER.warning("jar '" + file.getAbsolutePath() + "' contains offending class: " + name[0]
+ + "but: " + name[1]);
+ return true;
}
}
return true;