[jboss-svn-commits] JBL Code SVN: r23711 - in labs/jbossesb/workspace/mlittle/legstar/product: samples/quickstarts/tomcat_listener and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 5 05:49:29 EST 2008
Author: jim.ma
Date: 2008-11-05 05:49:28 -0500 (Wed, 05 Nov 2008)
New Revision: 23711
Modified:
labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatDispatchServlet.java
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/TomcatMessageComposer.java
labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/jboss-esb.xml
labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/readme.txt
labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/src/org/jboss/soa/esb/samples/quickstart/tomcatlistener/MyAction.java
Log:
Added DELETE and PUT support;created standalone tomcat engine for esb services
Modified: labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatDispatchServlet.java
===================================================================
--- labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatDispatchServlet.java 2008-11-05 10:25:42 UTC (rev 23710)
+++ labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatDispatchServlet.java 2008-11-05 10:49:28 UTC (rev 23711)
@@ -93,9 +93,9 @@
* For error occured during process
*/
protected void serveRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-
+
TomcatRequestWrapper wrapper = new TomcatRequestWrapper(request, response);
-
+
try {
if (synchronous) {
messageDeliveryAdapter.deliverSync(wrapper, serviceTimeout);
@@ -126,12 +126,21 @@
}
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
serveRequest(request, response);
}
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- doGet(request, response);
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ serveRequest(request, response);
}
+
+
+ protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ serveRequest(request, response);
+ }
+
+ protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ serveRequest(request, response);
+ }
}
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 2008-11-05 10:25:42 UTC (rev 23710)
+++ labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatGatewayListener.java 2008-11-05 10:49:28 UTC (rev 23711)
@@ -20,10 +20,12 @@
package org.jboss.soa.esb.listeners.gateway;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.management.Attribute;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
@@ -36,11 +38,17 @@
import org.apache.catalina.LifecycleException;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardEngine;
import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.core.StandardServer;
+import org.apache.catalina.core.StandardService;
import org.apache.catalina.core.StandardWrapper;
+import org.apache.catalina.loader.WebappLoader;
+import org.apache.catalina.servlets.DefaultServlet;
import org.apache.catalina.startup.ContextConfig;
import org.apache.log4j.Logger;
import org.apache.tomcat.util.IntrospectionUtils;
+import org.apache.tomcat.util.modeler.Registry;
import org.jboss.mx.util.MBeanServerLocator;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.addressing.EPR;
@@ -64,9 +72,8 @@
* components through jboss JMX console. When this listener is stoped, these components will be
* destoried automatically.
*
- * <p>The different tomcat listner can be started in same port and different context. This will allow
- * user define the server locator uses jboss default http port 8080, for example:
- * <code> http://localhost:8080/jbossesb/servicecategory/servicename </code>
+ * <p>The different tomcat listner can be started in same port with different context.for example:
+ * <code> http://localhost:8765/jbossesb/servicecategory/servicename </code>
*
* <p>This class uses the {@link org.jboss.soa.esb.listeners.gateway.TomcatMessageComposer}
* by default.
@@ -100,6 +107,9 @@
/**Record the count that the same connector/port is referenced by other Tomcat listener instance */
public static Map<String, Integer> connectorReference= new java.util.HashMap<String, Integer>();
+
+ /**JMX domain name for tomcat listener*/
+ public static String DOMAIN_NAME = "jboss.esb.tomcat";
/**Http host value*/
public String host = null;
@@ -127,11 +137,7 @@
/**The new created tomcat standard context, it reprents a web app*/
private StandardContext ctx = null;
-
- /** The domian name for JBoss embeded tomcat engine*/
- private String jbossWebDomain = null;
-
-
+
/** The default servlet used to dispatch the http request to ESB service*/
private String dispatchServletClassName = TomcatDispatchServlet.class.getName();
@@ -169,23 +175,9 @@
mbeanServer = MBeanServerLocator.locateJBoss();
- //Get the jboss web domain name
- try {
- ObjectName queryEngineName = new ObjectName("*:type=Engine");
- Set engines = mbeanServer.queryNames(queryEngineName, null);
- if (engines.size() != 0) {
- ObjectName engineName = (ObjectName) engines.iterator().next();
- jbossWebDomain = engineName.getDomain();
- } else {
- jbossWebDomain = "jboss.web";
- }
- } catch (Exception e) {
- jbossWebDomain = "jboss.web";
- }
-
//Check if the context already exists
try {
- ObjectName contextName = new ObjectName(jbossWebDomain + ":host=" + host + ",path=" + httpContext + ",*");
+ ObjectName contextName = new ObjectName("jboss.esb.tomcat:host=" + host + ",path=" + httpContext + ",*");
Set contexts = mbeanServer.queryNames(contextName, null);
if (contexts.size() > 0) {
throw new ConfigurationException("There is already an http context named " + httpContext + ", choose another one");
@@ -251,14 +243,29 @@
throw new ManagedLifecycleException(
"Unexpected request to initialise JBoss Remoting Gateway listener '" + getConfig().getName() + "'. Gateway already initialised.");
}
+ //TODO: Revisit it to see if it can be moved to ESB service initilize
+ try {
+ Set services = mbeanServer.queryMBeans(new ObjectName(DOMAIN_NAME + ":type=Service"), null);
+ if (services.size() == 0) {
+ StandardService service = new StandardService();
+ service.setName("jboss.esb.catalina");
+ Registry.getRegistry().registerComponent(service, new ObjectName(DOMAIN_NAME + ":type=Service"), null);
+ }
- try {
- endpointReference = new EPR(new URI(protocol + "://"+ host + ":" + port + this.httpContext));
+ Set engines = mbeanServer.queryMBeans(new ObjectName(DOMAIN_NAME + ":type=Engine"), null);
+ if (engines.size() == 0) {
+ StandardEngine engine = new StandardEngine();
+ engine.setDefaultHost("localhost");
+ engine.setDomain(DOMAIN_NAME);
+ engine.setName(DOMAIN_NAME + ".engine");
+ mbeanServer.setAttribute(new ObjectName(DOMAIN_NAME + ":type=Service"), new Attribute("container", engine));
+ Registry.getRegistry().registerComponent(engine, new ObjectName(DOMAIN_NAME + ":type=Engine"), null);
+ }
+ mbeanServer.invoke(new ObjectName(DOMAIN_NAME + ":type=Service"), "start", new Object[] {}, new String[] {});
+
} catch (Exception e) {
- throw new ManagedLifecycleException(
- "Remoting Listener configuration failed.", e);
- }
-
+ throw new ManagedLifecycleException("Tomcat gateway listner initialization failed", e);
+ }
initialized = true;
}
@@ -273,20 +280,19 @@
/**
- * Start the tomcat http server.It will firstly check if it really needs to create
+ * Start the tomcat http server.It will check if it really needs to create
* Tomcat connector and host. Then add these new tomcat component to tomcat Engine
* tree through JMX server.
* @throws Exception For error during start tomcat context
*/
@SuppressWarnings("unchecked")
- protected void startHttpServer() throws Exception {
-
- ObjectName standardHostName = new ObjectName(jbossWebDomain + ":host=" + host + ",type=Host");
- ObjectName stardardEngineName = new ObjectName(jbossWebDomain + ":type=Engine");
- ObjectName standardServiceName = new ObjectName(jbossWebDomain + ":serviceName=" + jbossWebDomain + ",type=Service");
- ObjectName connectorName = new ObjectName(jbossWebDomain + ":*,port=" + port + ",type=Connector");
+ protected void startHttpServer() throws Exception {
+ ObjectName hostName = new ObjectName(DOMAIN_NAME + ":host=" + host + ",type=Host");
+ ObjectName stardardEngineName = new ObjectName(DOMAIN_NAME + ":type=Engine");
+ ObjectName standardServiceName = new ObjectName(DOMAIN_NAME + ":type=Service");
+ ObjectName connectorName = new ObjectName(DOMAIN_NAME + ":*,port=" + port + ",type=Connector");
//Check if it needs to create host
- Set hosts = mbeanServer.queryNames(standardHostName, null);
+ Set hosts = mbeanServer.queryNames(hostName, null);
if (hosts.size() == 0) {
StandardHost newHost = new StandardHost();
newHost.setName(host);
@@ -342,13 +348,15 @@
//Create context
ctx = new StandardContext();
+ ctx.setLoader(new WebappLoader(getClass().getClassLoader()));
ContextConfig ctxCfg = new ContextConfig();
ctx.addLifecycleListener(ctxCfg);
+
ctxCfg.setDefaultWebXml("org/apache/catalin/startup/NO_DEFAULT_XML");
ctx.setPath(httpContext);
ctx.setDocBase(".");
initWebappDefaults(ctx);
- mbeanServer.invoke(standardHostName, "addChild", new Object[] { ctx }, new String[] { Container.class.getName() });
+ mbeanServer.invoke(hostName, "addChild", new Object[] { ctx }, new String[] { Container.class.getName() });
}
@@ -357,7 +365,12 @@
* @throws RegistryException For registry error when register this EPR
*/
private void registerEndpoint() throws ConfigurationException, RegistryException {
- String serviceDescription = getConfig().getAttribute(ListenerTagNames.SERVICE_DESCRIPTION_TAG);
+ try {
+ endpointReference = new EPR(new URI(protocol + "://"+ host + ":" + port + this.httpContext));
+ } catch (Exception e) {
+ throw new RegistryException("Tomcat gateway listener registration failed", e);
+ }
+ String serviceDescription = getConfig().getAttribute(ListenerTagNames.SERVICE_DESCRIPTION_TAG);
RegistryFactory.getRegistry().registerEPR(serviceCategory, serviceName, serviceDescription,
endpointReference, endpointReference.getAddr().getAddress());
}
@@ -380,7 +393,7 @@
*/
public void stopHttpServer() throws Exception {
//Destroy the created context
- ObjectName contextName = new ObjectName(jbossWebDomain + ":j2eeType=WebModule,name=//" + host + this.httpContext + ",*");
+ ObjectName contextName = new ObjectName(DOMAIN_NAME + ":j2eeType=WebModule,name=//" + host + this.httpContext + ",*");
Set engines = mbeanServer.queryNames(contextName, null);
if (engines.isEmpty()) {
throw new InstanceNotFoundException("HttpContext:" + httpContext + "not found");
@@ -395,7 +408,7 @@
Object obj = hostReference.get(host);
if (obj != null && (Integer)obj == 0) {
- ObjectName standardHostName = new ObjectName(jbossWebDomain + ":host=" + host + ",type=Host");
+ ObjectName standardHostName = new ObjectName(DOMAIN_NAME + ":host=" + host + ",type=Host");
try {
mbeanServer.invoke(standardHostName, "destroy", new Object[] {}, new String[] {});
} catch (InstanceNotFoundException e) {
@@ -406,11 +419,11 @@
obj = connectorReference.get(port) ;
if (obj != null && (Integer)obj == 0) {
- ObjectName connectorName = new ObjectName(jbossWebDomain + ":port=" + port + ",type=Connector");
+ ObjectName connectorName = new ObjectName(DOMAIN_NAME + ":port=" + port + ",type=Connector");
try {
mbeanServer.invoke(connectorName, "destroy", new Object[] {}, new String[] {});
} catch (InstanceNotFoundException e) {
- //This is expected
+ //Ignore it
logger.warn("Unable to destroy the Host " + connectorName.getCanonicalName(), e);
}
@@ -444,6 +457,7 @@
*/
protected void initWebappDefaults(StandardContext ctx) throws Exception {
StandardWrapper sw = (StandardWrapper) ctx.createWrapper();
+
sw.setServletClass(dispatchServletClassName);
sw.setName("default");
ctx.addChild(sw);
Modified: labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatMessageComposer.java
===================================================================
--- labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatMessageComposer.java 2008-11-05 10:25:42 UTC (rev 23710)
+++ labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatMessageComposer.java 2008-11-05 10:49:28 UTC (rev 23711)
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.util.Enumeration;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -28,6 +29,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.tomcat.util.IntrospectionUtils;
import org.jboss.internal.soa.esb.util.StreamUtils;
import org.jboss.soa.esb.actions.ActionUtils;
import org.jboss.soa.esb.helpers.ConfigTree;
@@ -62,6 +65,9 @@
/** Request parameter map key in esb message properties */
public static final String HTTP_REQUEST_PARAMETER_MAP = "RequestParameterMap";
+ /** Request information map key in esb message properties */
+ public static final String HTTP_REQUEST_INFO_MAP = "RequestInfoMap";
+
/** Reponse header map key in esb message properties */
public static final String HTTP_RESPONSE_HEADER_MAP = "ResponseHeaderMap";
@@ -93,7 +99,7 @@
@SuppressWarnings("unchecked")
protected void populateMessage(Message message, T requestWrapper)
throws MessageDeliverException {
- ServletRequest request = requestWrapper.getRequest();
+ HttpServletRequest request = requestWrapper.getRequest();
Map paraMap = request.getParameterMap();;
byte[] bodyBytes = null;
try {
@@ -102,8 +108,9 @@
throw new MessageDeliverException(
"Failed to read body data from http request", e);
}
-
- message.getProperties().setProperty(HTTP_REQUEST_HEADER_MAP, getHeaderMap(request));
+ //Set Http Header header
+ message.getProperties().setProperty(HTTP_REQUEST_INFO_MAP, getRequestInfo(request));
+ message.getProperties().setProperty(HTTP_REQUEST_HEADER_MAP, getHeaders(request));
if (paraMap != null && paraMap.size() > 0) {
message.getProperties().setProperty(this.HTTP_REQUEST_PARAMETER_MAP, paraMap);
}
@@ -158,17 +165,38 @@
* @return HeaderMap
*/
@SuppressWarnings("unchecked")
- public Map<String, Object> getHeaderMap(final ServletRequest request) {
+ public Map<String, Object> getHeaders(final HttpServletRequest request) {
Map headerMap = new java.util.HashMap<String, String>();
- HttpServletRequest httpRequest = (HttpServletRequest) request;
- Enumeration enumeration = httpRequest.getHeaderNames();
+ Enumeration enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String name = (String) enumeration.nextElement();
- String value = httpRequest.getHeader(name);
+ String value = request.getHeader(name);
headerMap.put(name, value);
}
-
return headerMap;
}
+
+ public Map<String, Object> getRequestInfo(HttpServletRequest request) {
+ Map<String, Object> requestInfoMap = new HashMap<String, Object>();
+ requestInfoMap.put("authType", request.getAuthType());
+ requestInfoMap.put("characterEncoding", request.getCharacterEncoding());
+ requestInfoMap.put("contentType", request.getContentType());
+ requestInfoMap.put("contextPath", request.getContextPath());
+ requestInfoMap.put("localAddr", request.getLocalAddr());
+ requestInfoMap.put("localName", request.getLocalName());
+ requestInfoMap.put("method", request.getMethod());
+ requestInfoMap.put("pathInfo", request.getPathInfo());
+ requestInfoMap.put("protocol", request.getProtocol());
+ requestInfoMap.put("queryString", request.getQueryString());
+ requestInfoMap.put("remoteAddr", request.getRemoteAddr());
+ requestInfoMap.put("remoteHost", request.getRemoteHost());
+ requestInfoMap.put("remoteUser", request.getRemoteUser());
+ requestInfoMap.put("contentLength", Integer.toString(request.getContentLength()));
+ requestInfoMap.put("requestSessionId", request.getRequestedSessionId());
+ requestInfoMap.put("requestURI", request.getRequestURI());
+ requestInfoMap.put("schema", request.getScheme());
+ requestInfoMap.put("serverName", request.getServerName());
+ return requestInfoMap;
+ }
}
Modified: labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/jboss-esb.xml
===================================================================
--- labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/jboss-esb.xml 2008-11-05 10:25:42 UTC (rev 23710)
+++ labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/jboss-esb.xml 2008-11-05 10:49:28 UTC (rev 23711)
@@ -10,8 +10,7 @@
/>
</jms-bus>
</jms-provider>
-
- <tomcat-provider name="HTTP" host="localhost" port="8080">
+ <tomcat-provider name="HTTP" host="localhost" port="8765">
<!--property name="maxThreads" value="150"/>
<property name="scheme" value="https"/>
<property name="secure" value="true"/>
Modified: labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/readme.txt
===================================================================
--- labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/readme.txt 2008-11-05 10:25:42 UTC (rev 23710)
+++ labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/readme.txt 2008-11-05 10:49:28 UTC (rev 23711)
@@ -12,6 +12,6 @@
To Run '.esb' archive mode:
===========================
1. In a command terminal window in this folder ("Window1"), type 'ant deploy'.
- 2. Open the web brower and send http request to "http://localhost:8080/jbossesb/tomcat/listener"
+ 2. Open the web brower and send http request to "http://localhost:8765/jbossesb/tomcat/listener"
3. Switch back to Application Server console to see the output from the ESB
4. In this folder ("Window1"), type 'ant undeploy'.
Modified: labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/src/org/jboss/soa/esb/samples/quickstart/tomcatlistener/MyAction.java
===================================================================
--- labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/src/org/jboss/soa/esb/samples/quickstart/tomcatlistener/MyAction.java 2008-11-05 10:25:42 UTC (rev 23710)
+++ labs/jbossesb/workspace/mlittle/legstar/product/samples/quickstarts/tomcat_listener/src/org/jboss/soa/esb/samples/quickstart/tomcatlistener/MyAction.java 2008-11-05 10:49:28 UTC (rev 23711)
@@ -48,6 +48,15 @@
System.out.println(key + " : " + headerMap.get(key));
}
+ System.out.println("------------Http Request Info-------------------");
+ Map<String, String> requestInfo = (Map<String, String>)message.getProperties().getProperty("RequestInfoMap");
+ Iterator<String> infoIte = requestInfo.keySet().iterator();
+ while(infoIte.hasNext()) {
+ String key = infoIte.next();
+ System.out.println(key + " : " + requestInfo.get(key));
+ }
+
+
System.out.println("------------Http Prameter Map-------------------");
Object obj = message.getProperties().getProperty("RequestParameterMap");
More information about the jboss-svn-commits
mailing list