[jboss-cvs] JBossAS SVN: r79793 - in trunk/tomcat/src/main/org/jboss/web: tomcat/metadata and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 21 03:10:59 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-10-21 03:10:58 -0400 (Tue, 21 Oct 2008)
New Revision: 79793
Added:
trunk/tomcat/src/main/org/jboss/web/jsf/integration/injection/JBossScanningInjectionProvider.java
Modified:
trunk/tomcat/src/main/org/jboss/web/jsf/integration/injection/JBossDelegatingInjectionProvider.java
trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ContextXMLObjectModelFactory.java
trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ServerXMLObjectModelFactory.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java
Log:
Restore tomcat changes:
------------------------------------------------------------------------
r79470 | remy.maucherat at jboss.com | 2008-10-14 09:42:38 -0700 (Tue, 14 Oct 2008) | 2 lines
- Handle SessionCookie (actually one of the most in demand features).
- Forgot the attributes of the root element. Ooops.
------------------------------------------------------------------------
r79489 | remy.maucherat at jboss.com | 2008-10-14 12:05:10 -0700 (Tue, 14 Oct 2008) | 1 line
- Fix bugs parsing realms and connectors.
------------------------------------------------------------------------
r79524 | emuckenhuber | 2008-10-15 05:50:59 -0700 (Wed, 15 Oct 2008) | 1 line
[JBAS-6099] make process annotations reusable
------------------------------------------------------------------------
r79525 | emuckenhuber | 2008-10-15 05:52:52 -0700 (Wed, 15 Oct 2008) | 1 line
[JBAS-6099] additional javadoc and constructor
------------------------------------------------------------------------
r79526 | emuckenhuber | 2008-10-15 05:53:30 -0700 (Wed, 15 Oct 2008) | 1 line
[JBAS-6099] add not metadata based injection provider
------------------------------------------------------------------------
r79543 | remy.maucherat at jboss.com | 2008-10-15 08:28:49 -0700 (Wed, 15 Oct 2008) | 2 lines
- Add new code for parsing server.xml and context.xml files.
- Use TomcatService.OLD_CODE flag to enable (and recompile the 3 files).
Modified: trunk/tomcat/src/main/org/jboss/web/jsf/integration/injection/JBossDelegatingInjectionProvider.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/jsf/integration/injection/JBossDelegatingInjectionProvider.java 2008-10-21 06:56:44 UTC (rev 79792)
+++ trunk/tomcat/src/main/org/jboss/web/jsf/integration/injection/JBossDelegatingInjectionProvider.java 2008-10-21 07:10:58 UTC (rev 79793)
@@ -33,6 +33,7 @@
/**
* A JSF injection provider. This class delegates the injection to the <code>TomcatInjectionContainer</code>.
+ * The processing of this injectionProvider is based on the <code>JBossWebMetaData</code>
*
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
@@ -40,7 +41,7 @@
public class JBossDelegatingInjectionProvider implements InjectionProvider
{
/** The injection container. */
- private TomcatInjectionContainer injectionContainer = null;
+ protected TomcatInjectionContainer injectionContainer = null;
/** The logger. */
private static final Logger log = Logger.getLogger(InjectionProvider.class);
@@ -52,12 +53,22 @@
if(context instanceof ServletContext && context != null)
{
ServletContext servletContext = (ServletContext) (context);
- this.injectionContainer = (TomcatInjectionContainer) servletContext.getAttribute(InstanceManager.class.getName());
+ this.injectionContainer = (TomcatInjectionContainer) servletContext
+ .getAttribute(InstanceManager.class.getName());
+
}
if(injectionContainer == null)
log.debug("JSF injection not available for this web deployment.");
}
+ protected JBossDelegatingInjectionProvider(TomcatInjectionContainer injectionContainer)
+ {
+ this.injectionContainer = injectionContainer;
+
+ if(injectionContainer == null)
+ log.debug("JSF injection not available for this web deployment.");
+ }
+
public void inject(Object object) throws InjectionProviderException
{
if(! checkInjectionContainer()) return;
Copied: trunk/tomcat/src/main/org/jboss/web/jsf/integration/injection/JBossScanningInjectionProvider.java (from rev 79746, trunk/tomcat/src/main/org/jboss/web/jsf/integration/injection/JBossScanningInjectionProvider.java)
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/jsf/integration/injection/JBossScanningInjectionProvider.java (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/jsf/integration/injection/JBossScanningInjectionProvider.java 2008-10-21 07:10:58 UTC (rev 79793)
@@ -0,0 +1,183 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, 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.jsf.integration.injection;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.faces.context.FacesContext;
+import javax.servlet.ServletContext;
+
+import org.apache.InstanceManager;
+import org.jboss.logging.Logger;
+import org.jboss.web.tomcat.service.TomcatInjectionContainer;
+
+import com.sun.faces.spi.InjectionProvider;
+import com.sun.faces.spi.InjectionProviderException;
+
+/**
+ * A JSF injection provider.
+ * The dynamic processing of annotations and injections is handled by the
+ * <code>TomcatInjectionContainer</code>.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class JBossScanningInjectionProvider implements InjectionProvider
+{
+
+ /** The injection container. */
+ protected TomcatInjectionContainer injectionContainer = null;
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(InjectionProvider.class);
+
+ public JBossScanningInjectionProvider()
+ {
+ Object context = FacesContext.getCurrentInstance().getExternalContext().getContext();
+ // In case of a servletContext - could maybe also be a PortletContext !?
+ if (context != null && context instanceof ServletContext)
+ {
+ ServletContext servletContext = (ServletContext) (context);
+ this.injectionContainer = (TomcatInjectionContainer) servletContext
+ .getAttribute(InstanceManager.class.getName());
+ }
+ if (injectionContainer == null)
+ log.debug("JSF injection not available for this web deployment.");
+ }
+
+ protected JBossScanningInjectionProvider(TomcatInjectionContainer injectionContainer)
+ {
+ this.injectionContainer = injectionContainer;
+
+ if(injectionContainer == null)
+ log.debug("JSF injection not available for this web deployment.");
+ }
+
+ /**
+ * Invoke a postConstruct method annotated with @PostConstruct
+ *
+ * @param managedBean the managed bean
+ * @throws InjectionProviderException
+ */
+ public void invokePostConstruct(Object managedBean) throws InjectionProviderException
+ {
+ try
+ {
+ Method postConstruct = getLifeCycleMethod(managedBean, PostConstruct.class);
+
+ if (postConstruct != null)
+ {
+ boolean accessibility = postConstruct.isAccessible();
+ postConstruct.setAccessible(true);
+ postConstruct.invoke(managedBean);
+ postConstruct.setAccessible(accessibility);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new InjectionProviderException("PostConstruct failed on managed bean.", e);
+ }
+ }
+
+ /**
+ * Invoke a preDestroy method annotated with @PreDestroy
+ *
+ * @param managedBean the managed bean
+ * @throws InjectionProviderException
+ */
+ public void invokePreDestroy(Object managedBean) throws InjectionProviderException
+ {
+ try
+ {
+ Method preDestroy = getLifeCycleMethod(managedBean, PreDestroy.class);
+
+ if (preDestroy != null)
+ {
+ boolean accessibility = preDestroy.isAccessible();
+ preDestroy.setAccessible(true);
+ preDestroy.invoke(managedBean);
+ preDestroy.setAccessible(accessibility);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new InjectionProviderException("PreDestroy failed on managed bean.", e);
+ }
+ }
+
+ /**
+ * Process annotations and injection for a managedBean.
+ * This delegates the processing of annotations and injection
+ * to the <code>TomcatInjectionContainer</code>.
+ *
+ * @param managedBean the managed bean
+ * @throws InjectionProviderException
+ */
+ public void inject(Object managedBean) throws InjectionProviderException
+ {
+ if(! checkInjectionContainer()) return;
+ try
+ {
+ // Process annotations
+ injectionContainer.processAnnotations(managedBean);
+
+ // Process injectors
+ injectionContainer.processInjectors(managedBean);
+
+ }
+ catch(Exception e)
+ {
+ throw new InjectionProviderException("Injection failed on managed bean.", e);
+ }
+ }
+
+ private Method getLifeCycleMethod(Object managedBean, Class<? extends Annotation> annotation)
+ {
+ Method[] methods = managedBean.getClass().getDeclaredMethods();
+ Method lifeCycleMethod = null;
+ for (int i = 0; i < methods.length; i++)
+ {
+ if (methods[i].isAnnotationPresent(annotation))
+ {
+ if ((lifeCycleMethod != null) || (methods[i].getParameterTypes().length != 0)
+ || (Modifier.isStatic(methods[i].getModifiers())) || (methods[i].getExceptionTypes().length > 0)
+ || (!methods[i].getReturnType().getName().equals("void")))
+ {
+ throw new IllegalArgumentException("Invalid PostConstruct method.");
+ }
+ lifeCycleMethod = methods[i];
+ }
+ }
+
+ return lifeCycleMethod;
+ }
+
+ private boolean checkInjectionContainer()
+ {
+ return injectionContainer != null;
+ }
+
+}
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ContextXMLObjectModelFactory.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ContextXMLObjectModelFactory.java 2008-10-21 06:56:44 UTC (rev 79792)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ContextXMLObjectModelFactory.java 2008-10-21 07:10:58 UTC (rev 79793)
@@ -42,6 +42,17 @@
public Object newRoot(Object root, UnmarshallingContext ctx, String namespaceURI, String localName, Attributes attrs)
{
ContextMetaData metaData = new ContextMetaData();
+ if(attrs != null)
+ {
+ for(int i = 0; i <attrs.getLength(); i++)
+ {
+ String key = attrs.getLocalName(i);
+ String value = attrs.getValue(i);
+ if( metaData.getAttributes() == null)
+ metaData.setAttributes(new HashMap<String, Object>());
+ metaData.getAttributes().put(key, value);
+ }
+ }
return metaData;
}
@@ -104,8 +115,6 @@
Set<String> excludeAttributes = new HashSet<String>();
Object child = null;
- // TODO child.setName(attrs.getValue("name"));
-
if(parent instanceof ContextMetaData)
{
// <Valve/>
@@ -117,11 +126,19 @@
// <Parameter/>
else if("Parameter".equals(localName))
child = new ParameterMetaData();
+ // <Realm/>
+ else if("Realm".equals(localName))
+ child = new RealmMetaData();
// <SessionCookie/>
else if("SessionCookie".equals(localName))
{
- child = new SessionCookieMetaData();
- // FIXME: attributes
+ SessionCookieMetaData sessionCookie = new SessionCookieMetaData();
+ sessionCookie.setComment(getAttribute("comment", null, attrs));
+ sessionCookie.setDomain(getAttribute("domain", null, attrs));
+ sessionCookie.setPath(getAttribute("path", null, attrs));
+ sessionCookie.setHttpOnly(Boolean.parseBoolean(getAttribute("httpOnly", null, attrs)));
+ sessionCookie.setSecure(Boolean.parseBoolean(getAttribute("secure", null, attrs)));
+ child = sessionCookie;
}
// <Resources/>
else if("Resources".equals(localName))
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ServerXMLObjectModelFactory.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ServerXMLObjectModelFactory.java 2008-10-21 06:56:44 UTC (rev 79792)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/metadata/ServerXMLObjectModelFactory.java 2008-10-21 07:10:58 UTC (rev 79793)
@@ -167,7 +167,12 @@
{
// <Connector/>
if("Connector".equals(localName))
- child = new ConnectorMetaData();
+ {
+ ConnectorMetaData connector = new ConnectorMetaData();
+ connector.setProtocol(getAttribute("protocol", excludeAttributes, attrs));
+ connector.setExecutor(getAttribute("executor", excludeAttributes, attrs));
+ child = connector;
+ }
// <Engine/>
else if("Engine".equals(localName))
{
@@ -190,7 +195,7 @@
if(parent instanceof EngineMetaData)
{
- // <Valve/>
+ // <Valve/>
if("Valve".equals(localName))
child = new ValveMetaData();
// <Host/>
@@ -206,6 +211,9 @@
// <Listener/>
else if("Listener".equals(localName))
child = new ListenerMetaData();
+ // <Realm/>
+ else if("Realm".equals(localName))
+ child = new RealmMetaData();
}
if(parent instanceof HostMetaData)
@@ -216,6 +224,9 @@
// <Listener/>
else if("Listener".equals(localName))
child = new ListenerMetaData();
+ // <Realm/>
+ else if("Realm".equals(localName))
+ child = new RealmMetaData();
}
// Handle attributes for AnyXmlMetaData
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java 2008-10-21 06:56:44 UTC (rev 79792)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java 2008-10-21 07:10:58 UTC (rev 79793)
@@ -244,7 +244,7 @@
processInjectors(instance);
if (!catalinaContext.getIgnoreAnnotations())
{
- processAnnotations(instance);
+ processDynamicBeanAnnotations(instance);
postConstruct(instance);
}
return instance;
@@ -258,7 +258,7 @@
processInjectors(instance);
if (!catalinaContext.getIgnoreAnnotations())
{
- processAnnotations(instance);
+ processDynamicBeanAnnotations(instance);
postConstruct(instance);
}
return instance;
@@ -269,7 +269,7 @@
processInjectors(instance);
if (!catalinaContext.getIgnoreAnnotations())
{
- processAnnotations(instance);
+ processDynamicBeanAnnotations(instance);
postConstruct(instance);
}
}
@@ -363,6 +363,22 @@
}
/**
+ * Process annotations for dynamic beans only.
+ *
+ * @param object the object
+ * @throws IllegalAccessException
+ * @throws InvocationTargetException
+ * @throws NamingException
+ */
+ protected void processDynamicBeanAnnotations(Object object)
+ throws IllegalAccessException, InvocationTargetException, NamingException
+ {
+ // Only process annotation on dynamic beans
+ if(isDynamicBean(object))
+ processAnnotations(object);
+ }
+
+ /**
* When we get here, we are assuming that any XML defined injection has been already done.
* We will set up more here if the class being processed is a dynamic class.
*
@@ -375,9 +391,6 @@
throws IllegalAccessException, InvocationTargetException, NamingException
{
final boolean trace = log.isTraceEnabled();
- // Only process annotation on dynamic beans
- if(! isDynamicBean(object))
- return;
Map<AccessibleObject, Injector> injectors = getEncInjectionsForClass(object.getClass(), true);
if (injectors == null)
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java 2008-10-21 06:56:44 UTC (rev 79792)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossContextConfig.java 2008-10-21 07:10:58 UTC (rev 79793)
@@ -21,19 +21,25 @@
*/
package org.jboss.web.tomcat.service.deployers;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletContext;
import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.deploy.SessionCookie;
import org.apache.catalina.startup.ContextConfig;
+import org.apache.tomcat.util.IntrospectionUtils;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
import org.jboss.logging.Logger;
@@ -67,6 +73,13 @@
import org.jboss.metadata.web.spec.WebResourceCollectionMetaData;
import org.jboss.metadata.web.spec.WebResourceCollectionsMetaData;
import org.jboss.metadata.web.spec.WelcomeFileListMetaData;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.web.tomcat.metadata.ContextMetaData;
+import org.jboss.web.tomcat.metadata.ContextXMLObjectModelFactory;
+import org.jboss.web.tomcat.metadata.ParameterMetaData;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
@SuppressWarnings("unchecked")
public class JBossContextConfig extends ContextConfig
@@ -505,6 +518,150 @@
}
+ /**
+ * Process a "init" event for this Context.
+ */
+ protected void init() {
+
+ if (TomcatService.OLD_CODE) {
+ super.init();
+ return;
+ }
+
+ context.setConfigured(false);
+ ok = true;
+
+ if (!context.getOverride()) {
+ processContextConfig("context.xml", false);
+ processContextConfig(getHostConfigPath(org.apache.catalina.startup.Constants.HostContextXml), false);
+ }
+ // This should come from the deployment unit
+ processContextConfig(context.getConfigFile(), true);
+
+ }
+
+
+ protected void processContextConfig(String resourceName, boolean local)
+ {
+ ContextMetaData contextMetaData = null;
+ try {
+ ObjectModelFactory factory = new ContextXMLObjectModelFactory();
+ Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
+ u.setSchemaValidation(false);
+ u.setValidation(false);
+ InputStream is = null;
+ try {
+ if (local)
+ {
+ VirtualFile vf = ((VFSDeploymentUnit) deploymentUnitLocal.get()).getFile(resourceName);
+ if (vf != null)
+ is = vf.openStream();
+ }
+ else
+ {
+ is = getClass().getClassLoader().getResourceAsStream(resourceName);
+ }
+ if (is == null) {
+ return;
+ }
+ contextMetaData = ContextMetaData.class.cast(u.unmarshal(is, factory, null));
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.error("XML error parsing: " + resourceName, e);
+ ok = false;
+ return;
+ }
+
+ try {
+ if (contextMetaData != null)
+ {
+
+ if (contextMetaData.getAttributes() != null) {
+ Iterator<String> names = contextMetaData.getAttributes().keySet().iterator();
+ while (names.hasNext()) {
+ String name = names.next();
+ String value = (String) contextMetaData.getAttributes().get(name);
+ IntrospectionUtils.setProperty(context, name, value);
+ }
+ }
+
+ TomcatService.addLifecycleListeners(context, contextMetaData.getListeners());
+
+ // Context/Realm
+ if (contextMetaData.getRealm() != null) {
+ context.setRealm((org.apache.catalina.Realm) TomcatService.getInstance(contextMetaData.getRealm(), null));
+ }
+
+ // Context/Valve
+ TomcatService.addValves(context, contextMetaData.getValves());
+
+ // Context/InstanceListener
+ if (contextMetaData.getInstanceListeners() != null) {
+ Iterator<String> listeners = contextMetaData.getInstanceListeners().iterator();
+ while (listeners.hasNext())
+ {
+ context.addInstanceListener(listeners.next());
+ }
+ }
+
+ // Context/Loader
+ if (contextMetaData.getLoader() != null) {
+ // This probably won't work very well in JBoss
+ context.setLoader((org.apache.catalina.Loader) TomcatService.getInstance(contextMetaData.getLoader(),
+ "org.apache.catalina.loader.WebappLoader"));
+ }
+
+ // Context/Manager
+ if (contextMetaData.getManager() != null) {
+ context.setManager((org.apache.catalina.Manager) TomcatService.getInstance(contextMetaData.getManager(),
+ "org.apache.catalina.session.StandardManager"));
+ }
+
+ // Context/Parameter
+ if (contextMetaData.getParameters() != null) {
+ Iterator<ParameterMetaData> parameterMetaDatas = contextMetaData.getParameters().iterator();
+ while (parameterMetaDatas.hasNext())
+ {
+ ParameterMetaData parameterMetaData = parameterMetaDatas.next();
+ context.addApplicationParameter((org.apache.catalina.deploy.ApplicationParameter) TomcatService.getInstance(parameterMetaData, null));
+ }
+ }
+
+ // Context/Resources
+ if (contextMetaData.getResources() != null) {
+ context.setResources((javax.naming.directory.DirContext) TomcatService.getInstance(contextMetaData.getResources(),
+ "org.apache.naming.resources.FileDirContext"));
+ }
+
+ // Context/SessionCookie
+ if (contextMetaData.getSessionCookie() != null) {
+ SessionCookie sessionCookie = new SessionCookie();
+ sessionCookie.setComment(contextMetaData.getSessionCookie().getComment());
+ sessionCookie.setDomain(contextMetaData.getSessionCookie().getDomain());
+ sessionCookie.setHttpOnly(contextMetaData.getSessionCookie().getHttpOnly());
+ sessionCookie.setPath(contextMetaData.getSessionCookie().getPath());
+ sessionCookie.setSecure(contextMetaData.getSessionCookie().getSecure());
+ context.setSessionCookie(sessionCookie);
+ }
+
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("Error processing: " + resourceName, e);
+ ok = false;
+ }
+
+ }
+
protected void destroy() {
if (runDestroy) {
super.destroy();
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java 2008-10-21 06:56:44 UTC (rev 79792)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java 2008-10-21 07:10:58 UTC (rev 79793)
@@ -186,59 +186,63 @@
}
Registry.getRegistry().registerComponent(context, objectName, config.getContextClassName());
- String ctxConfig = null;
- File warFile = new File(url.getFile());
- if (warFile.isDirectory() == false)
- {
- // Using VFS access
- VFSDirContext resources = new VFSDirContext();
- resources.setVirtualFile(webApp.getDeploymentUnit().getFile(""));
- context.setResources(resources);
- // Find META-INF/context.xml
- VirtualFile file = webApp.getDeploymentUnit().getFile(CONTEXT_CONFIG_FILE);
- if (file != null)
+ if (TomcatService.OLD_CODE) {
+ String ctxConfig = null;
+ File warFile = new File(url.getFile());
+ if (warFile.isDirectory() == false)
{
- // Copy the META-INF/context.xml from the VFS to the temp folder
- InputStream is = file.openStream();
- FileOutputStream fos = null;
- try
+ // Using VFS access
+ VFSDirContext resources = new VFSDirContext();
+ resources.setVirtualFile(webApp.getDeploymentUnit().getFile(""));
+ context.setResources(resources);
+ // Find META-INF/context.xml
+ VirtualFile file = webApp.getDeploymentUnit().getFile(CONTEXT_CONFIG_FILE);
+ if (file != null)
{
- byte[] buffer = new byte[512];
- int bytes;
- // FIXME: use JBoss'temp folder instead
- File tempFile = File.createTempFile("context-", ".xml");
- tempFile.deleteOnExit();
- fos = new FileOutputStream(tempFile);
- while ((bytes = is.read(buffer)) > 0)
+ // Copy the META-INF/context.xml from the VFS to the temp folder
+ InputStream is = file.openStream();
+ FileOutputStream fos = null;
+ try
{
- fos.write(buffer, 0, bytes);
+ byte[] buffer = new byte[512];
+ int bytes;
+ // FIXME: use JBoss'temp folder instead
+ File tempFile = File.createTempFile("context-", ".xml");
+ tempFile.deleteOnExit();
+ fos = new FileOutputStream(tempFile);
+ while ((bytes = is.read(buffer)) > 0)
+ {
+ fos.write(buffer, 0, bytes);
+ }
+ ctxConfig = tempFile.getAbsolutePath();
}
- ctxConfig = tempFile.getAbsolutePath();
- }
- finally
- {
- is.close();
- if (fos != null)
+ finally
{
- fos.close();
+ is.close();
+ if (fos != null)
+ {
+ fos.close();
+ }
}
}
}
- }
- else
- {
- // Using direct filesystem access: no operation needed
- // Find META-INF/context.xml
- File webDD = new File(warFile, CONTEXT_CONFIG_FILE);
- if (webDD.exists() == true)
+ else
{
- ctxConfig = webDD.getAbsolutePath();
+ // Using direct filesystem access: no operation needed
+ // Find META-INF/context.xml
+ File webDD = new File(warFile, CONTEXT_CONFIG_FILE);
+ if (webDD.exists() == true)
+ {
+ ctxConfig = webDD.getAbsolutePath();
+ }
}
+
+ context.setConfigFile(ctxConfig);
+ } else {
+ context.setConfigFile(CONTEXT_CONFIG_FILE);
}
-
context.setInstanceManager(injectionContainer);
context.setDocBase(url.getFile());
- context.setConfigFile(ctxConfig);
context.setDefaultContextXml("context.xml");
context.setDefaultWebXml("conf/web.xml");
context.setPublicId(metaData.getPublicID());
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java 2008-10-21 06:56:44 UTC (rev 79792)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java 2008-10-21 07:10:58 UTC (rev 79793)
@@ -23,7 +23,11 @@
package org.jboss.web.tomcat.service.deployers;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Iterator;
+import java.util.List;
import javax.management.Attribute;
import javax.management.MBeanServer;
@@ -37,7 +41,9 @@
import org.apache.catalina.Lifecycle;
import org.apache.catalina.connector.Connector;
+import org.apache.catalina.startup.Catalina;
import org.apache.catalina.startup.CatalinaProperties;
+import org.apache.tomcat.util.IntrospectionUtils;
import org.apache.tomcat.util.modeler.Registry;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
@@ -45,7 +51,19 @@
import org.jboss.system.ServiceMBeanSupport;
import org.jboss.system.server.Server;
import org.jboss.system.server.ServerImplMBean;
+import org.jboss.web.tomcat.metadata.AnyXmlMetaData;
+import org.jboss.web.tomcat.metadata.ConnectorMetaData;
+import org.jboss.web.tomcat.metadata.EngineMetaData;
+import org.jboss.web.tomcat.metadata.HostMetaData;
+import org.jboss.web.tomcat.metadata.ListenerMetaData;
+import org.jboss.web.tomcat.metadata.ServerMetaData;
+import org.jboss.web.tomcat.metadata.ServerXMLObjectModelFactory;
+import org.jboss.web.tomcat.metadata.ServiceMetaData;
+import org.jboss.web.tomcat.metadata.ValveMetaData;
import org.jboss.web.tomcat.security.HttpServletRequestPolicyContextHandler;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
/**
* Temporary workaround to support controlling the lifecycle of the webserver runtime portion of TomcatDeployer via a
@@ -80,6 +98,8 @@
this.tomcatDeployer = tomcatDeployer;
}
+ public static boolean OLD_CODE = true;
+
// In our lifecycle, we invoke the webserver lifecycle-related operations
// in the TomcatDeployer
@@ -101,21 +121,179 @@
String objectNameS = tomcatDeployer.getDomain() + ":type=server";
ObjectName objectName = new ObjectName(objectNameS);
- // Set the modeler Registry MBeanServer to the that of the tomcat service
- Registry.getRegistry().setMBeanServer(server);
+ if (OLD_CODE) {
- Registry.getRegistry().registerComponent(Class.forName("org.apache.catalina.startup.Catalina").newInstance(),
- objectName, "org.apache.catalina.startup.Catalina");
+ // Set the modeler Registry MBeanServer to the that of the tomcat service
+ Registry.getRegistry().setMBeanServer(server);
- server.setAttribute(objectName, new Attribute("catalinaHome", System.getProperty("jboss.server.home.dir")));
- server.setAttribute(objectName, new Attribute("configFile", tomcatDeployer.getConfigFile()));
- server.setAttribute(objectName, new Attribute("useNaming", new Boolean(false)));
- server.setAttribute(objectName, new Attribute("useShutdownHook", new Boolean(false)));
- server.setAttribute(objectName, new Attribute("await", new Boolean(false)));
- server.setAttribute(objectName, new Attribute("redirectStreams", new Boolean(false)));
+ Registry.getRegistry().registerComponent(Class.forName("org.apache.catalina.startup.Catalina").newInstance(),
+ objectName, "org.apache.catalina.startup.Catalina");
+ server.setAttribute(objectName, new Attribute("catalinaHome", System.getProperty("jboss.server.home.dir")));
+ server.setAttribute(objectName, new Attribute("configFile", tomcatDeployer.getConfigFile()));
+ server.setAttribute(objectName, new Attribute("useNaming", new Boolean(false)));
+ server.setAttribute(objectName, new Attribute("useShutdownHook", new Boolean(false)));
+ server.setAttribute(objectName, new Attribute("await", new Boolean(false)));
+ server.setAttribute(objectName, new Attribute("redirectStreams", new Boolean(false)));
+
+ } else {
+
+ // Parse main server.xml
+ // FIXME: this could be done somewhere else
+ ObjectModelFactory factory = new ServerXMLObjectModelFactory();
+ Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
+ u.setSchemaValidation(false);
+ u.setValidation(false);
+ InputStream is = null;
+ ServerMetaData serverMetaData = null;
+ try {
+ File configFile = new File(tomcatDeployer.getConfigFile());
+ if (configFile.exists())
+ {
+ is = new FileInputStream(configFile);
+ }
+ else
+ {
+ is = getClass().getClassLoader().getResourceAsStream(tomcatDeployer.getConfigFile());
+ }
+ if (is == null) {
+ log.error("Could not read configured server.xml (will try default): " + tomcatDeployer.getConfigFile());
+ is = getClass().getClassLoader().getResourceAsStream("server.xml");
+ }
+ serverMetaData = ServerMetaData.class.cast(u.unmarshal(is, factory, null));
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+
+ // FIXME: could try to do stuff with EngineConfig and HostConfig, although neither
+ // should be useful in JBoss
+
+ // Create the Catalina instance
+ Catalina catalina = new Catalina();
+ catalina.setCatalinaHome(System.getProperty("jboss.server.home.dir"));
+ catalina.setUseNaming(false);
+ catalina.setUseShutdownHook(false);
+ catalina.setAwait(false);
+ catalina.setRedirectStreams(false);
+
+ // Set the modeler Registry MBeanServer to the that of the tomcat service
+ Registry.getRegistry(null, null).setMBeanServer(server);
+ // Register the Catalina instance
+ Registry.getRegistry(null, null).registerComponent(catalina, objectName, "org.apache.catalina.startup.Catalina");
+
+ // Use the server.xml metadata to create a Server instance and assign it to the Catalina instance
+
+ // Server
+ org.apache.catalina.Server catalinaServer =
+ (org.apache.catalina.Server) getInstance(serverMetaData, "org.apache.catalina.core.StandardServer");
+ addLifecycleListeners(catalinaServer, serverMetaData.getListeners());
+
+ // Server/Service
+ if (serverMetaData.getServices() == null)
+ {
+ throw new IllegalArgumentException("No services");
+ }
+ Iterator<ServiceMetaData> serviceMetaDatas = serverMetaData.getServices().iterator();
+ while (serviceMetaDatas.hasNext())
+ {
+ ServiceMetaData serviceMetaData = serviceMetaDatas.next();
+ org.apache.catalina.Service service =
+ (org.apache.catalina.Service) getInstance(serviceMetaData, "org.apache.catalina.core.StandardService");
+ addLifecycleListeners(service, serviceMetaData.getListeners());
+ service.setServer(catalinaServer);
+ catalinaServer.addService(service);
+
+ // Server/Service/Executor
+ // FIXME
+
+ // Server/Service/Connector
+ if (serviceMetaData.getConnectors() != null)
+ {
+ Iterator<ConnectorMetaData> connectorMetaDatas = serviceMetaData.getConnectors().iterator();
+ while (connectorMetaDatas.hasNext())
+ {
+ ConnectorMetaData connectorMetaData = connectorMetaDatas.next();
+ Connector connector = new Connector(connectorMetaData.getProtocol());
+ if (connectorMetaData.getAttributes() != null)
+ {
+ Iterator<String> names = connectorMetaData.getAttributes().keySet().iterator();
+ while (names.hasNext())
+ {
+ String name = names.next();
+ String value = (String) connectorMetaData.getAttributes().get(name);
+ IntrospectionUtils.setProperty(connector, name, value);
+ }
+ }
+ service.addConnector(connector);
+ }
+ }
+
+ // Server/Service/Engine
+ EngineMetaData engineMetaData = serviceMetaData.getEngine();
+ org.apache.catalina.Engine engine =
+ (org.apache.catalina.Engine) getInstance(engineMetaData, "org.apache.catalina.core.StandardEngine");
+ addLifecycleListeners(engine, engineMetaData.getListeners());
+ engine.setName(engineMetaData.getName());
+ engine.setJvmRoute(engineMetaData.getJvmRoute());
+ engine.setDefaultHost(engineMetaData.getDefaultHost());
+ service.setContainer(engine);
+
+ // Server/Service/Engine/Realm
+ if (engineMetaData.getRealm() != null) {
+ engine.setRealm((org.apache.catalina.Realm) getInstance(engineMetaData.getRealm(), null));
+ }
+
+ // Server/Service/Engine/Valve
+ addValves(engine, engineMetaData.getValves());
+
+ // Server/Service/Engine/Host
+ if (engineMetaData.getHosts() != null)
+ {
+ Iterator<HostMetaData> hostMetaDatas = engineMetaData.getHosts().iterator();
+ while (hostMetaDatas.hasNext())
+ {
+ HostMetaData hostMetaData = hostMetaDatas.next();
+ org.apache.catalina.Host host =
+ (org.apache.catalina.Host) getInstance(hostMetaData, "org.apache.catalina.core.StandardHost");
+ addLifecycleListeners(host, hostMetaData.getListeners());
+ host.setName(hostMetaData.getName());
+ // FIXME: not really needed, and could hurt extensibility; probably needed until JBW GA with a fix
+ host.setConfigClass("org.jboss.web.tomcat.service.deployers.JBossContextConfig");
+ engine.addChild(host);
+
+ // Server/Service/Engine/Host/Realm
+ if (hostMetaData.getRealm() != null) {
+ host.setRealm((org.apache.catalina.Realm) getInstance(hostMetaData.getRealm(), null));
+ }
+
+ // Server/Service/Engine/Host/Valve
+ addValves(host, hostMetaData.getValves());
+
+ // Server/Service/Engine/Host/Alias
+ if (hostMetaData.getAliases() != null) {
+ Iterator<String> aliases = hostMetaData.getAliases().iterator();
+ while (aliases.hasNext()) {
+ host.addAlias(aliases.next());
+ }
+ }
+
+ }
+ }
+
+ }
+
+ // Set the resulting Server to the Catalina instance
+ catalina.setServer(catalinaServer);
+ }
+
+ // Start Tomcat
server.invoke(objectName, "create", new Object[]{}, new String[]{});
-
server.invoke(objectName, "start", new Object[]{}, new String[]{});
// Set up the authenticators in JNDI such that they can be configured for web apps
@@ -165,6 +343,84 @@
}
+ /**
+ * Create a JavaBean corresponding to the given metadata, similar to what the digester is doing.
+ */
+ protected static Object getInstance(AnyXmlMetaData metaData, String defaultClassName) throws Exception
+ {
+ String className = metaData.getClassName();
+ if (className == null) {
+ className = defaultClassName;
+ }
+ if (className == null) {
+ throw new IllegalArgumentException("No className specified for element");
+ }
+ Object instance = TomcatService.class.getClassLoader().loadClass(className).newInstance();
+ if (metaData.getAttributes() != null) {
+ Iterator<String> names = metaData.getAttributes().keySet().iterator();
+ while (names.hasNext()) {
+ String name = names.next();
+ String value = (String) metaData.getAttributes().get(name);
+ IntrospectionUtils.setProperty(instance, name, value);
+ }
+ }
+ return instance;
+ }
+
+ /**
+ * Associate lifecycle listeners with the instance, if it implements Lifecycle.
+ */
+ protected static void addLifecycleListeners(Object instance, List<ListenerMetaData> list) throws Exception
+ {
+ if (list == null) {
+ return;
+ }
+ org.apache.catalina.Lifecycle lifecycle = null;
+ if (!(instance instanceof org.apache.catalina.Lifecycle))
+ {
+ return;
+ }
+ else
+ {
+ lifecycle = (org.apache.catalina.Lifecycle) instance;
+ }
+ Iterator<ListenerMetaData> listenerMetaDatas = list.iterator();
+ while (listenerMetaDatas.hasNext())
+ {
+ ListenerMetaData listenerMetaData = listenerMetaDatas.next();
+ lifecycle.addLifecycleListener((org.apache.catalina.LifecycleListener) getInstance(listenerMetaData, null));
+ }
+
+ }
+
+
+ /**
+ * Associate valves with the instance, if it implements Lifecycle.
+ */
+ protected static void addValves(Object instance, List<ValveMetaData> list) throws Exception
+ {
+ if (list == null) {
+ return;
+ }
+ org.apache.catalina.Pipeline pipeline = null;
+ if (!(instance instanceof org.apache.catalina.Pipeline))
+ {
+ return;
+ }
+ else
+ {
+ pipeline = (org.apache.catalina.Pipeline) instance;
+ }
+ Iterator<ValveMetaData> valveMetaDatas = list.iterator();
+ while (valveMetaDatas.hasNext())
+ {
+ ValveMetaData valveMetaData = valveMetaDatas.next();
+ pipeline.addValve((org.apache.catalina.Valve) getInstance(valveMetaData, null));
+ }
+
+ }
+
+
@Override
protected void stopService() throws Exception
{
More information about the jboss-cvs-commits
mailing list