[jboss-svn-commits] JBL Code SVN: r25272 - labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/http.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Feb 14 09:51:22 EST 2009


Author: mark.little at jboss.com
Date: 2009-02-14 09:51:22 -0500 (Sat, 14 Feb 2009)
New Revision: 25272

Modified:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java
Log:
https://jira.jboss.org/jira/browse/JBESB-2193

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java	2009-02-14 13:55:14 UTC (rev 25271)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java	2009-02-14 14:51:22 UTC (rev 25272)
@@ -33,25 +33,57 @@
 
 /**
  * HTTP POST Factory.
+ * 
+ * CONTENT_TYPE and CHARSET can be overridden in the ConfigTree.
  *
  * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
  */
 public class POSTHttpMethodFactory implements HttpMethodFactory {
 
+	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;
     }
 
     public void setConfiguration(ConfigTree config) throws ConfigurationException {
         payloadProxy = new MessagePayloadProxy(config);
+        
+        _contentType = config.getAttribute(CONTENT_TYPE);
+        _charset = config.getAttribute(CHARSET);
     }
 
+    /**
+     * Given the input message get the PostMethod.
+     * 
+     * Content-type and charset can be overridden at configuration time.
+     */
     public HttpMethodBase getInstance(Message message) throws IOException {
         PostMethod method = new PostMethod(url.toString());
         try {
+        	StringRequestEntity entity;
+        	
+        	if ((_contentType == null) && (_charset == null))
+        		entity = new StringRequestEntity(payloadProxy.getPayload(message).toString());
+        	else
+        	{
+        		try
+        		{
+        			entity = new StringRequestEntity(payloadProxy.getPayload(message).toString(), _contentType, _charset);
+        		}
+        		catch (final Exception ex)
+        		{
+        			IOException ioe = new IOException("Failed to create StringRequestEntity with specified content-type and charset");
+                    ioe.initCause(ex);
+                    throw ioe;
+        		}
+        	}
             method.setRequestEntity(new StringRequestEntity(payloadProxy.getPayload(message).toString()));
         } catch (MessageDeliverException e) {
             IOException ioe = new IOException("Failed to access message payload.");




More information about the jboss-svn-commits mailing list