djencks 2004/01/18 22:38:23
Modified: modules/web/src/java/org/apache/geronimo/web
AbstractWebApplication.java
WebDeploymentPlanner.java
modules/web/src/java/org/apache/geronimo/web/deployment
WebDeployer.java WebModule.java
modules/web/src/java/org/apache/geronimo/web/jetty
JettyWebApplication.java
JettyWebApplicationContext.java
Log:
Make connection factory use from servlets work (untested). Make gbean-based
web deployment work.
Revision Changes Path
1.16 +45 -17
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebApplication.java
Index: AbstractWebApplication.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/AbstractWebApplication.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- AbstractWebApplication.java 16 Jan 2004 23:31:21 -0000 1.15
+++ AbstractWebApplication.java 19 Jan 2004 06:38:23 -0000 1.16
@@ -107,40 +107,42 @@
protected String deploymentDescriptorStr;
//jndi context for webapp
- protected Context context;
+ private Context componentContext;
//servlet definitions
protected String[] servlets;
- // context path of webapp
+ // componentContext path of webapp
protected String contextPath;
//class loading delegation model. Default to web-app scope
private boolean java2ClassLoadingCompliance;
private ClassLoader parentClassLoader;
private UserTransactionImpl userTransaction;
+ private String contextID;
/**
* User transaction must be a parameter since it is also possibly
already included in the ReadOnlyContext
* @param uri
* @param parentClassLoader
- * @param webApp
+ * @param deploymentDescriptorDoc
* @param geronimoWebAppDocument
* @param contextPath
- * @param context
+ * @param componentContext
* @param java2ClassLoadingCompliance
* @param userTransaction
* @param transactionManager
* @param trackedConnectionAssociator
*/
- public AbstractWebApplication(URI uri, ClassLoader parentClassLoader,
WebApp webApp, GeronimoWebAppDocument geronimoWebAppDocument, String
contextPath,
- Context context, boolean
java2ClassLoadingCompliance, UserTransactionImpl userTransaction,
TransactionManager transactionManager, TrackedConnectionAssociator
trackedConnectionAssociator) {
+ public AbstractWebApplication(URI uri, String contextID, ClassLoader
parentClassLoader, Document deploymentDescriptorDoc, GeronimoWebAppDocument
geronimoWebAppDocument, String contextPath,
+ Context componentContext, boolean
java2ClassLoadingCompliance, UserTransactionImpl userTransaction,
TransactionManager transactionManager, TrackedConnectionAssociator
trackedConnectionAssociator) {
this.uri = uri;
+ this.contextID = contextID;
this.parentClassLoader = parentClassLoader;
- this.webApp = webApp;
+ this.deploymentDescriptorDoc = deploymentDescriptorDoc;
this.geronimoWebAppDoc = geronimoWebAppDocument;
this.contextPath = contextPath;
- this.context = context;
+ this.componentContext = componentContext;
this.java2ClassLoadingCompliance = java2ClassLoadingCompliance;
this.userTransaction = userTransaction;
userTransaction.setTransactionManager(transactionManager);
@@ -156,11 +158,19 @@
webApp = webApplicationContext.webApp;
geronimoWebAppDoc = webApplicationContext.geronimoWebAppDoc;
contextPath = webApplicationContext.contextPath;
- context = webApplicationContext.context;
+ componentContext = webApplicationContext.context;
userTransaction = webApplicationContext.userTransaction;
java2ClassLoadingCompliance =
webApplicationContext.java2ClassLoadingCompliance;
}
+ public UserTransactionImpl getUserTransaction() {
+ return userTransaction;
+ }
+
+ public void setUserTransaction(UserTransactionImpl userTransaction) {
+ this.userTransaction = userTransaction;
+ }
+
public TransactionManager getTransactionManager() {
return userTransaction.getTransactionManager();
}
@@ -177,6 +187,22 @@
userTransaction.setTrackedConnectionAssociator(trackedConnectionAssociator);
}
+ public Document getDeploymentDescriptorDoc() {
+ return deploymentDescriptorDoc;
+ }
+
+ public void setDeploymentDescriptorDoc(Document deploymentDescriptorDoc)
{
+ this.deploymentDescriptorDoc = deploymentDescriptorDoc;
+ }
+
+ public String getContextID() {
+ return contextID;
+ }
+
+ public void setContextID(String contextID) {
+ this.contextID = contextID;
+ }
+
/** Get the URI of this webapp
* @return the URI of the webapp
* @see org.apache.geronimo.web.WebApplication#getURI()
@@ -188,7 +214,7 @@
/**
* Getter for classloading compliance. If true, then classloading will
* delegate first to parent classloader a la Java2 spec. If false, then
- * webapps wanting to load class will try their own context class loader
first.
+ * webapps wanting to load class will try their own componentContext
class loader first.
* @return true if application is using Java 2 compliant class loading
*/
public boolean getJava2ClassLoadingCompliance() {
@@ -201,7 +227,7 @@
* @see org.apache.geronimo.web.WebApplication#getComponentContext()
*/
public Context getComponentContext() {
- return context;
+ return componentContext;
}
/*
@@ -283,19 +309,21 @@
static {
GBeanInfoFactory infoFactory = new
GBeanInfoFactory(AbstractWebApplication.class.getName());
infoFactory.addAttribute(new GAttributeInfo("URI", true));
+ infoFactory.addAttribute(new GAttributeInfo("ContextID", true));
infoFactory.addAttribute(new GAttributeInfo("ParentClassLoader",
true));
infoFactory.addAttribute(new GAttributeInfo("ContextPath", true));
- infoFactory.addAttribute(new GAttributeInfo("DeploymentDescriptor",
true));
+ infoFactory.addAttribute(new
GAttributeInfo("DeploymentDescriptorDoc", true));
infoFactory.addAttribute(new GAttributeInfo("GeronimoWebAppDoc",
true));
- infoFactory.addAttribute(new
GAttributeInfo("Java2ClassloadingCompliance", true));
+ infoFactory.addAttribute(new
GAttributeInfo("Java2ClassLoadingCompliance", true));
infoFactory.addAttribute(new GAttributeInfo("ComponentContext",
true));
infoFactory.addAttribute(new GAttributeInfo("Servlets", false));
+ infoFactory.addAttribute(new GAttributeInfo("UserTransaction",
true));
infoFactory.addEndpoint(new GEndpointInfo("TransactionManager",
TransactionManager.class.getName()));
infoFactory.addEndpoint(new
GEndpointInfo("TrackedConnectionAssociator",
TrackedConnectionAssociator.class.getName()));
infoFactory.setConstructor(new GConstructorInfo(
- Arrays.asList(new Object[]{"URI", "ParentClassLoader",
"WebApp", "GeronimoWebAppDoc", "ContextPath",
- "Context", "Java2ClassLoadingCompliance",
"UserTransaction", "TransactionManager", "TrackedConnectionAssociator"}),
- Arrays.asList(new Object[]{URI.class, ClassLoader.class,
WebApp.class, GeronimoWebAppDocument.class, String.class,
+ Arrays.asList(new Object[]{"URI", "ContextID",
"ParentClassLoader", "DeploymentDescriptorDoc", "GeronimoWebAppDoc",
"ContextPath",
+ "ComponentContext",
"Java2ClassLoadingCompliance", "UserTransaction", "TransactionManager",
"TrackedConnectionAssociator"}),
+ Arrays.asList(new Object[]{URI.class, String.class,
ClassLoader.class, Document.class, GeronimoWebAppDocument.class, String.class,
Context.class, Boolean.TYPE,
UserTransactionImpl.class, TransactionManager.class,
TrackedConnectionAssociator.class})
));
1.4 +27 -1
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebDeploymentPlanner.java
Index: WebDeploymentPlanner.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/WebDeploymentPlanner.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebDeploymentPlanner.java 30 Dec 2003 08:28:57 -0000 1.3
+++ WebDeploymentPlanner.java 19 Jan 2004 06:38:23 -0000 1.4
@@ -70,6 +70,7 @@
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.transaction.UserTransaction;
+import javax.transaction.TransactionManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -94,6 +95,7 @@
import org.apache.geronimo.kernel.jmx.JMXKernel;
import org.apache.geronimo.kernel.service.GeronimoAttributeInfo;
import org.apache.geronimo.kernel.service.GeronimoMBeanInfo;
+import org.apache.geronimo.kernel.service.GeronimoMBeanEndpoint;
import org.apache.geronimo.naming.java.ComponentContextBuilder;
import org.apache.geronimo.naming.java.ReadOnlyContext;
import org.apache.geronimo.naming.java.ReferenceFactory;
@@ -102,6 +104,7 @@
import org.apache.geronimo.xml.deployment.GeronimoWebAppLoader;
import org.apache.geronimo.xml.deployment.LoaderUtil;
import org.apache.geronimo.xml.deployment.WebAppLoader;
+import
org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
@@ -121,11 +124,16 @@
private String webApplicationClass;
private String containerName;
+ private TransactionManager transactionManager;
+ private TrackedConnectionAssociator trackedConnectionAssociator;
+
public static GeronimoMBeanInfo getGeronimoMBeanInfo() throws Exception {
GeronimoMBeanInfo mbeanInfo =
AbstractDeploymentPlanner.getGeronimoMBeanInfo(WebDeploymentPlanner.class.getName());
mbeanInfo.addAttributeInfo(new
GeronimoAttributeInfo("WebApplicationClass", true, true, "Name of the class of
WebApplications"));
mbeanInfo.addAttributeInfo(new
GeronimoAttributeInfo("ContainerName", true, true, "Name of the Web
Container"));
+ mbeanInfo.addEndpoint(new
GeronimoMBeanEndpoint("TransactionManager", TransactionManager.class,
ObjectName.getInstance("geronimo.transaction:role=TransactionManager"), true));
+ mbeanInfo.addEndpoint(new
GeronimoMBeanEndpoint("TrackedConnectionAssociator",
TrackedConnectionAssociator.class,
ObjectName.getInstance("geronimo.connector:role=ConnectionTrackingCoordinator"),
true));
return mbeanInfo;
}
@@ -145,6 +153,22 @@
this.containerName = containerName;
}
+ public TransactionManager getTransactionManager() {
+ return transactionManager;
+ }
+
+ public void setTransactionManager(TransactionManager transactionManager)
{
+ this.transactionManager = transactionManager;
+ }
+
+ public TrackedConnectionAssociator getTrackedConnectionAssociator() {
+ return trackedConnectionAssociator;
+ }
+
+ public void setTrackedConnectionAssociator(TrackedConnectionAssociator
trackedConnectionAssociator) {
+ this.trackedConnectionAssociator = trackedConnectionAssociator;
+ }
+
/**
* Something to be deployed.
* We will deploy it if it looks and smells like a webapp. That is, it
@@ -225,6 +249,8 @@
webApplicationContext.geronimoWebAppDoc = geronimoWebAppDoc;
webApplicationContext.contextPath = getContextPath(baseURI);
webApplicationContext.userTransaction = new UserTransactionImpl();
+
webApplicationContext.userTransaction.setTransactionManager(transactionManager);
+
webApplicationContext.userTransaction.setTrackedConnectionAssociator(trackedConnectionAssociator);
webApplicationContext.context =
getComponentContext(geronimoWebAppDoc, webApplicationContext.userTransaction);
MBeanMetadata metadata = new MBeanMetadata(webApplicationName,
1.3 +87 -66
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/deployment/WebDeployer.java
Index: WebDeployer.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/deployment/WebDeployer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WebDeployer.java 17 Jan 2004 01:32:38 -0000 1.2
+++ WebDeployer.java 19 Jan 2004 06:38:23 -0000 1.3
@@ -67,15 +67,24 @@
import javax.management.ObjectName;
import javax.transaction.UserTransaction;
import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.deployment.DeploymentModule;
import org.apache.geronimo.deployment.ModuleFactory;
import
org.apache.geronimo.deployment.model.geronimo.web.GeronimoWebAppDocument;
import org.apache.geronimo.deployment.service.GBeanDefault;
import org.apache.geronimo.deployment.util.DeploymentHelper;
+import org.apache.geronimo.deployment.xml.ParserFactory;
+import org.apache.geronimo.gbean.GAttributeInfo;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoFactory;
+import org.apache.geronimo.gbean.GConstructorInfo;
+import org.apache.geronimo.gbean.GEndpointInfo;
+import org.apache.geronimo.gbean.GOperationInfo;
import org.apache.geronimo.kernel.deployment.DeploymentException;
import org.apache.geronimo.kernel.deployment.scanner.URLInfo;
-import org.apache.geronimo.kernel.jmx.JMXKernel;
import org.apache.geronimo.naming.java.ComponentContextBuilder;
import org.apache.geronimo.naming.java.ReadOnlyContext;
import org.apache.geronimo.naming.java.ReferenceFactory;
@@ -98,20 +107,63 @@
* */
public class WebDeployer implements ModuleFactory {
- private final DocumentBuilder parser;
+ private static final Log log = LogFactory.getLog(WebDeployer.class);
+
+ private final static GBeanInfo GBEAN_INFO;
+
+ private final ParserFactory parserFactory;
private final String type;//"Jetty"
- private ObjectName transactionManager;
- private ObjectName trackedConnectionAssociator;
- private String webApplicationClass;
+ private ObjectName transactionManagerNamePattern;
+ private ObjectName trackedConnectionAssociatorNamePattern;
+ private final String webApplicationClass;
+ private boolean java2ClassLoadingCompliance;
- public WebDeployer(DocumentBuilder parser, String type, String
webApplicationClass, ObjectName transactionManager, ObjectName
trackedConnectionAssociator) {
- this.parser = parser;
+ public WebDeployer(ParserFactory parserFactory, String type, String
webApplicationClass, boolean java2ClassLoadingCompliance, ObjectName
transactionManagerNamePattern, ObjectName
trackedConnectionAssociatorNamePattern) {
+ this.parserFactory = parserFactory;
this.type = type;
this.webApplicationClass = webApplicationClass;
- this.transactionManager = transactionManager;
- this.trackedConnectionAssociator = trackedConnectionAssociator;
+ this.java2ClassLoadingCompliance = java2ClassLoadingCompliance;
+ this.transactionManagerNamePattern = transactionManagerNamePattern;
+ this.trackedConnectionAssociatorNamePattern =
trackedConnectionAssociatorNamePattern;
+ }
+
+ public ObjectName getTransactionManagerNamePattern() {
+ return transactionManagerNamePattern;
+ }
+
+ public void setTransactionManagerNamePattern(ObjectName
transactionManagerNamePattern) {
+ this.transactionManagerNamePattern = transactionManagerNamePattern;
+ }
+
+ public ObjectName getTrackedConnectionAssociatorNamePattern() {
+ return trackedConnectionAssociatorNamePattern;
+ }
+
+ public void setTrackedConnectionAssociatorNamePattern(ObjectName
trackedConnectionAssociatorNamePattern) {
+ this.trackedConnectionAssociatorNamePattern =
trackedConnectionAssociatorNamePattern;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getWebApplicationClass() {
+ return webApplicationClass;
+ }
+
+ public boolean isJava2ClassLoadingCompliance() {
+ return java2ClassLoadingCompliance;
+ }
+
+ public void setJava2ClassLoadingCompliance(boolean
java2ClassLoadingCompliance) {
+ this.java2ClassLoadingCompliance = java2ClassLoadingCompliance;
+ }
+
+ //endpoint
+ public ParserFactory getParserFactory() {
+ return parserFactory;
}
public DeploymentModule getModule(URLInfo urlInfo, URI moduleID) throws
DeploymentException {
@@ -121,75 +173,44 @@
if (deploymentHelper.locateGeronimoDD() == null ||
deploymentHelper.locateJ2EEDD() == null) {
return null;
}
+ DocumentBuilder parser = null;
+ try {
+ parser = parserFactory.getParser();
+ } catch (ParserConfigurationException e) {
+ throw new DeploymentException("Could not configure parser", e);
+ }
Document webAppDoc = deploymentHelper.getJ2EEDoc(parser);
if (webAppDoc == null) {
return null;
}
+ GeronimoWebAppDocument geronimoWebAppDoc = null;
Document geronimoWebAppDocument =
deploymentHelper.getGeronimoDoc(parser);
if (geronimoWebAppDocument == null) {
- return null;
+ log.info("No Geronimo dd found, no local jndi context will be
available");
+ } else {
+ geronimoWebAppDoc =
GeronimoWebAppLoader.load(geronimoWebAppDocument);
}
- GeronimoWebAppDocument geronimoWebAppDoc =
GeronimoWebAppLoader.load(geronimoWebAppDocument);
-
- LinkedHashSet path = new LinkedHashSet();
- //for now we rely on the Jetty/whatever classloader.
-
- //I wonder what this does
- URI baseURI = URI.create(urlInfo.getUrl().toString()).normalize();
-
- Map values = new HashMap(8);
- values.put("URI", baseURI);
- values.put("ParentClassLoader", null);//What do we put here?
- values.put("ContextPath", getContextPath(baseURI));
- values.put("DeploymentDescriptor", webAppDoc);
- values.put("GeronimoWebAppDoc", geronimoWebAppDoc);
- values.put("Java2ClassloadingCompliance", Boolean.FALSE);
- UserTransactionImpl userTransaction = new UserTransactionImpl();
- values.put("ComponentContext",
getComponentContext(geronimoWebAppDoc, userTransaction));
- values.put("UserTransaction", userTransaction);
-
- Map endpoints = new HashMap(2);
- endpoints.put("TransactionManager",
Collections.singleton(transactionManager));
- endpoints.put("TrackedConnectionAssociator",
Collections.singleton(trackedConnectionAssociator));
-
- List gbeanDefaults = Collections.singletonList(new
GBeanDefault(webApplicationClass, getWebApplicationObjectName(baseURI), values,
endpoints));
- return new WebModule(moduleID, urlInfo, new ArrayList(path),
gbeanDefaults);
+ return new WebModule(moduleID, urlInfo, webAppDoc,
geronimoWebAppDoc, this);
}
- private String getContextPath(URI baseURI) {
- String path = baseURI.getPath();
-
- if (path.endsWith("/")) {
- path = path.substring(0, path.length() - 1);
- }
-
- int sepIndex = path.lastIndexOf('/');
- if (sepIndex > 0) {
- path = path.substring(sepIndex + 1);
- }
-
- if (path.endsWith(".war")) {
- path = path.substring(0, path.length() - 4);
- }
-
- return "/" + path;
- }
+ static {
+ GBeanInfoFactory infoFactory = new
GBeanInfoFactory(WebDeployer.class.getName());
+ infoFactory.addAttribute(new GAttributeInfo("Type", true));
+ infoFactory.addAttribute(new GAttributeInfo("WebApplicationClass",
true));
+ infoFactory.addAttribute(new
GAttributeInfo("Java2ClassLoadingCompliance", true));
+ infoFactory.addAttribute(new
GAttributeInfo("TransactionManagerNamePattern", true));
+ infoFactory.addAttribute(new
GAttributeInfo("TrackedConnectionAssociatorNamePattern", true));
+ infoFactory.addOperation(new GOperationInfo("getModule", new
String[]{URLInfo.class.getName(), URI.class.getName()}));
+ infoFactory.addEndpoint(new GEndpointInfo("ParserFactory",
ParserFactory.class.getName()));
+ infoFactory.setConstructor(new GConstructorInfo(new
String[]{"ParserFactory", "Type", "WebApplicationClass",
"Java2ClassLoadingCompliance", "TransactionManagerNamePattern",
"TrackedConnectionAssociatorNamePattern"},
+ new Class[]{ParserFactory.class, String.class, String.class,
Boolean.TYPE, ObjectName.class, ObjectName.class}));
+ GBEAN_INFO = infoFactory.getBeanInfo();
- private ReadOnlyContext getComponentContext(GeronimoWebAppDocument
geronimoWebAppDoc, UserTransaction userTransaction) throws DeploymentException {
- if (geronimoWebAppDoc != null) {
- ReferenceFactory referenceFactory = new
JMXReferenceFactory(null);//JMXKernel.getMBeanServerId(getServer()));
- ComponentContextBuilder builder = new
ComponentContextBuilder(referenceFactory, userTransaction);
- ReadOnlyContext context =
builder.buildContext(geronimoWebAppDoc.getWebApp());
- return context;
- } else {
- return null;
- }
}
- private String getWebApplicationObjectName(URI baseURI) {
- return AbstractWebContainer.BASE_WEB_APPLICATION_NAME +
AbstractWebContainer.CONTAINER_CLAUSE + type + ",module=" +
ObjectName.quote(baseURI.toString());
+ public static GBeanInfo getGBeanInfo() {
+ return GBEAN_INFO;
}
-
}
1.2 +105 -49
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/deployment/WebModule.java
Index: WebModule.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/deployment/WebModule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WebModule.java 16 Jan 2004 23:42:54 -0000 1.1
+++ WebModule.java 19 Jan 2004 06:38:23 -0000 1.2
@@ -57,22 +57,29 @@
package org.apache.geronimo.web.deployment;
import java.net.URI;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.net.URLClassLoader;
+import java.util.Arrays;
+import java.util.Collections;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
+import javax.transaction.UserTransaction;
import org.apache.geronimo.deployment.ConfigurationCallback;
import org.apache.geronimo.deployment.DeploymentModule;
-import org.apache.geronimo.deployment.service.GBeanDefault;
+import
org.apache.geronimo.deployment.model.geronimo.web.GeronimoWebAppDocument;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.InvalidConfigurationException;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
import org.apache.geronimo.kernel.deployment.DeploymentException;
import org.apache.geronimo.kernel.deployment.scanner.URLInfo;
+import org.apache.geronimo.naming.java.ComponentContextBuilder;
+import org.apache.geronimo.naming.java.ReadOnlyContext;
+import org.apache.geronimo.naming.java.ReferenceFactory;
+import org.apache.geronimo.naming.jmx.JMXReferenceFactory;
+import org.apache.geronimo.transaction.manager.UserTransactionImpl;
+import org.apache.geronimo.web.AbstractWebContainer;
+import org.w3c.dom.Document;
/**
*
@@ -83,14 +90,16 @@
public class WebModule implements DeploymentModule {
private final URI moduleID;
private final URLInfo urlInfo;
- private final List pathURIs;
- private final List gbeanDefaults;
+ private Document deploymentDescriptorDoc;
+ private GeronimoWebAppDocument geronimoWebAppDoc;
+ private WebDeployer webDeployer;
- public WebModule(URI moduleID, URLInfo urlInfo, List urls, List
gbeanDefaults) {
+ public WebModule(URI moduleID, URLInfo urlInfo, Document webAppDoc,
GeronimoWebAppDocument geronimoWebAppDoc, WebDeployer webDeployer) {
this.moduleID = moduleID;
this.urlInfo = urlInfo;
- this.pathURIs = urls;
- this.gbeanDefaults = gbeanDefaults;
+ this.deploymentDescriptorDoc = webAppDoc;
+ this.geronimoWebAppDoc = geronimoWebAppDoc;
+ this.webDeployer = webDeployer;
}
@@ -102,47 +111,94 @@
}
public void defineGBeans(ConfigurationCallback callback, ClassLoader cl)
throws DeploymentException {
- for (Iterator i = gbeanDefaults.iterator(); i.hasNext();) {
- GBeanDefault defs = (GBeanDefault) i.next();
- ObjectName name;
- try {
- name = new ObjectName(defs.getObjectName());
- } catch (MalformedObjectNameException e) {
- throw new DeploymentException("Invalid JMX ObjectName: " +
defs.getObjectName(), e);
- }
-
- GBeanInfo gbeanInfo = defs.getGBeanInfo();
- if (gbeanInfo == null) {
- String className = defs.getClassName();
- try {
- gbeanInfo = GBeanInfo.getGBeanInfo(className, cl);
- } catch (InvalidConfigurationException e) {
- throw new DeploymentException("Unable to get GBeanInfo
from class " + className, e);
- }
- }
-
- GBeanMBean gbean;
- try {
- gbean = new GBeanMBean(gbeanInfo);
- } catch (InvalidConfigurationException e) {
- throw new DeploymentException("Unable to create GMBean", e);
- }
- for (Iterator j = defs.getValues().entrySet().iterator();
j.hasNext();) {
- Map.Entry entry = (Map.Entry) j.next();
- try {
- gbean.setAttribute((String) entry.getKey(),
entry.getValue());
- } catch (Exception e) {
- throw new DeploymentException("Unable to set GMBean
attribute " + entry.getKey(), e);
- }
- }
- for (Iterator iterator =
defs.getEndpoints().entrySet().iterator(); iterator.hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
- gbean.setEndpointPatterns((String) entry.getKey(), (Set)
entry.getValue());
- }
- callback.addGBean(name, gbean);
+ GBeanInfo gbeanInfo;
+ try {
+ gbeanInfo =
GBeanInfo.getGBeanInfo(webDeployer.getWebApplicationClass(), cl);
+ } catch (InvalidConfigurationException e) {
+ throw new DeploymentException("Unable to get GBeanInfo from
class " + webDeployer.getWebApplicationClass(), e);
}
+
+ GBeanMBean gbean;
+ try {
+ gbean = new GBeanMBean(gbeanInfo);
+ } catch (InvalidConfigurationException e) {
+ throw new DeploymentException("Unable to create GMBean", e);
+ }
+
+ try {
+
getClass().getClassLoader().loadClass("org.apache.jasper.servlet.JspServlet");
+ } catch (ClassNotFoundException e) {
+ throw new DeploymentException("Could not load jsp servlet class:
urls: " +
Arrays.asList(((URLClassLoader)getClass().getClassLoader()).getURLs()), e);
+ }
+
+ //I wonder what this does
+ URI baseURI = URI.create(urlInfo.getUrl().toString()).normalize();
+
+ try {
+ gbean.setAttribute("URI", baseURI);
+ //this needs to be an endpoint to ConfigurationParent
+ gbean.setAttribute("ParentClassLoader", null);//What do we put
here?
+ gbean.setAttribute("ContextPath", getContextPath(baseURI));
+ gbean.setAttribute("DeploymentDescriptorDoc",
deploymentDescriptorDoc);
+ gbean.setAttribute("GeronimoWebAppDoc", geronimoWebAppDoc);
+ gbean.setAttribute("Java2ClassLoadingCompliance",
Boolean.valueOf(webDeployer.isJava2ClassLoadingCompliance()));
+ UserTransactionImpl userTransaction = new UserTransactionImpl();
+ gbean.setAttribute("ComponentContext",
getComponentContext(geronimoWebAppDoc, userTransaction));
+ gbean.setAttribute("UserTransaction", userTransaction);
+ } catch (Exception e) {
+ throw new DeploymentException("Unable to set WebApplication
attribute", e);
+ }
+
+ gbean.setEndpointPatterns("TransactionManager",
Collections.singleton(webDeployer.getTransactionManagerNamePattern()));
+ gbean.setEndpointPatterns("TrackedConnectionAssociator",
Collections.singleton(webDeployer.getTrackedConnectionAssociatorNamePattern()));
+
+
+ ObjectName name;
+ try {
+ name = ObjectName.getInstance(getWebApplicationObjectName());
+ } catch (MalformedObjectNameException e) {
+ throw new DeploymentException("Invalid JMX ObjectName: " +
getWebApplicationObjectName(), e);
+ }
+
+ callback.addGBean(name, gbean);
}
public void complete() {
}
+
+ private String getContextPath(URI baseURI) {
+ String path = baseURI.getPath();
+
+ if (path.endsWith("/")) {
+ path = path.substring(0, path.length() - 1);
+ }
+
+ int sepIndex = path.lastIndexOf('/');
+ if (sepIndex > 0) {
+ path = path.substring(sepIndex + 1);
+ }
+
+ if (path.endsWith(".war")) {
+ path = path.substring(0, path.length() - 4);
+ }
+
+ return "/" + path;
+ }
+
+
+ private ReadOnlyContext getComponentContext(GeronimoWebAppDocument
geronimoWebAppDoc, UserTransaction userTransaction) throws DeploymentException {
+ if (geronimoWebAppDoc != null) {
+ ReferenceFactory referenceFactory = new
JMXReferenceFactory(null);//JMXKernel.getMBeanServerId(getServer()));
+ ComponentContextBuilder builder = new
ComponentContextBuilder(referenceFactory, userTransaction);
+ ReadOnlyContext context =
builder.buildContext(geronimoWebAppDoc.getWebApp());
+ return context;
+ } else {
+ return null;
+ }
+ }
+
+ private String getWebApplicationObjectName() {
+ return AbstractWebContainer.BASE_WEB_APPLICATION_NAME +
AbstractWebContainer.CONTAINER_CLAUSE + webDeployer.getType() + ",module=" +
ObjectName.quote(moduleID.toString());
+ }
+
}
1.13 +11 -8
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebApplication.java
Index: JettyWebApplication.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebApplication.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- JettyWebApplication.java 16 Jan 2004 23:31:21 -0000 1.12
+++ JettyWebApplication.java 19 Jan 2004 06:38:23 -0000 1.13
@@ -24,6 +24,7 @@
import org.apache.geronimo.web.AbstractWebApplication;
import org.apache.geronimo.transaction.manager.UserTransactionImpl;
import org.mortbay.jetty.servlet.WebApplicationContext;
+import org.w3c.dom.Document;
/**
@@ -48,21 +49,20 @@
super(new org.apache.geronimo.web.WebApplicationContext());
}
- public JettyWebApplication(URI uri, ClassLoader parentClassLoader,
WebApp webApp, GeronimoWebAppDocument geronimoWebAppDocument, String
contextPath,
- Context context, boolean
java2ClassLoadingCompliance, UserTransactionImpl userTransaction,
TransactionManager transactionManager, TrackedConnectionAssociator
trackedConnectionAssociator) {
- super(uri, parentClassLoader, webApp, geronimoWebAppDocument,
contextPath, context,
+ public JettyWebApplication(URI uri, String contextID, ClassLoader
parentClassLoader, Document deploymentDescriptorDoc, GeronimoWebAppDocument
geronimoWebAppDocument, String contextPath,
+ Context componentContext, boolean
java2ClassLoadingCompliance, UserTransactionImpl userTransaction,
TransactionManager transactionManager, TrackedConnectionAssociator
trackedConnectionAssociator) {
+ super(uri, contextID, parentClassLoader, deploymentDescriptorDoc,
geronimoWebAppDocument, contextPath, componentContext,
java2ClassLoadingCompliance, userTransaction,
transactionManager, trackedConnectionAssociator);
if (uri == null) {
jettyContext = new JettyWebApplicationContext();
} else {
- jettyContext = new JettyWebApplicationContext(uri.toString());
+ jettyContext = new JettyWebApplicationContext(uri.toString(),
contextID, componentContext, transactionManager, trackedConnectionAssociator);
}
//we could perhaps use geronimo classloading
//jettyContext.setClassLoader(classLoader);
jettyContext.setParentClassLoader(parentClassLoader);
jettyContext.setContextPath(contextPath);
jettyContext.setClassLoaderJava2Compliant(java2ClassLoadingCompliance);
- jettyContext.setComponentContext(context);
}
/**
@@ -75,14 +75,17 @@
if (uri == null) {
jettyContext = new JettyWebApplicationContext();
} else {
- jettyContext = new JettyWebApplicationContext(uri.toString());
+ jettyContext = new JettyWebApplicationContext(uri.toString(),
+ null,
+ webApplicationContext.context,
+
webApplicationContext.userTransaction.getTransactionManager(),
+
webApplicationContext.userTransaction.getTrackedConnectionAssociator());
}
//we could perhaps use geronimo classloading
//jettyContext.setClassLoader(webApplicationContext.classLoader);
jettyContext.setParentClassLoader(webApplicationContext.parentClassLoader);
jettyContext.setContextPath(webApplicationContext.contextPath);
jettyContext.setClassLoaderJava2Compliant(webApplicationContext.java2ClassLoadingCompliance);
- jettyContext.setComponentContext(webApplicationContext.context);
}
1.6 +105 -9
incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebApplicationContext.java
Index: JettyWebApplicationContext.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/web/src/java/org/apache/geronimo/web/jetty/JettyWebApplicationContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JettyWebApplicationContext.java 30 Dec 2003 08:28:58 -0000 1.5
+++ JettyWebApplicationContext.java 19 Jan 2004 06:38:23 -0000 1.6
@@ -55,11 +55,27 @@
*/
package org.apache.geronimo.web.jetty;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
import javax.naming.Context;
+import javax.resource.ResourceException;
import javax.security.jacc.PolicyContext;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.connector.outbound.ConnectorComponentContext;
+import org.apache.geronimo.connector.outbound.ConnectorTransactionContext;
+import
org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
+import
org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultComponentContext;
+import
org.apache.geronimo.connector.outbound.connectiontracking.defaultimpl.DefaultTransactionContext;
import org.apache.geronimo.naming.java.ReadOnlyContext;
import org.apache.geronimo.naming.java.RootContext;
import org.mortbay.http.HttpRequest;
@@ -72,28 +88,90 @@
* @version $Revision$ $Date$
*/
public class JettyWebApplicationContext extends WebApplicationContext {
+
+ private static Log log =
LogFactory.getLog(JettyWebApplicationContext.class);
+
+
private Context componentContext;
private String contextID;
- private Log log = LogFactory.getLog(JettyWebApplicationContext.class);
+ private TransactionManager transactionManager;
+ private TrackedConnectionAssociator trackedConnectionAssociator;
+
+ //we don't examine the dd for these yet.
+ private final Set unshareableResources = Collections.EMPTY_SET;
+
+ //this should be replaced by global tx context handling.
+ private final Map transactionToTransactionContextMap =
Collections.synchronizedMap(new WeakHashMap());
public JettyWebApplicationContext() {
}
- public JettyWebApplicationContext(String webApp) {
+ public JettyWebApplicationContext(String webApp, String contextID,
Context componentContext, TransactionManager transactionManager,
TrackedConnectionAssociator trackedConnectionAssociator) {
super(webApp);
+ this.contextID = contextID;
+ this.componentContext = componentContext;
+ this.transactionManager = transactionManager;
+ this.trackedConnectionAssociator = trackedConnectionAssociator;
}
public Object enterContextScope(HttpRequest httpRequest, HttpResponse
httpResponse) {
log.info("Entering context " + httpRequest.getRequestURL());
- RootContext.setComponentContext((ReadOnlyContext)componentContext);
- PolicyContext.setContextID(contextID);
- return super.enterContextScope(httpRequest, httpResponse);
+ ReadOnlyContext oldContext = RootContext.getComponentContext();
+ RootContext.setComponentContext((ReadOnlyContext) componentContext);
+ String oldContextID = null;
+ try {
+ oldContextID = PolicyContext.getContextID();
+ } catch (Throwable e) {
+ log.info(e);
+ }
+ try {
+ PolicyContext.setContextID(contextID);
+ } catch (Throwable e) {
+ log.info(e);
+ }
+ //tx handling. Definitely a hack until we get a system wide tx
context system.
+ try {
+ Transaction transaction = transactionManager == null? null:
transactionManager.getTransaction();
+ ConnectorTransactionContext newConnectorTransactionContext;
+ if (transaction == null || transaction.getStatus() ==
Status.STATUS_COMMITTED || transaction.getStatus() == Status.STATUS_ROLLEDBACK)
{
+ newConnectorTransactionContext = new
DefaultTransactionContext(null);
+ } else {
+ newConnectorTransactionContext =
(ConnectorTransactionContext)
transactionToTransactionContextMap.get(transaction);
+ if (newConnectorTransactionContext == null) {
+ newConnectorTransactionContext = new
DefaultTransactionContext(transaction);
+ transactionToTransactionContextMap.put(transaction,
newConnectorTransactionContext);
+ }
+ }
+ Set oldUnshareableResources =
trackedConnectionAssociator.setUnshareableResources(unshareableResources);
+ ConnectorComponentContext oldConnectorComponentContext =
trackedConnectionAssociator.enter(new DefaultComponentContext());
+ ConnectorTransactionContext oldConnectorTransactionContext =
trackedConnectionAssociator.setConnectorTransactionContext(newConnectorTransactionContext);
+ Object scope = super.enterContextScope(httpRequest,
httpResponse);
+ ThreadContext threadContext = new
ThreadContext(oldUnshareableResources, oldConnectorComponentContext,
oldConnectorTransactionContext, oldContext, oldContextID, scope);
+ return threadContext;
+ } catch (SystemException e) {
+ throw new RuntimeException(e);
+ } catch (RollbackException e) {
+ throw new RuntimeException(e);
+ } catch (ResourceException e) {
+ throw new RuntimeException(e);
+ }
}
public void leaveContextScope(HttpRequest httpRequest, HttpResponse
httpResponse, Object o) {
- super.leaveContextScope(httpRequest, httpResponse, o);
- RootContext.setComponentContext(null);
- PolicyContext.setContextID(null);
+ ThreadContext threadContext = (ThreadContext) o;
+ super.leaveContextScope(httpRequest, httpResponse, threadContext ==
null? null: threadContext.scope);
+ if (threadContext == null) {
+ return;
+ }
+ try {
+
trackedConnectionAssociator.exit(threadContext.connectorComponentContext,
unshareableResources);
+ } catch (ResourceException e) {
+ throw new RuntimeException(e);
+ }
+
trackedConnectionAssociator.resetConnectorTransactionContext(threadContext.connectorTransactionContext);
+
trackedConnectionAssociator.setUnshareableResources(threadContext.unshareableResources);
+ RootContext.setComponentContext(threadContext.context);
+ PolicyContext.setContextID(threadContext.contextID);
log.info("Leaving context " + httpRequest.getRequestURL());
}
@@ -111,5 +189,23 @@
public void setContextID(String contextID) {
this.contextID = contextID;
+ }
+
+ private static class ThreadContext {
+ final Set unshareableResources;
+ final ConnectorComponentContext connectorComponentContext;
+ final ConnectorTransactionContext connectorTransactionContext;
+ final ReadOnlyContext context;
+ final String contextID;
+ final Object scope;
+
+ ThreadContext(Set unshareableResources, ConnectorComponentContext
connectorComponentContext, ConnectorTransactionContext
connectorTransactionContext, ReadOnlyContext context, String contextID, Object
scope) {
+ this.unshareableResources = unshareableResources;
+ this.connectorComponentContext = connectorComponentContext;
+ this.connectorTransactionContext = connectorTransactionContext;
+ this.context = context;
+ this.contextID = contextID;
+ this.scope = scope;
+ }
}
}