[jboss-svn-commits] JBL Code SVN: r29661 - 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
Mon Oct 19 09:44:18 EDT 2009
Author: kevin.conner at jboss.com
Date: 2009-10-19 09:44:18 -0400 (Mon, 19 Oct 2009)
New Revision: 29661
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java
Log:
Support byte[] payload: JBESB-2877
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-10-19 13:17:44 UTC (rev 29660)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/routing/http/POSTHttpMethodFactory.java 2009-10-19 13:44:18 UTC (rev 29661)
@@ -20,7 +20,9 @@
package org.jboss.soa.esb.actions.routing.http;
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;
@@ -32,7 +34,9 @@
import java.net.URL;
/**
- * HTTP POST Factory.
+ * HTTP POST Factory. Handles messages whose payload is a byte[] by
+ * converting the byte[] to a String; all other payloads are
+ * stringified by calling their toString() method.
*
* CONTENT_TYPE and CHARSET can be overridden in the ConfigTree.
*
@@ -66,26 +70,24 @@
*/
public HttpMethodBase getInstance(Message message) throws IOException {
PostMethod method = new PostMethod(url.toString());
- try {
- StringRequestEntity entity;
- 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;
- }
+ final RequestEntity entity;
+ try
+ {
+ 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 (final MessageDeliverException e)
+ {
+ IOException ioe = new IOException("Failed to access message payload.");
+ ioe.initCause(e);
+ throw ioe;
+ }
- method.setRequestEntity(new StringRequestEntity(payloadProxy.getPayload(message).toString()));
- } catch (MessageDeliverException e) {
- IOException ioe = new IOException("Failed to access message payload.");
- 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