[jboss-svn-commits] JBL Code SVN: r24603 - labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jan 8 03:23:56 EST 2009
Author: jim.ma
Date: 2009-01-08 03:23:56 -0500 (Thu, 08 Jan 2009)
New Revision: 24603
Modified:
labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatGatewayListener.java
labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatServer.java
Log:
Allowed tomcat gateway to start at jboss listened port 8080 or 8009
Modified: labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatGatewayListener.java
===================================================================
--- labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatGatewayListener.java 2009-01-08 08:02:07 UTC (rev 24602)
+++ labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatGatewayListener.java 2009-01-08 08:23:56 UTC (rev 24603)
@@ -26,6 +26,7 @@
import java.util.List;
import java.util.Set;
+import javax.management.InstanceNotFoundException;
import javax.management.ObjectName;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -118,9 +119,11 @@
/** The default servlet used to dispatch the http request to ESB service*/
private String dispatchServletClassName = TomcatDispatchServlet.class.getName();
- /***Protocol value */
+ /** Protocol value */
private Object protocol = "http";
+ /** Imply if the port number is the jboss.web used, if yes , the new created context will be attched to jboss web Servlet engine */
+ private boolean useJBossWebServletEngine = false;
/**Constuct the TomcatGatewyListner
* @param config The listener configuration
@@ -170,11 +173,26 @@
}
}
- //Check if the context already exists
- try {
- Set contexts = TomcatServer.getInstance().queryObjects(TomcatServer.DOMAIN_NAME + ":host=" + host + ",path=" + httpContext + ",*");
- if (contexts.size() > 0) {
- throw new ConfigurationException("There is already an http context named " + httpContext + ", choose another one");
+ try {
+ Set ports = TomcatServer.getInstance().queryObjects("jboss.web:port="+ port+",type=Connector,*");
+ if (ports.size() > 0) {
+ Set hosts = TomcatServer.getInstance().queryObjects("jboss.web:host=" + host +",type=Host");
+ if (hosts.isEmpty()) {
+ throw new ConfigurationException(new InstanceNotFoundException("ObjectName: "+ "jboss.web:host=" + host +",type=Host" + "Not found"));
+ }
+ Set contexts = TomcatServer.getInstance().queryObjects("jboss.web:host=" + host + ",path=" + httpContext + ",*");
+ if (contexts.size() > 0) {
+ throw new ConfigurationException("There is already an http context named " + httpContext + ", choose another one");
+ }
+
+ //the created context will be attached jboss.web domain
+ useJBossWebServletEngine = true;
+ } else {
+ //if the port is not the jboss.web used, check if the http context name is duplicate
+ Set contexts = TomcatServer.getInstance().queryObjects(TomcatServer.DOMAIN_NAME + ":host=" + host + ",path=" + httpContext + ",*");
+ if (contexts.size() > 0) {
+ throw new ConfigurationException("There is already an http context named " + httpContext + ", choose another one");
+ }
}
} catch (Exception e) {
throw new ConfigurationException(e);
@@ -264,15 +282,7 @@
*/
@SuppressWarnings("unchecked")
protected void startHttpServer() throws Exception {
- TomcatServer.getInstance().createHost(host);
- List<KeyValuePair> properties = getConfig().childPropertyList();
- String maxThreads = getConfig().getAttribute(ListenerTagNames.MAX_THREADS_TAG);
- if (maxThreads != null) {
- properties.add(new KeyValuePair("maxThreads", maxThreads));
- }
- TomcatServer.getInstance().createConnector(port, properties);
-
ctx = new StandardContext();
URL[] urls = new URL[]{};
URLClassLoader urlClassLoader = new URLClassLoader(urls, getClass().getClassLoader());
@@ -291,9 +301,25 @@
Thread.currentThread().setContextClassLoader(urlClassLoader);
initWebappDefaults(ctx);
Thread.currentThread().setContextClassLoader(oldloader);
- TomcatServer.getInstance().addContext(host, ctx);
+ String connectorName = TomcatServer.DOMAIN_NAME + ":port=" + port + ",type=Connector,*";
- String connectorName = TomcatServer.DOMAIN_NAME + ":*,port=" + port + ",type=Connector";
+ if (!useJBossWebServletEngine) {
+ TomcatServer.getInstance().createHost(host);
+
+ List<KeyValuePair> properties = getConfig().childPropertyList();
+ String maxThreads = getConfig().getAttribute(
+ ListenerTagNames.MAX_THREADS_TAG);
+ if (maxThreads != null) {
+ properties.add(new KeyValuePair("maxThreads", maxThreads));
+ }
+ TomcatServer.getInstance().createConnector(port, properties);
+ TomcatServer.getInstance().addContext(host, ctx);
+ } else {
+ //add it to jboss.web servlet engine
+ connectorName = "jboss.web:port=" + port + ",type=Connector,*";
+ TomcatServer.getInstance().addContext(new ObjectName("jboss.web:host=" + host + ",type=Host"), ctx);
+ }
+
Set connectors = TomcatServer.getInstance().queryObjects(connectorName);
if (connectors.isEmpty()) {
throw new javax.management.InstanceNotFoundException("ObjectName: "+ connectorName + "Not found");
@@ -339,12 +365,20 @@
* is no tomcat listner uses the generated host or connector, it will destory it
* @throws Exception For errors during stop tomcat connector or host
*/
+ @SuppressWarnings("unchecked")
public void stopHttpServer() throws Exception {
- //Destroy the created context
- TomcatServer.getInstance().destroyContext(host, port, httpContext);
+
+ //Destroy the created context
+ if (!useJBossWebServletEngine) {
+ TomcatServer.getInstance().destroyContext(host, port, httpContext);
+ } else {
+ Set<ObjectName> contexts = TomcatServer.getInstance().queryObjects("jboss.web:j2eeType=WebModule,name=//" + host + httpContext + ",*");
+ for (ObjectName obName : contexts) {
+ TomcatServer.getInstance().destroyContext(obName);
+ }
+ }
+ }
- }
-
/**Get the uncomposed message delivery dapater
* @return uncomposed message delivery adapter
* @throws ConfigurationException For configuation error
Modified: labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatServer.java
===================================================================
--- labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatServer.java 2009-01-08 08:02:07 UTC (rev 24602)
+++ labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatServer.java 2009-01-08 08:23:56 UTC (rev 24603)
@@ -34,7 +34,6 @@
import org.apache.catalina.core.StandardEngine;
import org.apache.catalina.core.StandardHost;
import org.apache.catalina.core.StandardService;
-import org.apache.catalina.realm.MemoryRealm;
import org.apache.tomcat.util.IntrospectionUtils;
import org.apache.tomcat.util.modeler.Registry;
import org.jboss.mx.util.MBeanServerLocator;
@@ -200,6 +199,11 @@
*/
public void addContext(String host, StandardContext ctx) throws Exception {
ObjectName hostName = new ObjectName(DOMAIN_NAME + ":host=" + host + ",type=Host");
+ addContext(hostName, ctx);
+ }
+
+
+ public void addContext(ObjectName hostName, StandardContext ctx) throws Exception {
mbeanServer.invoke(hostName, "addChild", new Object[] { ctx }, new String[] { Container.class.getName() });
}
@@ -248,6 +252,12 @@
mbeanServer.invoke(connectorName, "destroy", new Object[] {}, new String[] {});
}
}
+
+ public void destroyContext(ObjectName contextName) throws Exception {
+ mbeanServer.invoke(contextName, "destroy", new Object[] {},
+ new String[] {});
+ }
+
/**
* Query objects
More information about the jboss-svn-commits
mailing list