[jboss-svn-commits] JBL Code SVN: r25154 - 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
Mon Feb 9 04:03:26 EST 2009
Author: jim.ma
Date: 2009-02-09 04:03:26 -0500 (Mon, 09 Feb 2009)
New Revision: 25154
Modified:
labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayListener.java
labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpServerDelegate.java
Log:
Changed the default maxThreads=5 for Tomcat Connector; Fixed host name not found issue when start http gateway listener on port 8080 or 80
Modified: labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayListener.java
===================================================================
--- labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayListener.java 2009-02-09 06:36:14 UTC (rev 25153)
+++ labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayListener.java 2009-02-09 09:03:26 UTC (rev 25154)
@@ -19,9 +19,11 @@
*/
package org.jboss.soa.esb.listeners.gateway;
+import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
+import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -112,9 +114,16 @@
/**Http host value*/
public String host = null;
+ /**Http address value*/
+ public String address = null;
+
/**Http port value*/
public String port = null;
+ /** Default max threads */
+
+ public String maxThreads = "5";
+
/**listener contenxt */
public String httpContext = null;
@@ -147,6 +156,11 @@
public HttpGatewayListener(ConfigTree config) throws ConfigurationException {
super(config);
host = config.getAttribute(SERVER_HOST_TAG);
+ try {
+ address = InetAddress.getByName(host).getHostAddress();
+ }catch (Exception e) {
+ throw new ConfigurationException("Invalid host configuration");
+ }
port = config.getAttribute(SERVER_PORT_TAG);
httpContext = config.getAttribute(REQUEST_CONTEXT_TAG);
serviceCategory = config.getAttribute(ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG);
@@ -189,21 +203,18 @@
try {
Set ports = HttpServerDelegate.getInstance().queryObjects("jboss.web:port="+ port+",type=Connector,*");
- if (ports.size() > 0) {
- Set hosts = HttpServerDelegate.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 = HttpServerDelegate.getInstance().queryObjects("jboss.web:host=" + host + ",path=" + httpContext + ",*");
- if (contexts.size() > 0) {
+ if (ports.size() > 0) {
+ //When this gateway stared on JBoss default port 8080 or 80, the configured host will be ignored
+ Set contexts = HttpServerDelegate.getInstance().queryObjects("jboss.web:host=localhost" + ",path=" + httpContext + ",*");
+ if (contexts.size() > 0) {
throw new ConfigurationException("There is already an http context named " + httpContext + ", choose another one");
}
-
+ logger.info("This http gateway listener [" + config.getAttribute(ListenerTagNames.NAME_TAG) + "] will be started on JBoss default port " + port + " and the configured host will be ignored.");
//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 = HttpServerDelegate.getInstance().queryObjects(HttpServerDelegate.DOMAIN_NAME + ":host=" + host + ",path=" + httpContext + ",*");
+ Set contexts = HttpServerDelegate.getInstance().queryObjects(HttpServerDelegate.DOMAIN_NAME + ":host=" + HttpServerDelegate.defaultVHost + ",path=" + httpContext + ",*");
if (contexts.size() > 0) {
throw new ConfigurationException("There is already an http context named " + httpContext + ", choose another one");
}
@@ -315,28 +326,29 @@
Thread.currentThread().setContextClassLoader(urlClassLoader);
initWebappDefaults(ctx);
Thread.currentThread().setContextClassLoader(oldloader);
- String connectorName = HttpServerDelegate.DOMAIN_NAME + ":port=" + port + ",type=Connector,*";
-
- if (!useJBossWebServletEngine) {
- HttpServerDelegate.getInstance().createHost(host);
+ String encodedAddr = URLEncoder.encode("/" + address).toString();
+ String connectorName = HttpServerDelegate.DOMAIN_NAME + ":address=" + encodedAddr + ",port=" + port + ",type=Connector";
+ if (!useJBossWebServletEngine) {
+ //Create default Tomcat standard vHost "localhost"
+ HttpServerDelegate.getInstance().createHost(HttpServerDelegate.defaultVHost);
List<KeyValuePair> properties = getConfig().childPropertyList();
- String maxThreads = getConfig().getAttribute(
- ListenerTagNames.MAX_THREADS_TAG);
- if (maxThreads != null) {
- properties.add(new KeyValuePair("maxThreads", maxThreads));
+ if (getConfig().getAttribute(ListenerTagNames.MAX_THREADS_TAG) != null) {
+ maxThreads = getConfig().getAttribute(ListenerTagNames.MAX_THREADS_TAG);
}
- HttpServerDelegate.getInstance().createConnector(port, properties);
- HttpServerDelegate.getInstance().addContext(host, ctx);
+ properties.add(new KeyValuePair("maxThreads", maxThreads));
+
+ HttpServerDelegate.getInstance().createConnector(address, port, properties);
+ HttpServerDelegate.getInstance().addContext(HttpServerDelegate.defaultVHost, ctx);
} else {
//add it to jboss.web servlet engine
connectorName = "jboss.web:port=" + port + ",type=Connector,*";
- HttpServerDelegate.getInstance().addContext(new ObjectName("jboss.web:host=" + host + ",type=Host"), ctx);
+ HttpServerDelegate.getInstance().addContext(new ObjectName("jboss.web:host=localhost,type=Host"), ctx);
}
Set connectors = HttpServerDelegate.getInstance().queryObjects(connectorName);
if (connectors.isEmpty()) {
- throw new javax.management.InstanceNotFoundException("ObjectName: "+ connectorName + "Not found");
+ throw new javax.management.InstanceNotFoundException("ObjectName: "+ connectorName + " Not found");
}
ObjectName obj = (ObjectName)connectors.iterator().next();
try {
@@ -354,7 +366,7 @@
*/
private void registerEndpoint() throws ConfigurationException, RegistryException {
try {
- endpointReference = new HTTPEpr(new URI(protocol + "://"+ host + ":" + port + this.httpContext));
+ endpointReference = new HTTPEpr(new URI(protocol + "://"+ address + ":" + port + this.httpContext));
endpointReference.getAddr().addExtension("is-gateway", "true");
} catch (Exception e) {
throw new RegistryException("Tomcat gateway listener registration failed", e);
@@ -381,13 +393,12 @@
* @throws Exception For errors during stop tomcat connector or host
*/
@SuppressWarnings("unchecked")
- public void stopHttpServer() throws Exception {
-
+ public void stopHttpServer() throws Exception {
//Destroy the created context
if (!useJBossWebServletEngine) {
- HttpServerDelegate.getInstance().destroyContext(host, port, httpContext);
+ HttpServerDelegate.getInstance().destroyContext(HttpServerDelegate.defaultVHost, address, port, httpContext);
} else {
- Set<ObjectName> contexts = HttpServerDelegate.getInstance().queryObjects("jboss.web:j2eeType=WebModule,name=//" + host + httpContext + ",*");
+ Set<ObjectName> contexts = HttpServerDelegate.getInstance().queryObjects("jboss.web:j2eeType=WebModule,name=//localhost" + httpContext + ",*");
for (ObjectName obName : contexts) {
HttpServerDelegate.getInstance().destroyContext(obName);
}
Modified: labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpServerDelegate.java
===================================================================
--- labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpServerDelegate.java 2009-02-09 06:36:14 UTC (rev 25153)
+++ labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpServerDelegate.java 2009-02-09 09:03:26 UTC (rev 25154)
@@ -19,6 +19,7 @@
*/
package org.jboss.soa.esb.listeners.gateway;
+import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -47,6 +48,8 @@
*
*/
public class HttpServerDelegate {
+ public static final String defaultVHost = "localhost";
+
/**Record the count that the same host name is referenced by other Tomcat listener instance */
public static Map<String, Integer> hostReference= new java.util.HashMap<String, Integer>();
@@ -113,7 +116,7 @@
new ObjectName(DOMAIN_NAME + ":type=Realm"), null);
- engine.setDefaultHost("localhost");
+ engine.setDefaultHost(defaultVHost);
engine.setDomain(DOMAIN_NAME);
engine.setName(DOMAIN_NAME + ".engine");
mbeanServer.setAttribute(new ObjectName(DOMAIN_NAME
@@ -132,7 +135,7 @@
/**
* Add a tomcat StandardHost to tomcat engine
- * @param host host name
+ * @param host tomcat vhost name
* @throws Exception If there is error occured
*/
@SuppressWarnings("unchecked")
@@ -158,17 +161,18 @@
/**
* Add a tomcat Connector to tomcat Enginer/Service
+ * @param address the connector address
* @param port the connector port
* @param properties The properties to configure this connector
* @throws Exception when error is occured
*/
@SuppressWarnings("unchecked")
- public void createConnector(String port, List<KeyValuePair> properties) throws Exception {
+ public void createConnector(String address, String port, List<KeyValuePair> properties) throws Exception {
ObjectName standardServiceName = new ObjectName(DOMAIN_NAME + ":type=Service");
- ObjectName connectorName = new ObjectName(DOMAIN_NAME + ":*,port=" + port + ",type=Connector");
- Set connectors = mbeanServer.queryNames(connectorName, null);
+ Set connectors = queryObjects(DOMAIN_NAME + ":address=" + URLEncoder.encode("/" + address).toString() +",port="
+ + port + ",type=Connector,*");
if (connectors.size() == 0) {
- Connector connector = null;
+ Connector connector = null;
connector = new Connector("org.apache.coyote.http11.Http11Protocol");
connector.setPort(Integer.parseInt(port));
@@ -177,7 +181,9 @@
if (!effected) {
connector.setProperty(property.getKey(), property.getValue());
}
- }
+ }
+
+ connector.setAttribute("address", address);
mbeanServer.invoke(standardServiceName, "addConnector",
new Object[] { connector }, new String[] { Connector.class
.getName() });
@@ -193,7 +199,7 @@
/**
* Add a StandardContext to a specific host
- * @param host the host name
+ * @param host tomcat vhost name
* @param ctx new created StandardContext
* @throws Exception when error occurs
*/
@@ -212,13 +218,14 @@
/**
* Destroy the created context. This method will also check if this context's parent StandardHost
* and Connector can be destroyed also. There are reference counters for Connector and Host
- * @param host host name
+ * @param host tomcat vhost name
+ * @param address the Connector address
* @param port port number
* @param httpContext the new created httpContext name
* @throws Exception if failed to destroy
*/
@SuppressWarnings("unchecked")
- public void destroyContext(String host, String port, String httpContext)
+ public void destroyContext(String host, String address, String port, String httpContext)
throws Exception {
ObjectName contextName = new ObjectName(DOMAIN_NAME
+ ":j2eeType=WebModule,name=//" + host + httpContext
@@ -247,9 +254,12 @@
obj = connectorReference.get(port);
if (obj != null && (Integer) obj == 0) {
- ObjectName connectorName = new ObjectName(DOMAIN_NAME + ":port="
- + port + ",type=Connector");
- mbeanServer.invoke(connectorName, "destroy", new Object[] {}, new String[] {});
+ Set connectors = queryObjects(DOMAIN_NAME + ":address=" + URLEncoder.encode("/" + address).toString() +",port="
+ + port + ",type=Connector,*");
+ if (connectors.size() > 0) {
+ ObjectName connector = (ObjectName)connectors.iterator().next();
+ mbeanServer.invoke(connector, "destroy", new Object[] {},new String[] {});
+ }
}
}
More information about the jboss-svn-commits
mailing list