tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kma...@apache.org
Subject svn commit: r676649 - in /openejb/trunk/openejb3: assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/ container/openejb-core/src/main/java/org/apache/openejb/config/
Date Mon, 14 Jul 2008 17:08:10 GMT
Author: kmalhi
Date: Mon Jul 14 10:08:09 2008
New Revision: 676649

URL: http://svn.apache.org/viewvc?rev=676649&view=rev
Log:
OPENEJB-797:Unable to load servlet class: javax.faces.webapp.FacesServlet
FIXED this issue

How it was fixed:-
Added support in ReadDescriptors to read a JSF 1.2 descriptor
Updated WebModule to store JSF info (as a List of FacesConfig instances)
Updated AnnotationDeployer to scan for JSF ManagedBean classes also
Updated DeploymentLoader to also store FacesConfig instances in a WebModule
Updated TomcatWebappBuilder to also store FacesConfig instances in the WebModule



Modified:
    openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.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/ReadDescriptors.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java

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=676649&r1=676648&r2=676649&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
Mon Jul 14 10:08:09 2008
@@ -19,6 +19,7 @@
 
 import static org.apache.openejb.tomcat.catalina.BackportUtil.getServlet;
 import static org.apache.openejb.tomcat.catalina.BackportUtil.*;
+
 import org.apache.openejb.tomcat.common.LegacyAnnotationProcessor;
 import org.apache.openejb.tomcat.common.TomcatVersion;
 import org.apache.catalina.Container;
@@ -66,6 +67,8 @@
 import org.apache.openejb.core.CoreWebDeploymentInfo;
 import org.apache.openejb.core.CoreContainerSystem;
 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.util.LogCategory;
@@ -85,8 +88,10 @@
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.TreeMap;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -371,8 +376,23 @@
             } catch (NamingException e) {
             }
         }
-
-
+       // Add support for Sun JSF implementation. Sun's JSF impl looks for a AnnotationProcessor
(aka DefaultAnnotationProcessor) in the 
+        // ServletContext . We simply add that here
+/*        try {
+        	 ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
+             Context context = containerSystem.getJNDIContext();
+             context = (Context) context.lookup("java:openejb/ejb");
+			standardContext.getServletContext().setAttribute(AnnotationProcessor.class.getName(),
new DefaultAnnotationProcessor(context));
+		} catch (NamingException e) {
+			logger.error(e.getMessage(), e);
+		}
+        try {
+        	Context compEnv = (Context) ContextBindings.getClassLoader().lookup("comp/env");
+			standardContext.getServletContext().setAttribute(AnnotationProcessor.class.getName(),
new DefaultAnnotationProcessor(compEnv));
+		} catch (NamingException e) {
+			logger.error(e.getMessage(), e);
+		}
+*/
         OpenEJBValve openejbValve = new OpenEJBValve();
         standardContext.getPipeline().addValve(openejbValve);
     }
@@ -605,7 +625,14 @@
         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);
+			// TODO :kmalhi:: Remove stack trace after testing
+			e1.printStackTrace();
+		}
         // 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()) {
@@ -649,6 +676,78 @@
 
         return webModule;
     }
+    /**
+     * Finds all faces configuration files and stores them in the WebModule
+     * @param webModule
+     * @throws OpenEJBException
+     */
+    private static void addFacesConfigs(WebModule webModule) throws OpenEJBException {
+        // TODO : kmalhi :: Add support to scrape META-INF/faces-config.xml in jar files
+    	// look at section 10.4.2, 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.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.toURL();
+					facesConfigLocations.add(url);
+				} catch (IOException e) {
+					// TODO: kmalhi:: Remove the printStackTrace after testing
+					e.printStackTrace();
+				}
+        	}
+        }
+        // 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));
+            }
+        }
+    }
 
     private void removeRef(WebApp webApp, String name) {
         webApp.getEnvEntryMap().remove(name);

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=676649&r1=676648&r2=676649&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
Mon Jul 14 10:08:09 2008
@@ -33,6 +33,8 @@
 import org.apache.openejb.jee.EjbReference;
 import org.apache.openejb.jee.EnterpriseBean;
 import org.apache.openejb.jee.ExcludeList;
+import org.apache.openejb.jee.FacesConfig;
+import org.apache.openejb.jee.FacesManagedBean;
 import org.apache.openejb.jee.Filter;
 import org.apache.openejb.jee.Handler;
 import org.apache.openejb.jee.HandlerChains;
@@ -659,7 +661,19 @@
                     }
                 }
             }
-
+            for (FacesConfig facesConfig: webModule.getFacesConfigs()) {
+            	for(FacesManagedBean bean: facesConfig.getManagedBean()){
+            		String managedBeanClass = bean.getManagedBeanClass().trim();
+                    if (managedBeanClass != null) {
+                        try {
+                            Class clazz = classLoader.loadClass(managedBeanClass);
+                            classes.add(clazz);
+                        } catch (ClassNotFoundException e) {
+                            throw new OpenEJBException("Unable to load JSF managed bean class:
" + managedBeanClass, e);
+                        }
+                    }
+            	}
+            }
             ClassFinder inheritedClassFinder = createInheritedClassFinder(classes.toArray(new
Class<?>[classes.size()]));
 
             // Currently we only process the JNDI annotations for web applications

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=676649&r1=676648&r2=676649&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
Mon Jul 14 10:08:09 2008
@@ -51,10 +51,12 @@
 import org.apache.openejb.jee.ApplicationClient;
 import org.apache.openejb.jee.Connector;
 import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.FacesConfig;
 import org.apache.openejb.jee.JavaWsdlMapping;
 import org.apache.openejb.jee.JaxbJavaee;
 import org.apache.openejb.jee.JspConfig;
 import org.apache.openejb.jee.Module;
+import org.apache.openejb.jee.ParamValue;
 import org.apache.openejb.jee.Taglib;
 import org.apache.openejb.jee.TldTaglib;
 import org.apache.openejb.jee.WebApp;
@@ -566,6 +568,8 @@
         // load webservices descriptor
         addWebservices(webModule);
 
+        // load faces configuration files
+        addFacesConfigs(webModule);
         return webModule;
     }
 
@@ -677,7 +681,78 @@
             }
         }
     }
+    /**
+     * Finds all faces configuration files and stores them in the WebModule
+     * @param webModule
+     * @throws OpenEJBException
+     */
+    private static void addFacesConfigs(WebModule webModule) throws OpenEJBException {
+        // TODO : kmalhi :: Add support to scrape META-INF/faces-config.xml in jar files
+    	// look at section 10.4.2, 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.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.toURL();
+					facesConfigLocations.add(url);
+				} catch (IOException e) {
+					// TODO: kmalhi:: Remove the printStackTrace after testing
+					e.printStackTrace();
+				}
+        	}
+        }
+        // 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));
+            }
+        }
+    }
     private static Set<URL> scanClassLoaderForTagLibs(ClassLoader parentClassLoader)
throws OpenEJBException {
         Set<URL> urls = new HashSet<URL>();
         if (parentClassLoader == null) return urls;

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=676649&r1=676648&r2=676649&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java
Mon Jul 14 10:08:09 2008
@@ -22,6 +22,7 @@
 import org.apache.openejb.jee.ApplicationClient;
 import org.apache.openejb.jee.Connector;
 import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.FacesConfig;
 import org.apache.openejb.jee.HandlerChains;
 import org.apache.openejb.jee.JavaWsdlMapping;
 import org.apache.openejb.jee.JaxbJavaee;
@@ -512,7 +513,24 @@
         }
         return tldTaglib;
     }
-
+    
+    public static FacesConfig readFacesConfig(URL url) throws OpenEJBException {
+        FacesConfig facesConfig;
+        try {
+     		JAXBElement<FacesConfig> element = (JAXBElement<FacesConfig>) JaxbJavaee
+    		.unmarshal(FacesConfig.class, url.openStream());
+     		facesConfig = element.getValue();
+        } catch (SAXException e) {
+            throw new OpenEJBException("Cannot parse the faces configuration file: " + url.toExternalForm(),
e);
+        } catch (JAXBException e) {
+            throw new OpenEJBException("Cannot unmarshall the faces configuration file: "
+ url.toExternalForm(), e);
+        } catch (IOException e) {
+            throw new OpenEJBException("Cannot read the faces configuration file: " + url.toExternalForm(),
e);
+        } catch (Exception e) {
+            throw new OpenEJBException("Encountered unknown error parsing the faces configuration
file: " + url.toExternalForm(), e);
+        }
+        return facesConfig;
+    }
     private Source getSource(Object o) {
         if (o instanceof URL) {
             return new UrlSource((URL) o);

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=676649&r1=676648&r2=676649&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
Mon Jul 14 10:08:09 2008
@@ -16,17 +16,18 @@
  */
 package org.apache.openejb.config;
 
-import org.apache.openejb.jee.WebApp;
-import org.apache.openejb.jee.TldTaglib;
-import org.apache.openejb.jee.Webservices;
-
-import java.util.Map;
+import java.io.File;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
-import java.util.ArrayList;
+import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
-import java.io.File;
+
+import org.apache.openejb.jee.FacesConfig;
+import org.apache.openejb.jee.TldTaglib;
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.jee.Webservices;
 
 /**
  * @version $Rev$ $Date$
@@ -44,6 +45,8 @@
     private final String moduleId;
     private final List<TldTaglib> taglibs = new ArrayList<TldTaglib>();
     private final Set<String> watchedResources = new TreeSet<String>();
+    // List of all faces configuration files found in this web module
+    private final List<FacesConfig> facesConfigs = new ArrayList<FacesConfig>();
 
     public WebModule(WebApp webApp, String contextRoot, ClassLoader classLoader, String jarLocation,
String moduleId) {
         this.webApp = webApp;
@@ -151,4 +154,7 @@
     public Set<String> getWatchedResources() {
         return watchedResources;
     }
+    public List<FacesConfig> getFacesConfigs() {
+		return facesConfigs;
+	}
 }



Mime
View raw message