[jboss-svn-commits] JBL Code SVN: r35870 - in labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta: src/org/jboss/soa/esb/listeners/gateway/camel and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Nov 4 13:42:14 EDT 2010
Author: tfennelly
Date: 2010-11-04 13:42:13 -0400 (Thu, 04 Nov 2010)
New Revision: 35870
Added:
labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapperUnitTest.java
Modified:
labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapper.java
labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java
Log:
https://jira.jboss.org/browse/JBESB-3525
Add support for scheduled connectors in camel gateway
Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapper.java 2010-11-04 16:24:53 UTC (rev 35869)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapper.java 2010-11-04 17:42:13 UTC (rev 35870)
@@ -28,6 +28,7 @@
import java.util.Map;
import org.apache.camel.util.UnsafeUriCharactersEncoder;
+import org.apache.log4j.Logger;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.dom.YADOMUtil;
import org.jboss.soa.esb.listeners.config.xbeanmodel130.CamelGatewayDocument;
@@ -46,6 +47,13 @@
*/
public class CamelGatewayMapper {
+ /**
+ * ESB schedule timer scheme token.
+ */
+ private static final String ESBSCHEDULE = "esbschedule";
+
+ private static final Logger logger = Logger.getLogger(CamelGatewayMapper.class);
+
public static Element map(final Element root, final CamelGatewayDocument.CamelGateway gateway, final XMLBeansModel model) throws ConfigurationException {
final Element gatewayNode = YADOMUtil.addElement(root, "listener");
@@ -170,14 +178,50 @@
return null;
}
- private static void addRouteXML(URI fromURI, URI toURI, List<String> routeXMLs) throws ConfigurationException {
+ protected static void addRouteXML(URI fromURI, URI toURI, List<String> routeXMLs) throws ConfigurationException {
if (fromURI != null) {
StringBuilder sb = new StringBuilder();
- sb.append("<route><from uri=\"");
- sb.append(fromURI);
- sb.append("\"/><to uri=\"");
- sb.append(toURI);
- sb.append("\"/></route>");
+ String scheme = fromURI.getScheme();
+ StringBuilder timerURIBuilder = null;
+
+ sb.append("<route>");
+ if(scheme != null && scheme.equalsIgnoreCase(ESBSCHEDULE)) {
+ String[] tokens = fromURI.getSchemeSpecificPart().split(":");
+
+ if(tokens.length == 1) {
+ throw new ConfigurationException("Invalid use of esbschedule timer in from URI '" + scheme + "'. Must include a schedule timer value e.g. 'esbschedule:5000:file://etc'.");
+ }
+
+ try {
+ int timer = Integer.parseInt(tokens[0]);
+
+ timerURIBuilder = new StringBuilder();
+ timerURIBuilder.append("timer://" + fromURI.hashCode() + "?fixedRate=true&delay=0&period=" + timer);
+ } catch(NumberFormatException e) {
+ throw new ConfigurationException("Invalid esbschedule timer time '" + scheme + "'. Must be a valid integer.", e);
+ }
+
+ // Reconstruct the uri, excluding the esbschedule bits......
+ StringBuilder newFromURI = new StringBuilder();
+ for(int i = 1; i < tokens.length; i++) {
+ if(newFromURI.length() > 0) {
+ newFromURI.append(":");
+ }
+ newFromURI.append(tokens[i]);
+ }
+ fromURI = URI.create(newFromURI.toString());
+ }
+
+ if(timerURIBuilder != null) {
+ sb.append("<from uri=\"").append(timerURIBuilder.toString()).append("\"/>");
+ sb.append("<to uri=\"").append(fromURI).append("\"/>");
+ } else {
+ sb.append("<from uri=\"").append(fromURI).append("\"/>");
+ }
+
+ sb.append("<to uri=\"").append(toURI).append("\"/>");
+ sb.append("</route>");
+
routeXMLs.add(sb.toString());
}
}
Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java 2010-11-04 16:24:53 UTC (rev 35869)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java 2010-11-04 17:42:13 UTC (rev 35870)
@@ -188,6 +188,7 @@
JAXBContext jaxbContext = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
Unmarshaller um = jaxbContext.createUnmarshaller();
RoutesDefinition rd = (RoutesDefinition)um.unmarshal(new StringReader(routesXML));
+
camelContext.addRouteDefinitions(rd.getRoutes());
} catch (Exception e) {
throw new ManagedLifecycleException("problem adding routes", e);
Added: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapperUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapperUnitTest.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapperUnitTest.java 2010-11-04 17:42:13 UTC (rev 35870)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.config.mappers130;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.soa.esb.ConfigurationException;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:tom.fennelly at gmail.com">tom.fennelly at gmail.com</a>
+ */
+public class CamelGatewayMapperUnitTest extends TestCase {
+
+ public void test_addRouteXML() throws ConfigurationException {
+
+ List<String> routeXMLs = new ArrayList<String>();
+
+ CamelGatewayMapper.addRouteXML(URI.create("file://indir?delete=true"), URI.create("jbossesb://blah"), routeXMLs);
+ CamelGatewayMapper.addRouteXML(URI.create("esbschedule:5000:file://indir?delete=true"), URI.create("jbossesb://blah"), routeXMLs);
+
+ assertEquals("<route><from uri=\"file://indir?delete=true\"/><to uri=\"jbossesb://blah\"/></route>", routeXMLs.get(0));
+ assertTrue(routeXMLs.get(1).startsWith("<route><from uri=\"timer://"));
+ assertTrue(routeXMLs.get(1).endsWith("?fixedRate=true&delay=0&period=5000\"/><to uri=\"file://indir?delete=true\"/><to uri=\"jbossesb://blah\"/></route>"));
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapperUnitTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the jboss-svn-commits
mailing list