[jboss-svn-commits] JBL Code SVN: r24158 - in labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners: gateway and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Dec 1 01:19:11 EST 2008


Author: jim.ma
Date: 2008-12-01 01:19:11 -0500 (Mon, 01 Dec 2008)
New Revision: 24158

Modified:
   labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
   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
Log:
Added allowHttpMethod configuration to TomcatGatewayListener

Modified: labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java
===================================================================
--- labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java	2008-12-01 00:25:22 UTC (rev 24157)
+++ labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/ListenerTagNames.java	2008-12-01 06:19:11 UTC (rev 24158)
@@ -134,5 +134,6 @@
     public static final String HOST_TAG = "host";
     public static final String PORT_TAG = "port";
     public static final String CONTEXT_TAG = "context";
+    public static final String ALLOW_HTTP_METHOD = "allowHttpMethod";
     
 }

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-12-01 00:25:22 UTC (rev 24157)
+++ labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatDispatchServlet.java	2008-12-01 06:19:11 UTC (rev 24158)
@@ -30,6 +30,7 @@
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.couriers.FaultMessageException;
 import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
 import org.jboss.soa.esb.listeners.message.UncomposedMessageDeliveryAdapter;
 import org.jboss.soa.esb.message.Message;
 
@@ -44,13 +45,24 @@
 public class TomcatDispatchServlet extends HttpServlet {
 	private static final long serialVersionUID = 1L;
 
+    private static final String METHOD_DELETE = "DELETE";
+    private static final String METHOD_HEAD = "HEAD";
+    private static final String METHOD_GET = "GET";
+    private static final String METHOD_OPTIONS = "OPTIONS";
+    private static final String METHOD_POST = "POST";
+    private static final String METHOD_PUT = "PUT";
+    private static final String METHOD_TRACE = "TRACE";
+	
 	/** If this a synchronous invocation * */
 	private boolean synchronous = true;
 	
 	/** asyncResponse file location */
     private String asyncResponse = null;
 
-	private int serviceTimeout = 20000;
+    private int serviceTimeout = 20000;
+	
+	/** Default allow http method list */
+    private String allowHttpMethods = "POST,GET";
 
 	/** ESB message delivery adapter */
 	public UncomposedMessageDeliveryAdapter messageDeliveryAdapter = null;
@@ -77,6 +89,10 @@
 		} catch (ConfigurationException e) {
 			throw new ServletException(e);
 		}
+		
+		if (config.getAttribute(ListenerTagNames.ALLOW_HTTP_METHOD) != null) {
+			allowHttpMethods = config.getAttribute(ListenerTagNames.ALLOW_HTTP_METHOD).toUpperCase();
+		}
 
 	}
 
@@ -133,22 +149,89 @@
 
 	}
 	
-	
+	@Override
 	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-		serveRequest(request, response); 
+		if (isSupportMethod(METHOD_GET)) {
+			serveRequest(request, response);
+		} else {
+			super.doGet(request, response);
+		}
 	}
 	
+	@Override
 	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-		serveRequest(request, response);
+		if (isSupportMethod(METHOD_POST)) {
+			serveRequest(request, response);
+		} else {
+			super.doPost(request, response);
+		}
 	}
 	
-	
+	@Override
 	protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-		serveRequest(request, response);
+		if (isSupportMethod(METHOD_PUT)) {
+			serveRequest(request, response);
+		} else {
+			super.doPut(request, response);
+		}
 	}
-	
+	@Override
 	protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-		serveRequest(request, response);
+		if (isSupportMethod(METHOD_DELETE)) {
+			serveRequest(request, response);
+		} else {
+			super.doDelete(request, response);
+		}
 	}
-		
+	
+	 protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+
+		boolean ALLOW_GET = isSupportMethod(METHOD_GET);
+		boolean ALLOW_HEAD = ALLOW_GET;
+		boolean ALLOW_POST = isSupportMethod(METHOD_POST);
+		boolean ALLOW_PUT = isSupportMethod(METHOD_PUT);
+		boolean ALLOW_DELETE = isSupportMethod(METHOD_DELETE);
+		boolean ALLOW_TRACE = true;
+		boolean ALLOW_OPTIONS = true;
+
+		String allow = null;
+		if (ALLOW_GET)
+			if (allow == null) allow = METHOD_GET;
+		if (ALLOW_HEAD)
+			if (allow == null) allow = METHOD_HEAD;
+			else
+				allow += ", " + METHOD_HEAD;
+		if (ALLOW_POST)
+			if (allow == null) allow = METHOD_POST;
+			else
+				allow += ", " + METHOD_POST;
+		if (ALLOW_PUT)
+			if (allow == null) allow = METHOD_PUT;
+			else
+				allow += ", " + METHOD_PUT;
+		if (ALLOW_DELETE)
+			if (allow == null) allow = METHOD_DELETE;
+			else
+				allow += ", " + METHOD_DELETE;
+		if (ALLOW_TRACE)
+			if (allow == null) allow = METHOD_TRACE;
+			else
+				allow += ", " + METHOD_TRACE;
+		if (ALLOW_OPTIONS)
+			if (allow == null) allow = METHOD_OPTIONS;
+			else
+				allow += ", " + METHOD_OPTIONS;
+
+		resp.setHeader("Allow", allow);
+	}
+	 
+	 
+	/**
+	 * Check if support this http method
+	 * @param http method name
+	 * @return true if supported or false if not supported
+	 */
+	private boolean isSupportMethod(String name) {
+		return allowHttpMethods.indexOf(name) >= 0;
+	}		
 }

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-12-01 00:25:22 UTC (rev 24157)
+++ labs/jbossesb/workspace/mlittle/legstar/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/TomcatGatewayListener.java	2008-12-01 06:19:11 UTC (rev 24158)
@@ -20,8 +20,8 @@
 package org.jboss.soa.esb.listeners.gateway;
 
 import java.net.URI;
+import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import javax.management.ObjectName;
@@ -128,7 +128,7 @@
 		if (config.getAttribute(DISPATCH_SERVLET_CLASS) != null) {
 			dispatchServletClassName = config.getAttribute(DISPATCH_SERVLET_CLASS);
 		}
-		
+				
         boolean synchronous = !config.getAttribute("synchronous", "true").equalsIgnoreCase("false");
         if (!synchronous) {
 			String asyncResponse = config.getAttribute("asyncResponse");
@@ -139,8 +139,27 @@
 				}
 			}
 		}
-		
-		
+        
+        //validate allow http method configuration
+        if (config.getAttribute(ListenerTagNames.ALLOW_HTTP_METHOD) != null) {
+        	String allowMethods = config.getAttribute(ListenerTagNames.ALLOW_HTTP_METHOD);
+        	String[] methods = allowMethods.split(",");
+        	List<String> standardMesthods = new ArrayList<String>();
+        	standardMesthods.add("GET");
+        	standardMesthods.add("POST");
+        	standardMesthods.add("DELETE");
+        	standardMesthods.add("PUT");
+        	standardMesthods.add("OPTIONS");
+        	standardMesthods.add("HEAD");
+        	standardMesthods.add("TRACE");
+        	
+        	for (String method : methods) {
+        		if (!standardMesthods.contains(method.toUpperCase())) {
+        			throw new ConfigurationException("Invalid allow http method configuration, please specify the specify method list with comma-separated(e.g. POST,GET,PUT,DELETE"); 
+        		}
+        	}
+        }
+        		
 		//Check if the context already exists
 		try {
 			Set contexts = TomcatServer.getInstance().queryObjects(TomcatServer.DOMAIN_NAME + ":host=" + host + ",path=" + httpContext + ",*");




More information about the jboss-svn-commits mailing list