[jboss-svn-commits] JBL Code SVN: r21149 - in labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta: tests/src/org/jboss/soa/esb/actions/routing and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jul 22 02:19:36 EDT 2008


Author: jervisliu
Date: 2008-07-22 02:19:36 -0400 (Tue, 22 Jul 2008)
New Revision: 21149

Added:
   labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/http/
   labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/http/HttpRouterUnitTest.java
Modified:
   labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpMethodFactory.java
   labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java
Log:
updated according to Tom's suggestion

Modified: labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpMethodFactory.java
===================================================================
--- labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpMethodFactory.java	2008-07-22 06:09:43 UTC (rev 21148)
+++ labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpMethodFactory.java	2008-07-22 06:19:36 UTC (rev 21149)
@@ -61,7 +61,7 @@
             } catch (ClassCastException e) {
                 throw new ConfigurationException("Class '" + className + "' must implement '" + HttpMethodFactory.class.getName() + "'.");
             } catch (ClassNotFoundException e) {
-                throw new ConfigurationException("Class '" + className + "' not found on classpath.");
+                throw new ConfigurationException("Class '" + className + "' not found on classpath. Http method " + method + " may not be supported.");                
             } catch (IllegalAccessException e) {
                 throw new ConfigurationException("Class '" + className + "' cannot be instantiated.", e);
             } catch (InstantiationException e) {

Modified: labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java
===================================================================
--- labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java	2008-07-22 06:09:43 UTC (rev 21148)
+++ labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java	2008-07-22 06:19:36 UTC (rev 21149)
@@ -40,6 +40,7 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Properties;
+import java.util.regex.PatternSyntaxException;
 
 /**
  * Http router.
@@ -62,8 +63,7 @@
     private String contentType;
     private ConfigTree[] requestHeaders;
     
-    //REVISIT: we may want to get this list from config.
-    private final static String[] WELL_KNOWN_HEADERS = new String[]{"SOAPAction", "Content-Type", "Accept"};
+    private String[] wellKnownHeaderList = new String[]{};
 			
     public HttpRouter(ConfigTree config) throws ConfigurationException {
         super(config);
@@ -79,13 +79,13 @@
         extractHttpClientProps(config);
         httpclient = HttpClientFactory.createHttpClient(httpClientProps);
         method = config.getRequiredAttribute("method");
-        if(!"POST".equals(method) && !"GET".equals(method)) {
-       	    throw new ConfigurationException("Invalid HTTP method '" + method + "'. Only POST|GET are suppported");
-        }
         
         responseType = ResponseType.valueOf(config.getAttribute("responseType", ResponseType.STRING.toString()));
-        methodFactory = HttpMethodFactory.Factory.getInstance(method, config, endpointUrl);
+        methodFactory = HttpMethodFactory.Factory.getInstance(method.toUpperCase(), config, endpointUrl);
         contentType = config.getAttribute("Content-Type", "text/xml;charset=UTF-8");
+
+        wellKnownHeaderList = extractWellKnownHeaderListConfig();
+        
         requestHeaders = config.getChildren("header");
     }
 
@@ -126,6 +126,26 @@
 
         return message;
     }
+    
+    private String[] extractWellKnownHeaderListConfig() throws ConfigurationException {
+        String wellKnownHeaders = config.getAttribute("WellKnownHeaderList", "");
+        String[] headerList = new String[]{};
+        
+        try {
+        	headerList = wellKnownHeaders.split(",");
+        } catch (PatternSyntaxException e) {
+            throw new ConfigurationException("Invalid wellKnownHeaderList '" + wellKnownHeaders +"'. The well-known header list" +
+            		" must be seperated with ','.", e);       	
+        }
+        
+        if(headerList.length ==1 && headerList[0].equals("")) {
+        	headerList = new String[]{};
+        }
+        for(int i=0; i< headerList.length; i++) {
+        	headerList[i] = headerList[i].trim();
+        }    	
+        return headerList;
+    }
 
     private void attachResponseDetails(Message message, HttpMethodBase method, int responseCode) {
         HttpResponse response = new HttpResponse(responseCode);
@@ -161,7 +181,7 @@
     }
     
     private void setWellKnownHttpHeaders(HttpMethodBase method, Message message) {
-		for (String headerName : WELL_KNOWN_HEADERS) {
+		for (String headerName : wellKnownHeaderList) {
 			Object soapAction = getHttpHeaders(message, headerName);
 			if (soapAction != null
 					&& !((String) soapAction).equalsIgnoreCase("")) {
@@ -183,6 +203,10 @@
         return null;
     }
 
+    public String[] getWellKnownHeaderList() {
+    	return wellKnownHeaderList;
+    }
+    
     public void route(Object object) throws ActionProcessingException {
         // Not used!
     }

Added: labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/http/HttpRouterUnitTest.java
===================================================================
--- labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/http/HttpRouterUnitTest.java	                        (rev 0)
+++ labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/tests/src/org/jboss/soa/esb/actions/routing/http/HttpRouterUnitTest.java	2008-07-22 06:19:36 UTC (rev 21149)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.actions.routing.http;
+
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
+import junit.framework.JUnit4TestAdapter;
+
+import java.util.List;
+import java.util.ArrayList;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.body.content.BytesBody;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class HttpRouterUnitTest
+{
+	
+	@Before
+	public void setUp()
+	{
+	}
+
+	@Test
+	public void testRouter_EmptyWellKnownHeaderList() throws ConfigurationException
+	{    
+                ConfigTree tree = new ConfigTree("EmptyWellKnownHeaderList");
+                tree.setAttribute("endpointUrl", "http://foo.bar");
+                tree.setAttribute("method", "post");
+		HttpRouter router = new HttpRouter(tree);
+                String[] headerList = router.getWellKnownHeaderList();
+                assertEquals(0, headerList.length);
+	}
+
+	@Test
+	public void testRouter_ValidWellKnownHeaderList() throws ConfigurationException
+	{    
+                ConfigTree tree = new ConfigTree("ValidWellKnownHeaderList");
+                tree.setAttribute("endpointUrl", "http://foo.bar");
+                tree.setAttribute("method", "post");
+                tree.setAttribute("WellKnownHeaderList", "SOAPAction, Content-Type, Accept");
+		HttpRouter router = new HttpRouter(tree);
+                String[] headerList = router.getWellKnownHeaderList();
+                assertEquals(3, headerList.length);
+
+                List headers = new ArrayList();
+                headers.add("SOAPAction");
+                headers.add("Content-Type");        
+                headers.add("Accept");    
+                for(String h : headerList) {
+                    if(headers.contains(h)) {
+        		headers.remove(h);
+                    }
+                }
+        
+                assertEquals(0, headers.size());
+	}
+	
+	public static junit.framework.Test suite() {
+		return new JUnit4TestAdapter(HttpRouterUnitTest.class);
+	}
+	
+}




More information about the jboss-svn-commits mailing list