[jboss-svn-commits] JBL Code SVN: r37337 - labs/jbossesb/tags/GSS-SOA-3222-CP02/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 Aug 2 17:06:24 EDT 2011


Author: tcunning
Date: 2011-08-02 17:06:23 -0400 (Tue, 02 Aug 2011)
New Revision: 37337

Added:
   labs/jbossesb/tags/GSS-SOA-3222-CP02/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/AbstractHttpMethodFactory.java
Modified:
   labs/jbossesb/tags/GSS-SOA-3222-CP02/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java
Log:
JBESB-3655
Checking in byte[] patches for 4.4.CP3.


Added: labs/jbossesb/tags/GSS-SOA-3222-CP02/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/AbstractHttpMethodFactory.java
===================================================================
--- labs/jbossesb/tags/GSS-SOA-3222-CP02/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/AbstractHttpMethodFactory.java	                        (rev 0)
+++ labs/jbossesb/tags/GSS-SOA-3222-CP02/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/AbstractHttpMethodFactory.java	2011-08-02 21:06:23 UTC (rev 37337)
@@ -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 {}
+
+}

Modified: labs/jbossesb/tags/GSS-SOA-3222-CP02/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java
===================================================================
--- labs/jbossesb/tags/GSS-SOA-3222-CP02/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java	2011-08-02 20:53:36 UTC (rev 37336)
+++ labs/jbossesb/tags/GSS-SOA-3222-CP02/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java	2011-08-02 21:06:23 UTC (rev 37337)
@@ -19,45 +19,62 @@
  */
 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.helpers.ConfigTree;
 import org.jboss.soa.esb.listeners.message.MessageDeliverException;
-import org.jboss.soa.esb.helpers.ConfigTree;
 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.
  *
  * @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 {
 
-    private URL url;
+    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 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 {
+        super.setConfiguration(config) ;
+
         payloadProxy = new MessagePayloadProxy(config);
+        _contentType = config.getAttribute(CONTENT_TYPE);
+        _charset = config.getAttribute(CHARSET);
+
     }
 
     public HttpMethodBase getInstance(Message message) throws IOException {
-        PostMethod method = new PostMethod(url.toString());
+        PostMethod method = new PostMethod( getEndpointPathAndQuery() );
+	
+	final RequestEntity entity;
         try {
-            method.setRequestEntity(new StringRequestEntity(payloadProxy.getPayload(message).toString()));
+            final Object payload = payloadProxy.getPayload(message);
+            if (payload instanceof byte[])
+                entity = new ByteArrayRequestEntity((byte[])payload, _contentType);
+            else
+                entity = new StringRequestEntity(String.valueOf(payload), _contentType, _charset);
         } catch (MessageDeliverException e) {
-            IOException ioe = new IOException("Failed to access message payload.");
+            IOException ioe = new IOException("Failed to access message payload:" + e.getMessage());
             ioe.initCause(e);
             throw ioe;
         }
+        method.setRequestEntity(entity);
         return method;
     }
-}
\ No newline at end of file
+    
+}



More information about the jboss-svn-commits mailing list