[jboss-svn-commits] JBL Code SVN: r25994 - in labs/jbossesb/branches/JBESB_4_4_GA_FP/product: install/conf and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Apr 9 13:03:18 EDT 2009


Author: tfennelly
Date: 2009-04-09 13:03:18 -0400 (Thu, 09 Apr 2009)
New Revision: 25994

Modified:
   labs/jbossesb/branches/JBESB_4_4_GA_FP/product/etc/schemas/xml/jbossesb-1.1.0.xsd
   labs/jbossesb/branches/JBESB_4_4_GA_FP/product/install/conf/jbossesb-properties.xml
   labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers110/HttpListenerMapper.java
   labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpMessageComposer.java
Log:
https://jira.jboss.org/jira/browse/JBESB-2517

Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/etc/schemas/xml/jbossesb-1.1.0.xsd
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/etc/schemas/xml/jbossesb-1.1.0.xsd	2009-04-09 16:05:19 UTC (rev 25993)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/etc/schemas/xml/jbossesb-1.1.0.xsd	2009-04-09 17:03:18 UTC (rev 25994)
@@ -1755,10 +1755,23 @@
                             </xsd:documentation>
                         </xsd:annotation>
                     </xsd:attribute>
+                    <xsd:attribute name="payloadAs" type="jesb:payloadAs" use="optional">
+                        <xsd:annotation>
+                            <xsd:documentation xml:lang="en">
+                                Set the ESB Message payload ass either a String or an array of bytes.
+                            </xsd:documentation>
+                        </xsd:annotation>
+                    </xsd:attribute>
                 </xsd:extension>
 			</xsd:complexContent>
 		</xsd:complexType>
 	</xsd:element>
+    <xsd:simpleType name="payloadAs">
+        <xsd:restriction base="xsd:NMTOKEN">
+            <xsd:enumeration value="STRING"/>
+            <xsd:enumeration value="BYTES"/>
+        </xsd:restriction>
+    </xsd:simpleType>
 
 	<!-- 88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
 		Groovy Gateway Type Implementations.

Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/install/conf/jbossesb-properties.xml
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/install/conf/jbossesb-properties.xml	2009-04-09 16:05:19 UTC (rev 25993)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/install/conf/jbossesb-properties.xml	2009-04-09 17:03:18 UTC (rev 25994)
@@ -35,6 +35,7 @@
 		<property name="org.jboss.soa.esb.jndi.server.url" value="${jboss.esb.bind.address}:1099"/>
 		<property name="org.jboss.soa.esb.persistence.connection.factory" 	value="org.jboss.internal.soa.esb.persistence.format.MessageStoreFactoryImpl"/>
         <property name="org.jboss.soa.esb.loadbalancer.policy" value="org.jboss.soa.esb.listeners.ha.RoundRobin"/>
+        <property name="org.jboss.soa.esb.mime.text.types" value="text/*;application/xml;application/*-xml"/>
         <property name="jboss.esb.invm.scope.default" value="NONE"/>
     </properties>
     <properties name="security">

Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers110/HttpListenerMapper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers110/HttpListenerMapper.java	2009-04-09 16:05:19 UTC (rev 25993)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers110/HttpListenerMapper.java	2009-04-09 17:03:18 UTC (rev 25994)
@@ -8,6 +8,7 @@
 import org.jboss.soa.esb.listeners.config.xbeanmodel110.HttpBusDocument.HttpBus;
 import org.jboss.soa.esb.listeners.config.xbeanmodel110.HttpListenerDocument.HttpListener;
 import org.jboss.soa.esb.listeners.config.xbeanmodel110.HttpProviderDocument.HttpProvider;
+import org.jboss.soa.esb.listeners.config.xbeanmodel110.PayloadAs;
 import org.jboss.soa.esb.listeners.gateway.HttpGatewayDeploymentFactory;
 import org.w3c.dom.Element;
 
@@ -61,6 +62,7 @@
             String jbossWebXml = bus.getJbossWebXml();
             String urlPattern = listener.getUrlPattern();
             String allowMethods = listener.getAllowMethods();
+            PayloadAs.Enum payloadAs = listener.getPayloadAs();
 
             listenerNode.setAttribute("gatewayClass", HttpGatewayDeploymentFactory.class.getName());
 			listenerNode.setAttribute(ListenerTagNames.IS_GATEWAY_TAG, "true");
@@ -75,6 +77,9 @@
             if(allowMethods != null) {
                 listenerNode.setAttribute("allowMethods", allowMethods);
             }
+            if(payloadAs != null) {
+                listenerNode.setAttribute("payloadAs", payloadAs.toString());
+            }
         } else {
 			throw new ConfigurationException("Invalid <http-listener> config [" + listener.getName() +"]. <http-listener> is currently only supported as a gateway listener.");
         }

Modified: labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpMessageComposer.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpMessageComposer.java	2009-04-09 16:05:19 UTC (rev 25993)
+++ labs/jbossesb/branches/JBESB_4_4_GA_FP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/HttpMessageComposer.java	2009-04-09 17:03:18 UTC (rev 25994)
@@ -20,7 +20,10 @@
 package org.jboss.soa.esb.listeners.gateway;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.util.*;
+import java.util.regex.Pattern;
+import java.nio.charset.Charset;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -37,6 +40,7 @@
 import org.jboss.soa.esb.message.MessagePayloadProxy;
 import org.jboss.soa.esb.message.MessagePayloadProxy.NullPayloadHandling;
 import org.jboss.soa.esb.message.body.content.BytesBody;
+import org.jboss.soa.esb.common.ModulePropertyManager;
 
 /**
  * Http Message Composer.
@@ -76,7 +80,10 @@
 	/** Message payload proxy */
 	private MessagePayloadProxy payloadProxy;
 
-	/*
+    private String payloadAs;
+    private Pattern[] textMimePatterns;
+
+    /*
 	 * Method for configue the payload proxy
 	 */
 	public void setConfiguration(ConfigTree config) {
@@ -86,8 +93,18 @@
 				BytesBody.BYTES_LOCATION },
 				new String[] { ActionUtils.POST_ACTION_DATA });
 		payloadProxy.setNullSetPayloadHandling(NullPayloadHandling.LOG);
-	}
 
+        payloadAs = config.getAttribute("payloadAs");
+        if(payloadAs == null) {
+            // Get the globally configured text mime types...
+            String[] textTypes = ModulePropertyManager.getPropertyManager("core").getProperty("org.jboss.soa.esb.mime.text.types", "text/*;application/xml;application/*-xml").split(";");
+            textMimePatterns = new Pattern[textTypes.length];
+            for(int i = 0; i < textMimePatterns.length; i++) {
+                textMimePatterns[i] = Pattern.compile(textTypes[i].trim().replace("*", ".*"));
+            }
+        }
+    }
+
 	protected MessagePayloadProxy getPayloadProxy() {
 		return payloadProxy;
 	}
@@ -96,8 +113,7 @@
 	 *Method for populating the ESB aware message from a HttpServletRequest
 	 */
 	@SuppressWarnings("unchecked")
-	protected void populateMessage(Message message, T requestWrapper)
-			throws MessageDeliverException {
+	protected void populateMessage(Message message, T requestWrapper) throws MessageDeliverException {
 		HttpServletRequest request = requestWrapper.getRequest();
 		Map paraMap = request.getParameterMap();
 		byte[] bodyBytes = null;
@@ -108,18 +124,57 @@
 			throw new MessageDeliverException("Failed to read body data from http request", e);
 		}
 
+        String characterEncoding = request.getCharacterEncoding();
+        Charset charset;
+        if(characterEncoding == null) {
+            charset = Charset.defaultCharset();
+        } else {
+            charset = Charset.forName(characterEncoding);
+        }
+
+        if(payloadAs == null) {
+            String contentType = request.getContentType();
+
+            if(contentType != null && isTextMimetype(contentType)) {
+                try {
+                    payloadProxy.setPayload(message, new String(bodyBytes, charset.name()));
+                } catch (UnsupportedEncodingException e) {
+                    throw new MessageDeliverException("Invalid Character encoding '" + characterEncoding + "' set on request.", e);
+                }
+            } else {
+                payloadProxy.setPayload(message, bodyBytes);
+            }
+        } else if(payloadAs.equals("STRING")) {
+            try {
+                payloadProxy.setPayload(message, new String(bodyBytes, charset.name()));
+            } catch (UnsupportedEncodingException e) {
+                throw new MessageDeliverException("Invalid Character encoding '" + characterEncoding + "' set on request.", e);
+            }
+        } else {
+            payloadProxy.setPayload(message, bodyBytes);
+        }
+
         //Set http request info
 		message.getProperties().setProperty(HTTP_REQUEST_INFO_MAP, getRequestInfo(request));
 		if (paraMap != null && !paraMap.isEmpty()) {
 		   message.getProperties().setProperty(this.HTTP_REQUEST_PARAMETER_MAP, paraMap);
 		}
-
-        payloadProxy.setPayload(message, bodyBytes);
 	}
 
-	/*
-	 * Method for decompsing a esb message to a HttpServletResponse
-	 */
+    private boolean isTextMimetype(String contentType) {
+        for(int i = 0; i < textMimePatterns.length; i++) {
+            if(textMimePatterns[i].matcher(contentType).matches()) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+
+    /*
+    * Method for decompsing a esb message to a HttpServletResponse
+    */
 	@SuppressWarnings("unchecked")
 	public Object decompose(Message message, T requestWrapper) throws MessageDeliverException {
         HttpServletRequest request = requestWrapper.getRequest();




More information about the jboss-svn-commits mailing list