[jboss-svn-commits] JBL Code SVN: r25754 - in labs/jbossesb/branches/JBESB_4_4_GA_FP/product: rosetta/src/org/jboss/soa/esb/listeners/config/mappers110 and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Mar 19 13:21:20 EDT 2009


Author: tfennelly
Date: 2009-03-19 13:21:20 -0400 (Thu, 19 Mar 2009)
New Revision: 25754

Modified:
   labs/jbossesb/branches/JBESB_4_4_GA_FP/product/etc/schemas/xml/jbossesb-1.1.0.xsd
   labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers110/HttpListenerMapper.java
   labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayServlet.java
   labs/jbossesb/branches/JBESB_4_4_GA_FP/product/samples/quickstarts/http_gateway/jboss-esb.xml
Log:
https://jira.jboss.org/jira/browse/JBESB-2474
https://jira.jboss.org/jira/browse/JBESB-2475

Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/etc/schemas/xml/jbossesb-1.1.0.xsd
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/etc/schemas/xml/jbossesb-1.1.0.xsd	2009-03-19 16:49:43 UTC (rev 25753)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/etc/schemas/xml/jbossesb-1.1.0.xsd	2009-03-19 17:21:20 UTC (rev 25754)
@@ -1747,6 +1747,14 @@
                             </xsd:documentation>
                         </xsd:annotation>
                     </xsd:attribute>
+                    <xsd:attribute name="allowMethods" type="xsd:string" use="optional" default="OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE">
+                        <xsd:annotation>
+                            <xsd:documentation xml:lang="en">
+                                A list of methods allowed for this listener.  A 403 response (Forbidden) is returned if the
+                                request method does not match one of the listed allow methods.
+                            </xsd:documentation>
+                        </xsd:annotation>
+                    </xsd:attribute>
                 </xsd:extension>
 			</xsd:complexContent>
 		</xsd:complexType>

Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers110/HttpListenerMapper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers110/HttpListenerMapper.java	2009-03-19 16:49:43 UTC (rev 25753)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers110/HttpListenerMapper.java	2009-03-19 17:21:20 UTC (rev 25754)
@@ -60,17 +60,21 @@
             String webXml = bus.getWebXml();
             String jbossWebXml = bus.getJbossWebXml();
             String urlPattern = listener.getUrlPattern();
+            String allowMethods = listener.getAllowMethods();
 
             listenerNode.setAttribute("gatewayClass", HttpGatewayDeploymentFactory.class.getName());
 			listenerNode.setAttribute(ListenerTagNames.IS_GATEWAY_TAG, "true");
 
+            listenerNode.setAttribute("urlPattern", urlPattern);
             if(webXml != null) {
                 listenerNode.setAttribute("webXml", webXml);
             }
             if(jbossWebXml != null) {
                 listenerNode.setAttribute("jbossWebXml", jbossWebXml);
             }
-            listenerNode.setAttribute("urlPattern", urlPattern);
+            if(allowMethods != null) {
+                listenerNode.setAttribute("allowMethods", allowMethods);
+            }
         } else {
 			throw new ConfigurationException("Invalid <http-listener> config [" + listener.getName() +"]. <http-listener> is currently only supported as a gateway listener.");
         }

Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayServlet.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayServlet.java	2009-03-19 16:49:43 UTC (rev 25753)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpGatewayServlet.java	2009-03-19 17:21:20 UTC (rev 25754)
@@ -38,6 +38,9 @@
 import javax.servlet.ServletConfig;
 import java.io.IOException;
 import java.util.Enumeration;
+import java.util.Arrays;
+import java.util.List;
+import java.security.Principal;
 
 /**
  * Http Gateway Servlet.
@@ -49,11 +52,14 @@
  */
 public class HttpGatewayServlet extends HttpServlet {
 
+    private static final String DEFAULT_METHODS = "OPTIONS,GET,HEAD,POST,PUT,DELETE,TRACE";
     private Service service;
     private ServiceInvoker serviceInvoker;
     private MessageComposer<HttpRequestWrapper> messageComposer;
     private String mep;
     private long blockingTimeout;
+    private List<String> allowMethods;
+    private String allowHeaderValue;
 
     public void init(ServletConfig config) throws ServletException {
         service = new Service(config.getInitParameter(ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG), config.getInitParameter(ListenerTagNames.TARGET_SERVICE_NAME_TAG));
@@ -74,9 +80,30 @@
 
         blockingTimeout = configTree.getLongAttribute("synchronousTimeout", 30000);
         mep = Configuration.getMep(configTree);
+        allowMethods = Arrays.asList(configTree.getAttribute("allowMethods", DEFAULT_METHODS).toUpperCase().split(","));
+        for(int i = 0; i < allowMethods.size(); i++) {
+            String method = allowMethods.get(i).trim();
+            allowMethods.set(i, method);
+            if(i == 0) {
+                allowHeaderValue = method;
+            } else {
+                allowHeaderValue += ", " + method;
+            }
+        }
     }
 
     protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+        if(!allowMethods.contains(req.getMethod())) {
+            resp.setContentLength(0);
+            resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
+            return;
+        } else if(req.getMethod().equals("OPTIONS")) {
+            resp.setContentLength(0);
+            resp.setStatus(HttpServletResponse.SC_OK);
+            resp.setHeader("Allow", allowHeaderValue);
+            return;
+        }
+
         HttpRequestWrapper wrapper = new HttpRequestWrapper(req, resp, service);
 
         Message inMessage;

Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/samples/quickstarts/http_gateway/jboss-esb.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/samples/quickstarts/http_gateway/jboss-esb.xml	2009-03-19 16:49:43 UTC (rev 25753)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/samples/quickstarts/http_gateway/jboss-esb.xml	2009-03-19 17:21:20 UTC (rev 25754)
@@ -15,7 +15,7 @@
             <listeners>
                 <!-- Receives: http://<host>:<port>/ordermgt/in/* and returns some details of the
                                request as the response (mep="RequestResponse"). -->
-                <http-listener name="1" busidref="ordermgt" urlPattern="/in/*" is-gateway="true" />
+                <http-listener name="1" busidref="ordermgt" urlPattern="/in/*" is-gateway="true" allowMethods="GET,OPTIONS" />
             </listeners>
             <actions mep="RequestResponse">
                 <action name="print" class="org.jboss.soa.esb.samples.quickstart.httpgateway.MyAction"/>




More information about the jboss-svn-commits mailing list