You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2011/01/07 17:03:17 UTC
svn commit: r1056366 - in /openejb/trunk/openejb3:
assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/
assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/
container/open...
Author: jlmonteiro
Date: Fri Jan 7 16:03:17 2011
New Revision: 1056366
URL: http://svn.apache.org/viewvc?rev=1056366&view=rev
Log:
OPENEJB-1231 Webapp context.xml setting allows app to be ignored entirely by OpenEJB
OPENEJB-1230 Webapp scanning include/exclude via context.xml settings
OPENEJB-1417 webservices.xml not read when embedded in Tomcat
OPENEJB-1418 Refactor TomcatWebAppBuilder
Modified:
openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/BootstrapTest.java
openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java
openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWsRegistry.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ClassPathApplication.java
Modified: openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/BootstrapTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/BootstrapTest.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/BootstrapTest.java (original)
+++ openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/BootstrapTest.java Fri Jan 7 16:03:17 2011
@@ -30,6 +30,8 @@ import javax.naming.InitialContext;
import java.io.IOException;
public class BootstrapTest {
+ private static final int SERVER_PORT = 8091;
+ private static final String SERVER_BASE_URL = "http://localhost:" + SERVER_PORT;
private Server server;
@Before
@@ -37,7 +39,7 @@ public class BootstrapTest {
OpenEJBLifecycle ejbLifecycle = new OpenEJBLifecycle();
ejbLifecycle.addApplication("target/test/ejb-examples-1.1-SNAPSHOT.war");
- server = new Server(9091);
+ server = new Server(SERVER_PORT);
server.addBean(ejbLifecycle);
ejbLifecycle.setServer(server);
server.start();
@@ -53,7 +55,7 @@ public class BootstrapTest {
@Test
public void testShouldInjectEjbsIntoServlet() throws Exception {
- String url = "http://localhost:9091/annotated";
+ String url = SERVER_BASE_URL + "/annotated";
String[] stringsToCheck = new String[] { "@EJB=proxy=org.superbiz.servlet.AnnotatedEJBLocal;deployment=AnnotatedEJB;pk=null",
"@EJB.getName()=foo",
@@ -78,7 +80,7 @@ public class BootstrapTest {
@Test
public void testShouldLoadPersistenceContext() throws Exception {
- String url = "http://localhost:9091/jpa";
+ String url = SERVER_BASE_URL + "/jpa";
String[] stringsToCheck = new String[] { "@PersistenceUnit=org.apache.openjpa.persistence.EntityManagerFactoryImpl",
"Loaded [JpaBean id=",
@@ -89,7 +91,7 @@ public class BootstrapTest {
@Test
public void testShouldJndiTree() throws Exception {
- String url = "http://localhost:9091/jndi";
+ String url = SERVER_BASE_URL + "/jndi";
String[] stringsToCheck = new String[] { "env=",
"env/__=",
Modified: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java (original)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java Fri Jan 7 16:03:17 2011
@@ -46,36 +46,25 @@ import org.apache.openejb.assembler.clas
import org.apache.openejb.assembler.classic.WebAppInfo;
import org.apache.openejb.config.AnnotationDeployer;
import org.apache.openejb.config.AppModule;
-import org.apache.openejb.config.ClientModule;
import org.apache.openejb.config.ConfigurationFactory;
import org.apache.openejb.config.DeploymentLoader;
-import org.apache.openejb.config.EjbModule;
-import org.apache.openejb.config.ReadDescriptors;
-import org.apache.openejb.config.UnknownModuleTypeException;
import org.apache.openejb.config.WebModule;
import org.apache.openejb.core.CoreContainerSystem;
import org.apache.openejb.core.WebContext;
import org.apache.openejb.core.ivm.naming.SystemComponentReference;
import org.apache.openejb.core.webservices.JaxWsUtils;
import org.apache.openejb.jee.EnvEntry;
-import org.apache.openejb.jee.FacesConfig;
-import org.apache.openejb.jee.ParamValue;
import org.apache.openejb.jee.WebApp;
import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.server.webservices.WsService;
import org.apache.openejb.server.webservices.WsServlet;
import org.apache.openejb.spi.ContainerSystem;
-import static org.apache.openejb.tomcat.catalina.BackportUtil.getNamingContextListener;
-import static org.apache.openejb.tomcat.catalina.BackportUtil.getServlet;
import org.apache.openejb.tomcat.common.LegacyAnnotationProcessor;
import org.apache.openejb.tomcat.common.TomcatVersion;
import org.apache.openejb.tomcat.loader.TomcatHelper;
import org.apache.openejb.util.LinkResolver;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
-import org.apache.openejb.util.URLs;
-import org.apache.xbean.finder.ResourceFinder;
-import org.apache.xbean.finder.UrlSet;
import org.omg.CORBA.ORB;
import javax.ejb.spi.HandleDelegate;
@@ -87,15 +76,15 @@ import javax.transaction.TransactionMana
import javax.transaction.TransactionSynchronizationRegistry;
import java.io.File;
import java.io.IOException;
-import java.net.URL;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.TreeMap;
+import static org.apache.openejb.tomcat.catalina.BackportUtil.getNamingContextListener;
+import static org.apache.openejb.tomcat.catalina.BackportUtil.getServlet;
+
/**
* Web application builder.
*
@@ -301,9 +290,7 @@ public class TomcatWebAppBuilder impleme
@SuppressWarnings("unchecked")
@Override
public void start(StandardContext standardContext) {
- if (standardContext.getServletContext().getAttribute(IGNORE_CONTEXT) != null) {
- return;
- }
+ if (isIgnored(standardContext)) return;
Assembler a = getAssembler();
if (a == null) {
@@ -369,9 +356,7 @@ public class TomcatWebAppBuilder impleme
*/
@Override
public void afterStart(StandardContext standardContext) {
- if (standardContext.getServletContext().getAttribute(IGNORE_CONTEXT) != null) {
- return;
- }
+ if (isIgnored(standardContext)) return;
// if appInfo is null this is a failed deployment... just ignore
ContextInfo contextInfo = getContextInfo(standardContext);
@@ -379,38 +364,6 @@ public class TomcatWebAppBuilder impleme
return;
}
- WsService wsService = SystemInstance.get().getComponent(WsService.class);
- if (wsService != null) {
- List<WebAppInfo> webApps = contextInfo.appInfo.webApps;
- for (WebAppInfo webApp : webApps) {
- wsService.afterApplicationCreated(webApp);
- }
- }
-
- // replace any webservices with the webservice servlet
- // HACK: use a temp class loader because the class may have been loaded before
- // the openejb classes were added to the system class path so the WebService anntation
- // will not be present on the class
- ClassLoader tempClassLoader = ClassLoaderUtil.createTempClassLoader(standardContext.getLoader().getClassLoader());
- for (Container container : standardContext.findChildren()) {
- if (container instanceof Wrapper) {
- Wrapper wrapper = (Wrapper) container;
- String servletClass = wrapper.getServletClass();
- try {
- Class<?> clazz = tempClassLoader.loadClass(servletClass);
- if (JaxWsUtils.isWebService(clazz)) {
- wrapper.setServletClass(WsServlet.class.getName());
- if (getServlet(wrapper) != null) {
- wrapper.load();
- wrapper.unload();
- }
- }
- } catch (Exception e) {
- // will be reported by the tomcat
- }
- }
- }
-
// bind extra stuff at the java:comp level which can only be
// bound after the context is created
String listenerName = getNamingContextListener(standardContext).getName();
@@ -471,6 +424,16 @@ public class TomcatWebAppBuilder impleme
standardContext.getPipeline().addValve(openejbValve);
}
+ private static boolean isIgnored(StandardContext standardContext) {
+ // useful to disable web applications deployment
+ // it can be placed in the context.xml file, server.xml, ...
+ // see http://tomcat.apache.org/tomcat-5.5-doc/config/context.html#Context_Parameters
+ if (standardContext.getServletContext().getAttribute(IGNORE_CONTEXT) != null) return true;
+ if (standardContext.getServletContext().getInitParameter(IGNORE_CONTEXT) != null) return true;
+
+ return false;
+ }
+
/**
* {@inheritDoc}
*/
@@ -492,9 +455,7 @@ public class TomcatWebAppBuilder impleme
*/
@Override
public void afterStop(StandardContext standardContext) {
- if (standardContext.getServletContext().getAttribute(IGNORE_CONTEXT) != null) {
- return;
- }
+ if (isIgnored(standardContext)) return;
ContextInfo contextInfo = getContextInfo(standardContext);
if (contextInfo != null && contextInfo.appInfo != null && contextInfo.deployer == null) {
@@ -685,83 +646,20 @@ public class TomcatWebAppBuilder impleme
* @return a openejb application module
*/
private AppModule loadApplication(StandardContext standardContext) {
- // create the web module
- WebModule webModule = createWebModule(standardContext);
-
- // create the app module
- AppModule appModule = new AppModule(webModule);
-
- // add the web module itself
- appModule.getWebModules().add(webModule);
-
- // check each url to determine if it is an ejb jar
- for (URL url : getUrls(standardContext)) {
- try {
- Class moduleType = new DeploymentLoader().discoverModuleType(url, standardContext.getLoader().getClassLoader(), true);
- if (EjbModule.class.isAssignableFrom(moduleType)) {
- File file;
- if (url.getProtocol().equals("jar")) {
- url = new URL(url.getFile().replaceFirst("!.*$", ""));
- file = URLs.toFile(url);
- } else if (url.getProtocol().equals("file")) {
- file = URLs.toFile(url);
- } else {
- logger.warning("Not loading " + moduleType.getSimpleName() + ". Unknown protocol " + url.getProtocol());
- continue;
- }
-
- logger.info("Found ejb module " + moduleType.getSimpleName() + " in war " + standardContext.getPath());
-
-
- // create the ejb module and set its moduleId to the webapp context root name
- EjbModule ejbModule = new EjbModule(webModule.getClassLoader(), getEjbModuleId(standardContext), file.getAbsolutePath(), null, null);
- ejbModule.setClientModule(new ClientModule(null, ejbModule.getClassLoader(), ejbModule.getJarLocation(), null, ejbModule.getModuleId()));
-
- // EJB deployment descriptors
- try {
- ResourceFinder ejbResourceFinder = new ResourceFinder("", standardContext.getLoader().getClassLoader(), file.toURI().toURL());
- Map<String, URL> descriptors = ejbResourceFinder.getResourcesMap("META-INF/");
- descriptors = DeploymentLoader.altDDSources(descriptors, true);
- ejbModule.getAltDDs().putAll(descriptors);
- ejbModule.getClientModule().getAltDDs().putAll(descriptors);
- } catch (IOException e) {
- logger.error("Unable to determine descriptors in jar.", e);
- }
-
- // add module to app
- appModule.getEjbModules().add(ejbModule);
- }
- } catch (IOException e) {
- logger.warning("Unable to determine the module type of " + url.toExternalForm() + ": Exception: " + e.getMessage(), e);
- } catch (UnknownModuleTypeException ignore) {
- }
-
- }
+ ServletContext servletContext = standardContext.getServletContext();
- // Persistence Units via META-INF/persistence.xml
+ TomcatDeploymentLoader tomcatDeploymentLoader = new TomcatDeploymentLoader(standardContext, getId(standardContext));
+ AppModule appModule = null;
try {
- ResourceFinder finder = new ResourceFinder("", standardContext.getLoader().getClassLoader());
- List<URL> persistenceUrls = finder.findAll("META-INF/persistence.xml");
- appModule.getAltDDs().put("persistence.xml", persistenceUrls);
- } catch (IOException e) {
- logger.warning("Cannot load persistence-units from 'META-INF/persistence.xml' : " + e.getMessage(), e);
+ appModule = tomcatDeploymentLoader.load(new File(servletContext.getRealPath(".")).getParentFile());
+ } catch (OpenEJBException e) {
+ throw new RuntimeException(e);
}
- return appModule;
- }
+ // create the web module
+ loadWebModule(appModule, standardContext);
- /**
- * Strips off the / from the context root and returns the remaining String
- *
- * @param standardContext
- * @return the name of the context root for the webapp
- */
- private String getEjbModuleId(StandardContext standardContext) {
- String ejbModuleId = standardContext.getName();
- if (ejbModuleId.startsWith("/")) {
- ejbModuleId = ejbModuleId.substring(1);
- }
- return ejbModuleId;
+ return appModule;
}
/**
@@ -771,34 +669,14 @@ public class TomcatWebAppBuilder impleme
* @param standardContext tomcat context instance
* @return a openejb web module
*/
- private WebModule createWebModule(StandardContext standardContext) {
- // todo replace this code with DeploymentLoader
- ServletContext servletContext = standardContext.getServletContext();
-
- // read the web.xml
- WebApp webApp = new WebApp();
- try {
- URL webXmlUrl = servletContext.getResource("/WEB-INF/web.xml");
- if (webXmlUrl != null) {
- webApp = ReadDescriptors.readWebApp(webXmlUrl);
- }
- } catch (Exception e) {
- logger.error("Unable to load web.xml in war " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
- }
+ private void loadWebModule(AppModule appModule, StandardContext standardContext) {
+ WebModule webModule = appModule.getWebModules().get(0);
+ WebApp webApp = webModule.getWebApp();
// create the web module
- String basePath = new File(servletContext.getRealPath(".")).getParentFile().getAbsolutePath();
- ClassLoader classLoader = ClassLoaderUtil.createTempClassLoader(standardContext.getLoader().getClassLoader());
String path = standardContext.getPath();
System.out.println("context path = " + path);
- WebModule webModule = new WebModule(webApp, path, classLoader, basePath, getId(standardContext));
webModule.setHost(standardContext.getHostname());
- // add faces configurations
- try {
- addFacesConfigs(webModule);
- } catch (OpenEJBException e1) {
- logger.error("Unable to add faces config modules in " + standardContext.getPath() + ": Exception: " + e1.getMessage(), e1);
- }
// Add all Tomcat env entries to context so they can be overriden by the env.properties file
NamingResources naming = standardContext.getNamingResources();
for (ContextEnvironment environment : naming.findEnvironments()) {
@@ -813,16 +691,7 @@ public class TomcatWebAppBuilder impleme
envEntry.setEnvEntryType(environment.getType());
}
- // process the annotations
- try {
- AnnotationDeployer annotationDeployer = new AnnotationDeployer();
- annotationDeployer.deploy(webModule);
- } catch (OpenEJBException e) {
- logger.error("Unable to process annotation in " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
- }
-
// remove all jndi entries where there is a configured Tomcat resource or resource-link
- webApp = webModule.getWebApp();
for (ContextResource resource : naming.findResources()) {
String name = resource.getName();
removeRef(webApp, name);
@@ -840,85 +709,6 @@ public class TomcatWebAppBuilder impleme
}
}
- return webModule;
- }
-
- /**
- * Finds all faces configuration files and stores them in the WebModule.
- *
- * @param webModule web module
- * @throws OpenEJBException for exception
- */
- private static void addFacesConfigs(WebModule webModule) throws OpenEJBException {
- //*************************IMPORTANT*******************************************
- // This method is an exact copy of org.apache.openejb.config.DeploymentLoader.addFacesConfigs(WebModule webModule)
- // Any changes to this method here would most probably need to also be reflected in the DeploymentLoader.addFacesConfigs method.
- //*************************IMPORTANT*******************************************
- // TODO : kmalhi :: Add support to scrape META-INF/faces-config.xml in jar files
- // look at section 10.4.2 of the JSF v1.2 spec, bullet 1 for details
- Set<URL> facesConfigLocations = new HashSet<URL>();
-
- // web.xml contains faces config locations in the context parameter javax.faces.CONFIG_FILES
- File warFile = new File(webModule.getJarLocation());
- WebApp webApp = webModule.getWebApp();
- if (webApp != null) {
- List<ParamValue> contextParam = webApp.getContextParam();
- for (ParamValue value : contextParam) {
- boolean foundContextParam = value.getParamName().trim().equals("javax.faces.CONFIG_FILES");
- if (foundContextParam) {
- // the value is a comma separated list of config files
- String commaDelimitedListOfFiles = value.getParamValue().trim();
- String[] configFiles = commaDelimitedListOfFiles.split(",");
- // trim any extra spaces in each file
- String[] trimmedConfigFiles = new String[configFiles.length];
- for (int i = 0; i < configFiles.length; i++) {
- trimmedConfigFiles[i] = configFiles[i].trim();
- }
- // convert each file to a URL and add it to facesConfigLocations
- for (String location : trimmedConfigFiles) {
- if (!location.startsWith("/")) {
- logger.error("A faces configuration file should be context relative when specified in web.xml. Please fix the value of context parameter javax.faces.CONFIG_FILES for the file " + location);
- }
- try {
- File file = new File(warFile, location).getCanonicalFile().getAbsoluteFile();
- URL url = file.toURI().toURL();
- facesConfigLocations.add(url);
-
- } catch (IOException e) {
- logger.error("Faces configuration file location bad: " + location, e);
- }
- }
- break;
- }
- }
-
- }
-
- // Search for WEB-INF/faces-config.xml
- File webInf = new File(warFile, "WEB-INF");
- if (webInf.isDirectory()) {
- File facesConfigFile = new File(webInf, "faces-config.xml");
- if (facesConfigFile.exists()) {
- try {
- facesConfigFile = facesConfigFile.getCanonicalFile().getAbsoluteFile();
- URL url = facesConfigFile.toURI().toURL();
- facesConfigLocations.add(url);
- } catch (IOException e) {
- logger.error("addFacesConfigs: Failed to process facesConfigFile", e);
- }
- }
- }
- // load the faces configuration files
- // TODO:kmalhi:: Its good to have separate FacesConfig objects for multiple configuration files, but what if there is a conflict where the same
- // managebean is declared in two different files, which one wins? -- check the jsf spec, Hopefully JSF should be able to check for this and
- // flag an error and not allow the application to be deployed.
- for (URL location : facesConfigLocations) {
- FacesConfig facesConfig = ReadDescriptors.readFacesConfig(location);
- webModule.getFacesConfigs().add(facesConfig);
- if ("file".equals(location.getProtocol())) {
- webModule.getWatchedResources().add(URLs.toFilePath(location));
- }
- }
}
/**
@@ -939,25 +729,6 @@ public class TomcatWebAppBuilder impleme
}
/**
- * Gets urls in a web application.
- *
- * @param standardContext context
- * @return list of url
- */
- private List<URL> getUrls(StandardContext standardContext) {
- List<URL> urls = null;
- try {
- ClassLoader classLoader = standardContext.getLoader().getClassLoader();
- UrlSet urlSet = new UrlSet(classLoader);
- urlSet = urlSet.exclude(classLoader.getParent());
- urls = urlSet.getUrls();
- } catch (IOException e) {
- logger.warning("Unable to determine URLs in web application " + standardContext.getPath(), e);
- }
- return urls;
- }
-
- /**
* Binds given object into given component context.
*
* @param comp context
Modified: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWsRegistry.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWsRegistry.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWsRegistry.java (original)
+++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWsRegistry.java Fri Jan 7 16:03:17 2011
@@ -36,11 +36,14 @@ import org.apache.catalina.core.Standard
import org.apache.catalina.deploy.LoginConfig;
import org.apache.catalina.deploy.SecurityCollection;
import org.apache.catalina.deploy.SecurityConstraint;
+import org.apache.openejb.ClassLoaderUtil;
+import org.apache.openejb.core.webservices.JaxWsUtils;
import org.apache.openejb.server.httpd.HttpListener;
import org.apache.openejb.server.webservices.WsRegistry;
import org.apache.openejb.server.webservices.WsServlet;
import org.apache.openejb.tomcat.loader.TomcatHelper;
+import static org.apache.openejb.tomcat.catalina.BackportUtil.getServlet;
import static org.apache.openejb.tomcat.catalina.TomcatWebAppBuilder.IGNORE_CONTEXT;
import java.net.URI;
@@ -84,6 +87,14 @@ public class TomcatWsRegistry implements
throw new IllegalArgumentException("Could not find servlet " + contextRoot + " in web application context " + context.getName());
}
+ // for Pojo web services, we need to change the servlet class which is the service implementation
+ // by the WsServler class
+ wrapper.setServletClass(WsServlet.class.getName());
+ if (getServlet(wrapper) != null) {
+ wrapper.load();
+ wrapper.unload();
+ }
+
setWsContainer(context, wrapper, wsContainer);
// add service locations
@@ -217,7 +228,7 @@ public class TomcatWsRegistry implements
wrapper.setName("webservice");
wrapper.setServletClass(WsServlet.class.getName());
- // add add servlet to context
+ // add servlet to context
context.addChild(wrapper);
wrapper.addMapping("/*");
context.addServletMapping("/*", "webservice");
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java Fri Jan 7 16:03:17 2011
@@ -66,6 +66,14 @@ public class ClassLoaderUtil {
});
}
+ public static File getUrlCachedName(String appId, URL url) {
+ return urlCache.getUrlCachedName(appId, url);
+ }
+
+ public static boolean isUrlCached(String appId, URL url) {
+ return urlCache.isUrlCached(appId, url);
+ }
+
public static URLClassLoader createClassLoader(String appId, URL[] urls, ClassLoader parent) {
urls = urlCache.cacheUrls(appId, urls);
URLClassLoader classLoader = new URLClassLoader(urls, parent);
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Fri Jan 7 16:03:17 2011
@@ -16,54 +16,9 @@
*/
package org.apache.openejb.config;
-import static org.apache.openejb.config.DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY;
-
-import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Collection;
-import java.util.Set;
-
import org.apache.openejb.OpenEJBException;
import org.apache.openejb.Vendor;
-import org.apache.openejb.assembler.classic.AppInfo;
-import org.apache.openejb.assembler.classic.Assembler;
-import org.apache.openejb.assembler.classic.BmpEntityContainerInfo;
-import org.apache.openejb.assembler.classic.ClientInfo;
-import org.apache.openejb.assembler.classic.CmpEntityContainerInfo;
-import org.apache.openejb.assembler.classic.ConnectionManagerInfo;
-import org.apache.openejb.assembler.classic.ConnectorInfo;
-import org.apache.openejb.assembler.classic.ContainerInfo;
-import org.apache.openejb.assembler.classic.ContainerSystemInfo;
-import org.apache.openejb.assembler.classic.EjbJarInfo;
-import org.apache.openejb.assembler.classic.FacilitiesInfo;
-import org.apache.openejb.assembler.classic.HandlerChainInfo;
-import org.apache.openejb.assembler.classic.HandlerInfo;
-import org.apache.openejb.assembler.classic.JndiContextInfo;
-import org.apache.openejb.assembler.classic.MdbContainerInfo;
-import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
-import org.apache.openejb.assembler.classic.OpenEjbConfigurationFactory;
-import org.apache.openejb.assembler.classic.ProxyFactoryInfo;
-import org.apache.openejb.assembler.classic.ResourceInfo;
-import org.apache.openejb.assembler.classic.SecurityServiceInfo;
-import org.apache.openejb.assembler.classic.ServiceInfo;
-import org.apache.openejb.assembler.classic.StatefulSessionContainerInfo;
-import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
-import org.apache.openejb.assembler.classic.TransactionServiceInfo;
-import org.apache.openejb.assembler.classic.WebAppInfo;
-import org.apache.openejb.assembler.classic.SingletonSessionContainerInfo;
-import org.apache.openejb.assembler.classic.ManagedContainerInfo;
-import static org.apache.openejb.config.ServiceUtils.implies;
+import org.apache.openejb.assembler.classic.*;
import org.apache.openejb.config.sys.AbstractService;
import org.apache.openejb.config.sys.ConnectionManager;
import org.apache.openejb.config.sys.Container;
@@ -82,14 +37,34 @@ import org.apache.openejb.jee.Handler;
import org.apache.openejb.jee.HandlerChain;
import org.apache.openejb.jee.HandlerChains;
import org.apache.openejb.jee.ParamValue;
-import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.loader.FileUtils;
import org.apache.openejb.loader.Options;
+import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
import org.apache.openejb.util.Messages;
import org.apache.openejb.util.SuperProperties;
import org.apache.openejb.util.URISupport;
+import org.apache.openejb.util.URLs;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.apache.openejb.config.DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY;
+import static org.apache.openejb.config.ServiceUtils.implies;
public class ConfigurationFactory implements OpenEjbConfigurationFactory {
@@ -413,14 +388,14 @@ public class ConfigurationFactory implem
FileUtils base = SystemInstance.get().getBase();
- List<String> declaredApps = new ArrayList<String>(deployments.size());
+ List<URL> declaredAppsUrls = new ArrayList<URL>();
try {
for (Deployments deployment : deployments) {
- DeploymentsResolver.loadFrom(deployment, base, declaredApps);
+ DeploymentsResolver.loadFrom(deployment, base, declaredAppsUrls);
}
} catch (SecurityException ignored) {
}
- return declaredApps;
+ return toString(declaredAppsUrls);
}
public ArrayList<File> getModulesFromClassPath(List<String> declaredApps, ClassLoader classLoader) {
@@ -428,19 +403,29 @@ public class ConfigurationFactory implem
if (declaredApps == null) {
declaredApps = getDeclaredApps();
}
- List<String> classpathApps = new ArrayList<String>();
-
- DeploymentsResolver.loadFromClasspath(base, classpathApps, classLoader);
+ List<URL> classpathAppsUrls = new ArrayList<URL>();
+ DeploymentsResolver.loadFromClasspath(base, classpathAppsUrls, classLoader);
ArrayList<File> jarFiles = new ArrayList<File>();
- for (String path : classpathApps) {
- if (declaredApps.contains(path)) continue;
+ for (URL path : classpathAppsUrls) {
+ if (declaredApps.contains(URLs.toFilePath(path))) continue;
- jarFiles.add(new File(path));
+ jarFiles.add(new File(URLs.toFilePath(path)));
}
return jarFiles;
}
+ private List<String> toString (List<URL> urls) {
+ List<String> toReturn = new ArrayList<String>(urls.size());
+ for (URL url : urls) {
+ try {
+ toReturn.add(url.toString());
+ } catch (Exception ignore) {
+ }
+ }
+ return toReturn;
+ }
+
public ContainerInfo createContainerInfo(Container container) throws OpenEJBException {
Class<? extends ContainerInfo> infoClass = getContainerInfoType(container.getType());
if (infoClass == null) {
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java Fri Jan 7 16:03:17 2011
@@ -17,34 +17,6 @@
*/
package org.apache.openejb.config;
-import static org.apache.openejb.util.URLs.toFile;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-
-import javax.xml.bind.JAXBException;
-
import org.apache.openejb.ClassLoaderUtil;
import org.apache.openejb.OpenEJB;
import org.apache.openejb.OpenEJBException;
@@ -65,6 +37,8 @@ import org.apache.openejb.jee.TldTaglib;
import org.apache.openejb.jee.WebApp;
import org.apache.openejb.jee.WebserviceDescription;
import org.apache.openejb.jee.Webservices;
+import org.apache.openejb.loader.FileUtils;
+import org.apache.openejb.loader.Options;
import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.util.AnnotationFinder;
import org.apache.openejb.util.JarExtractor;
@@ -76,10 +50,38 @@ import org.apache.xbean.finder.ResourceF
import org.apache.xbean.finder.UrlSet;
import org.xml.sax.SAXException;
+import javax.xml.bind.JAXBException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import static org.apache.openejb.util.URLs.toFile;
+
/**
* @version $Revision$ $Date$
*/
-public class DeploymentLoader {
+public class DeploymentLoader implements DeploymentFilterable {
public static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, "org.apache.openejb.util.resources");
public static final Set<Class<? extends DeploymentModule>> ALL_SUPPORTED_MODULE_TYPES;
private static final String OPENEJB_ALTDD_PREFIX = "openejb.altdd.prefix";
@@ -111,7 +113,7 @@ public class DeploymentLoader {
public DeploymentLoader(String ddDir, Set<Class<? extends DeploymentModule>> loadingRequiredModuleTypes) {
this.ddDir = ddDir;
//Might always need AppModule, as without it, we might ignore the EAR type application
- if(loadingRequiredModuleTypes == ALL_SUPPORTED_MODULE_TYPES) {
+ if (loadingRequiredModuleTypes == ALL_SUPPORTED_MODULE_TYPES) {
this.loadingRequiredModuleTypes = loadingRequiredModuleTypes;
} else {
this.loadingRequiredModuleTypes = new HashSet<Class<? extends DeploymentModule>>(loadingRequiredModuleTypes);
@@ -163,9 +165,9 @@ public class DeploymentLoader {
// when we have a possible ejb-jar file (only ejb-jars result in a ClassFinder being used)
URL tempURL = baseUrl;
if (jarFile.isFile() && UrlCache.cacheDir != null &&
- !jarFile.getName().endsWith(".ear") &&
- !jarFile.getName().endsWith(".war") &&
- !jarFile.getName().endsWith(".rar")) {
+ !jarFile.getName().endsWith(".ear") &&
+ !jarFile.getName().endsWith(".war") &&
+ !jarFile.getName().endsWith(".rar")) {
try {
tmpFile = File.createTempFile("AppModule-", "", UrlCache.cacheDir);
JarExtractor.copy(URLs.toFile(baseUrl), tmpFile);
@@ -231,7 +233,7 @@ public class DeploymentLoader {
final File file = toFile(baseUrl);
AppModule appModule = new AppModule(OpenEJB.class.getClassLoader(), file.getAbsolutePath());
- addWebModule(appModule, baseUrl, OpenEJB.class.getClassLoader(), null, null);
+ addWebModule(appModule, baseUrl, OpenEJB.class.getClassLoader(), getContextRoot(), getModuleName());
return appModule;
} else if (PersistenceModule.class.equals(moduleClass) && loadingRequiredModuleTypes.contains(PersistenceModule.class)) {
String jarLocation = URLs.toFilePath(baseUrl);
@@ -323,6 +325,9 @@ public class DeploymentLoader {
HashMap<String, URL> files = new HashMap<String, URL>();
scanDir(appDir, files, "");
files.remove("META-INF/MANIFEST.MF");
+
+ // todo we should also filter URLs here using DeploymentsResolver.loadFromClasspath
+
for (Map.Entry<String, URL> entry : files.entrySet()) {
if (entry.getKey().startsWith("lib/")) continue;
if (!entry.getKey().matches(".*\\.(jar|war|rar|ear)")) continue;
@@ -339,7 +344,7 @@ public class DeploymentLoader {
resouceModules.put(entry.getKey(), entry.getValue());
} else if (WebModule.class.equals(moduleType)
&& (loadingRequiredModuleTypes.contains(WebModule.class) || loadingRequiredModuleTypes.contains(EjbModule.class) || loadingRequiredModuleTypes
- .contains(PersistenceModule.class))) {
+ .contains(PersistenceModule.class))) {
webModules.put(entry.getKey(), entry.getValue());
}
} catch (UnsupportedOperationException e) {
@@ -430,6 +435,13 @@ public class DeploymentLoader {
for (String moduleName : ejbModules.keySet()) {
try {
URL ejbUrl = ejbModules.get(moduleName);
+ // we should try to use a reference to the temp classloader
+ if (ClassLoaderUtil.isUrlCached(appModule.getJarLocation(), ejbUrl)) {
+ try {
+ ejbUrl = ClassLoaderUtil.getUrlCachedName(appModule.getJarLocation(), ejbUrl).toURI().toURL();
+
+ } catch (MalformedURLException ignore) { }
+ }
File ejbFile = toFile(ejbUrl);
String absolutePath = ejbFile.getAbsolutePath();
@@ -446,6 +458,13 @@ public class DeploymentLoader {
for (String moduleName : clientModules.keySet()) {
try {
URL clientUrl = clientModules.get(moduleName);
+ // we should try to use a reference to the temp classloader
+ if (ClassLoaderUtil.isUrlCached(appModule.getJarLocation(), clientUrl)) {
+ try {
+ clientUrl = ClassLoaderUtil.getUrlCachedName(appModule.getJarLocation(), clientUrl).toURI().toURL();
+
+ } catch (MalformedURLException ignore) { }
+ }
File clientFile = toFile(clientUrl);
String absolutePath = clientFile.getAbsolutePath();
@@ -461,6 +480,13 @@ public class DeploymentLoader {
for (String moduleName : resouceModules.keySet()) {
try {
URL rarUrl = resouceModules.get(moduleName);
+ // we should try to use a reference to the temp classloader
+ if (ClassLoaderUtil.isUrlCached(appModule.getJarLocation(), rarUrl)) {
+ try {
+ rarUrl = ClassLoaderUtil.getUrlCachedName(appModule.getJarLocation(), rarUrl).toURI().toURL();
+
+ } catch (MalformedURLException ignore) { }
+ }
ConnectorModule connectorModule = createConnectorModule(appId, URLs.toFilePath(rarUrl), appClassLoader, moduleName);
appModule.getConnectorModules().add(connectorModule);
@@ -479,9 +505,16 @@ public class DeploymentLoader {
}
}
+ // Persistence Units
if (loadingRequiredModuleTypes.contains(PersistenceModule.class)) {
- // Persistence Units
- addPersistenceUnits(appModule, urls);
+ // we don't need all URLs here but only a filtered list
+ // moreover, we should use cached (tempclassloader) instead
+ Properties p = new Properties();
+ p.put(appModule.getModuleId(), appModule.getJarLocation());
+ FileUtils base = new FileUtils(appModule.getModuleId(), appModule.getModuleId(), p);
+ List<URL> filteredUrls = new ArrayList<URL>();
+ DeploymentsResolver.loadFromClasspath(base, filteredUrls, appModule.getClassLoader());
+ addPersistenceUnits(appModule, filteredUrls.toArray(new URL[filteredUrls.size()]));
}
return appModule;
@@ -565,66 +598,84 @@ public class DeploymentLoader {
}
protected void addWebModule(AppModule appModule, URL warUrl, ClassLoader parentClassLoader, String contextRoot, String moduleName) throws OpenEJBException {
+
+ // create and add the WebModule
String warPath = URLs.toFilePath(warUrl);
WebModule webModule = createWebModule(appModule.getJarLocation(), warPath, parentClassLoader, contextRoot, moduleName);
if (loadingRequiredModuleTypes.contains(WebModule.class)) {
appModule.getWebModules().add(webModule);
}
+ // get urls in web application
+ List<URL> urls = new ArrayList<URL>();
ClassLoader webClassLoader = webModule.getClassLoader();
- if (loadingRequiredModuleTypes.contains(EjbModule.class)) {
- boolean addEjbModule = false;
- EjbJar ejbJar = null;
- URL ejbJarXmlUrl = (URL) webModule.getAltDDs().get("ejb-jar.xml");
- if (ejbJarXmlUrl == null) {
- if (webModule.getWebApp() != null && webModule.getWebApp().isMetadataComplete()) {
- addEjbModule = false;
- } else {
- // get urls in web application
- List<URL> urls = null;
- try {
- UrlSet urlSet = new UrlSet(webClassLoader);
- urlSet = urlSet.exclude(webClassLoader.getParent().getParent());
- urls = urlSet.getUrls();
- } catch (IOException e) {
- logger.warning("Unable to determine URLs in classloader", e);
- }
+ // get include/exclude properties from context-param
+ Options contextParams = new Options(getContextParams(webModule.getWebApp().getContextParam()));
+ String include = contextParams.get(CLASSPATH_INCLUDE, "");
+ String exclude = contextParams.get(CLASSPATH_EXCLUDE, ".*");
+ Set<RequireDescriptors> requireDescriptors = contextParams.getAll(CLASSPATH_REQUIRE_DESCRIPTOR, RequireDescriptors.CLIENT);
+ boolean filterDescriptors = contextParams.get(CLASSPATH_FILTER_DESCRIPTORS, false);
+ boolean filterSystemApps = contextParams.get(CLASSPATH_FILTER_SYSTEMAPPS, true);
+
+ contextParams.getProperties().put(moduleName, warPath);
+ FileUtils base = new FileUtils(moduleName, moduleName, contextParams.getProperties());
+ DeploymentsResolver.loadFromClasspath(base, urls, webClassLoader, include, exclude, requireDescriptors, filterDescriptors, filterSystemApps);
+
+ // we need to exclude previously deployed modules
+ UrlSet urlSet = new UrlSet(urls);
+ urlSet = urlSet.exclude(new UrlSet(appModule.getAdditionalLibraries())); // there should not be modules in /lib
+ for (EjbModule ejbModule : appModule.getEjbModules()) {
+ try {
+ urlSet = urlSet.exclude(new File(ejbModule.getJarLocation()));
- // clean jar URLs
- for (int i = 0; i < urls.size(); i++) {
- URL url = urls.get(i);
- if (url.getProtocol().equals("jar")) {
- try {
- url = new URL(url.getFile().replaceFirst("!.*$", ""));
- urls.set(i, url);
- } catch (MalformedURLException ignored) {
- }
- }
- }
+ } catch (MalformedURLException ignore) { }
+ }
+ for (ClientModule clientModule : appModule.getClientModules()) {
+ try {
+ urlSet = urlSet.exclude(new File(clientModule.getJarLocation()));
+ } catch (MalformedURLException ignore) { }
+ }
+ // for persistence.xml, there is already a check in addPersistenceUnit to remove duplicates
+ urls = urlSet.getUrls();
- addEjbModule = checkAnnotations(urls, webClassLoader, true, false) != null;
- }
- } else {
- addEjbModule = true;
- ejbJar = ReadDescriptors.readEjbJar(ejbJarXmlUrl);
- }
+ // save the filtered list so that it can be used elsewhere
+ webModule.setFilteredUrls(urls);
+
+ // Check each URL to determine if it is an EJB jar
+ for (URL url : urls) {
+ try {
+ Class moduleType = discoverModuleType(url, webClassLoader, true);
+
+ File file = toFile(url);
+ String absolutePath = file.getAbsolutePath();
+
+ if (EjbModule.class.isAssignableFrom(moduleType) && loadingRequiredModuleTypes.contains(EjbModule.class)) {
+ logger.info("Found ejb module " + moduleType.getSimpleName() + " in war " + contextRoot);
+
+ EjbModule ejbModule = createEjbModule(url, absolutePath, webClassLoader, getModuleName());
+ appModule.getEjbModules().add(ejbModule);
- if (addEjbModule) {
- EjbModule ejbModule = new EjbModule(webClassLoader, webModule.getModuleId(), warPath, ejbJar, null);
- ejbModule.getAltDDs().putAll(webModule.getAltDDs());
- if (loadingRequiredModuleTypes.contains(WsModule.class)) {
- addWebservices(ejbModule);
}
- appModule.getEjbModules().add(ejbModule);
+ } catch (IOException e) {
+ logger.warning("Unable to determine the module type of " + url.toExternalForm() + ": Exception: " + e.getMessage(), e);
+ } catch (UnknownModuleTypeException ignore) {
}
}
if (loadingRequiredModuleTypes.contains(PersistenceModule.class)) {
// Persistence Units
- addPersistenceUnits(appModule);
+ addPersistenceUnits(appModule, urls.toArray(new URL[urls.size()]));
+ }
+ }
+
+ private Properties getContextParams(List<ParamValue> contextParam) {
+ Properties properties = new Properties();
+ for (ParamValue paramValue : contextParam) {
+ properties.put(paramValue.getParamName(), paramValue.getParamValue());
}
+ return properties;
}
protected WebModule createWebModule(String appId, String warPath, ClassLoader parentClassLoader, String contextRoot, String moduleName) throws OpenEJBException {
@@ -674,6 +725,14 @@ public class DeploymentLoader {
return webModule;
}
+ protected String getContextRoot() {
+ return null;
+ }
+
+ protected String getModuleName() {
+ return null;
+ }
+
public static URL[] getWebappUrls(File warFile) {
List<URL> webClassPath = new ArrayList<URL>();
File webInfDir = new File(warFile, "WEB-INF");
@@ -818,9 +877,6 @@ public class DeploymentLoader {
*/
private void addFacesConfigs(WebModule webModule) throws OpenEJBException {
//*************************IMPORTANT*******************************************
- // This method is an exact copy of org.apache.openejb.tomcat.catalina.TomcatWebAppBuilder.addFacesConfigs(WebModule webModule)
- // Any changes to this method here would most probably need to also be reflected in the TomcatWebAppBuilder.addFacesConfigs method.
- //*************************IMPORTANT*******************************************
// TODO : kmalhi :: Add support to scrape META-INF/faces-config.xml in jar files
// look at section 10.4.2 of the JSF v1.2 spec, bullet 1 for details
Set<URL> facesConfigLocations = new HashSet<URL>();
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java Fri Jan 7 16:03:17 2011
@@ -40,18 +40,11 @@ import java.util.EnumSet;
/**
* @version $Rev$ $Date$
*/
-public class DeploymentsResolver {
+public class DeploymentsResolver implements DeploymentFilterable {
- public static final String DEPLOYMENTS_CLASSPATH_PROPERTY = "openejb.deployments.classpath";
- static final String SEARCH_CLASSPATH_FOR_DEPLOYMENTS_PROPERTY = DEPLOYMENTS_CLASSPATH_PROPERTY;
- public static final String CLASSPATH_INCLUDE = "openejb.deployments.classpath.include";
- private static final String CLASSPATH_EXCLUDE = "openejb.deployments.classpath.exclude";
- private static final String CLASSPATH_REQUIRE_DESCRIPTOR = RequireDescriptors.PROPERTY;
- private static final String CLASSPATH_FILTER_DESCRIPTORS = "openejb.deployments.classpath.filter.descriptors";
- private static final String CLASSPATH_FILTER_SYSTEMAPPS = "openejb.deployments.classpath.filter.systemapps";
private static final Logger logger = DeploymentLoader.logger;
- public static void loadFrom(Deployments dep, FileUtils path, List<String> jarList) {
+ public static void loadFrom(Deployments dep, FileUtils path, List<URL> jarList) {
////////////////////////////////
//
@@ -62,7 +55,7 @@ public class DeploymentsResolver {
try {
File jar = path.getFile(dep.getJar(), false);
if (!jarList.contains(jar.getAbsolutePath())) {
- jarList.add(jar.getAbsolutePath());
+ jarList.add(jar.toURI().toURL());
}
} catch (Exception ignored) {
}
@@ -84,26 +77,35 @@ public class DeploymentsResolver {
////////////////////////////////
File ejbJarXml = new File(dir, "META-INF" + File.separator + "ejb-jar.xml");
if (ejbJarXml.exists()) {
- if (!jarList.contains(dir.getAbsolutePath())) {
- jarList.add(dir.getAbsolutePath());
+ try {
+ if (!jarList.contains(dir.getAbsolutePath())) {
+ jarList.add(dir.toURI().toURL());
+ }
+ } catch (MalformedURLException ignore) {
}
return;
}
File appXml = new File(dir, "META-INF" + File.separator + "application.xml");
if (appXml.exists()) {
- if (!jarList.contains(dir.getAbsolutePath())) {
- jarList.add(dir.getAbsolutePath());
+ try {
+ if (!jarList.contains(dir.getAbsolutePath())) {
+ jarList.add(dir.toURI().toURL());
+ }
+ } catch (MalformedURLException ignore) {
}
return;
}
File raXml = new File(dir, "META-INF" + File.separator + "ra.xml");
- if (raXml.exists()) {
- if (!jarList.contains(dir.getAbsolutePath())) {
- jarList.add(dir.getAbsolutePath());
- }
- return;
+ if (raXml.exists()) {
+ try {
+ if (!jarList.contains(dir.getAbsolutePath())) {
+ jarList.add(dir.toURI().toURL());
+ }
+ } catch (MalformedURLException ignore) {
+ }
+ return;
}
////////////////////////////////
@@ -113,16 +115,19 @@ public class DeploymentsResolver {
////////////////////////////////
boolean hasNestedArchives = false;
for (File file : dir.listFiles()) {
- if (file.getName().endsWith(".jar") || file.getName().endsWith(".war")|| file.getName().endsWith(".rar")|| file.getName().endsWith(".ear")) {
- if (jarList.contains(file.getAbsolutePath())) continue;
- jarList.add(file.getAbsolutePath());
- hasNestedArchives = true;
- } else if (new File(file, "META-INF").exists()){ // Unpacked ear or jar
- jarList.add(file.getAbsolutePath());
- hasNestedArchives = true;
- } else if (new File(file, "WEB-INF").exists()){ // Unpacked webapp
- jarList.add(file.getAbsolutePath());
- hasNestedArchives = true;
+ try {
+ if (file.getName().endsWith(".jar") || file.getName().endsWith(".war")|| file.getName().endsWith(".rar")|| file.getName().endsWith(".ear")) {
+ if (jarList.contains(file.getAbsolutePath())) continue;
+ jarList.add(file.toURI().toURL());
+ hasNestedArchives = true;
+ } else if (new File(file, "META-INF").exists()){ // Unpacked ear or jar
+ jarList.add(file.toURI().toURL());
+ hasNestedArchives = true;
+ } else if (new File(file, "WEB-INF").exists()){ // Unpacked webapp
+ jarList.add(file.toURI().toURL());
+ hasNestedArchives = true;
+ }
+ } catch (Exception ignore) {
}
}
@@ -136,8 +141,11 @@ public class DeploymentsResolver {
DeploymentLoader.scanDir(dir, files, "");
for (String fileName : files.keySet()) {
if (fileName.endsWith(".class")) {
- if (!jarList.contains(dir.getAbsolutePath())) {
- jarList.add(dir.getAbsolutePath());
+ try {
+ if (!jarList.contains(dir.getAbsolutePath())) {
+ jarList.add(dir.toURI().toURL());
+ }
+ } catch (MalformedURLException ignore) {
}
return;
}
@@ -161,8 +169,7 @@ public class DeploymentsResolver {
* 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(FileUtils base, List<String> jarList, ClassLoader classLoader) {
-
+ public static void loadFromClasspath(FileUtils base, List<URL> jarList, ClassLoader classLoader) {
Options options = SystemInstance.get().getOptions();
String include = options.get(CLASSPATH_INCLUDE, "");
String exclude = options.get(CLASSPATH_EXCLUDE, ".*");
@@ -170,6 +177,14 @@ public class DeploymentsResolver {
boolean filterDescriptors = options.get(CLASSPATH_FILTER_DESCRIPTORS, false);
boolean filterSystemApps = options.get(CLASSPATH_FILTER_SYSTEMAPPS, true);
+ loadFromClasspath(base, jarList, classLoader,
+ include, exclude, requireDescriptors, filterDescriptors, filterSystemApps);
+ }
+
+ public static void loadFromClasspath(FileUtils base, List<URL> jarList, ClassLoader classLoader,
+ String include, String exclude, Set<RequireDescriptors> requireDescriptors,
+ boolean filterDescriptors, boolean filterSystemApps) {
+
try {
UrlSet urlSet = new UrlSet(classLoader);
UrlSet includes = urlSet.matching(include);
@@ -358,7 +373,7 @@ public class DeploymentsResolver {
return urlSet;
}
- private static void processUrls(List<URL> urls, ClassLoader classLoader, Set<RequireDescriptors> requireDescriptors, FileUtils base, List<String> jarList) {
+ private static void processUrls(List<URL> urls, ClassLoader classLoader, Set<RequireDescriptors> requireDescriptors, FileUtils base, List<URL> jarList) {
for (URL url : urls) {
Deployments deployment;
String path;
@@ -385,7 +400,7 @@ public class DeploymentsResolver {
loadFrom(deployment, base, jarList);
} else {
if (!jarList.contains(path)){
- jarList.add(path);
+ jarList.add(url);
}
}
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java Fri Jan 7 16:03:17 2011
@@ -44,10 +44,13 @@ public class FinderFactory {
public AbstractFinder create(DeploymentModule module) throws Exception {
if (module instanceof WebModule) {
WebModule webModule = (WebModule) module;
- File file = new File(webModule.getJarLocation());
- URL[] urls = DeploymentLoader.getWebappUrls(file);
final ClassLoader webClassLoader = webModule.getClassLoader();
- return new ClassFinder(webClassLoader, asList(urls));
+ if (webModule.getFilteredUrls() == null) {
+ return new ClassFinder(webClassLoader);
+
+ } else {
+ return new ClassFinder(webClassLoader, webModule.getFilteredUrls());
+ }
}
if (module.getJarLocation() != null) {
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java Fri Jan 7 16:03:17 2011
@@ -17,6 +17,7 @@
package org.apache.openejb.config;
import java.io.File;
+import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -50,6 +51,8 @@ public class WebModule implements WsModu
private final List<FacesConfig> facesConfigs = new ArrayList<FacesConfig>();
private AbstractFinder finder;
+ // keep the list of filtered URL we got after applying include/exclude pattern (@See DeploymentsResolver.loadFromClasspath)
+ private List<URL> filteredUrls;
public WebModule(WebApp webApp, String contextRoot, ClassLoader classLoader, String jarLocation, String moduleId) {
this.webApp = webApp;
@@ -90,6 +93,14 @@ public class WebModule implements WsModu
validation = new ValidationContext(WebModule.class, jarLocation);
}
+ public List<URL> getFilteredUrls() {
+ return filteredUrls;
+ }
+
+ public void setFilteredUrls(List<URL> filteredUrls) {
+ this.filteredUrls = filteredUrls;
+ }
+
public AbstractFinder getFinder() {
return finder;
}
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java Fri Jan 7 16:03:17 2011
@@ -128,9 +128,10 @@ public class WsDeployer implements Dynam
servletMappings.put(servletMapping.getServletName(), servletMapping);
}
- // add port declarations for webservices
+ // add port declarations for Pojo webservices
WebserviceDescription webserviceDescription;
for (Servlet servlet : webApp.getServlet()) {
+ // the implementation class will be replaced by the WsServlet in the WsRegistry
String className = servlet.getServletClass();
// Skip JSPs
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java Fri Jan 7 16:03:17 2011
@@ -247,16 +247,21 @@ public class JaxWsUtils {
public static String getServiceInterface(Class<?> clazz) {
WebService webService = clazz.getAnnotation(WebService.class);
+ String endpointInterface = null;
if (webService != null && webService.endpointInterface() != null) {
- String endpointInterface = webService.endpointInterface().trim();
- if (endpointInterface.length() == 0) endpointInterface = null;
- return endpointInterface;
+ endpointInterface = webService.endpointInterface().trim();
+ if (endpointInterface.length() == 0) {
+ endpointInterface = null;
+
+ } else {
+ return endpointInterface;
+ }
}
// if the bean implements only one WebService class, that is the SEI
- String endpointInterface = null;
- for (Class intf : clazz.getInterfaces()) {
- webService = clazz.getAnnotation(WebService.class);
+ for (Class<?> intf : clazz.getInterfaces()) {
+ // interface MUST also have a @WebService
+ webService = intf.getAnnotation(WebService.class);
if (webService != null) {
if (endpointInterface == null) {
endpointInterface = intf.getName();
@@ -268,11 +273,7 @@ public class JaxWsUtils {
}
}
- if (endpointInterface != null) {
- return endpointInterface;
- }
-
- return null;
+ return endpointInterface;
}
public static String getServiceWsdlLocation(Class<?> clazz, ClassLoader loader) {
Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java Fri Jan 7 16:03:17 2011
@@ -138,6 +138,19 @@ public class UrlCache {
}
}
+ public File getUrlCachedName(String appId, URL url) {
+ Map<URL, File> appCache = getAppCache(appId);
+ if (appCache.containsKey(url)) {
+ return appCache.get(url);
+ }
+ return null;
+ }
+
+ public boolean isUrlCached(String appId, URL url) {
+ Map<URL, File> appCache = getAppCache(appId);
+ return appCache.containsKey(url);
+ }
+
private synchronized File cacheUrl(String appId, URL url) {
File sourceFile;
if (!"file".equals(url.getProtocol())) {
Modified: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ClassPathApplication.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ClassPathApplication.java?rev=1056366&r1=1056365&r2=1056366&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ClassPathApplication.java (original)
+++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ClassPathApplication.java Fri Jan 7 16:03:17 2011
@@ -18,6 +18,7 @@
package org.apache.openejb.spring;
import java.io.File;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -33,6 +34,7 @@ import org.apache.openejb.assembler.clas
import org.apache.openejb.config.ConfigurationFactory;
import org.apache.openejb.config.DeploymentsResolver;
import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.util.URLs;
@Exported
public class ClassPathApplication extends AbstractApplication {
@@ -50,18 +52,18 @@ public class ClassPathApplication extend
protected List<AppInfo> loadApplications() throws OpenEJBException {
Set<String> declaredApplications = getDeployedApplications();
- List<String> classpathApps = new ArrayList<String>();
+ List<URL> classpathApps = new ArrayList<URL>();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
DeploymentsResolver.loadFromClasspath(SystemInstance.get().getBase(), classpathApps, classLoader);
ArrayList<File> jarFiles = new ArrayList<File>();
- for (String path : classpathApps) {
- if (declaredApplications.contains(path)) continue;
+ for (URL path : classpathApps) {
+ if (declaredApplications.contains(URLs.toFilePath(path))) continue;
// todo hack to avoid picking up application.xml in openejb-core module
- if (path.indexOf("openejb-core/target/test-classes") > 0) continue;
+ if (URLs.toFilePath(path).indexOf("openejb-core/target/test-classes") > 0) continue;
- jarFiles.add(new File(path));
+ jarFiles.add(URLs.toFile(path));
}
List<AppInfo> appInfos = new ArrayList<AppInfo>();
Re: svn commit: r1056366 - in /openejb/trunk/openejb3: assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/ assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/ container/open...
Posted by David Jencks <da...@yahoo.com>.
Hi Jean-Louis,
An easy way to test a bunch of stuff without worrying about the ee tck :-) is to build geronimo (trunk) and then check out the open source tck runners and try the jcdi tck.
svn co https://svn.apache.org/repos/asf/geronimo/tck/branches/3.0
mvn clean install
to actually run the jcdi tck you need a fancier command line like
cd jcdi-tck-runner
mvn clean test -Dgeronimo-assembly -Dincontainer -DassemblyId=tomcat7-javaee6 -Dcurrent
hope this helps
thanks
david jencks
On Jan 10, 2011, at 12:05 AM, Jean-Louis MONTEIRO wrote:
>
> Hi David,
>
> It works under Tomcat because of the TomcatDeploymentLoader which overrides
> that method.
> Dunno how OpenEJB actually works in Geronimo.
>
> Definitely an area where i need to work on.
> If you have any inputs to help me, I'd be grateful.
>
> I mean, how can I test OpenEJB in Geronimo?
>
> Jean-Louis
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/Re-svn-commit-r1056366-in-openejb-trunk-openejb3-assembly-openejb-jetty-openejb-jetty-common-src-tes-tp3204818p3206724.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
Re: svn commit: r1056366 - in /openejb/trunk/openejb3:
assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/
assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/
container/open...
Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Hi David,
It works under Tomcat because of the TomcatDeploymentLoader which overrides
that method.
Dunno how OpenEJB actually works in Geronimo.
Definitely an area where i need to work on.
If you have any inputs to help me, I'd be grateful.
I mean, how can I test OpenEJB in Geronimo?
Jean-Louis
--
View this message in context: http://openejb.979440.n4.nabble.com/Re-svn-commit-r1056366-in-openejb-trunk-openejb3-assembly-openejb-jetty-openejb-jetty-common-src-tes-tp3204818p3206724.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.
Re: svn commit: r1056366 - in /openejb/trunk/openejb3: assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/ assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/ container/open...
Posted by David Jencks <da...@yahoo.com>.
I think theres a problem with this patch. It appears to break deployment of all web apps in geronimo. The code path I see involves
Caused by: java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:399)
at org.apache.openejb.config.DeploymentLoader.addWebModule(DeploymentLoader.java:621)
at org.apache.openejb.config.DeploymentLoader.load(DeploymentLoader.java:236)
line 236:
addWebModule(appModule, baseUrl, OpenEJB.class.getClassLoader(), getContextRoot(), getModuleName());
protected String getModuleName() {
return null;
}
line 621:
contextParams.getProperties().put(moduleName, warPath);
I don't see any way this code path can possibly avoid the NPE I'm seeing.
thanks
david jencks
On Jan 7, 2011, at 8:03 AM, jlmonteiro@apache.org wrote:
> Author: jlmonteiro
> Date: Fri Jan 7 16:03:17 2011
> New Revision: 1056366
>
> URL: http://svn.apache.org/viewvc?rev=1056366&view=rev
> Log:
> OPENEJB-1231 Webapp context.xml setting allows app to be ignored entirely by OpenEJB
> OPENEJB-1230 Webapp scanning include/exclude via context.xml settings
> OPENEJB-1417 webservices.xml not read when embedded in Tomcat
> OPENEJB-1418 Refactor TomcatWebAppBuilder
>
> Modified:
> openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/BootstrapTest.java
> openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java
> openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWsRegistry.java
> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java
> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java
> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java
> openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
> openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ClassPathApplication.java
>
> Modified: openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/BootstrapTest.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/BootstrapTest.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/BootstrapTest.java (original)
> +++ openejb/trunk/openejb3/assembly/openejb-jetty/openejb-jetty-common/src/test/java/org/apache/openejb/jetty/test/BootstrapTest.java Fri Jan 7 16:03:17 2011
> @@ -30,6 +30,8 @@ import javax.naming.InitialContext;
> import java.io.IOException;
>
> public class BootstrapTest {
> + private static final int SERVER_PORT = 8091;
> + private static final String SERVER_BASE_URL = "http://localhost:" + SERVER_PORT;
> private Server server;
>
> @Before
> @@ -37,7 +39,7 @@ public class BootstrapTest {
> OpenEJBLifecycle ejbLifecycle = new OpenEJBLifecycle();
> ejbLifecycle.addApplication("target/test/ejb-examples-1.1-SNAPSHOT.war");
>
> - server = new Server(9091);
> + server = new Server(SERVER_PORT);
> server.addBean(ejbLifecycle);
> ejbLifecycle.setServer(server);
> server.start();
> @@ -53,7 +55,7 @@ public class BootstrapTest {
>
> @Test
> public void testShouldInjectEjbsIntoServlet() throws Exception {
> - String url = "http://localhost:9091/annotated";
> + String url = SERVER_BASE_URL + "/annotated";
>
> String[] stringsToCheck = new String[] { "@EJB=proxy=org.superbiz.servlet.AnnotatedEJBLocal;deployment=AnnotatedEJB;pk=null",
> "@EJB.getName()=foo",
> @@ -78,7 +80,7 @@ public class BootstrapTest {
>
> @Test
> public void testShouldLoadPersistenceContext() throws Exception {
> - String url = "http://localhost:9091/jpa";
> + String url = SERVER_BASE_URL + "/jpa";
>
> String[] stringsToCheck = new String[] { "@PersistenceUnit=org.apache.openjpa.persistence.EntityManagerFactoryImpl",
> "Loaded [JpaBean id=",
> @@ -89,7 +91,7 @@ public class BootstrapTest {
>
> @Test
> public void testShouldJndiTree() throws Exception {
> - String url = "http://localhost:9091/jndi";
> + String url = SERVER_BASE_URL + "/jndi";
>
> String[] stringsToCheck = new String[] { "env=",
> "env/__=",
>
> Modified: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java (original)
> +++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java Fri Jan 7 16:03:17 2011
> @@ -46,36 +46,25 @@ import org.apache.openejb.assembler.clas
> import org.apache.openejb.assembler.classic.WebAppInfo;
> import org.apache.openejb.config.AnnotationDeployer;
> import org.apache.openejb.config.AppModule;
> -import org.apache.openejb.config.ClientModule;
> import org.apache.openejb.config.ConfigurationFactory;
> import org.apache.openejb.config.DeploymentLoader;
> -import org.apache.openejb.config.EjbModule;
> -import org.apache.openejb.config.ReadDescriptors;
> -import org.apache.openejb.config.UnknownModuleTypeException;
> import org.apache.openejb.config.WebModule;
> import org.apache.openejb.core.CoreContainerSystem;
> import org.apache.openejb.core.WebContext;
> import org.apache.openejb.core.ivm.naming.SystemComponentReference;
> import org.apache.openejb.core.webservices.JaxWsUtils;
> import org.apache.openejb.jee.EnvEntry;
> -import org.apache.openejb.jee.FacesConfig;
> -import org.apache.openejb.jee.ParamValue;
> import org.apache.openejb.jee.WebApp;
> import org.apache.openejb.loader.SystemInstance;
> import org.apache.openejb.server.webservices.WsService;
> import org.apache.openejb.server.webservices.WsServlet;
> import org.apache.openejb.spi.ContainerSystem;
> -import static org.apache.openejb.tomcat.catalina.BackportUtil.getNamingContextListener;
> -import static org.apache.openejb.tomcat.catalina.BackportUtil.getServlet;
> import org.apache.openejb.tomcat.common.LegacyAnnotationProcessor;
> import org.apache.openejb.tomcat.common.TomcatVersion;
> import org.apache.openejb.tomcat.loader.TomcatHelper;
> import org.apache.openejb.util.LinkResolver;
> import org.apache.openejb.util.LogCategory;
> import org.apache.openejb.util.Logger;
> -import org.apache.openejb.util.URLs;
> -import org.apache.xbean.finder.ResourceFinder;
> -import org.apache.xbean.finder.UrlSet;
> import org.omg.CORBA.ORB;
>
> import javax.ejb.spi.HandleDelegate;
> @@ -87,15 +76,15 @@ import javax.transaction.TransactionMana
> import javax.transaction.TransactionSynchronizationRegistry;
> import java.io.File;
> import java.io.IOException;
> -import java.net.URL;
> import java.util.HashMap;
> -import java.util.HashSet;
> import java.util.Iterator;
> import java.util.List;
> import java.util.Map;
> -import java.util.Set;
> import java.util.TreeMap;
>
> +import static org.apache.openejb.tomcat.catalina.BackportUtil.getNamingContextListener;
> +import static org.apache.openejb.tomcat.catalina.BackportUtil.getServlet;
> +
> /**
> * Web application builder.
> *
> @@ -301,9 +290,7 @@ public class TomcatWebAppBuilder impleme
> @SuppressWarnings("unchecked")
> @Override
> public void start(StandardContext standardContext) {
> - if (standardContext.getServletContext().getAttribute(IGNORE_CONTEXT) != null) {
> - return;
> - }
> + if (isIgnored(standardContext)) return;
>
> Assembler a = getAssembler();
> if (a == null) {
> @@ -369,9 +356,7 @@ public class TomcatWebAppBuilder impleme
> */
> @Override
> public void afterStart(StandardContext standardContext) {
> - if (standardContext.getServletContext().getAttribute(IGNORE_CONTEXT) != null) {
> - return;
> - }
> + if (isIgnored(standardContext)) return;
>
> // if appInfo is null this is a failed deployment... just ignore
> ContextInfo contextInfo = getContextInfo(standardContext);
> @@ -379,38 +364,6 @@ public class TomcatWebAppBuilder impleme
> return;
> }
>
> - WsService wsService = SystemInstance.get().getComponent(WsService.class);
> - if (wsService != null) {
> - List<WebAppInfo> webApps = contextInfo.appInfo.webApps;
> - for (WebAppInfo webApp : webApps) {
> - wsService.afterApplicationCreated(webApp);
> - }
> - }
> -
> - // replace any webservices with the webservice servlet
> - // HACK: use a temp class loader because the class may have been loaded before
> - // the openejb classes were added to the system class path so the WebService anntation
> - // will not be present on the class
> - ClassLoader tempClassLoader = ClassLoaderUtil.createTempClassLoader(standardContext.getLoader().getClassLoader());
> - for (Container container : standardContext.findChildren()) {
> - if (container instanceof Wrapper) {
> - Wrapper wrapper = (Wrapper) container;
> - String servletClass = wrapper.getServletClass();
> - try {
> - Class<?> clazz = tempClassLoader.loadClass(servletClass);
> - if (JaxWsUtils.isWebService(clazz)) {
> - wrapper.setServletClass(WsServlet.class.getName());
> - if (getServlet(wrapper) != null) {
> - wrapper.load();
> - wrapper.unload();
> - }
> - }
> - } catch (Exception e) {
> - // will be reported by the tomcat
> - }
> - }
> - }
> -
> // bind extra stuff at the java:comp level which can only be
> // bound after the context is created
> String listenerName = getNamingContextListener(standardContext).getName();
> @@ -471,6 +424,16 @@ public class TomcatWebAppBuilder impleme
> standardContext.getPipeline().addValve(openejbValve);
> }
>
> + private static boolean isIgnored(StandardContext standardContext) {
> + // useful to disable web applications deployment
> + // it can be placed in the context.xml file, server.xml, ...
> + // see http://tomcat.apache.org/tomcat-5.5-doc/config/context.html#Context_Parameters
> + if (standardContext.getServletContext().getAttribute(IGNORE_CONTEXT) != null) return true;
> + if (standardContext.getServletContext().getInitParameter(IGNORE_CONTEXT) != null) return true;
> +
> + return false;
> + }
> +
> /**
> * {@inheritDoc}
> */
> @@ -492,9 +455,7 @@ public class TomcatWebAppBuilder impleme
> */
> @Override
> public void afterStop(StandardContext standardContext) {
> - if (standardContext.getServletContext().getAttribute(IGNORE_CONTEXT) != null) {
> - return;
> - }
> + if (isIgnored(standardContext)) return;
>
> ContextInfo contextInfo = getContextInfo(standardContext);
> if (contextInfo != null && contextInfo.appInfo != null && contextInfo.deployer == null) {
> @@ -685,83 +646,20 @@ public class TomcatWebAppBuilder impleme
> * @return a openejb application module
> */
> private AppModule loadApplication(StandardContext standardContext) {
> - // create the web module
> - WebModule webModule = createWebModule(standardContext);
> -
> - // create the app module
> - AppModule appModule = new AppModule(webModule);
> -
> - // add the web module itself
> - appModule.getWebModules().add(webModule);
> -
> - // check each url to determine if it is an ejb jar
> - for (URL url : getUrls(standardContext)) {
> - try {
> - Class moduleType = new DeploymentLoader().discoverModuleType(url, standardContext.getLoader().getClassLoader(), true);
> - if (EjbModule.class.isAssignableFrom(moduleType)) {
> - File file;
> - if (url.getProtocol().equals("jar")) {
> - url = new URL(url.getFile().replaceFirst("!.*$", ""));
> - file = URLs.toFile(url);
> - } else if (url.getProtocol().equals("file")) {
> - file = URLs.toFile(url);
> - } else {
> - logger.warning("Not loading " + moduleType.getSimpleName() + ". Unknown protocol " + url.getProtocol());
> - continue;
> - }
> -
> - logger.info("Found ejb module " + moduleType.getSimpleName() + " in war " + standardContext.getPath());
> -
> -
> - // create the ejb module and set its moduleId to the webapp context root name
> - EjbModule ejbModule = new EjbModule(webModule.getClassLoader(), getEjbModuleId(standardContext), file.getAbsolutePath(), null, null);
> - ejbModule.setClientModule(new ClientModule(null, ejbModule.getClassLoader(), ejbModule.getJarLocation(), null, ejbModule.getModuleId()));
> -
> - // EJB deployment descriptors
> - try {
> - ResourceFinder ejbResourceFinder = new ResourceFinder("", standardContext.getLoader().getClassLoader(), file.toURI().toURL());
> - Map<String, URL> descriptors = ejbResourceFinder.getResourcesMap("META-INF/");
> - descriptors = DeploymentLoader.altDDSources(descriptors, true);
> - ejbModule.getAltDDs().putAll(descriptors);
> - ejbModule.getClientModule().getAltDDs().putAll(descriptors);
> - } catch (IOException e) {
> - logger.error("Unable to determine descriptors in jar.", e);
> - }
> -
> - // add module to app
> - appModule.getEjbModules().add(ejbModule);
> - }
> - } catch (IOException e) {
> - logger.warning("Unable to determine the module type of " + url.toExternalForm() + ": Exception: " + e.getMessage(), e);
> - } catch (UnknownModuleTypeException ignore) {
> - }
> -
> - }
> + ServletContext servletContext = standardContext.getServletContext();
>
> - // Persistence Units via META-INF/persistence.xml
> + TomcatDeploymentLoader tomcatDeploymentLoader = new TomcatDeploymentLoader(standardContext, getId(standardContext));
> + AppModule appModule = null;
> try {
> - ResourceFinder finder = new ResourceFinder("", standardContext.getLoader().getClassLoader());
> - List<URL> persistenceUrls = finder.findAll("META-INF/persistence.xml");
> - appModule.getAltDDs().put("persistence.xml", persistenceUrls);
> - } catch (IOException e) {
> - logger.warning("Cannot load persistence-units from 'META-INF/persistence.xml' : " + e.getMessage(), e);
> + appModule = tomcatDeploymentLoader.load(new File(servletContext.getRealPath(".")).getParentFile());
> + } catch (OpenEJBException e) {
> + throw new RuntimeException(e);
> }
>
> - return appModule;
> - }
> + // create the web module
> + loadWebModule(appModule, standardContext);
>
> - /**
> - * Strips off the / from the context root and returns the remaining String
> - *
> - * @param standardContext
> - * @return the name of the context root for the webapp
> - */
> - private String getEjbModuleId(StandardContext standardContext) {
> - String ejbModuleId = standardContext.getName();
> - if (ejbModuleId.startsWith("/")) {
> - ejbModuleId = ejbModuleId.substring(1);
> - }
> - return ejbModuleId;
> + return appModule;
> }
>
> /**
> @@ -771,34 +669,14 @@ public class TomcatWebAppBuilder impleme
> * @param standardContext tomcat context instance
> * @return a openejb web module
> */
> - private WebModule createWebModule(StandardContext standardContext) {
> - // todo replace this code with DeploymentLoader
> - ServletContext servletContext = standardContext.getServletContext();
> -
> - // read the web.xml
> - WebApp webApp = new WebApp();
> - try {
> - URL webXmlUrl = servletContext.getResource("/WEB-INF/web.xml");
> - if (webXmlUrl != null) {
> - webApp = ReadDescriptors.readWebApp(webXmlUrl);
> - }
> - } catch (Exception e) {
> - logger.error("Unable to load web.xml in war " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
> - }
> + private void loadWebModule(AppModule appModule, StandardContext standardContext) {
> + WebModule webModule = appModule.getWebModules().get(0);
> + WebApp webApp = webModule.getWebApp();
>
> // create the web module
> - String basePath = new File(servletContext.getRealPath(".")).getParentFile().getAbsolutePath();
> - ClassLoader classLoader = ClassLoaderUtil.createTempClassLoader(standardContext.getLoader().getClassLoader());
> String path = standardContext.getPath();
> System.out.println("context path = " + path);
> - WebModule webModule = new WebModule(webApp, path, classLoader, basePath, getId(standardContext));
> webModule.setHost(standardContext.getHostname());
> - // add faces configurations
> - try {
> - addFacesConfigs(webModule);
> - } catch (OpenEJBException e1) {
> - logger.error("Unable to add faces config modules in " + standardContext.getPath() + ": Exception: " + e1.getMessage(), e1);
> - }
> // Add all Tomcat env entries to context so they can be overriden by the env.properties file
> NamingResources naming = standardContext.getNamingResources();
> for (ContextEnvironment environment : naming.findEnvironments()) {
> @@ -813,16 +691,7 @@ public class TomcatWebAppBuilder impleme
> envEntry.setEnvEntryType(environment.getType());
> }
>
> - // process the annotations
> - try {
> - AnnotationDeployer annotationDeployer = new AnnotationDeployer();
> - annotationDeployer.deploy(webModule);
> - } catch (OpenEJBException e) {
> - logger.error("Unable to process annotation in " + standardContext.getPath() + ": Exception: " + e.getMessage(), e);
> - }
> -
> // remove all jndi entries where there is a configured Tomcat resource or resource-link
> - webApp = webModule.getWebApp();
> for (ContextResource resource : naming.findResources()) {
> String name = resource.getName();
> removeRef(webApp, name);
> @@ -840,85 +709,6 @@ public class TomcatWebAppBuilder impleme
> }
> }
>
> - return webModule;
> - }
> -
> - /**
> - * Finds all faces configuration files and stores them in the WebModule.
> - *
> - * @param webModule web module
> - * @throws OpenEJBException for exception
> - */
> - private static void addFacesConfigs(WebModule webModule) throws OpenEJBException {
> - //*************************IMPORTANT*******************************************
> - // This method is an exact copy of org.apache.openejb.config.DeploymentLoader.addFacesConfigs(WebModule webModule)
> - // Any changes to this method here would most probably need to also be reflected in the DeploymentLoader.addFacesConfigs method.
> - //*************************IMPORTANT*******************************************
> - // TODO : kmalhi :: Add support to scrape META-INF/faces-config.xml in jar files
> - // look at section 10.4.2 of the JSF v1.2 spec, bullet 1 for details
> - Set<URL> facesConfigLocations = new HashSet<URL>();
> -
> - // web.xml contains faces config locations in the context parameter javax.faces.CONFIG_FILES
> - File warFile = new File(webModule.getJarLocation());
> - WebApp webApp = webModule.getWebApp();
> - if (webApp != null) {
> - List<ParamValue> contextParam = webApp.getContextParam();
> - for (ParamValue value : contextParam) {
> - boolean foundContextParam = value.getParamName().trim().equals("javax.faces.CONFIG_FILES");
> - if (foundContextParam) {
> - // the value is a comma separated list of config files
> - String commaDelimitedListOfFiles = value.getParamValue().trim();
> - String[] configFiles = commaDelimitedListOfFiles.split(",");
> - // trim any extra spaces in each file
> - String[] trimmedConfigFiles = new String[configFiles.length];
> - for (int i = 0; i < configFiles.length; i++) {
> - trimmedConfigFiles[i] = configFiles[i].trim();
> - }
> - // convert each file to a URL and add it to facesConfigLocations
> - for (String location : trimmedConfigFiles) {
> - if (!location.startsWith("/")) {
> - logger.error("A faces configuration file should be context relative when specified in web.xml. Please fix the value of context parameter javax.faces.CONFIG_FILES for the file " + location);
> - }
> - try {
> - File file = new File(warFile, location).getCanonicalFile().getAbsoluteFile();
> - URL url = file.toURI().toURL();
> - facesConfigLocations.add(url);
> -
> - } catch (IOException e) {
> - logger.error("Faces configuration file location bad: " + location, e);
> - }
> - }
> - break;
> - }
> - }
> -
> - }
> -
> - // Search for WEB-INF/faces-config.xml
> - File webInf = new File(warFile, "WEB-INF");
> - if (webInf.isDirectory()) {
> - File facesConfigFile = new File(webInf, "faces-config.xml");
> - if (facesConfigFile.exists()) {
> - try {
> - facesConfigFile = facesConfigFile.getCanonicalFile().getAbsoluteFile();
> - URL url = facesConfigFile.toURI().toURL();
> - facesConfigLocations.add(url);
> - } catch (IOException e) {
> - logger.error("addFacesConfigs: Failed to process facesConfigFile", e);
> - }
> - }
> - }
> - // load the faces configuration files
> - // TODO:kmalhi:: Its good to have separate FacesConfig objects for multiple configuration files, but what if there is a conflict where the same
> - // managebean is declared in two different files, which one wins? -- check the jsf spec, Hopefully JSF should be able to check for this and
> - // flag an error and not allow the application to be deployed.
> - for (URL location : facesConfigLocations) {
> - FacesConfig facesConfig = ReadDescriptors.readFacesConfig(location);
> - webModule.getFacesConfigs().add(facesConfig);
> - if ("file".equals(location.getProtocol())) {
> - webModule.getWatchedResources().add(URLs.toFilePath(location));
> - }
> - }
> }
>
> /**
> @@ -939,25 +729,6 @@ public class TomcatWebAppBuilder impleme
> }
>
> /**
> - * Gets urls in a web application.
> - *
> - * @param standardContext context
> - * @return list of url
> - */
> - private List<URL> getUrls(StandardContext standardContext) {
> - List<URL> urls = null;
> - try {
> - ClassLoader classLoader = standardContext.getLoader().getClassLoader();
> - UrlSet urlSet = new UrlSet(classLoader);
> - urlSet = urlSet.exclude(classLoader.getParent());
> - urls = urlSet.getUrls();
> - } catch (IOException e) {
> - logger.warning("Unable to determine URLs in web application " + standardContext.getPath(), e);
> - }
> - return urls;
> - }
> -
> - /**
> * Binds given object into given component context.
> *
> * @param comp context
>
> Modified: openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWsRegistry.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWsRegistry.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWsRegistry.java (original)
> +++ openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWsRegistry.java Fri Jan 7 16:03:17 2011
> @@ -36,11 +36,14 @@ import org.apache.catalina.core.Standard
> import org.apache.catalina.deploy.LoginConfig;
> import org.apache.catalina.deploy.SecurityCollection;
> import org.apache.catalina.deploy.SecurityConstraint;
> +import org.apache.openejb.ClassLoaderUtil;
> +import org.apache.openejb.core.webservices.JaxWsUtils;
> import org.apache.openejb.server.httpd.HttpListener;
> import org.apache.openejb.server.webservices.WsRegistry;
> import org.apache.openejb.server.webservices.WsServlet;
> import org.apache.openejb.tomcat.loader.TomcatHelper;
>
> +import static org.apache.openejb.tomcat.catalina.BackportUtil.getServlet;
> import static org.apache.openejb.tomcat.catalina.TomcatWebAppBuilder.IGNORE_CONTEXT;
>
> import java.net.URI;
> @@ -84,6 +87,14 @@ public class TomcatWsRegistry implements
> throw new IllegalArgumentException("Could not find servlet " + contextRoot + " in web application context " + context.getName());
> }
>
> + // for Pojo web services, we need to change the servlet class which is the service implementation
> + // by the WsServler class
> + wrapper.setServletClass(WsServlet.class.getName());
> + if (getServlet(wrapper) != null) {
> + wrapper.load();
> + wrapper.unload();
> + }
> +
> setWsContainer(context, wrapper, wsContainer);
>
> // add service locations
> @@ -217,7 +228,7 @@ public class TomcatWsRegistry implements
> wrapper.setName("webservice");
> wrapper.setServletClass(WsServlet.class.getName());
>
> - // add add servlet to context
> + // add servlet to context
> context.addChild(wrapper);
> wrapper.addMapping("/*");
> context.addServletMapping("/*", "webservice");
>
> Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java (original)
> +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/ClassLoaderUtil.java Fri Jan 7 16:03:17 2011
> @@ -66,6 +66,14 @@ public class ClassLoaderUtil {
> });
> }
>
> + public static File getUrlCachedName(String appId, URL url) {
> + return urlCache.getUrlCachedName(appId, url);
> + }
> +
> + public static boolean isUrlCached(String appId, URL url) {
> + return urlCache.isUrlCached(appId, url);
> + }
> +
> public static URLClassLoader createClassLoader(String appId, URL[] urls, ClassLoader parent) {
> urls = urlCache.cacheUrls(appId, urls);
> URLClassLoader classLoader = new URLClassLoader(urls, parent);
>
> Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java (original)
> +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ConfigurationFactory.java Fri Jan 7 16:03:17 2011
> @@ -16,54 +16,9 @@
> */
> package org.apache.openejb.config;
>
> -import static org.apache.openejb.config.DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY;
> -
> -import java.io.File;
> -import java.net.URI;
> -import java.net.URISyntaxException;
> -import java.net.URL;
> -import java.net.URLClassLoader;
> -import java.util.ArrayList;
> -import java.util.Arrays;
> -import java.util.Collections;
> -import java.util.Comparator;
> -import java.util.HashMap;
> -import java.util.List;
> -import java.util.Map;
> -import java.util.Properties;
> -import java.util.Collection;
> -import java.util.Set;
> -
> import org.apache.openejb.OpenEJBException;
> import org.apache.openejb.Vendor;
> -import org.apache.openejb.assembler.classic.AppInfo;
> -import org.apache.openejb.assembler.classic.Assembler;
> -import org.apache.openejb.assembler.classic.BmpEntityContainerInfo;
> -import org.apache.openejb.assembler.classic.ClientInfo;
> -import org.apache.openejb.assembler.classic.CmpEntityContainerInfo;
> -import org.apache.openejb.assembler.classic.ConnectionManagerInfo;
> -import org.apache.openejb.assembler.classic.ConnectorInfo;
> -import org.apache.openejb.assembler.classic.ContainerInfo;
> -import org.apache.openejb.assembler.classic.ContainerSystemInfo;
> -import org.apache.openejb.assembler.classic.EjbJarInfo;
> -import org.apache.openejb.assembler.classic.FacilitiesInfo;
> -import org.apache.openejb.assembler.classic.HandlerChainInfo;
> -import org.apache.openejb.assembler.classic.HandlerInfo;
> -import org.apache.openejb.assembler.classic.JndiContextInfo;
> -import org.apache.openejb.assembler.classic.MdbContainerInfo;
> -import org.apache.openejb.assembler.classic.OpenEjbConfiguration;
> -import org.apache.openejb.assembler.classic.OpenEjbConfigurationFactory;
> -import org.apache.openejb.assembler.classic.ProxyFactoryInfo;
> -import org.apache.openejb.assembler.classic.ResourceInfo;
> -import org.apache.openejb.assembler.classic.SecurityServiceInfo;
> -import org.apache.openejb.assembler.classic.ServiceInfo;
> -import org.apache.openejb.assembler.classic.StatefulSessionContainerInfo;
> -import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
> -import org.apache.openejb.assembler.classic.TransactionServiceInfo;
> -import org.apache.openejb.assembler.classic.WebAppInfo;
> -import org.apache.openejb.assembler.classic.SingletonSessionContainerInfo;
> -import org.apache.openejb.assembler.classic.ManagedContainerInfo;
> -import static org.apache.openejb.config.ServiceUtils.implies;
> +import org.apache.openejb.assembler.classic.*;
> import org.apache.openejb.config.sys.AbstractService;
> import org.apache.openejb.config.sys.ConnectionManager;
> import org.apache.openejb.config.sys.Container;
> @@ -82,14 +37,34 @@ import org.apache.openejb.jee.Handler;
> import org.apache.openejb.jee.HandlerChain;
> import org.apache.openejb.jee.HandlerChains;
> import org.apache.openejb.jee.ParamValue;
> -import org.apache.openejb.loader.SystemInstance;
> import org.apache.openejb.loader.FileUtils;
> import org.apache.openejb.loader.Options;
> +import org.apache.openejb.loader.SystemInstance;
> import org.apache.openejb.util.LogCategory;
> import org.apache.openejb.util.Logger;
> import org.apache.openejb.util.Messages;
> import org.apache.openejb.util.SuperProperties;
> import org.apache.openejb.util.URISupport;
> +import org.apache.openejb.util.URLs;
> +
> +import java.io.File;
> +import java.net.URI;
> +import java.net.URISyntaxException;
> +import java.net.URL;
> +import java.net.URLClassLoader;
> +import java.util.ArrayList;
> +import java.util.Arrays;
> +import java.util.Collection;
> +import java.util.Collections;
> +import java.util.Comparator;
> +import java.util.HashMap;
> +import java.util.List;
> +import java.util.Map;
> +import java.util.Properties;
> +import java.util.Set;
> +
> +import static org.apache.openejb.config.DeploymentsResolver.DEPLOYMENTS_CLASSPATH_PROPERTY;
> +import static org.apache.openejb.config.ServiceUtils.implies;
>
> public class ConfigurationFactory implements OpenEjbConfigurationFactory {
>
> @@ -413,14 +388,14 @@ public class ConfigurationFactory implem
>
> FileUtils base = SystemInstance.get().getBase();
>
> - List<String> declaredApps = new ArrayList<String>(deployments.size());
> + List<URL> declaredAppsUrls = new ArrayList<URL>();
> try {
> for (Deployments deployment : deployments) {
> - DeploymentsResolver.loadFrom(deployment, base, declaredApps);
> + DeploymentsResolver.loadFrom(deployment, base, declaredAppsUrls);
> }
> } catch (SecurityException ignored) {
> }
> - return declaredApps;
> + return toString(declaredAppsUrls);
> }
>
> public ArrayList<File> getModulesFromClassPath(List<String> declaredApps, ClassLoader classLoader) {
> @@ -428,19 +403,29 @@ public class ConfigurationFactory implem
> if (declaredApps == null) {
> declaredApps = getDeclaredApps();
> }
> - List<String> classpathApps = new ArrayList<String>();
> -
> - DeploymentsResolver.loadFromClasspath(base, classpathApps, classLoader);
> + List<URL> classpathAppsUrls = new ArrayList<URL>();
> + DeploymentsResolver.loadFromClasspath(base, classpathAppsUrls, classLoader);
>
> ArrayList<File> jarFiles = new ArrayList<File>();
> - for (String path : classpathApps) {
> - if (declaredApps.contains(path)) continue;
> + for (URL path : classpathAppsUrls) {
> + if (declaredApps.contains(URLs.toFilePath(path))) continue;
>
> - jarFiles.add(new File(path));
> + jarFiles.add(new File(URLs.toFilePath(path)));
> }
> return jarFiles;
> }
>
> + private List<String> toString (List<URL> urls) {
> + List<String> toReturn = new ArrayList<String>(urls.size());
> + for (URL url : urls) {
> + try {
> + toReturn.add(url.toString());
> + } catch (Exception ignore) {
> + }
> + }
> + return toReturn;
> + }
> +
> public ContainerInfo createContainerInfo(Container container) throws OpenEJBException {
> Class<? extends ContainerInfo> infoClass = getContainerInfoType(container.getType());
> if (infoClass == null) {
>
> Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java (original)
> +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java Fri Jan 7 16:03:17 2011
> @@ -17,34 +17,6 @@
> */
> package org.apache.openejb.config;
>
> -import static org.apache.openejb.util.URLs.toFile;
> -
> -import java.io.File;
> -import java.io.IOException;
> -import java.io.InputStream;
> -import java.net.MalformedURLException;
> -import java.net.URL;
> -import java.net.URLDecoder;
> -import java.util.ArrayList;
> -import java.util.Arrays;
> -import java.util.Collection;
> -import java.util.Collections;
> -import java.util.HashMap;
> -import java.util.HashSet;
> -import java.util.Iterator;
> -import java.util.LinkedHashSet;
> -import java.util.LinkedList;
> -import java.util.List;
> -import java.util.Map;
> -import java.util.Set;
> -import java.util.TreeMap;
> -import java.util.jar.Attributes;
> -import java.util.jar.JarEntry;
> -import java.util.jar.JarFile;
> -import java.util.jar.Manifest;
> -
> -import javax.xml.bind.JAXBException;
> -
> import org.apache.openejb.ClassLoaderUtil;
> import org.apache.openejb.OpenEJB;
> import org.apache.openejb.OpenEJBException;
> @@ -65,6 +37,8 @@ import org.apache.openejb.jee.TldTaglib;
> import org.apache.openejb.jee.WebApp;
> import org.apache.openejb.jee.WebserviceDescription;
> import org.apache.openejb.jee.Webservices;
> +import org.apache.openejb.loader.FileUtils;
> +import org.apache.openejb.loader.Options;
> import org.apache.openejb.loader.SystemInstance;
> import org.apache.openejb.util.AnnotationFinder;
> import org.apache.openejb.util.JarExtractor;
> @@ -76,10 +50,38 @@ import org.apache.xbean.finder.ResourceF
> import org.apache.xbean.finder.UrlSet;
> import org.xml.sax.SAXException;
>
> +import javax.xml.bind.JAXBException;
> +import java.io.File;
> +import java.io.IOException;
> +import java.io.InputStream;
> +import java.net.MalformedURLException;
> +import java.net.URL;
> +import java.net.URLDecoder;
> +import java.util.ArrayList;
> +import java.util.Arrays;
> +import java.util.Collection;
> +import java.util.Collections;
> +import java.util.HashMap;
> +import java.util.HashSet;
> +import java.util.Iterator;
> +import java.util.LinkedHashSet;
> +import java.util.LinkedList;
> +import java.util.List;
> +import java.util.Map;
> +import java.util.Properties;
> +import java.util.Set;
> +import java.util.TreeMap;
> +import java.util.jar.Attributes;
> +import java.util.jar.JarEntry;
> +import java.util.jar.JarFile;
> +import java.util.jar.Manifest;
> +
> +import static org.apache.openejb.util.URLs.toFile;
> +
> /**
> * @version $Revision$ $Date$
> */
> -public class DeploymentLoader {
> +public class DeploymentLoader implements DeploymentFilterable {
> public static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP_CONFIG, "org.apache.openejb.util.resources");
> public static final Set<Class<? extends DeploymentModule>> ALL_SUPPORTED_MODULE_TYPES;
> private static final String OPENEJB_ALTDD_PREFIX = "openejb.altdd.prefix";
> @@ -111,7 +113,7 @@ public class DeploymentLoader {
> public DeploymentLoader(String ddDir, Set<Class<? extends DeploymentModule>> loadingRequiredModuleTypes) {
> this.ddDir = ddDir;
> //Might always need AppModule, as without it, we might ignore the EAR type application
> - if(loadingRequiredModuleTypes == ALL_SUPPORTED_MODULE_TYPES) {
> + if (loadingRequiredModuleTypes == ALL_SUPPORTED_MODULE_TYPES) {
> this.loadingRequiredModuleTypes = loadingRequiredModuleTypes;
> } else {
> this.loadingRequiredModuleTypes = new HashSet<Class<? extends DeploymentModule>>(loadingRequiredModuleTypes);
> @@ -163,9 +165,9 @@ public class DeploymentLoader {
> // when we have a possible ejb-jar file (only ejb-jars result in a ClassFinder being used)
> URL tempURL = baseUrl;
> if (jarFile.isFile() && UrlCache.cacheDir != null &&
> - !jarFile.getName().endsWith(".ear") &&
> - !jarFile.getName().endsWith(".war") &&
> - !jarFile.getName().endsWith(".rar")) {
> + !jarFile.getName().endsWith(".ear") &&
> + !jarFile.getName().endsWith(".war") &&
> + !jarFile.getName().endsWith(".rar")) {
> try {
> tmpFile = File.createTempFile("AppModule-", "", UrlCache.cacheDir);
> JarExtractor.copy(URLs.toFile(baseUrl), tmpFile);
> @@ -231,7 +233,7 @@ public class DeploymentLoader {
> final File file = toFile(baseUrl);
>
> AppModule appModule = new AppModule(OpenEJB.class.getClassLoader(), file.getAbsolutePath());
> - addWebModule(appModule, baseUrl, OpenEJB.class.getClassLoader(), null, null);
> + addWebModule(appModule, baseUrl, OpenEJB.class.getClassLoader(), getContextRoot(), getModuleName());
> return appModule;
> } else if (PersistenceModule.class.equals(moduleClass) && loadingRequiredModuleTypes.contains(PersistenceModule.class)) {
> String jarLocation = URLs.toFilePath(baseUrl);
> @@ -323,6 +325,9 @@ public class DeploymentLoader {
> HashMap<String, URL> files = new HashMap<String, URL>();
> scanDir(appDir, files, "");
> files.remove("META-INF/MANIFEST.MF");
> +
> + // todo we should also filter URLs here using DeploymentsResolver.loadFromClasspath
> +
> for (Map.Entry<String, URL> entry : files.entrySet()) {
> if (entry.getKey().startsWith("lib/")) continue;
> if (!entry.getKey().matches(".*\\.(jar|war|rar|ear)")) continue;
> @@ -339,7 +344,7 @@ public class DeploymentLoader {
> resouceModules.put(entry.getKey(), entry.getValue());
> } else if (WebModule.class.equals(moduleType)
> && (loadingRequiredModuleTypes.contains(WebModule.class) || loadingRequiredModuleTypes.contains(EjbModule.class) || loadingRequiredModuleTypes
> - .contains(PersistenceModule.class))) {
> + .contains(PersistenceModule.class))) {
> webModules.put(entry.getKey(), entry.getValue());
> }
> } catch (UnsupportedOperationException e) {
> @@ -430,6 +435,13 @@ public class DeploymentLoader {
> for (String moduleName : ejbModules.keySet()) {
> try {
> URL ejbUrl = ejbModules.get(moduleName);
> + // we should try to use a reference to the temp classloader
> + if (ClassLoaderUtil.isUrlCached(appModule.getJarLocation(), ejbUrl)) {
> + try {
> + ejbUrl = ClassLoaderUtil.getUrlCachedName(appModule.getJarLocation(), ejbUrl).toURI().toURL();
> +
> + } catch (MalformedURLException ignore) { }
> + }
> File ejbFile = toFile(ejbUrl);
> String absolutePath = ejbFile.getAbsolutePath();
>
> @@ -446,6 +458,13 @@ public class DeploymentLoader {
> for (String moduleName : clientModules.keySet()) {
> try {
> URL clientUrl = clientModules.get(moduleName);
> + // we should try to use a reference to the temp classloader
> + if (ClassLoaderUtil.isUrlCached(appModule.getJarLocation(), clientUrl)) {
> + try {
> + clientUrl = ClassLoaderUtil.getUrlCachedName(appModule.getJarLocation(), clientUrl).toURI().toURL();
> +
> + } catch (MalformedURLException ignore) { }
> + }
> File clientFile = toFile(clientUrl);
> String absolutePath = clientFile.getAbsolutePath();
>
> @@ -461,6 +480,13 @@ public class DeploymentLoader {
> for (String moduleName : resouceModules.keySet()) {
> try {
> URL rarUrl = resouceModules.get(moduleName);
> + // we should try to use a reference to the temp classloader
> + if (ClassLoaderUtil.isUrlCached(appModule.getJarLocation(), rarUrl)) {
> + try {
> + rarUrl = ClassLoaderUtil.getUrlCachedName(appModule.getJarLocation(), rarUrl).toURI().toURL();
> +
> + } catch (MalformedURLException ignore) { }
> + }
> ConnectorModule connectorModule = createConnectorModule(appId, URLs.toFilePath(rarUrl), appClassLoader, moduleName);
>
> appModule.getConnectorModules().add(connectorModule);
> @@ -479,9 +505,16 @@ public class DeploymentLoader {
> }
> }
>
> + // Persistence Units
> if (loadingRequiredModuleTypes.contains(PersistenceModule.class)) {
> - // Persistence Units
> - addPersistenceUnits(appModule, urls);
> + // we don't need all URLs here but only a filtered list
> + // moreover, we should use cached (tempclassloader) instead
> + Properties p = new Properties();
> + p.put(appModule.getModuleId(), appModule.getJarLocation());
> + FileUtils base = new FileUtils(appModule.getModuleId(), appModule.getModuleId(), p);
> + List<URL> filteredUrls = new ArrayList<URL>();
> + DeploymentsResolver.loadFromClasspath(base, filteredUrls, appModule.getClassLoader());
> + addPersistenceUnits(appModule, filteredUrls.toArray(new URL[filteredUrls.size()]));
> }
>
> return appModule;
> @@ -565,66 +598,84 @@ public class DeploymentLoader {
> }
>
> protected void addWebModule(AppModule appModule, URL warUrl, ClassLoader parentClassLoader, String contextRoot, String moduleName) throws OpenEJBException {
> +
> + // create and add the WebModule
> String warPath = URLs.toFilePath(warUrl);
> WebModule webModule = createWebModule(appModule.getJarLocation(), warPath, parentClassLoader, contextRoot, moduleName);
> if (loadingRequiredModuleTypes.contains(WebModule.class)) {
> appModule.getWebModules().add(webModule);
> }
>
> + // get urls in web application
> + List<URL> urls = new ArrayList<URL>();
> ClassLoader webClassLoader = webModule.getClassLoader();
>
> - if (loadingRequiredModuleTypes.contains(EjbModule.class)) {
> - boolean addEjbModule = false;
> - EjbJar ejbJar = null;
> - URL ejbJarXmlUrl = (URL) webModule.getAltDDs().get("ejb-jar.xml");
> - if (ejbJarXmlUrl == null) {
> - if (webModule.getWebApp() != null && webModule.getWebApp().isMetadataComplete()) {
> - addEjbModule = false;
> - } else {
> - // get urls in web application
> - List<URL> urls = null;
> - try {
> - UrlSet urlSet = new UrlSet(webClassLoader);
> - urlSet = urlSet.exclude(webClassLoader.getParent().getParent());
> - urls = urlSet.getUrls();
> - } catch (IOException e) {
> - logger.warning("Unable to determine URLs in classloader", e);
> - }
> + // get include/exclude properties from context-param
> + Options contextParams = new Options(getContextParams(webModule.getWebApp().getContextParam()));
> + String include = contextParams.get(CLASSPATH_INCLUDE, "");
> + String exclude = contextParams.get(CLASSPATH_EXCLUDE, ".*");
> + Set<RequireDescriptors> requireDescriptors = contextParams.getAll(CLASSPATH_REQUIRE_DESCRIPTOR, RequireDescriptors.CLIENT);
> + boolean filterDescriptors = contextParams.get(CLASSPATH_FILTER_DESCRIPTORS, false);
> + boolean filterSystemApps = contextParams.get(CLASSPATH_FILTER_SYSTEMAPPS, true);
> +
> + contextParams.getProperties().put(moduleName, warPath);
> + FileUtils base = new FileUtils(moduleName, moduleName, contextParams.getProperties());
> + DeploymentsResolver.loadFromClasspath(base, urls, webClassLoader, include, exclude, requireDescriptors, filterDescriptors, filterSystemApps);
> +
> + // we need to exclude previously deployed modules
> + UrlSet urlSet = new UrlSet(urls);
> + urlSet = urlSet.exclude(new UrlSet(appModule.getAdditionalLibraries())); // there should not be modules in /lib
> + for (EjbModule ejbModule : appModule.getEjbModules()) {
> + try {
> + urlSet = urlSet.exclude(new File(ejbModule.getJarLocation()));
>
> - // clean jar URLs
> - for (int i = 0; i < urls.size(); i++) {
> - URL url = urls.get(i);
> - if (url.getProtocol().equals("jar")) {
> - try {
> - url = new URL(url.getFile().replaceFirst("!.*$", ""));
> - urls.set(i, url);
> - } catch (MalformedURLException ignored) {
> - }
> - }
> - }
> + } catch (MalformedURLException ignore) { }
> + }
> + for (ClientModule clientModule : appModule.getClientModules()) {
> + try {
> + urlSet = urlSet.exclude(new File(clientModule.getJarLocation()));
> + } catch (MalformedURLException ignore) { }
> + }
> + // for persistence.xml, there is already a check in addPersistenceUnit to remove duplicates
> + urls = urlSet.getUrls();
>
> - addEjbModule = checkAnnotations(urls, webClassLoader, true, false) != null;
> - }
> - } else {
> - addEjbModule = true;
> - ejbJar = ReadDescriptors.readEjbJar(ejbJarXmlUrl);
> - }
> + // save the filtered list so that it can be used elsewhere
> + webModule.setFilteredUrls(urls);
> +
> + // Check each URL to determine if it is an EJB jar
> + for (URL url : urls) {
> + try {
> + Class moduleType = discoverModuleType(url, webClassLoader, true);
> +
> + File file = toFile(url);
> + String absolutePath = file.getAbsolutePath();
> +
> + if (EjbModule.class.isAssignableFrom(moduleType) && loadingRequiredModuleTypes.contains(EjbModule.class)) {
> + logger.info("Found ejb module " + moduleType.getSimpleName() + " in war " + contextRoot);
> +
> + EjbModule ejbModule = createEjbModule(url, absolutePath, webClassLoader, getModuleName());
> + appModule.getEjbModules().add(ejbModule);
>
> - if (addEjbModule) {
> - EjbModule ejbModule = new EjbModule(webClassLoader, webModule.getModuleId(), warPath, ejbJar, null);
> - ejbModule.getAltDDs().putAll(webModule.getAltDDs());
> - if (loadingRequiredModuleTypes.contains(WsModule.class)) {
> - addWebservices(ejbModule);
> }
>
> - appModule.getEjbModules().add(ejbModule);
> + } catch (IOException e) {
> + logger.warning("Unable to determine the module type of " + url.toExternalForm() + ": Exception: " + e.getMessage(), e);
> + } catch (UnknownModuleTypeException ignore) {
> }
> }
>
> if (loadingRequiredModuleTypes.contains(PersistenceModule.class)) {
> // Persistence Units
> - addPersistenceUnits(appModule);
> + addPersistenceUnits(appModule, urls.toArray(new URL[urls.size()]));
> + }
> + }
> +
> + private Properties getContextParams(List<ParamValue> contextParam) {
> + Properties properties = new Properties();
> + for (ParamValue paramValue : contextParam) {
> + properties.put(paramValue.getParamName(), paramValue.getParamValue());
> }
> + return properties;
> }
>
> protected WebModule createWebModule(String appId, String warPath, ClassLoader parentClassLoader, String contextRoot, String moduleName) throws OpenEJBException {
> @@ -674,6 +725,14 @@ public class DeploymentLoader {
> return webModule;
> }
>
> + protected String getContextRoot() {
> + return null;
> + }
> +
> + protected String getModuleName() {
> + return null;
> + }
> +
> public static URL[] getWebappUrls(File warFile) {
> List<URL> webClassPath = new ArrayList<URL>();
> File webInfDir = new File(warFile, "WEB-INF");
> @@ -818,9 +877,6 @@ public class DeploymentLoader {
> */
> private void addFacesConfigs(WebModule webModule) throws OpenEJBException {
> //*************************IMPORTANT*******************************************
> - // This method is an exact copy of org.apache.openejb.tomcat.catalina.TomcatWebAppBuilder.addFacesConfigs(WebModule webModule)
> - // Any changes to this method here would most probably need to also be reflected in the TomcatWebAppBuilder.addFacesConfigs method.
> - //*************************IMPORTANT*******************************************
> // TODO : kmalhi :: Add support to scrape META-INF/faces-config.xml in jar files
> // look at section 10.4.2 of the JSF v1.2 spec, bullet 1 for details
> Set<URL> facesConfigLocations = new HashSet<URL>();
>
> Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java (original)
> +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java Fri Jan 7 16:03:17 2011
> @@ -40,18 +40,11 @@ import java.util.EnumSet;
> /**
> * @version $Rev$ $Date$
> */
> -public class DeploymentsResolver {
> +public class DeploymentsResolver implements DeploymentFilterable {
>
> - public static final String DEPLOYMENTS_CLASSPATH_PROPERTY = "openejb.deployments.classpath";
> - static final String SEARCH_CLASSPATH_FOR_DEPLOYMENTS_PROPERTY = DEPLOYMENTS_CLASSPATH_PROPERTY;
> - public static final String CLASSPATH_INCLUDE = "openejb.deployments.classpath.include";
> - private static final String CLASSPATH_EXCLUDE = "openejb.deployments.classpath.exclude";
> - private static final String CLASSPATH_REQUIRE_DESCRIPTOR = RequireDescriptors.PROPERTY;
> - private static final String CLASSPATH_FILTER_DESCRIPTORS = "openejb.deployments.classpath.filter.descriptors";
> - private static final String CLASSPATH_FILTER_SYSTEMAPPS = "openejb.deployments.classpath.filter.systemapps";
> private static final Logger logger = DeploymentLoader.logger;
>
> - public static void loadFrom(Deployments dep, FileUtils path, List<String> jarList) {
> + public static void loadFrom(Deployments dep, FileUtils path, List<URL> jarList) {
>
> ////////////////////////////////
> //
> @@ -62,7 +55,7 @@ public class DeploymentsResolver {
> try {
> File jar = path.getFile(dep.getJar(), false);
> if (!jarList.contains(jar.getAbsolutePath())) {
> - jarList.add(jar.getAbsolutePath());
> + jarList.add(jar.toURI().toURL());
> }
> } catch (Exception ignored) {
> }
> @@ -84,26 +77,35 @@ public class DeploymentsResolver {
> ////////////////////////////////
> File ejbJarXml = new File(dir, "META-INF" + File.separator + "ejb-jar.xml");
> if (ejbJarXml.exists()) {
> - if (!jarList.contains(dir.getAbsolutePath())) {
> - jarList.add(dir.getAbsolutePath());
> + try {
> + if (!jarList.contains(dir.getAbsolutePath())) {
> + jarList.add(dir.toURI().toURL());
> + }
> + } catch (MalformedURLException ignore) {
> }
> return;
> }
>
> File appXml = new File(dir, "META-INF" + File.separator + "application.xml");
> if (appXml.exists()) {
> - if (!jarList.contains(dir.getAbsolutePath())) {
> - jarList.add(dir.getAbsolutePath());
> + try {
> + if (!jarList.contains(dir.getAbsolutePath())) {
> + jarList.add(dir.toURI().toURL());
> + }
> + } catch (MalformedURLException ignore) {
> }
> return;
> }
>
> File raXml = new File(dir, "META-INF" + File.separator + "ra.xml");
> - if (raXml.exists()) {
> - if (!jarList.contains(dir.getAbsolutePath())) {
> - jarList.add(dir.getAbsolutePath());
> - }
> - return;
> + if (raXml.exists()) {
> + try {
> + if (!jarList.contains(dir.getAbsolutePath())) {
> + jarList.add(dir.toURI().toURL());
> + }
> + } catch (MalformedURLException ignore) {
> + }
> + return;
> }
>
> ////////////////////////////////
> @@ -113,16 +115,19 @@ public class DeploymentsResolver {
> ////////////////////////////////
> boolean hasNestedArchives = false;
> for (File file : dir.listFiles()) {
> - if (file.getName().endsWith(".jar") || file.getName().endsWith(".war")|| file.getName().endsWith(".rar")|| file.getName().endsWith(".ear")) {
> - if (jarList.contains(file.getAbsolutePath())) continue;
> - jarList.add(file.getAbsolutePath());
> - hasNestedArchives = true;
> - } else if (new File(file, "META-INF").exists()){ // Unpacked ear or jar
> - jarList.add(file.getAbsolutePath());
> - hasNestedArchives = true;
> - } else if (new File(file, "WEB-INF").exists()){ // Unpacked webapp
> - jarList.add(file.getAbsolutePath());
> - hasNestedArchives = true;
> + try {
> + if (file.getName().endsWith(".jar") || file.getName().endsWith(".war")|| file.getName().endsWith(".rar")|| file.getName().endsWith(".ear")) {
> + if (jarList.contains(file.getAbsolutePath())) continue;
> + jarList.add(file.toURI().toURL());
> + hasNestedArchives = true;
> + } else if (new File(file, "META-INF").exists()){ // Unpacked ear or jar
> + jarList.add(file.toURI().toURL());
> + hasNestedArchives = true;
> + } else if (new File(file, "WEB-INF").exists()){ // Unpacked webapp
> + jarList.add(file.toURI().toURL());
> + hasNestedArchives = true;
> + }
> + } catch (Exception ignore) {
> }
> }
>
> @@ -136,8 +141,11 @@ public class DeploymentsResolver {
> DeploymentLoader.scanDir(dir, files, "");
> for (String fileName : files.keySet()) {
> if (fileName.endsWith(".class")) {
> - if (!jarList.contains(dir.getAbsolutePath())) {
> - jarList.add(dir.getAbsolutePath());
> + try {
> + if (!jarList.contains(dir.getAbsolutePath())) {
> + jarList.add(dir.toURI().toURL());
> + }
> + } catch (MalformedURLException ignore) {
> }
> return;
> }
> @@ -161,8 +169,7 @@ public class DeploymentsResolver {
> * 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(FileUtils base, List<String> jarList, ClassLoader classLoader) {
> -
> + public static void loadFromClasspath(FileUtils base, List<URL> jarList, ClassLoader classLoader) {
> Options options = SystemInstance.get().getOptions();
> String include = options.get(CLASSPATH_INCLUDE, "");
> String exclude = options.get(CLASSPATH_EXCLUDE, ".*");
> @@ -170,6 +177,14 @@ public class DeploymentsResolver {
> boolean filterDescriptors = options.get(CLASSPATH_FILTER_DESCRIPTORS, false);
> boolean filterSystemApps = options.get(CLASSPATH_FILTER_SYSTEMAPPS, true);
>
> + loadFromClasspath(base, jarList, classLoader,
> + include, exclude, requireDescriptors, filterDescriptors, filterSystemApps);
> + }
> +
> + public static void loadFromClasspath(FileUtils base, List<URL> jarList, ClassLoader classLoader,
> + String include, String exclude, Set<RequireDescriptors> requireDescriptors,
> + boolean filterDescriptors, boolean filterSystemApps) {
> +
> try {
> UrlSet urlSet = new UrlSet(classLoader);
> UrlSet includes = urlSet.matching(include);
> @@ -358,7 +373,7 @@ public class DeploymentsResolver {
> return urlSet;
> }
>
> - private static void processUrls(List<URL> urls, ClassLoader classLoader, Set<RequireDescriptors> requireDescriptors, FileUtils base, List<String> jarList) {
> + private static void processUrls(List<URL> urls, ClassLoader classLoader, Set<RequireDescriptors> requireDescriptors, FileUtils base, List<URL> jarList) {
> for (URL url : urls) {
> Deployments deployment;
> String path;
> @@ -385,7 +400,7 @@ public class DeploymentsResolver {
> loadFrom(deployment, base, jarList);
> } else {
> if (!jarList.contains(path)){
> - jarList.add(path);
> + jarList.add(url);
> }
> }
>
>
> Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java (original)
> +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/FinderFactory.java Fri Jan 7 16:03:17 2011
> @@ -44,10 +44,13 @@ public class FinderFactory {
> public AbstractFinder create(DeploymentModule module) throws Exception {
> if (module instanceof WebModule) {
> WebModule webModule = (WebModule) module;
> - File file = new File(webModule.getJarLocation());
> - URL[] urls = DeploymentLoader.getWebappUrls(file);
> final ClassLoader webClassLoader = webModule.getClassLoader();
> - return new ClassFinder(webClassLoader, asList(urls));
> + if (webModule.getFilteredUrls() == null) {
> + return new ClassFinder(webClassLoader);
> +
> + } else {
> + return new ClassFinder(webClassLoader, webModule.getFilteredUrls());
> + }
> }
>
> if (module.getJarLocation() != null) {
>
> Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java (original)
> +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java Fri Jan 7 16:03:17 2011
> @@ -17,6 +17,7 @@
> package org.apache.openejb.config;
>
> import java.io.File;
> +import java.net.URL;
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.List;
> @@ -50,6 +51,8 @@ public class WebModule implements WsModu
> private final List<FacesConfig> facesConfigs = new ArrayList<FacesConfig>();
> private AbstractFinder finder;
>
> + // keep the list of filtered URL we got after applying include/exclude pattern (@See DeploymentsResolver.loadFromClasspath)
> + private List<URL> filteredUrls;
>
> public WebModule(WebApp webApp, String contextRoot, ClassLoader classLoader, String jarLocation, String moduleId) {
> this.webApp = webApp;
> @@ -90,6 +93,14 @@ public class WebModule implements WsModu
> validation = new ValidationContext(WebModule.class, jarLocation);
> }
>
> + public List<URL> getFilteredUrls() {
> + return filteredUrls;
> + }
> +
> + public void setFilteredUrls(List<URL> filteredUrls) {
> + this.filteredUrls = filteredUrls;
> + }
> +
> public AbstractFinder getFinder() {
> return finder;
> }
>
> Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java (original)
> +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WsDeployer.java Fri Jan 7 16:03:17 2011
> @@ -128,9 +128,10 @@ public class WsDeployer implements Dynam
> servletMappings.put(servletMapping.getServletName(), servletMapping);
> }
>
> - // add port declarations for webservices
> + // add port declarations for Pojo webservices
> WebserviceDescription webserviceDescription;
> for (Servlet servlet : webApp.getServlet()) {
> + // the implementation class will be replaced by the WsServlet in the WsRegistry
> String className = servlet.getServletClass();
>
> // Skip JSPs
>
> Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java (original)
> +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/JaxWsUtils.java Fri Jan 7 16:03:17 2011
> @@ -247,16 +247,21 @@ public class JaxWsUtils {
>
> public static String getServiceInterface(Class<?> clazz) {
> WebService webService = clazz.getAnnotation(WebService.class);
> + String endpointInterface = null;
> if (webService != null && webService.endpointInterface() != null) {
> - String endpointInterface = webService.endpointInterface().trim();
> - if (endpointInterface.length() == 0) endpointInterface = null;
> - return endpointInterface;
> + endpointInterface = webService.endpointInterface().trim();
> + if (endpointInterface.length() == 0) {
> + endpointInterface = null;
> +
> + } else {
> + return endpointInterface;
> + }
> }
>
> // if the bean implements only one WebService class, that is the SEI
> - String endpointInterface = null;
> - for (Class intf : clazz.getInterfaces()) {
> - webService = clazz.getAnnotation(WebService.class);
> + for (Class<?> intf : clazz.getInterfaces()) {
> + // interface MUST also have a @WebService
> + webService = intf.getAnnotation(WebService.class);
> if (webService != null) {
> if (endpointInterface == null) {
> endpointInterface = intf.getName();
> @@ -268,11 +273,7 @@ public class JaxWsUtils {
> }
> }
>
> - if (endpointInterface != null) {
> - return endpointInterface;
> - }
> -
> - return null;
> + return endpointInterface;
> }
>
> public static String getServiceWsdlLocation(Class<?> clazz, ClassLoader loader) {
>
> Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java (original)
> +++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java Fri Jan 7 16:03:17 2011
> @@ -138,6 +138,19 @@ public class UrlCache {
> }
> }
>
> + public File getUrlCachedName(String appId, URL url) {
> + Map<URL, File> appCache = getAppCache(appId);
> + if (appCache.containsKey(url)) {
> + return appCache.get(url);
> + }
> + return null;
> + }
> +
> + public boolean isUrlCached(String appId, URL url) {
> + Map<URL, File> appCache = getAppCache(appId);
> + return appCache.containsKey(url);
> + }
> +
> private synchronized File cacheUrl(String appId, URL url) {
> File sourceFile;
> if (!"file".equals(url.getProtocol())) {
>
> Modified: openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ClassPathApplication.java
> URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ClassPathApplication.java?rev=1056366&r1=1056365&r2=1056366&view=diff
> ==============================================================================
> --- openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ClassPathApplication.java (original)
> +++ openejb/trunk/openejb3/container/openejb-spring/src/main/java/org/apache/openejb/spring/ClassPathApplication.java Fri Jan 7 16:03:17 2011
> @@ -18,6 +18,7 @@
> package org.apache.openejb.spring;
>
> import java.io.File;
> +import java.net.URL;
> import java.util.ArrayList;
> import java.util.Collection;
> import java.util.List;
> @@ -33,6 +34,7 @@ import org.apache.openejb.assembler.clas
> import org.apache.openejb.config.ConfigurationFactory;
> import org.apache.openejb.config.DeploymentsResolver;
> import org.apache.openejb.loader.SystemInstance;
> +import org.apache.openejb.util.URLs;
>
> @Exported
> public class ClassPathApplication extends AbstractApplication {
> @@ -50,18 +52,18 @@ public class ClassPathApplication extend
> protected List<AppInfo> loadApplications() throws OpenEJBException {
> Set<String> declaredApplications = getDeployedApplications();
>
> - List<String> classpathApps = new ArrayList<String>();
> + List<URL> classpathApps = new ArrayList<URL>();
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
>
> DeploymentsResolver.loadFromClasspath(SystemInstance.get().getBase(), classpathApps, classLoader);
>
> ArrayList<File> jarFiles = new ArrayList<File>();
> - for (String path : classpathApps) {
> - if (declaredApplications.contains(path)) continue;
> + for (URL path : classpathApps) {
> + if (declaredApplications.contains(URLs.toFilePath(path))) continue;
> // todo hack to avoid picking up application.xml in openejb-core module
> - if (path.indexOf("openejb-core/target/test-classes") > 0) continue;
> + if (URLs.toFilePath(path).indexOf("openejb-core/target/test-classes") > 0) continue;
>
> - jarFiles.add(new File(path));
> + jarFiles.add(URLs.toFile(path));
> }
>
> List<AppInfo> appInfos = new ArrayList<AppInfo>();
>
>