[jboss-cvs] JBossAS SVN: r59900 - in branches/Branch_4_2/tomcat: src/main/org/jboss/web and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Jan 21 20:36:27 EST 2007
Author: stan.silvert at jboss.com
Date: 2007-01-21 20:36:27 -0500 (Sun, 21 Jan 2007)
New Revision: 59900
Added:
branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/
branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/
branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/config/
branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java
branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/config/Log4JConversionFilter.java
branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/serialization/
branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/serialization/JBossFacesObjectInputStream.java
branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/serialization/JBossSerializationProvider.java
Modified:
branches/Branch_4_2/tomcat/build.xml
branches/Branch_4_2/tomcat/src/resources/web.xml
Log:
Add JSF 1.2 integration code. JSF not yet working with latest JBossWeb.
Modified: branches/Branch_4_2/tomcat/build.xml
===================================================================
--- branches/Branch_4_2/tomcat/build.xml 2007-01-22 01:34:57 UTC (rev 59899)
+++ branches/Branch_4_2/tomcat/build.xml 2007-01-22 01:36:27 UTC (rev 59900)
@@ -54,7 +54,9 @@
<!-- The combined library classpath -->
<path id="library.classpath">
<path refid="sun.servlet.classpath"/>
+ <path refid="sun.jsf.classpath"/>
<path refid="apache.commons.classpath"/>
+ <path refid="apache.log4j.classpath"/>
<path refid="junit.junit.classpath"/>
<path refid="dom4j.dom4j.classpath"/>
<path refid="oswego.concurrent.classpath"/>
@@ -151,8 +153,8 @@
<mkdir dir="${build.classes}"/>
<javac destdir="${build.classes}"
optimize="${javac.optimize}"
- target="${javac.target}"
- source="${javac.source}"
+ target="1.5"
+ source="1.5"
debug="${javac.debug}"
depend="${javac.depend}"
verbose="${javac.verbose}"
@@ -225,14 +227,22 @@
</fileset>
</copy>
- <copy todir="${build.deploy}/jboss-web.deployer/jsf-libs">
- <fileset dir="${apache.myfaces.lib}">
- <include name="jstl.jar"/>
- <include name="myfaces-api.jar"/>
- <include name="myfaces-impl.jar"/>
- </fileset>
- </copy>
+ <copy todir="${build.deploy}/jboss-web.deployer"
+ file="${sun.jstl.lib}/jstl.jar" />
+ <copy todir="${build.deploy}/jboss-web.deployer/jsf-libs">
+ <fileset dir="${sun.jsf.lib}">
+ <include name="*.jar" />
+ </fileset>
+ </copy>
+
+ <!-- jar for jsf integration classes -->
+ <jar jarfile="${build.deploy}/jboss-web.deployer/jsf-libs/jboss-faces.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/web/jsf/integration/**"/>
+ </fileset>
+ </jar>
+
<jar jarfile="${build.deploy}/jboss-web.deployer/jbossweb-service.jar"
manifest="${build.etc}/default.mf">
<!-- The service classes -->
Added: branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java
===================================================================
--- branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java (rev 0)
+++ branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/config/JBossJSFConfigureListener.java 2007-01-22 01:36:27 UTC (rev 59900)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jsf.integration.config;
+
+import com.sun.faces.config.ConfigureListener;
+import com.sun.faces.util.Util;
+import java.util.logging.Filter;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import org.jboss.logging.Logger;
+
+/**
+ * This ServletContextListener sets up a JBoss-specific environment for JSF
+ * and then delegates the rest of the setup to the JSF RI.
+ *
+ * @author Stan Silvert
+ */
+public class JBossJSFConfigureListener extends ConfigureListener
+{
+
+ private static Logger LOG = Logger.getLogger(JBossJSFConfigureListener.class);
+
+ public static final String SHOULD_LOG_CONFIG_MESSAGES = "com.sun.faces.displayConfiguration";
+
+ private ServletContext servletContext;
+
+ @Override
+ public void contextInitialized(ServletContextEvent event)
+ {
+ this.servletContext = event.getServletContext();
+
+ // If the pluginClass is not set, assume Log4J
+ if (System.getProperty("org.jboss.logging.Logger.pluginClass") == null)
+ {
+ setLog4J();
+ }
+
+ super.contextInitialized(event);
+ }
+
+ /**
+ * If Log4J is being used, set a filter that converts JSF RI java.util.logger
+ * messages to Log4J messages.
+ */
+ private void setLog4J()
+ {
+ Filter conversionFilter = new Log4JConversionFilter(logConfigMessages());
+
+ java.util.logging.Logger.getLogger(Util.FACES_LOGGER)
+ .setFilter(conversionFilter);
+ java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.APPLICATION_LOGGER)
+ .setFilter(conversionFilter);
+ java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.CONFIG_LOGGER)
+ .setFilter(conversionFilter);
+ java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.CONTEXT_LOGGER)
+ .setFilter(conversionFilter);
+ java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.LIFECYCLE_LOGGER)
+ .setFilter(conversionFilter);
+ java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.RENDERKIT_LOGGER)
+ .setFilter(conversionFilter);
+ java.util.logging.Logger.getLogger(Util.FACES_LOGGER + Util.TAGLIB_LOGGER)
+ .setFilter(conversionFilter);
+ }
+
+ // should we log the configuration messages?
+ private boolean logConfigMessages()
+ {
+ String shouldLogConfigParam = this.servletContext.getInitParameter(SHOULD_LOG_CONFIG_MESSAGES);
+ return (shouldLogConfigParam != null) && (shouldLogConfigParam.equalsIgnoreCase("true"));
+ }
+
+}
Added: branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/config/Log4JConversionFilter.java
===================================================================
--- branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/config/Log4JConversionFilter.java (rev 0)
+++ branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/config/Log4JConversionFilter.java 2007-01-22 01:36:27 UTC (rev 59900)
@@ -0,0 +1,156 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jsf.integration.config;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Filter;
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.SimpleFormatter;
+import org.jboss.logging.Logger;
+
+/**
+ * This filter is used to convert java.util.logging messages from the JSF RI
+ * to Log4J messages.
+ *
+ * @author Stan Silvert
+ */
+public class Log4JConversionFilter implements Filter
+{
+
+ // cache Logger instances. Logger.getLogger() is known to be slow.
+ // See http://www.qos.ch/logging/thinkAgain.jsp
+ private Map<String, Logger> loggerCache = new HashMap<String, Logger>();
+
+ private Formatter formatter = new SimpleFormatter();
+
+ // should we log the INFO level config messages that tell about
+ // servlet context params?
+ private boolean logConfigMessages;
+
+ public Log4JConversionFilter(boolean logConfigMessages)
+ {
+ this.logConfigMessages = logConfigMessages;
+ }
+
+ private boolean isConfigStartupMessage(LogRecord record)
+ {
+ return record.getMessage().equals("jsf.config.listener.version") ||
+ record.getMessage().equals("jsf.config.listener.version.complete");
+ }
+
+ /**
+ * If the JSF RI message should be logged, convert the JDK 1.4
+ * LogRecord to a Log4J message.
+ *
+ * @return <code>false</code> because JDK 1.4 logging should not happen
+ * for JSF if this filter is active.
+ */
+ public boolean isLoggable(LogRecord record)
+ {
+ if (!logConfigMessages && isConfigStartupMessage(record)) return false;
+
+ Logger logger = getLogger(record);
+
+ if (record.getThrown() != null)
+ {
+ logWithThrowable(logger, record);
+ }
+ else
+ {
+ logWithoutThrowable(logger, record);
+ }
+
+ return false;
+ }
+
+ private void logWithThrowable(Logger logger, LogRecord record)
+ {
+ int loggedLevel = record.getLevel().intValue();
+ Object message = formatter.formatMessage(record);
+ Throwable throwable = record.getThrown();
+
+ if (loggedLevel == Level.INFO.intValue())
+ {
+ logger.info(message, throwable);
+ return;
+ }
+
+ if (loggedLevel == Level.WARNING.intValue())
+ {
+ logger.warn(message, throwable);
+ return;
+ }
+
+ if (loggedLevel == Level.SEVERE.intValue())
+ {
+ logger.fatal(message, throwable);
+ return;
+ }
+
+ logger.info(message, throwable);
+ }
+
+ private void logWithoutThrowable(Logger logger, LogRecord record)
+ {
+ int loggedLevel = record.getLevel().intValue();
+ Object message = formatter.formatMessage(record);
+
+ if (loggedLevel == Level.INFO.intValue())
+ {
+ logger.info(message);
+ return;
+ }
+
+ if (loggedLevel == Level.WARNING.intValue())
+ {
+ logger.warn(message);
+ return;
+ }
+
+ if (loggedLevel == Level.SEVERE.intValue())
+ {
+ logger.fatal(message);
+ return;
+ }
+
+ logger.info(message);
+ }
+
+ // get the Log4J logger corresponding to the java.util.logger.LogRecord
+ private Logger getLogger(LogRecord record)
+ {
+ String loggerName = record.getLoggerName();
+ Logger logger = loggerCache.get(loggerName);
+ if (logger == null)
+ {
+ logger = Logger.getLogger(loggerName);
+ loggerCache.put(loggerName, logger);
+ }
+
+ return logger;
+ }
+
+}
Added: branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/serialization/JBossFacesObjectInputStream.java
===================================================================
--- branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/serialization/JBossFacesObjectInputStream.java (rev 0)
+++ branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/serialization/JBossFacesObjectInputStream.java 2007-01-22 01:36:27 UTC (rev 59900)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jsf.integration.serialization;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectStreamClass;
+import org.jboss.serial.io.JBossObjectInputStream;
+
+/**
+ * Provides override of resolveClass() as required by the JSF spi. See javadoc
+ * of com.sun.faces.spi.SerializationProvider.createObjectInputStream for details.
+ *
+ * @author Stan Silvert
+ */
+public class JBossFacesObjectInputStream extends JBossObjectInputStream
+{
+ /**
+ * Create new JBossFacesObjectInputStream.
+ */
+ public JBossFacesObjectInputStream(InputStream source) throws IOException
+ {
+ super(source);
+ }
+
+ /**
+ * Make sure this resolves to a class from the proper class loader.
+ */
+ protected Class resolveClass(ObjectStreamClass streamClass) throws ClassNotFoundException, IOException
+ {
+ return Class.forName(streamClass.getName(), true, Thread.currentThread().getContextClassLoader());
+ }
+
+}
Added: branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/serialization/JBossSerializationProvider.java
===================================================================
--- branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/serialization/JBossSerializationProvider.java (rev 0)
+++ branches/Branch_4_2/tomcat/src/main/org/jboss/web/jsf/integration/serialization/JBossSerializationProvider.java 2007-01-22 01:36:27 UTC (rev 59900)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jsf.integration.serialization;
+
+import com.sun.faces.spi.SerializationProvider;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import org.jboss.logging.Logger;
+import org.jboss.serial.io.JBossObjectOutputStream;
+
+/**
+ * Provides interface between JSF RI and JBoss Serialization for better
+ * performance of client-side state saving.
+ *
+ * @author Stan Silvert
+ */
+public class JBossSerializationProvider implements SerializationProvider
+{
+ private static final Logger LOG = Logger.getLogger(JBossSerializationProvider.class);
+
+ /**
+ * No-arg constructor required.
+ */
+ public JBossSerializationProvider()
+ {
+ LOG.info("Using JBoss Serialization for JavaServer Faces.");
+ }
+
+ /**
+ * Create a fast ObjectInputStream using JBoss Serialization.
+ */
+ public ObjectInputStream createObjectInputStream(InputStream source) throws IOException {
+ return new JBossFacesObjectInputStream(source);
+ }
+
+ /**
+ * Create a fast ObjectOutputStream using JBoss Serialization.
+ */
+ public ObjectOutputStream createObjectOutputStream(OutputStream destination) throws IOException
+ {
+ return new JBossObjectOutputStream(destination);
+ }
+
+}
Modified: branches/Branch_4_2/tomcat/src/resources/web.xml
===================================================================
--- branches/Branch_4_2/tomcat/src/resources/web.xml 2007-01-22 01:34:57 UTC (rev 59899)
+++ branches/Branch_4_2/tomcat/src/resources/web.xml 2007-01-22 01:36:27 UTC (rev 59900)
@@ -13,6 +13,7 @@
<!-- -->
<!-- WARNING: Do not configure application-specific resources here! -->
<!-- They should go in the "/WEB-INF/web.xml" file in your application. -->
+
<!-- ================== Common filter Configuration ==================== -->
<filter>
@@ -34,6 +35,20 @@
<listener-class>org.jboss.web.tomcat.security.SecurityFlushSessionListener</listener-class>
</listener>
+ <!-- Configures JSF for a web application if the javax.faces.webapp.FacesServlet is declared -->
+ <!-- in web.xml. -->
+ <listener>
+ <listener-class>org.jboss.web.jsf.integration.config.JBossJSFConfigureListener</listener-class>
+ </listener>
+
+ <!-- Listens to all web app lifecycle events so that @PreDestroy can be called on -->
+ <!-- JSF managed beans that go out of scope. You can comment this out if you -->
+ <!-- don't use JSF or you don't use annotations on your managed beans. -->
+ <listener>
+ <listener-class>com.sun.faces.application.WebappLifecycleListener</listener-class>
+ </listener>
+
+
<!-- ================== Built In Servlet Definitions ==================== -->
@@ -239,6 +254,31 @@
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
+
+ <!-- Use a custom options class to allow the shared tag lib descriptors
+ to be loaded from jars in the tomcat sar conf/tlds directory. The
+ standard options implementation can only find taglibs based on the
+ class loader classpath.
+ -->
+ <init-param>
+ <param-name>engineOptionsClass</param-name>
+ <param-value>org.jboss.web.tomcat.service.jasper.JspServletOptions</param-value>
+ </init-param>
+ <!-- Specify the jars relative to the jbossweb-tomcat6.sar that should
+ be scanned for common tag lib descriptors to include in every war
+ deployment.
+ -->
+ <init-param>
+ <description>JSF standard tlds</description>
+ <param-name>tagLibJar0</param-name>
+ <param-value>jsf-libs/jsf-impl.jar</param-value>
+ </init-param>
+ <init-param>
+ <description>JSTL standard tlds</description>
+ <param-name>tagLibJar1</param-name>
+ <param-value>jstl.jar</param-value>
+ </init-param>
+
<load-on-startup>3</load-on-startup>
</servlet>
More information about the jboss-cvs-commits
mailing list