[jboss-svn-commits] JBL Code SVN: r30590 - in labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb: http/configurators and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Dec 11 02:27:51 EST 2009


Author: dward
Date: 2009-12-11 02:27:50 -0500 (Fri, 11 Dec 2009)
New Revision: 30590

Added:
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/AbstractHttpMethodFactory.java
Modified:
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/GETHttpMethodFactory.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/http/configurators/HttpProtocol.java
Log:
Fix for JBESB-3021


Added: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/AbstractHttpMethodFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/AbstractHttpMethodFactory.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/AbstractHttpMethodFactory.java	2009-12-11 07:27:50 UTC (rev 30590)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2009
+ */
+package org.jboss.soa.esb.actions.routing.http;
+
+import java.net.URL;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * AbstractHttpMethodFactory.
+ * 
+ * @author dward at jboss.org
+ */
+public abstract class AbstractHttpMethodFactory implements HttpMethodFactory
+{
+	
+	private URL endpoint;
+
+    public void setEndpoint(URL endpoint)
+    {
+    	this.endpoint = endpoint;
+    }
+    
+    protected String getEndpointPathAndQuery()
+    {
+    	StringBuilder sb = new StringBuilder();
+    	String path = endpoint.getPath();
+    	sb.append("".equals(path) ? "/" : path);
+    	String query = endpoint.getQuery();
+    	if (query != null)
+    	{
+    		sb.append("?");
+    		sb.append(query);
+    	}
+    	return sb.toString();
+    }
+    
+    public void setConfiguration(ConfigTree config) throws ConfigurationException {}
+
+}


Property changes on: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/AbstractHttpMethodFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/GETHttpMethodFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/GETHttpMethodFactory.java	2009-12-11 07:07:28 UTC (rev 30589)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/GETHttpMethodFactory.java	2009-12-11 07:27:50 UTC (rev 30590)
@@ -19,32 +19,20 @@
  */
 package org.jboss.soa.esb.actions.routing.http;
 
+import java.io.IOException;
+
 import org.apache.commons.httpclient.HttpMethodBase;
 import org.apache.commons.httpclient.methods.GetMethod;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.message.Message;
 
-import java.io.IOException;
-import java.net.URL;
-
 /**
  * HTTP GET Factory.
  * 
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */
-public class GETHttpMethodFactory implements HttpMethodFactory {
+public class GETHttpMethodFactory extends AbstractHttpMethodFactory {
 
-    private URL url;
-
-    public void setEndpoint(URL url) {
-        this.url = url;
-    }
-
-    public void setConfiguration(ConfigTree config) throws ConfigurationException {
-    }
-
     public HttpMethodBase getInstance(Message message) throws IOException {
-        return new GetMethod(url.toString());
+        return new GetMethod( getEndpointPathAndQuery() );
     }
-}
+}
\ No newline at end of file

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java	2009-12-11 07:07:28 UTC (rev 30589)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/HttpRouter.java	2009-12-11 07:27:50 UTC (rev 30590)
@@ -30,6 +30,7 @@
 import java.util.Set;
 
 import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HostConfiguration;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpMethodBase;
 import org.apache.commons.httpclient.HttpStatus;
@@ -67,6 +68,7 @@
     private ConfigTree config;
     private java.util.Properties httpClientProps = new java.util.Properties();
     private HttpClient httpclient;
+    private HostConfiguration hostconfig;
     private URL endpointUrl;
     private String method;
     private HttpMethodFactory methodFactory;
@@ -84,7 +86,6 @@
         coreProperties.add("method");
         coreProperties.add("responseType");
         coreProperties.add("Content-Type");
-        coreProperties.add("method");
     }
     
     public HttpRouter(ConfigTree config) throws ConfigurationException {
@@ -100,6 +101,12 @@
         // to the HttpClientFacatory...
         extractHttpClientProps(config);
         httpclient = HttpClientFactory.createHttpClient(httpClientProps);
+        
+        // JBESB-3021: we need to hold onto the configured HostConfiguration then replace it with a dummy instance because
+        // executeMethod overrides the Protocol on us with one from a static (yuck!) map if the instances are the same!
+        hostconfig = httpclient.getHostConfiguration();
+        httpclient.setHostConfiguration(new HostConfiguration());
+        
         method = config.getRequiredAttribute("method");
         
         responseType = ResponseType.valueOf(config.getAttribute("responseType", ResponseType.STRING.toString()));
@@ -121,7 +128,8 @@
             try {
                 setRequestHeaders(method, message);
                 
-                int responseCode = httpclient.executeMethod(method);
+                // JBESB-3021: use the hostconfig with the appropriate Protocol
+                int responseCode = httpclient.executeMethod(hostconfig, method);
                 if(responseCode != HttpStatus.SC_OK) {
                     logger.warn("Received status code '" + responseCode + "' on HTTP " + method + " request to '" + endpointUrl + "'.");
                 }
@@ -294,7 +302,8 @@
         super.destroy();
     }
 
-    private void extractHttpClientProps(ConfigTree config) {
+    @SuppressWarnings("deprecation")
+	private void extractHttpClientProps(ConfigTree config) {
         ConfigTree[] httpClientConfigTrees = config.getChildren("http-client-property");
 
         httpClientProps.setProperty(HttpClientFactory.TARGET_HOST_URL, endpointUrl.toString());

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java	2009-12-11 07:07:28 UTC (rev 30589)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java	2009-12-11 07:27:50 UTC (rev 30590)
@@ -19,20 +19,19 @@
  */
 package org.jboss.soa.esb.actions.routing.http;
 
+import java.io.IOException;
+
 import org.apache.commons.httpclient.HttpMethodBase;
 import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
 import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.commons.httpclient.methods.RequestEntity;
 import org.apache.commons.httpclient.methods.StringRequestEntity;
 import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.listeners.message.MessageDeliverException;
 import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.message.MessagePayloadProxy;
 
-import java.io.IOException;
-import java.net.URL;
-
 /**
  * HTTP POST Factory.  Handles messages whose payload is a byte[] by
  * converting the byte[] to a String; all other payloads are
@@ -42,20 +41,16 @@
  *
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */
-public class POSTHttpMethodFactory implements HttpMethodFactory {
+public class POSTHttpMethodFactory extends AbstractHttpMethodFactory {
 
 	public static final String CONTENT_TYPE = "org.jboss.soa.esb.actions.routing.http.contentType";
 	public static final String CHARSET = "org.jboss.soa.esb.actions.routing.http.charset";
 	
-    private URL url;
     private MessagePayloadProxy payloadProxy;
     private String _contentType = null;
     private String _charset = null;
-    
-    public void setEndpoint(URL url) {
-        this.url = url;
-    }
 
+    @Override
     public void setConfiguration(ConfigTree config) throws ConfigurationException {
         payloadProxy = new MessagePayloadProxy(config);
         
@@ -69,7 +64,7 @@
      * Content-type and charset can be overridden at configuration time.
      */
     public HttpMethodBase getInstance(Message message) throws IOException {
-        PostMethod method = new PostMethod(url.toString());
+        PostMethod method = new PostMethod( getEndpointPathAndQuery() );
 
         final RequestEntity entity;
         try

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/http/configurators/HttpProtocol.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/http/configurators/HttpProtocol.java	2009-12-11 07:07:28 UTC (rev 30589)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/http/configurators/HttpProtocol.java	2009-12-11 07:27:50 UTC (rev 30590)
@@ -19,6 +19,19 @@
  */
 package org.jboss.soa.esb.http.configurators;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.GeneralSecurityException;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.util.Properties;
+
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.ProxyHost;
 import org.apache.commons.httpclient.contrib.ssl.StrictSSLProtocolSocketFactory;
@@ -33,19 +46,6 @@
 import org.jboss.soa.esb.http.protocol.ProtocolSocketFactoryBuilder;
 import org.jboss.soa.esb.util.ClassUtil;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.security.GeneralSecurityException;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.cert.CertificateException;
-import java.util.Properties;
-
 /**
  * HTTP Protocol configurator.
  * <p/>
@@ -77,7 +77,7 @@
         URI targetURI = getTargetURI(properties, true);
         String factory;
         String scheme = targetURI.getScheme();
-        final int port ;
+        int port = targetURI.getPort();
         org.apache.commons.httpclient.protocol.Protocol protocol;
         KeyMaterial keyMaterial = null;
         ProtocolSocketFactory socketFactory;
@@ -86,26 +86,35 @@
             // We're only interested in HTTP for this...
             return;
         }
-
-        if(scheme.equals("https")) {
+        
+        boolean secure = "https".equals(scheme);
+        if (secure) {
             factory = properties.getProperty("protocol-socket-factory", StrictSSLProtocolSocketFactory.class.getName());
             keyMaterial = getKeyMaterial(properties);
-            setHttpsProxyHost(httpClient, properties);
-
-            port = 443;
+            if (port == -1) {
+            	port = 443;
+            }
         } else {
             factory = properties.getProperty("protocol-socket-factory", DefaultProtocolSocketFactory.class.getName());
-            setHttpProxyHost(httpClient, properties);
-
-            port = 80;
+            if (port == -1) {
+            	port = 80;
+            }
         }
         assertPropertySetAndNotBlank(factory, "protocol-socket-factory");
         socketFactory = createFactoryClass(factory, keyMaterial, properties);
         
-
         // And finally... configure the host with the protocol....
         protocol = new Protocol(scheme, socketFactory, port);
         Protocol.registerProtocol(scheme, protocol);
+        // these lines have to happen after registerProtocol, otherwise they pick up the wrong static value
+        if (secure) {
+        	setHttpsProxyHost(httpClient, properties);
+        } else {
+        	setHttpProxyHost(httpClient, properties);
+        }
+        // JBESB-3021: the registerProtocol map is static (yuck!); we need to make sure to use the right protocol.
+        // See HttpRouter (JBESB-3021 comments) for more information.
+        httpClient.getHostConfiguration().setHost(targetURI.getHost(), port, protocol);
     }
     
     /**
@@ -197,7 +206,7 @@
         ProtocolSocketFactory socketFactory = null;
 
         try {
-            Class factoryClass = ClassUtil.forName(factory, HttpProtocol.class);
+            Class<?> factoryClass = ClassUtil.forName(factory, HttpProtocol.class);
 
             if(ProtocolSocketFactoryBuilder.class.isAssignableFrom(factoryClass)) {
                 try {



More information about the jboss-svn-commits mailing list