[jboss-svn-commits] JBL Code SVN: r21047 - labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/src/org/jboss/soa/esb/actions/routing/http.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jul 15 21:42:01 EDT 2008


Author: jervisliu
Date: 2008-07-15 21:42:01 -0400 (Tue, 15 Jul 2008)
New Revision: 21047

Modified:
   labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java
Log:
JBESB-1866: HttpRouter can not handle http headers properly

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-16 00:02:21 UTC (rev 21046)
+++ labs/jbossesb/workspace/jervisliu/jbossesb_router/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java	2008-07-16 01:42:01 UTC (rev 21047)
@@ -61,7 +61,10 @@
     private ResponseType responseType;
     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"};
+			
     public HttpRouter(ConfigTree config) throws ConfigurationException {
         super(config);
         this.config = config;
@@ -76,6 +79,10 @@
         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);
         contentType = config.getAttribute("Content-Type", "text/xml;charset=UTF-8");
@@ -88,7 +95,7 @@
             method = methodFactory.getInstance(message);
 
             try {
-                setRequestHeaders(method);
+                setRequestHeaders(method, message);
                 
                 int responseCode = httpclient.executeMethod(method);
                 if(responseCode != HttpStatus.SC_OK) {
@@ -134,9 +141,12 @@
         message.getBody().add(HttpResponse.RESPONSE_KEY, response);
     }
 
-    private void setRequestHeaders(HttpMethodBase method) {
-        method.setRequestHeader("Content-Type", contentType);
-
+    private void setRequestHeaders(HttpMethodBase method, Message message) {
+        //Try best to keep all the well-known HTTP headers that were sent from the client. 
+    	setWellKnownHttpHeaders(method, message);
+		
+		//The setting of HTTP headers from config still takes precedence. So do not set 
+		//a HTTP header in config if you want to keep the value sent from the client.
         for (int i = 0; i < requestHeaders.length; i++) {
             ConfigTree header = requestHeaders[i];
             String name = header.getAttribute("name");
@@ -149,6 +159,29 @@
             }
         }
     }
+    
+    private void setWellKnownHttpHeaders(HttpMethodBase method, Message message) {
+		for (String headerName : WELL_KNOWN_HEADERS) {
+			Object soapAction = getHttpHeaders(message, headerName);
+			if (soapAction != null
+					&& !((String) soapAction).equalsIgnoreCase("")) {
+				method.setRequestHeader(headerName, (String) soapAction);
+			}
+		}
+	}
+    
+    // HTTP header field names are case-insensitive
+    private Object getHttpHeaders(Message esbMessage, String headerName) {
+    	
+        org.jboss.soa.esb.message.Properties ps = esbMessage.getProperties();
+        for(String name : ps.getNames()) {
+        	if (name.equalsIgnoreCase(headerName)) {
+        		return ps.getProperty(name);
+        	}
+        }
+        
+        return null;
+    }
 
     public void route(Object object) throws ActionProcessingException {
         // Not used!




More information about the jboss-svn-commits mailing list