[jboss-svn-commits] JBL Code SVN: r38086 - in labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/listeners: gateway/camel and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri May 11 16:12:41 EDT 2012


Author: tcunning
Date: 2012-05-11 16:12:36 -0400 (Fri, 11 May 2012)
New Revision: 38086

Modified:
   labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers131/CamelGatewayMapper.java
   labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java
Log:
JBESB-3797
Decode all unsafe characters before sending route XML to Camel.


Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers131/CamelGatewayMapper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers131/CamelGatewayMapper.java	2012-05-11 16:18:33 UTC (rev 38085)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers131/CamelGatewayMapper.java	2012-05-11 20:12:36 UTC (rev 38086)
@@ -21,6 +21,9 @@
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -209,7 +212,7 @@
 					}
 					newFromURI.append(tokens[i]);
 				}
-				fromURI = URI.create(newFromURI.toString());
+				fromURI = createURI(newFromURI.toString());
 			}
 			
 			if(timerURIBuilder != null) {

Modified: labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java	2012-05-11 16:18:33 UTC (rev 38085)
+++ labs/jbossesb/branches/JBESB_4_11_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java	2012-05-11 20:12:36 UTC (rev 38086)
@@ -54,6 +54,8 @@
 import org.apache.camel.model.RoutesDefinition;
 import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.util.UnsafeUriCharactersEncoder;
+
 import org.apache.log4j.Logger;
 import org.dom4j.DocumentHelper;
 import org.dom4j.io.OutputFormat;
@@ -109,9 +111,12 @@
 	private static final String AS6_CLASS_RESOLVER = "org.jboss.soa.esb.listeners.gateway.camel.as6.JBossPackageScanClassResolver";
 	
 	private static final boolean isAS4;
-        private static final boolean isAS5;
+    private static final boolean isAS5;
 	private static final boolean isAS6;
 
+	private static final char[] UNSAFE_CHARS = { ' ', '\"', '#', '<', '>', '%',
+		'[',  '\\', ']', '^', '`', '{', '|', '}', '~' };
+	
 	static {
 		try {
 			MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
@@ -142,7 +147,7 @@
 		} else {	
 			//routesXML = URLDecoder.decode(routesXML);
 			routesXML = routesXML.replaceAll("&", "&amp;");
-			routesXML = routesXML.replaceAll("%20", " ");
+			routesXML = decodeUnsafeURICharacters(routesXML);
 		}
 		jndiEnvironment = JndiUtil.parseEnvironmentProperties(config);
 		jndiEnvironment.setProperty(Context.PROVIDER_URL, config.getAttribute(JMSEpr.JNDI_URL_TAG, Configuration.getJndiServerURL()));
@@ -150,6 +155,24 @@
 		jndiEnvironment.setProperty(Context.URL_PKG_PREFIXES, config.getAttribute(JMSEpr.JNDI_PKG_PREFIX_TAG, Configuration.getJndiServerPkgPrefix()));
 	}
 
+	/* 
+	 * In CamelGatewayMapper, we use UnsafeUriCharactersEncoder to encode the URI
+	 * before deploying.   Here we need to decode those characters before sending the
+	 * routes to Camel.
+	 */
+	public String decodeUnsafeURICharacters(String routesXML) {
+		String result = routesXML;
+		
+		for (int i = 0; i < UNSAFE_CHARS.length; i++) {
+			String character = Character.toString(UNSAFE_CHARS[i]);
+
+			result = result.replaceAll(UnsafeUriCharactersEncoder.encode(character),
+					character);
+		}
+		
+		return result;
+	}
+	
 	@Override
 	protected void doInitialise() throws ManagedLifecycleException {
 		try {
@@ -229,16 +252,7 @@
 			Unmarshaller um = jaxbContext.createUnmarshaller();
 			RoutesDefinition rd = (RoutesDefinition)um.unmarshal(new StringReader(routesXML));
 			
-			List<RouteDefinition> unEscapedRoutes = rd.getRoutes();
-			for (RouteDefinition route : unEscapedRoutes) {
-				for (FromDefinition input : route.getInputs() ) {
-					System.out.println(input.getShortName());
-				}
-				for (ProcessorDefinition pd : route.getOutputs()) {
-					System.out.println(pd.getShortName());			
-				}
-			}
-				
+			List<RouteDefinition> unEscapedRoutes = rd.getRoutes();				
 			camelContext.addRouteDefinitions(rd.getRoutes());
 		} catch (Exception e) {
 			throw new ManagedLifecycleException("problem adding routes", e);



More information about the jboss-svn-commits mailing list