[jboss-cvs] JBossAS SVN: r111364 - in trunk: server/src/main/java/org/jboss/deployment/dependency and 10 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri May 13 03:08:06 EDT 2011
Author: jaikiran
Date: 2011-05-13 03:08:06 -0400 (Fri, 13 May 2011)
New Revision: 111364
Added:
trunk/server/src/main/java/org/jboss/deployment/JSFDeployment.java
trunk/server/src/main/java/org/jboss/web/deployers/FacesConfigParsingDeployer.java
trunk/server/src/main/java/org/jboss/web/deployers/FacesConfigParsingUtil.java
trunk/server/src/main/java/org/jboss/web/deployers/WebContextParamFacesConfigParsingDeployer.java
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/BaseServlet.java
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/DummyResource.java
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFBaseComponent.java
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanInLibJarMetaInf.java
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanInMetaInf.java
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleJSFManagedBean.java
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleNonWebComponent.java
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleServlet.java
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SomeNonManagedPOJOInLibJar.java
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/unit/
trunk/testsuite/src/main/org/jboss/test/web/jbas8318/unit/ResourceInjectionOnNonJavaEEComponentsTestCase.java
trunk/testsuite/src/resources/web/jbas-8318/
trunk/testsuite/src/resources/web/jbas-8318/test-jsf-injection.jsp
Modified:
trunk/server/src/main/java/org/jboss/deployment/dependency/ContainerDependencyMetaData.java
trunk/server/src/main/java/org/jboss/web/deployers/SpecCompliantWarAnnotationDeployer.java
trunk/testsuite/imports/sections/web.xml
trunk/tomcat/src/resources/standalone/war-deployers-jboss-beans.xml
trunk/tomcat/src/resources/standard/war-deployers-jboss-beans.xml
trunk/tomcat/src/resources/war-deployers-jboss-beans.xml
Log:
JBAS-8318 Fix for processing annotations only on JavaEE components. Minor bit of additional changes remain
Added: trunk/server/src/main/java/org/jboss/deployment/JSFDeployment.java
===================================================================
--- trunk/server/src/main/java/org/jboss/deployment/JSFDeployment.java (rev 0)
+++ trunk/server/src/main/java/org/jboss/deployment/JSFDeployment.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.deployment;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+/**
+ * Metadata to hold information about the JSF managed bean classes present in a deployment.
+ *
+ * @author Jaikiran Pai
+ */
+public class JSFDeployment {
+ /**
+ * Collection of fully qualified class names of JSF managed beans
+ */
+ private Collection<String> managedBeans = new HashSet<String>();
+
+ /**
+ * Returns a collection of fully qualified classnames of JSF managed beans
+ * belong to this JSF deployment
+ *
+ * @return
+ */
+ public Collection<String> getManagedBeans() {
+ return this.managedBeans;
+ }
+
+ /**
+ * Adds the passed <code>managedBeanClass</code> to the collection of managed bean class names.
+ *
+ * @param managedBeanClass The fully qualified classname of the JSF managed bean.
+ * @throws IllegalArgumentException If the passed <code>managedBeanClass</code> is null or an empty string.
+ */
+ public void addManagedBean(String managedBeanClass) {
+ if (managedBeanClass == null || managedBeanClass.trim().isEmpty()) {
+ throw new IllegalArgumentException("Managed bean class cannot be null or empty string");
+ }
+ this.managedBeans.add(managedBeanClass);
+ }
+}
Modified: trunk/server/src/main/java/org/jboss/deployment/dependency/ContainerDependencyMetaData.java
===================================================================
--- trunk/server/src/main/java/org/jboss/deployment/dependency/ContainerDependencyMetaData.java 2011-05-13 06:37:08 UTC (rev 111363)
+++ trunk/server/src/main/java/org/jboss/deployment/dependency/ContainerDependencyMetaData.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -141,7 +141,7 @@
public void addInjectionTargets(Set<ResourceInjectionTargetMetaData> injectionTargets)
{
- log.info("addInjectionTargets, " + injectionTargets);
+ log.debug("addInjectionTargets, " + injectionTargets);
this.targets.addAll(injectionTargets);
}
@@ -152,7 +152,7 @@
public void addJndiDependency(JndiDependencyMetaData jdmd)
{
- log.info("addJndiDependency, " + jdmd);
+ log.debug("addJndiDependency, " + jdmd);
jndiDepends.add(jdmd);
}
Added: trunk/server/src/main/java/org/jboss/web/deployers/FacesConfigParsingDeployer.java
===================================================================
--- trunk/server/src/main/java/org/jboss/web/deployers/FacesConfigParsingDeployer.java (rev 0)
+++ trunk/server/src/main/java/org/jboss/web/deployers/FacesConfigParsingDeployer.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,178 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.web.deployers;
+
+import org.jboss.deployers.spi.structure.MetaDataTypeFilter;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.deployer.AbstractVFSParsingDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployment.JSFDeployment;
+import org.jboss.logging.Logger;
+import org.jboss.vfs.VirtualFile;
+import org.jboss.vfs.VirtualFileFilterWithAttributes;
+import org.jboss.vfs.VisitorAttributes;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+/**
+ * Parses a faces-config.xml file, present in WEB-INF or META-INF folders, for the presence of JSF managed beans and
+ * updates the {@link JSFDeployment} metadata with this information.
+ * <p/>
+ * Note that this deployer is just interested in the presence of any JSF managed beans in the faces configuration files
+ * and doesn't do any real parsing of the faces configuration files. The real and complete parsing of the faces
+ * configuration files is left to the JSF implementation provider.
+ *
+ * @author Jaikiran Pai
+ * @see https://issues.jboss.org/browse/JBAS-8318
+ */
+public class FacesConfigParsingDeployer extends AbstractVFSParsingDeployer<JSFDeployment> {
+
+ /**
+ * Logger
+ */
+ private static final Logger logger = Logger.getLogger(FacesConfigParsingDeployer.class);
+
+ /**
+ * Create a new FacesConfigParsingDeployer.
+ */
+ public FacesConfigParsingDeployer() {
+ // we output JSFDeployment
+ super(JSFDeployment.class);
+ // we parse faces-config.xml file
+ this.setName("faces-config.xml");
+ // allow multiple faces-config.xml in the deployment unit
+ this.setAllowMultipleFiles(true);
+ }
+
+ @Override
+ protected boolean allowsReparse() {
+ return true;
+ }
+
+ /**
+ * Finds the files with the passed <code>name</code>, under the metadata locations, in the deployment unit and passes
+ * each such file to {@link #parse(org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit, VirtualFile, org.jboss.deployment.JSFDeployment)}
+ * method of this deployer.
+ * <p/>
+ * Note that we override this method due to a bug in the parsing deployers, which results in only 1 file with the "name" being picked up
+ * from the metadata locations of the unit, even if there are more than one files with that name.
+ * For example: If a .war had faces-config.xml in .war/WEB-INF and .war/lib/somejar.jar/META-INF folders, then ideally both these
+ * files should have been picked up. But due to a bug in the parsing deployers, only the .war/WEB-INF/faces-config.xml would be picked up.
+ * Hence we override this method to fix the problem, by picking all available faces-config.xml from the metadata locations and parsing
+ * each of those.
+ *
+ * @param unit The deployment unit
+ * @param name The name of the file the deployer is interested in
+ * @param output The metadata output
+ * @return
+ * @throws Exception
+ */
+ @Override
+ protected JSFDeployment parse(DeploymentUnit unit, String name, JSFDeployment output) throws Exception {
+ if (unit instanceof VFSDeploymentUnit == false) {
+ return null;
+ }
+
+ if (ignoreName(unit, name)) {
+ return null;
+ }
+
+ VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
+ List<VirtualFile> facesConfigXmlFiles = vfsDeploymentUnit.getMetaDataFiles(new FacesConfigXmlFileNameMatchFilter(), MetaDataTypeFilter.ALL);
+ if (facesConfigXmlFiles == null || facesConfigXmlFiles.isEmpty()) {
+ return null;
+ }
+ JSFDeployment jsfDeployment = vfsDeploymentUnit.getAttachment(JSFDeployment.class);
+ for (VirtualFile facesConfigXmlFile : facesConfigXmlFiles) {
+ if (this.ignoreFile(vfsDeploymentUnit, facesConfigXmlFile)) {
+ continue;
+ }
+ jsfDeployment = this.parse(vfsDeploymentUnit, facesConfigXmlFile, jsfDeployment);
+ }
+ return jsfDeployment;
+ }
+
+ /**
+ * Parse the passed faces configuration <code>file</code> and update the <code>jsfDeployment</code> with the class names
+ * of the managed beans configured in that file.
+ *
+ * @param unit The deployment unit
+ * @param file The faces configuration file
+ * @param jsfDeployment The {@link JSFDeployment} metadata
+ * @return
+ * @throws Exception
+ */
+ @Override
+ protected JSFDeployment parse(VFSDeploymentUnit unit, VirtualFile file, JSFDeployment jsfDeployment) throws Exception {
+ URL facesConfigURL = file.toURL();
+ if (jsfDeployment == null) {
+ // create the jsf deployment. Note that we don't have to attach it to the deployment unit, since that part
+ // will be done by the AbstractVFSParsingDeployer which will attach the return value of this method to the unit.
+ jsfDeployment = new JSFDeployment();
+ }
+ // parse the xml file and update the jsf deployment
+ FacesConfigParsingUtil.parse(unit, facesConfigURL, jsfDeployment);
+ // return the updated jsf deployment
+ return jsfDeployment;
+ }
+
+ /**
+ * A file name based virtual file filter which accepts only files named faces-config.xml which
+ * are present in a META-INF folder or a WEB-INF folder.
+ */
+ private class FacesConfigXmlFileNameMatchFilter implements VirtualFileFilterWithAttributes {
+
+ public VisitorAttributes getAttributes() {
+ return VisitorAttributes.LEAVES_ONLY;
+ }
+
+ /**
+ * Returns true if the file is named faces-config.xml and is present in META-INF or WEB-INF folder.
+ * Else returns false.
+ *
+ * @param file
+ * @return
+ */
+ public boolean accepts(VirtualFile file) {
+ if (file == null) {
+ return false;
+ }
+ String fileName = file.getName();
+ if (fileName.equals("faces-config.xml")) {
+ // file name matches, now make sure its parent is META-INF or WEB-INF
+ VirtualFile parent = file.getParent();
+ if (parent == null) {
+ return false;
+ }
+ String parentName = parent.getName();
+ if (parentName.equals("META-INF") || parentName.equals("WEB-INF")) {
+ // it's a match!
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+}
Added: trunk/server/src/main/java/org/jboss/web/deployers/FacesConfigParsingUtil.java
===================================================================
--- trunk/server/src/main/java/org/jboss/web/deployers/FacesConfigParsingUtil.java (rev 0)
+++ trunk/server/src/main/java/org/jboss/web/deployers/FacesConfigParsingUtil.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,224 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.web.deployers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployment.JSFDeployment;
+import org.jboss.logging.Logger;
+import org.jboss.util.xml.JBossEntityResolver;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+/**
+ * Use the {@link #parse(org.jboss.deployers.structure.spi.DeploymentUnit, java.net.URL, org.jboss.deployment.JSFDeployment)}
+ * method to parse a JSF faces configuration file
+ * <p/>
+ * Note that this class and the parse method just look for the presence of JSF managed beans and on finding such managed beans,
+ * update the {@link JSFDeployment}, passed to the parse method, with the managed bean class name.
+ * This class should <b>not</b> be used as a full fledged faces config file parser. The real and complete parsing of the
+ * faces configuration files is left to the JSF implementation provider.
+ *
+ * @author Jaikiran Pai
+ * @see https://issues.jboss.org/browse/JBAS-8318
+ */
+public class FacesConfigParsingUtil
+{
+ /**
+ * Logger
+ */
+ private static final Logger logger = Logger.getLogger(FacesConfigParsingUtil.class);
+
+ /**
+ * Entity resolver for JSF configuration files
+ */
+ private static final JBossEntityResolver jBossJSFEntityResolver = new JBossEntityResolver();
+
+ static
+ {
+ // JSF 1.0
+ jBossJSFEntityResolver.registerEntity("-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN", "web-facesconfig_1_0.dtd");
+ jBossJSFEntityResolver.registerEntity("http://java.sun.com/dtd/web-facesconfig_1_0.dtd", "web-facesconfig_1_0.dtd");
+ // JSF 1.1
+ jBossJSFEntityResolver.registerEntity("-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN", "web-facesconfig_1_1.dtd");
+ jBossJSFEntityResolver.registerEntity("http://java.sun.com/dtd/web-facesconfig_1_1.dtd", "web-facesconfig_1_1.dtd");
+ // JSF 1.2
+ jBossJSFEntityResolver.registerEntity("http://java.sun.com/xml/ns/j2ee/web-facesconfig_1_2.xsd", "web-facesconfig_1_2.xsd");
+ // JSF 2.0
+ // TODO: I can't find the facesconfig 2.0 xsd in our distribution. Enable and set the value correctly, once we figure out where it is
+ //jBossJSFEntityResolver.registerEntity("http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd", what here?);
+
+ }
+
+ /**
+ * Parses the faces configuration file represented by the <code>facesConfigXmlURL</code> and checks for the presence of
+ * any JSF managed beans. On finding any managed beans, this method updates the passed <code>jsfDeployment</code> with the
+ * managed bean class name.
+ *
+ * @param unit The deployment unit
+ * @param facesConfigXmlURL The faces config file URL
+ * @param jsfDeployment The JSFDeployment which will be updated with any managed bean class names, that might be found in the
+ * faces config file.
+ * @throws Exception
+ */
+ public static void parse(final DeploymentUnit unit, final URL facesConfigXmlURL, final JSFDeployment jsfDeployment) throws Exception
+ {
+ logger.debug("Checking for the presence of JSF managed-bean(s) in JSF config file: " + facesConfigXmlURL + " in deployment unit: " + unit);
+ // get the parser factory
+ SAXParserFactory parserFactory = getParserFactory();
+ // create a parser
+ SAXParser saxParser = parserFactory.newSAXParser();
+ InputStream inputStream = null;
+ try
+ {
+ // get the input stream and the input source for the faces config file
+ inputStream = getInputStream(facesConfigXmlURL);
+ InputSource inputSource = new InputSource(getInputStream(facesConfigXmlURL));
+ inputSource.setSystemId(facesConfigXmlURL.toExternalForm());
+
+ // parse it!
+ saxParser.parse(inputSource, new DefaultHandler()
+ {
+ /**
+ * Flag to keep track of managed-bean-class element being processed
+ */
+ private boolean managedBeanClassElementProcessingInProgress;
+
+ /**
+ * Uses the {@link JBossEntityResolver} to resolve the entity. If it cannot be resolved by the {@link JBossEntityResolver}
+ * then this method lets the {@link DefaultHandler} to resolve it.
+ *
+ * @param publicId
+ * @param systemId
+ * @return
+ * @throws IOException
+ * @throws SAXException
+ */
+ @Override
+ public InputSource resolveEntity(String publicId, String systemId) throws IOException, SAXException
+ {
+ // try resolving it with the JBossEntityResolver
+ InputSource source = jBossJSFEntityResolver.resolveEntity(publicId, systemId);
+ if (source != null)
+ {
+ return source;
+ }
+ // we couldn't resolve, so let the default handler try to resolve it
+ return super.resolveEntity(publicId, systemId);
+ }
+
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
+ {
+ // we are only interested in managed-bean-class element.
+ if (localName.equals("managed-bean-class"))
+ {
+ this.managedBeanClassElementProcessingInProgress = true;
+ }
+ // let the super do its job
+ super.startElement(uri, localName, qName, attributes);
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException
+ {
+ // reset the flag when the managed-bean-class element ends
+ if (localName.equals("managed-bean-class"))
+ {
+ this.managedBeanClassElementProcessingInProgress = false;
+ }
+ // let super do its job
+ super.endElement(uri, localName, qName);
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException
+ {
+ // if we are currently processing the managed-bean-class element, then fetch the managed bean
+ // class name text
+ if (this.managedBeanClassElementProcessingInProgress)
+ {
+ // get the managed bean class name
+ String managedBeanClassName = new String(ch, start, length);
+ if (!managedBeanClassName.trim().isEmpty())
+ {
+ logger.debug("Found JSF managed bean class: " + managedBeanClassName + " in unit " + unit);
+ // add it to the jsf deployment
+ jsfDeployment.addManagedBean(managedBeanClassName);
+ }
+ }
+ // let super do its job now
+ super.characters(ch, start, length);
+ }
+ });
+ }
+ finally
+ {
+ if (inputStream != null)
+ {
+ inputStream.close();
+ }
+ }
+ return;
+
+ }
+
+ /**
+ * Returns a instance of {@link SAXParserFactory}
+ *
+ * @return
+ */
+ private static SAXParserFactory getParserFactory()
+ {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setValidating(false);
+ factory.setNamespaceAware(true);
+ return factory;
+ }
+
+ /**
+ * Returns the {@link InputStream} for the passed <code>url</code>
+ *
+ * @param url
+ * @return
+ * @throws IOException
+ */
+ private static InputStream getInputStream(URL url) throws IOException
+ {
+ URLConnection conn = url.openConnection();
+ conn.setUseCaches(false);
+ return new BufferedInputStream(conn.getInputStream());
+
+ }
+
+}
Modified: trunk/server/src/main/java/org/jboss/web/deployers/SpecCompliantWarAnnotationDeployer.java
===================================================================
--- trunk/server/src/main/java/org/jboss/web/deployers/SpecCompliantWarAnnotationDeployer.java 2011-05-13 06:37:08 UTC (rev 111363)
+++ trunk/server/src/main/java/org/jboss/web/deployers/SpecCompliantWarAnnotationDeployer.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -23,11 +23,9 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
+import javax.annotation.ManagedBean;
import javax.servlet.AsyncListener;
import javax.servlet.Filter;
import javax.servlet.Servlet;
@@ -41,6 +39,7 @@
import javax.servlet.jsp.tagext.Tag;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployment.JSFDeployment;
import org.jboss.metadata.annotation.creator.AnnotationContext;
import org.jboss.metadata.annotation.creator.web.Web30MetaDataCreator;
import org.jboss.metadata.annotation.finder.AnnotationFinder;
@@ -76,7 +75,7 @@
* However, for this {@link SpecCompliantWarAnnotationDeployer} to work correctly, we need to know if a specific class
* has been marked as a JSF managed bean (via faces-config.xml). Currently there's no way to get that information
* during deployment phase of a unit. Needs more thought on how to get this working cleanly.
- * @see https://issues.jboss.org/browse/JBAS-8775. Once this deployer is fully functional, it will replace the
+ * @see https://issues.jboss.org/browse/JBAS-8775. Once this deployer is fully functional, it will replace the
* {@link WarAnnotationMetaDataDeployer}
*
* @author Jaikiran Pai
@@ -87,9 +86,10 @@
public SpecCompliantWarAnnotationDeployer()
{
-
+ // run after the JSFDeployment attaching deployer(s) have run, so that we can get hold of the jsf managed beans
+ this.addInput(JSFDeployment.class);
}
-
+
@Override
protected void processMetaData(VFSDeploymentUnit unit, List<VirtualFile> classpath) throws Exception
{
@@ -111,17 +111,17 @@
annotations.addAll(annotationContext.getFieldAnnotations());
Collection<Class<?>> specEligibleResourceInjectionClasses = this.getResourceInjectionEligibleWebAppClasses(resourceIndex, classpath);
- if (specEligibleResourceInjectionClasses.isEmpty())
- {
- return;
- }
boolean metaData = false;
+ JSFDeployment jsfDeployment = unit.getAttachment(JSFDeployment.class);
for (VirtualFile path : classpath)
{
Collection<Class<?>> eligibleAnnotatedClasses = new HashSet<Class<?>>();
for (Class<? extends Annotation> annotation : annotations)
{
Collection<Class<?>> annotatedClasses = resourceIndex.getAnnotatedClasses(path, annotation);
+ // include the jsf and Java EE6 managed beans as eligible for resource injection
+ specEligibleResourceInjectionClasses.addAll(this.getManagedBeans(jsfDeployment, annotatedClasses));
+ // filter out any extra non-spec classes which shouldn't be picked up for resource injection processing
eligibleAnnotatedClasses.addAll(this.retainResourceInjectionEligibleWebAppClasses(specEligibleResourceInjectionClasses, annotatedClasses));
}
WebMetaData annotationMetaData = creator.create(eligibleAnnotatedClasses);
@@ -237,4 +237,43 @@
return eligibleClasses;
}
+ private Collection<Class<?>> getManagedBeans(final JSFDeployment jsfDeployment, Collection<Class<?>> classes)
+ {
+ if (classes == null || classes.isEmpty())
+ {
+ return new HashSet<Class<?>>();
+ }
+ Collection<String> jsfManagedBeansClassNames = Collections.emptySet();
+ if (jsfDeployment != null)
+ {
+ jsfManagedBeansClassNames = jsfDeployment.getManagedBeans();
+ }
+ Collection<Class<?>> managedBeans = new HashSet<Class<?>>();
+ for (Class<?> klass : classes)
+ {
+ if (this.isJavaEE6ManagedBean(klass))
+ {
+ managedBeans.add(klass);
+ }
+ else if (this.isJSFManagedBean(jsfManagedBeansClassNames, klass))
+ {
+ managedBeans.add(klass);
+ }
+ }
+ return managedBeans;
+ }
+
+ private boolean isJSFManagedBean(final Collection<String> jsfManagedBeanClassNames, final Class<?> klass)
+ {
+ if (jsfManagedBeanClassNames == null || jsfManagedBeanClassNames.isEmpty())
+ {
+ return false;
+ }
+ return jsfManagedBeanClassNames.contains(klass.getName());
+ }
+
+ private boolean isJavaEE6ManagedBean(final Class<?> klass)
+ {
+ return klass.isAnnotationPresent(ManagedBean.class);
+ }
}
Added: trunk/server/src/main/java/org/jboss/web/deployers/WebContextParamFacesConfigParsingDeployer.java
===================================================================
--- trunk/server/src/main/java/org/jboss/web/deployers/WebContextParamFacesConfigParsingDeployer.java (rev 0)
+++ trunk/server/src/main/java/org/jboss/web/deployers/WebContextParamFacesConfigParsingDeployer.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,188 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.web.deployers;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployment.JSFDeployment;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.javaee.spec.ParamValueMetaData;
+import org.jboss.metadata.web.spec.WebMetaData;
+import org.jboss.vfs.VirtualFile;
+
+import java.util.List;
+
+/**
+ * Deployer which picks up .war deployments and parses the JSF faces configuration files listed in the
+ * javax.faces.CONFIG_FILES context param of the web.xml of the deployment.
+ * <p/>
+ * Note that this deployer is just interested in the presence of any JSF managed beans in the faces configuration files
+ * listed in the javax.faces.CONFIG_FILES and doesn't do any real parsing of the faces configuration files. The real and
+ * complete parsing of the faces configuration files is left to the JSF implementation provider.
+ *
+ * @author Jaikiran Pai
+ * @see https://issues.jboss.org/browse/JBAS-8318
+ */
+public class WebContextParamFacesConfigParsingDeployer extends AbstractDeployer
+{
+ /**
+ * Logger
+ */
+ private static Logger logger = Logger.getLogger(WebContextParamFacesConfigParsingDeployer.class);
+
+ /**
+ * javax.faces.CONFIG_FILES context param
+ */
+ private static final String JAVAX_FACES_CONFIG_FILES_CONTEXT_PARAM_NAME = "javax.faces.CONFIG_FILES";
+
+ /**
+ * The default location /WEB-INF/faces-config.xml for an application
+ */
+ private static final String WEB_INF_FACES_CONFIG_XML = "/WEB-INF/faces-config.xml";
+
+ /**
+ *
+ */
+ public WebContextParamFacesConfigParsingDeployer()
+ {
+ // we depend on the parsed web.xml
+ this.setInput(WebMetaData.class);
+ // we output JSFDeployment
+ this.setOutput(JSFDeployment.class);
+ // we run in Parse phase
+ this.setStage(DeploymentStages.PARSE);
+ }
+
+
+ /**
+ * Checks for the presence of {@link WebMetaData} attachment in the deployment unit and then checks for
+ * javax.faces.CONFIG_FILES context param in the web metadata. If found, each of the paths specified in the
+ * context param value are resolved relative to the deployment unit root and the resulting file is parsed as
+ * a faces configuration file, to check for the presence of any JSF managed beans. If any JSF managed beans are found,
+ * those are then registered in a {@link JSFDeployment}, which is then attached to the deployment unit.
+ *
+ * @param unit The deployment unit being processed
+ * @throws DeploymentException
+ */
+ public void deploy(final DeploymentUnit unit) throws DeploymentException
+ {
+ // we require a VFSDeploymentUnit, to be able to pick up context relative
+ // config files
+ if (unit instanceof VFSDeploymentUnit == false)
+ {
+ return;
+ }
+ final VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit) unit;
+ // get hold of the parsed web.xml metadata
+ WebMetaData webMetaData = unit.getAttachment(WebMetaData.class);
+ // shouldn't really happen, because we have set WebMetaData as a required input.
+ if (webMetaData == null)
+ {
+ return;
+ }
+ List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
+ if (contextParams == null || contextParams.isEmpty())
+ {
+ return;
+ }
+ JSFDeployment jsfDeployment = vfsDeploymentUnit.getAttachment(JSFDeployment.class);
+ if (jsfDeployment == null)
+ {
+ // create and attach
+ jsfDeployment = new JSFDeployment();
+ vfsDeploymentUnit.addAttachment(JSFDeployment.class, jsfDeployment);
+ }
+ for (ParamValueMetaData contextParam : contextParams)
+ {
+ if (contextParam == null)
+ {
+ continue;
+ }
+ if (JAVAX_FACES_CONFIG_FILES_CONTEXT_PARAM_NAME.equals(contextParam.getParamName()))
+ {
+ try
+ {
+ logger.debug("Found " + JAVAX_FACES_CONFIG_FILES_CONTEXT_PARAM_NAME + " param with values: "
+ + contextParam.getParamValue() + " in unit " + vfsDeploymentUnit);
+ // process each of the paths specified in the context param value
+ this.processConfigFilesContextParamValue(vfsDeploymentUnit, jsfDeployment, contextParam.getParamValue());
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Parses the context param value representing the relative paths to faces configuration files. Each of the file
+ * represented by the path, is then parsed using {@link FacesConfigParsingUtil} to check for the presence of JSF
+ * managed beans
+ *
+ * @param vfsDeploymentUnit The deployment unit
+ * @param jsfDeployment The JSF deployment metadata
+ * @param configFilesContextParamValue The javax.faces.CONFIG_FILES context param value
+ * @throws Exception
+ */
+ private void processConfigFilesContextParamValue(final VFSDeploymentUnit vfsDeploymentUnit, final JSFDeployment jsfDeployment, final String configFilesContextParamValue) throws Exception
+ {
+ if (configFilesContextParamValue == null)
+ {
+ return;
+ }
+ // trim the context param value
+ String trimmedConfigParamValues = configFilesContextParamValue.trim();
+ // split the paths which are separated by "," delimiter
+ String[] paths = trimmedConfigParamValues.split(",");
+ for (String path : paths)
+ {
+ // trim each path
+ path = path.trim();
+ if (path.isEmpty())
+ {
+ continue;
+ }
+ // skip this path, since .war/WEB-INF/faces-config.xml is by default parsed
+ // (by a separate deployer)
+ if (WEB_INF_FACES_CONFIG_XML.equals(path))
+ {
+ continue;
+ }
+ // get hold of the file relative to the deployment unit root
+ VirtualFile facesConfigXml = vfsDeploymentUnit.getRoot().getChild(path);
+ // for a file which wasn't found, just log a WARN and move on to the next
+ if (facesConfigXml == null)
+ {
+ logger.warn("Faces config xml not found at relative path: " + path + " in unit " + vfsDeploymentUnit.getRoot());
+ continue;
+ }
+ logger.debug("Found faces config xml with relative path: " + path + " in unit " + vfsDeploymentUnit.getRoot());
+ // parse the faces config file
+ FacesConfigParsingUtil.parse(vfsDeploymentUnit, facesConfigXml.toURL(), jsfDeployment);
+ }
+ }
+}
Modified: trunk/testsuite/imports/sections/web.xml
===================================================================
--- trunk/testsuite/imports/sections/web.xml 2011-05-13 06:37:08 UTC (rev 111363)
+++ trunk/testsuite/imports/sections/web.xml 2011-05-13 07:08:06 UTC (rev 111364)
@@ -952,6 +952,33 @@
<include name="jboss-service.xml"/>
</fileset>
</jar>
-
+
+ <jar destfile="${build.lib}/jbas-8318-jsf-beans.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/test/web/jbas8318/JSFManagedBeanInLibJarMetaInf.class"/>
+ </fileset>
+ <fileset dir="${build.resources}/web/jbas-8318/jar">
+ <include name="META-INF/*.xml"/>
+ </fileset>
+ </jar>
+
+ <war destfile="${build.lib}/jbas-8318.war" webxml="${build.resources}/web/jbas-8318/WEB-INF/web.xml">
+ <webinf dir="${build.resources}/web/jbas-8318/WEB-INF">
+ <include name="*"/>
+ </webinf>
+ <classes dir="${build.classes}">
+ <include name="org/jboss/test/web/jbas8318/*.class"/>
+ </classes>
+ <fileset dir="${build.resources}/web/jbas-8318">
+ <include name="**/*.jsp"/>
+ </fileset>
+ <fileset dir="${build.resources}/web/jbas-8318">
+ <include name="META-INF/*.xml"/>
+ </fileset>
+ <lib dir="${build.lib}">
+ <include name="jbas-8318-jsf-beans.jar"/>
+ </lib>
+ </war>
+
</target>
</project>
Added: trunk/testsuite/src/main/org/jboss/test/web/jbas8318/BaseServlet.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/jbas8318/BaseServlet.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/jbas8318/BaseServlet.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.web.jbas8318;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServlet;
+import javax.transaction.UserTransaction;
+
+/**
+ * User: jpai
+ */
+public class BaseServlet extends HttpServlet
+{
+ @Resource
+ protected UserTransaction utInServletBase;
+
+ protected String envEntryStringInServletBase;
+
+ @Resource(name="simpleString")
+ public void setSimpleEnvEntry(String envEntry)
+ {
+ this.envEntryStringInServletBase = envEntry;
+ }
+
+}
Added: trunk/testsuite/src/main/org/jboss/test/web/jbas8318/DummyResource.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/jbas8318/DummyResource.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/jbas8318/DummyResource.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.web.jbas8318;
+
+import java.io.Serializable;
+
+/**
+ * User: jpai
+ */
+public class DummyResource implements Serializable
+{
+}
Added: trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFBaseComponent.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFBaseComponent.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFBaseComponent.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.web.jbas8318;
+
+import javax.annotation.Resource;
+import javax.transaction.UserTransaction;
+
+/**
+ * User: jpai
+ */
+public class JSFBaseComponent
+{
+ @Resource
+ protected UserTransaction utInBaseClass;
+
+ protected String envEntryStringInBaseClass;
+
+ @Resource(name="simpleString")
+ public void setSimpleEnvEntry(String envEntry)
+ {
+ this.envEntryStringInBaseClass = envEntry;
+ }
+}
Added: trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanInLibJarMetaInf.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanInLibJarMetaInf.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanInLibJarMetaInf.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.web.jbas8318;
+
+import javax.annotation.Resource;
+import javax.faces.FacesException;
+import javax.jms.Queue;
+import javax.jms.Topic;
+
+/**
+ * User: jpai
+ */
+public class JSFManagedBeanInLibJarMetaInf
+{
+ @Resource (mappedName = "queue/DLQ")
+ private Queue queue;
+
+ public boolean isQueueInjected()
+ {
+ if (this.queue == null)
+ {
+ throw new FacesException("Queue was not injected in " + this.getClass().getName());
+ }
+ return true;
+ }
+}
Added: trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanInMetaInf.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanInMetaInf.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanInMetaInf.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.web.jbas8318;
+
+import javax.annotation.Resource;
+import javax.faces.FacesException;
+import javax.jms.Queue;
+
+/**
+ * User: jpai
+ */
+public class JSFManagedBeanInMetaInf
+{
+ @Resource (mappedName = "queue/DLQ")
+ private Queue dlq;
+
+ public boolean isQueueInjected()
+ {
+ if (this.dlq == null)
+ {
+ throw new FacesException("Queue is not injected in " + JSFManagedBeanInMetaInf.class.getName());
+ }
+ return true;
+ }
+
+}
Added: trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleJSFManagedBean.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleJSFManagedBean.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleJSFManagedBean.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.web.jbas8318;
+
+import javax.annotation.Resource;
+import javax.faces.FacesException;
+import javax.jms.Queue;
+import javax.transaction.UserTransaction;
+
+/**
+ * User: jpai
+ */
+public class SimpleJSFManagedBean extends JSFBaseComponent
+{
+
+ @Resource(mappedName = "queue/DLQ")
+ private Queue dlq;
+
+ @Resource(name = "simpleString")
+ private String simpleString;
+
+ @Resource
+ private UserTransaction userTransaction;
+
+ public boolean isSimpleEnvEntryInjected()
+ {
+ if (this.simpleString == null)
+ {
+ throw new FacesException("Simple env entry string was not injected in JSF managed bean");
+ }
+ return true;
+ }
+
+ public boolean isUserTransactionInjected()
+ {
+ if (this.userTransaction == null)
+ {
+ throw new FacesException("UserTransaction was not injected in JSF managed bean");
+ }
+ return true;
+ }
+
+ public boolean isQueueInjected()
+ {
+ if (this.dlq == null)
+ {
+ throw new FacesException("Queue was not injected in JSF managed bean");
+ }
+ return true;
+ }
+
+ public boolean isBaseClassResourcesInjected()
+ {
+ if (this.envEntryStringInBaseClass == null)
+ {
+ throw new FacesException("Simple env-entry string in base class of JSF managed bean was not injected");
+ }
+ if (this.utInBaseClass == null)
+ {
+ throw new FacesException("UserTransaction in base class of JSF managed bean was not injected");
+ }
+ return true;
+ }
+}
Added: trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleNonWebComponent.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleNonWebComponent.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleNonWebComponent.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.web.jbas8318;
+
+import javax.annotation.Resource;
+
+/**
+ * User: jpai
+ */
+public class SimpleNonWebComponent
+{
+
+ @Resource
+ private DummyResource dummyResource;
+
+ public DummyResource getDummyResource()
+ {
+ return this.dummyResource;
+ }
+}
Added: trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleServlet.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleServlet.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SimpleServlet.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.web.jbas8318;
+
+import javax.annotation.Resource;
+import javax.jms.Queue;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * User: jpai
+ */
+public class SimpleServlet extends BaseServlet
+{
+
+ public static final String SUCCESS_MESSAGE = "Success!";
+
+ @Resource
+ private javax.transaction.UserTransaction userTransaction;
+
+ @Resource (name="simpleString")
+ private String simpleEnvResource;
+
+ @Resource(mappedName = "queue/DLQ")
+ private Queue dlq;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ if (this.userTransaction == null)
+ {
+ throw new ServletException("UserTransaction resource not injected in the servlet");
+ }
+
+ if (this.dlq == null)
+ {
+ throw new ServletException("Queue not injected in the servlet");
+ }
+ if (this.simpleEnvResource == null)
+ {
+ throw new ServletException("Simple string env resource not injected in the servlet");
+ }
+ // check base class injections
+ if (this.utInServletBase == null)
+ {
+ throw new ServletException("UserTransaction in base class of servlet not injected");
+ }
+ if (this.envEntryStringInServletBase == null)
+ {
+ throw new ServletException("Simple env-entry string in base class of servlet not injected");
+ }
+ // everything injected
+ resp.getOutputStream().print(SUCCESS_MESSAGE);
+ }
+}
Added: trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SomeNonManagedPOJOInLibJar.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SomeNonManagedPOJOInLibJar.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/jbas8318/SomeNonManagedPOJOInLibJar.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.web.jbas8318;
+
+import javax.annotation.Resource;
+
+/**
+ * User: jpai
+ */
+public class SomeNonManagedPOJOInLibJar
+{
+
+ @Resource
+ private DummyResource unInjectable;
+
+ public DummyResource getUnInjectable()
+ {
+ return this.unInjectable;
+ }
+}
Added: trunk/testsuite/src/main/org/jboss/test/web/jbas8318/unit/ResourceInjectionOnNonJavaEEComponentsTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/web/jbas8318/unit/ResourceInjectionOnNonJavaEEComponentsTestCase.java (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/web/jbas8318/unit/ResourceInjectionOnNonJavaEEComponentsTestCase.java 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.web.jbas8318.unit;
+
+import junit.framework.Test;
+import org.apache.commons.httpclient.HttpMethod;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.util.web.HttpUtils;
+import org.jboss.test.web.jbas8318.SimpleServlet;
+
+import java.net.URL;
+
+/**
+ * Tests that Java EE resource injections on non-Java EE components are not processed and don't lead to deployment issues.
+ *
+ * @see https://issues.jboss.org/browse/JBAS-8318 for more details
+ * User: jpai
+ */
+public class ResourceInjectionOnNonJavaEEComponentsTestCase extends JBossTestCase
+{
+ private String baseURL = HttpUtils.getBaseURL();
+
+ private static final org.jboss.logging.Logger logger = org.jboss.logging.Logger.getLogger(ResourceInjectionOnNonJavaEEComponentsTestCase.class);
+
+ public ResourceInjectionOnNonJavaEEComponentsTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(ResourceInjectionOnNonJavaEEComponentsTestCase.class, "jbas-8318.war");
+ }
+
+
+ /**
+ * Test that Java EE resource injection in a servlet works as expected
+ *
+ * @throws Exception
+ */
+ public void testInjectionInServlet() throws Exception
+ {
+ URL url = new URL(baseURL + "jbas-8318/SimpleServlet");
+ HttpMethod request = HttpUtils.accessURL(url);
+ String response = request.getResponseBodyAsString();
+ logger.info("Response for url " + url + " is " + response);
+ assertEquals("Unexpected response from servlet", SimpleServlet.SUCCESS_MESSAGE, response);
+ }
+
+ /**
+ * Tests that Java EE resource injection in a JSF managed bean works as expected
+ *
+ * @throws Exception
+ */
+ public void testInjectionInJSFManagedBean() throws Exception
+ {
+ URL url = new URL(baseURL + "jbas-8318/test-jsf-injection.jsf");
+ HttpMethod request = HttpUtils.accessURL(url);
+ int statusCode = request.getStatusCode();
+ logger.info("Got status code: " + statusCode + " for URL " + url);
+ String response = request.getResponseBodyAsString();
+ logger.info("Response for URL " + url + " is " + response);
+ // no exceptions == injection worked fine and test passed.
+ // TODO: We might want to test for the html output to really make sure of the output.
+ }
+
+}
Added: trunk/testsuite/src/resources/web/jbas-8318/test-jsf-injection.jsp
===================================================================
--- trunk/testsuite/src/resources/web/jbas-8318/test-jsf-injection.jsp (rev 0)
+++ trunk/testsuite/src/resources/web/jbas-8318/test-jsf-injection.jsp 2011-05-13 07:08:06 UTC (rev 111364)
@@ -0,0 +1,32 @@
+<%@page contentType="text/html"%>
+<%@page pageEncoding="UTF-8"%>
+<%@page import="org.jboss.test.web.jbas8318.*" %>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>JBAS-8318 JSF injection test</title>
+ </head>
+ <body>
+ <f:view>
+
+ <h:outputText rendered="#{simpleManagedBean.simpleEnvEntryInjected}" value="Success: Injection of simple env-entry string is ok" />
+ <br/>
+ <h:outputText rendered="#{simpleManagedBean.queueInjected}" value="Success: Injection of Queue is ok" />
+ <br/>
+ <h:outputText rendered="#{simpleManagedBean.userTransactionInjected}" value="Success: Injection of UserTransaction is ok" />
+ <br/>
+ <h:outputText rendered="#{simpleManagedBean.baseClassResourcesInjected}" value="Success: Injection of resources in base class is ok" />
+ <br/>
+
+ <h:outputText rendered="#{jsfManagedBeanInMetaInf.queueInjected}" value="Success: Injection of Queue in JSF managed bean configured in .war/META-INF/faces-config.xml is ok" />
+ <br/>
+
+ <h:outputText rendered="#{libJarJSFManagedBean.queueInjected}" value="Success: Injection of Queue in JSF managed bean configured in .war/lib/*.jar/META-INF/faces-config.xml is ok" />
+ <br/>
+ </f:view>
+ </body>
+</html>
Modified: trunk/tomcat/src/resources/standalone/war-deployers-jboss-beans.xml
===================================================================
--- trunk/tomcat/src/resources/standalone/war-deployers-jboss-beans.xml 2011-05-13 06:37:08 UTC (rev 111363)
+++ trunk/tomcat/src/resources/standalone/war-deployers-jboss-beans.xml 2011-05-13 07:08:06 UTC (rev 111364)
@@ -49,7 +49,7 @@
class="org.jboss.web.deployers.SharedJBossWebMetaDataDeployer">
<property name="webXml">${jboss.server.home.url}/deploy/jbossweb.sar/web.xml</property>
</bean>
- <bean name="WebAnnotationMetaDataDeployer" class="org.jboss.web.deployers.WarAnnotationMetaDataDeployer">
+ <bean name="WebAnnotationMetaDataDeployer" class="org.jboss.web.deployers.SpecCompliantWarAnnotationDeployer">
<property name="relativeOrder">2005</property>
<!-- Order this after AopMetaDataDeployer *if it is present* -->
<install method="addInput">
@@ -57,6 +57,23 @@
</install>
</bean>
+ <!--
+
+ Checks for the presence of JSF managed beans in WEB-INF/faces-config.xml and META-INF/faces-config.xml files
+ See https://issues.jboss.org/browse/JBAS-8318 for more details
+
+ -->
+ <bean name="FacesConfigParsingDeployer" class="org.jboss.web.deployers.FacesConfigParsingDeployer"/>
+
+ <!--
+
+ Checks for the presence of JSF managed beans in the files specified as context param values of
+ javax.faces.CONFIG_FILES context param of a web application.
+ See https://issues.jboss.org/browse/JBAS-8318 for more details
+
+ -->
+ <bean name="WebContextParamFacesConfigParsingDeployer" class="org.jboss.web.deployers.WebContextParamFacesConfigParsingDeployer"/>
+
<!-- See JBAS-6062 -->
<bean name="WebXmlLessDeployer" class="org.jboss.deployment.LegacyWebXmlLessDeployer"/>
Modified: trunk/tomcat/src/resources/standard/war-deployers-jboss-beans.xml
===================================================================
--- trunk/tomcat/src/resources/standard/war-deployers-jboss-beans.xml 2011-05-13 06:37:08 UTC (rev 111363)
+++ trunk/tomcat/src/resources/standard/war-deployers-jboss-beans.xml 2011-05-13 07:08:06 UTC (rev 111364)
@@ -50,7 +50,7 @@
class="org.jboss.web.deployers.SharedJBossWebMetaDataDeployer">
<property name="webXml">${jboss.server.home.url}/deploy/jbossweb.sar/web.xml</property>
</bean>
- <bean name="WebAnnotationMetaDataDeployer" class="org.jboss.web.deployers.WarAnnotationMetaDataDeployer">
+ <bean name="WebAnnotationMetaDataDeployer" class="org.jboss.web.deployers.SpecCompliantWarAnnotationDeployer">
<property name="relativeOrder">2005</property>
<!-- Order this after AopMetaDataDeployer *if it is present* -->
<install method="addInput">
@@ -58,6 +58,23 @@
</install>
</bean>
+ <!--
+
+ Checks for the presence of JSF managed beans in WEB-INF/faces-config.xml and META-INF/faces-config.xml files
+ See https://issues.jboss.org/browse/JBAS-8318 for more details
+
+ -->
+ <bean name="FacesConfigParsingDeployer" class="org.jboss.web.deployers.FacesConfigParsingDeployer"/>
+
+ <!--
+
+ Checks for the presence of JSF managed beans in the files specified as context param values of
+ javax.faces.CONFIG_FILES context param of a web application.
+ See https://issues.jboss.org/browse/JBAS-8318 for more details
+
+ -->
+ <bean name="WebContextParamFacesConfigParsingDeployer" class="org.jboss.web.deployers.WebContextParamFacesConfigParsingDeployer"/>
+
<!-- See JBAS-6062 -->
<bean name="WebXmlLessDeployer" class="org.jboss.deployment.LegacyWebXmlLessDeployer"/>
@@ -243,10 +260,9 @@
</uninstall>
</bean>
-
- <!-- A custom (a.k.a hack) deployer for merging jbossweb metadata -->
- <bean name="MergedJBossWebMetaDataDeployer"
- class="org.jboss.web.deployers.MergedJBossWebMetaDataHackDeployer">
- </bean>
+ <bean name="MergedJBossWebMetaDataDeployer"
+ class="org.jboss.web.deployers.MergedJBossWebMetaDataDeployer">
+ </bean>
+
</deployment>
Modified: trunk/tomcat/src/resources/war-deployers-jboss-beans.xml
===================================================================
--- trunk/tomcat/src/resources/war-deployers-jboss-beans.xml 2011-05-13 06:37:08 UTC (rev 111363)
+++ trunk/tomcat/src/resources/war-deployers-jboss-beans.xml 2011-05-13 07:08:06 UTC (rev 111364)
@@ -50,7 +50,7 @@
class="org.jboss.web.deployers.SharedJBossWebMetaDataDeployer">
<property name="webXml">${jboss.server.home.url}/deploy/jbossweb.sar/web.xml</property>
</bean>
- <bean name="WebAnnotationMetaDataDeployer" class="org.jboss.web.deployers.WarAnnotationMetaDataDeployer">
+ <bean name="WebAnnotationMetaDataDeployer" class="org.jboss.web.deployers.SpecCompliantWarAnnotationDeployer">
<property name="relativeOrder">2005</property>
<!-- Order this after AopMetaDataDeployer *if it is present* -->
<install method="addInput">
@@ -58,6 +58,23 @@
</install>
</bean>
+ <!--
+
+ Checks for the presence of JSF managed beans in WEB-INF/faces-config.xml and META-INF/faces-config.xml files
+ See https://issues.jboss.org/browse/JBAS-8318 for more details
+
+ -->
+ <bean name="FacesConfigParsingDeployer" class="org.jboss.web.deployers.FacesConfigParsingDeployer"/>
+
+ <!--
+
+ Checks for the presence of JSF managed beans in the files specified as context param values of
+ javax.faces.CONFIG_FILES context param of a web application.
+ See https://issues.jboss.org/browse/JBAS-8318 for more details
+
+ -->
+ <bean name="WebContextParamFacesConfigParsingDeployer" class="org.jboss.web.deployers.WebContextParamFacesConfigParsingDeployer"/>
+
<!-- See JBAS-6062 -->
<bean name="WebXmlLessDeployer" class="org.jboss.deployment.LegacyWebXmlLessDeployer"/>
More information about the jboss-cvs-commits
mailing list