[jboss-svn-commits] JBL Code SVN: r32999 - in labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product: rosetta/src/org/jboss/soa/esb/listeners/config/mappers130 and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri May 21 15:51:13 EDT 2010
Author: dward
Date: 2010-05-21 15:51:12 -0400 (Fri, 21 May 2010)
New Revision: 32999
Removed:
labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGatewayConfig.java
Modified:
labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/etc/schemas/xml/jbossesb-1.3.0.xsd
labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapper.java
labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java
labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/samples/quickstarts/camel_helloworld/jboss-esb-unfiltered.xml
Log:
We now support everything the Camel JAXB <routes> tag supports, and WITHOUT depending upon Spring! WOOT!
Modified: labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/etc/schemas/xml/jbossesb-1.3.0.xsd
===================================================================
--- labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/etc/schemas/xml/jbossesb-1.3.0.xsd 2010-05-21 18:38:52 UTC (rev 32998)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/etc/schemas/xml/jbossesb-1.3.0.xsd 2010-05-21 19:51:12 UTC (rev 32999)
@@ -2052,7 +2052,7 @@
<xsd:element name="route" type="xsd:anyType">
<xsd:annotation>
<xsd:documentation xml:lang="en">
- Camel "route", loosely allowing for Spring XML
+ Camel "route", loosely allowing for Camel XML
config without being dependent on it here.
</xsd:documentation>
</xsd:annotation>
@@ -2070,7 +2070,7 @@
<xsd:element maxOccurs="unbounded" minOccurs="0"
ref="jesb:route" />
</xsd:sequence>
- <xsd:attribute name="from" type="xsd:string"
+ <xsd:attribute name="from-uri" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:documentation xml:lang="en">
@@ -2109,7 +2109,7 @@
<xsd:element maxOccurs="unbounded" minOccurs="0"
ref="jesb:route" />
</xsd:sequence>
- <xsd:attribute name="from" type="xsd:string"
+ <xsd:attribute name="from-uri" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:documentation xml:lang="en">
Modified: labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapper.java
===================================================================
--- labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapper.java 2010-05-21 18:38:52 UTC (rev 32998)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapper.java 2010-05-21 19:51:12 UTC (rev 32999)
@@ -20,6 +20,7 @@
package org.jboss.soa.esb.listeners.config.mappers130;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@@ -33,7 +34,6 @@
import org.jboss.soa.esb.listeners.config.xbeanmodel130.CamelBusDocument.CamelBus;
import org.jboss.soa.esb.listeners.config.xbeanmodel130.ServiceDocument.Service;
import org.jboss.soa.esb.listeners.gateway.camel.CamelGateway;
-import org.jboss.soa.esb.listeners.gateway.camel.CamelGatewayConfig;
import org.jboss.soa.esb.listeners.gateway.camel.JBossESBComponent;
import org.w3c.dom.Element;
@@ -44,91 +44,97 @@
*/
public class CamelGatewayMapper {
- public static Element map(final Element root, final CamelGatewayDocument.CamelGateway listener, final XMLBeansModel model) throws ConfigurationException {
- final Element listenerNode = YADOMUtil.addElement(root, "listener");
+ public static Element map(final Element root, final CamelGatewayDocument.CamelGateway gateway, final XMLBeansModel model) throws ConfigurationException {
+ final Element gatewayNode = YADOMUtil.addElement(root, "listener");
- listenerNode.setAttribute("name", listener.getName());
+ gatewayNode.setAttribute("name", gateway.getName());
- URI toURI = createToURI(listener, model);
+ URI toURI = createToURI(gateway, model);
List<String> routeXMLs = new ArrayList<String>();
- // <camel-gateway from="">
- URI fromURI = CamelGatewayConfig.createURI(listener.getFrom());
- addRouteXML(fromURI, toURI, routeXMLs);
+ // <camel-gateway from-uri="">
+ URI gatewayFromURI = createURI(gateway.getFromUri());
- // <camel-gateway><route>
- boolean spring = false;
- for (XmlObject route : listener.getRouteList()) {
- if (addRouteXML(route, toURI, routeXMLs)) {
- spring = true;
- }
- }
-
final CamelBus bus;
try {
- bus = (CamelBus)model.getOptionalBus(listener.getBusidref());
+ bus = (CamelBus)model.getOptionalBus(gateway.getBusidref());
} catch (ClassCastException e) {
- throw new ConfigurationException("Invalid busid reference [" + listener.getBusidref() + "] on gateway [" + listener.getName() + "]. A <camel-gateway> must reference a <camel-bus>.");
+ throw new ConfigurationException("Invalid busid reference [" + gateway.getBusidref() + "] on gateway [" + gateway.getName() + "]. A <camel-gateway> must reference a <camel-bus>.");
}
- if(bus != null) {
+ if (bus != null) {
try {
- // <camel-bus from="">
- if (fromURI == null) {
- fromURI = CamelGatewayConfig.createURI(bus.getFrom());
- addRouteXML(fromURI, toURI, routeXMLs);
+ if (gatewayFromURI == null) {
+ // <camel-bus from-uri="">
+ URI busFromURI = createURI(bus.getFromUri());
+ addRouteXML(busFromURI, toURI, routeXMLs);
}
-
- // <camel-bus><route>
+ // <camel-bus><route>*
for (XmlObject route : bus.getRouteList()) {
- if (addRouteXML(route, toURI, routeXMLs)) {
- spring = true;
- }
+ addRouteXML(route, toURI, routeXMLs);
}
} catch (ClassCastException e) {
- throw new ConfigurationException("Invalid bus config [" + listener.getBusidref() + "]. Should be contained within a <camel-provider> instance. Unexpected exception - this should have caused a validation error!");
+ throw new ConfigurationException("Invalid bus config [" + gateway.getBusidref() + "]. Should be contained within a <camel-provider> instance. Unexpected exception - this should have caused a validation error!");
}
}
+
+ addRouteXML(gatewayFromURI, toURI, routeXMLs);
+ // <camel-gateway><route>*
+ for (XmlObject route : gateway.getRouteList()) {
+ addRouteXML(route, toURI, routeXMLs);
+ }
// Map the standard listener attributes - common across all listener types...
- MapperUtil.mapDefaultAttributes(listener, listenerNode, model);
+ MapperUtil.mapDefaultAttributes(gateway, gatewayNode, model);
// Map the <property> elements targeted at the listener - from the listener itself.
- MapperUtil.mapProperties(listener.getPropertyList(), listenerNode);
+ MapperUtil.mapProperties(gateway.getPropertyList(), gatewayNode);
- listenerNode.setAttribute("gatewayClass", CamelGateway.class.getName());
+ gatewayNode.setAttribute("gatewayClass", CamelGateway.class.getName());
- // Map the spring attribute
- listenerNode.setAttribute(CamelGatewayConfig.SPRING, Boolean.valueOf(spring).toString());
-
- // Map the from attribute
- if (fromURI != null) {
- Element propertyElement = listenerNode.getOwnerDocument().createElement("property");
- propertyElement.setAttribute("name", CamelGatewayConfig.FROM);
- propertyElement.setAttribute("value", fromURI.toString());
- listenerNode.appendChild(propertyElement);
- }
-
- if (toURI != null) {
- // Map the to attribute
- Element propertyElement = listenerNode.getOwnerDocument().createElement("property");
- propertyElement.setAttribute("name", CamelGatewayConfig.TO);
- propertyElement.setAttribute("value", toURI.toString());
- listenerNode.appendChild(propertyElement);
- }
-
// Map the route attribute
for (String routeXML : routeXMLs) {
- Element propertyElement = listenerNode.getOwnerDocument().createElement("property");
- propertyElement.setAttribute("name", CamelGatewayConfig.ROUTE);
+ Element propertyElement = gatewayNode.getOwnerDocument().createElement("property");
+ propertyElement.setAttribute("name", CamelGateway.ROUTE);
propertyElement.setAttribute("value", routeXML);
- listenerNode.appendChild(propertyElement);
+ gatewayNode.appendChild(propertyElement);
}
- return listenerNode;
+ return gatewayNode;
}
+ private static URI createToURI(final CamelGatewayDocument.CamelGateway listener, final XMLBeansModel model) throws ConfigurationException {
+ Service service = model.getService(listener);
+ Map<String,Object> toParams = new LinkedHashMap<String,Object>();
+ toParams.put(JBossESBComponent.CATEGORY, service.getCategory());
+ toParams.put(JBossESBComponent.NAME, service.getName());
+ boolean async = Boolean.valueOf(listener.getAsync()).booleanValue();
+ toParams.put(JBossESBComponent.ASYNC, String.valueOf(async));
+ if (!async) {
+ toParams.put(JBossESBComponent.TIMEOUT, String.valueOf(listener.getTimeout()));
+ }
+ try {
+ return JBossESBComponent.createEndpointURI(JBossESBComponent.SERVICE, toParams);
+ } catch (Exception e) {
+ throw new ConfigurationException("problem creating endpoint uri", e);
+ }
+ }
+
+ private static URI createURI(String str) throws ConfigurationException {
+ if (str != null) {
+ str = str.trim();
+ if (str.length() > 0) {
+ try {
+ return new URI(str);
+ } catch (URISyntaxException e) {
+ throw new ConfigurationException("problem creating URI: " + str, e);
+ }
+ }
+ }
+ return null;
+ }
+
private static void addRouteXML(URI fromURI, URI toURI, List<String> routeXMLs) throws ConfigurationException {
if (fromURI != null) {
StringBuilder sb = new StringBuilder();
@@ -141,13 +147,12 @@
}
}
- private static boolean addRouteXML(XmlObject route, URI toURI, List<String> routeXMLs) {
- boolean added = false;
- if (route != null) {
+ private static void addRouteXML(XmlObject routes, URI toURI, List<String> routeXMLs) {
+ if (routes != null) {
XmlOptions xo = new XmlOptions();
xo.setSaveOuter();
xo.setSavePrettyPrint();
- String routeXML = route.xmlText(xo);
+ String routeXML = routes.xmlText(xo);
routeXML = routeXML.replaceAll(" xmlns=\".*\"", "");
routeXML = routeXML.replaceAll(" ", "");
routeXML = routeXML.replaceAll("\\n", "");
@@ -157,26 +162,7 @@
sb.append("\"/></route>");
routeXML = routeXML.replaceAll("</route>", sb.toString());
routeXMLs.add(routeXML);
- added = true;
}
- return added;
}
-
- private static URI createToURI(final CamelGatewayDocument.CamelGateway listener, final XMLBeansModel model) throws ConfigurationException {
- Service service = model.getService(listener);
- Map<String,Object> toParams = new LinkedHashMap<String,Object>();
- toParams.put(JBossESBComponent.CATEGORY, service.getCategory());
- toParams.put(JBossESBComponent.NAME, service.getName());
- boolean async = Boolean.valueOf(listener.getAsync()).booleanValue();
- toParams.put(JBossESBComponent.ASYNC, String.valueOf(async));
- if (!async) {
- toParams.put(JBossESBComponent.TIMEOUT, String.valueOf(listener.getTimeout()));
- }
- try {
- return JBossESBComponent.createEndpointURI(JBossESBComponent.SERVICE, toParams);
- } catch (Exception e) {
- throw new ConfigurationException("problem creating endpoint uri", e);
- }
- }
}
Modified: labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java
===================================================================
--- labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java 2010-05-21 18:38:52 UTC (rev 32998)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java 2010-05-21 19:51:12 UTC (rev 32999)
@@ -19,12 +19,16 @@
*/
package org.jboss.soa.esb.listeners.gateway.camel;
-import java.net.URI;
+import java.io.StringReader;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+
import org.apache.camel.CamelContext;
-import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.SimpleRegistry;
+import org.apache.camel.model.Constants;
+import org.apache.camel.model.RoutesDefinition;
import org.apache.log4j.Logger;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.helpers.ConfigTree;
@@ -38,55 +42,52 @@
*/
public class CamelGateway extends AbstractManagedLifecycle {
+ public static final String ROUTE = "route";
+
private static final Logger logger = Logger.getLogger(CamelGateway.class);
- private final boolean spring;
- private final URI fromURI;
- private final URI toURI;
- private final String camelContextXML;
-
+ private final String routesXML;
private CamelContext camelContext;
public CamelGateway(ConfigTree config) throws ConfigurationException {
super(config);
- CamelGatewayConfig camelConfig = new CamelGatewayConfig(config);
- spring = camelConfig.isSpring();
- fromURI = camelConfig.getFromURI();
- toURI = camelConfig.getToURI();
- camelContextXML = camelConfig.getCamelContextXML();
- if (logger.isDebugEnabled()) {
- logger.debug("spring: " + spring);
- logger.debug("fromURI: " + fromURI);
- logger.debug("toURI: " + toURI);
- logger.debug("camelContextXML: " + camelContextXML);
+ StringBuilder sb = new StringBuilder();
+ sb.append("<routes>");
+ boolean routesDefined = false;
+ for (ConfigTree property: config.getChildren("property")) {
+ if (ROUTE.equals(property.getRequiredAttribute("name"))) {
+ String xml = property.getRequiredAttribute("value");
+ if (xml != null) {
+ xml = xml.trim();
+ xml = xml.replaceAll("&", "&");
+ if (xml.length() > 0) {
+ sb.append(xml);
+ routesDefined = true;
+ }
+ }
+ }
}
+ if (!routesDefined) {
+ throw new ConfigurationException("no routes defined; add at least one route");
+ }
+ sb.append("</routes>");
+ routesXML = sb.toString();
}
@Override
protected void doInitialise() throws ManagedLifecycleException {
- if (!spring) {
- // no dependency on Spring
- camelContext = new DefaultCamelContext(new SimpleRegistry());
- camelContext.disableJMX();
- camelContext.addComponent(JBossESBComponent.JBOSSESB, new JBossESBComponent());
- try {
- logger.info("adding route from [" + fromURI + "] to [" + toURI + "]");
- camelContext.addRoutes(new RouteBuilder() {
- public void configure() throws Exception {
- from(fromURI.toString()).to(toURI.toString());
- }
- });
- } catch (Exception e) {
- throw new ManagedLifecycleException("problem adding route", e);
- }
- } else {
- // dependency on Spring
- logger.info("adding routes using Spring");
- // TODO: remove and use Spring
- camelContext = new DefaultCamelContext(new SimpleRegistry());
- camelContext.disableJMX();
- camelContext.addComponent(JBossESBComponent.JBOSSESB, new JBossESBComponent());
- logger.info("camelContextXML: " + camelContextXML);
+ camelContext = new DefaultCamelContext(new SimpleRegistry());
+ camelContext.disableJMX();
+ camelContext.addComponent(JBossESBComponent.JBOSSESB, new JBossESBComponent());
+ logger.info("adding routes [" + routesXML + "]");
+ String jaxbRoutesXML = routesXML.replaceFirst("<routes>", "<routes xmlns=\"http://camel.apache.org/schema/spring\">").replaceAll("&", "&");
+ try {
+ JAXBContext jc = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
+ Unmarshaller um = jc.createUnmarshaller();
+ RoutesDefinition rd = (RoutesDefinition)um.unmarshal(new StringReader(jaxbRoutesXML));
+ camelContext.addRouteDefinitions(rd.getRoutes());
+ } catch (Exception e) {
+ throw new ManagedLifecycleException("problem adding routes", e);
}
}
Deleted: labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGatewayConfig.java
===================================================================
--- labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGatewayConfig.java 2010-05-21 18:38:52 UTC (rev 32998)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGatewayConfig.java 2010-05-21 19:51:12 UTC (rev 32999)
@@ -1,116 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2010
- */
-package org.jboss.soa.esb.listeners.gateway.camel;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import org.jboss.internal.soa.esb.assertion.AssertArgument;
-import org.jboss.soa.esb.ConfigurationException;
-import org.jboss.soa.esb.helpers.ConfigTree;
-
-/**
- * CamelGatewayConfig.
- *
- * @author dward at jboss.org
- */
-public class CamelGatewayConfig {
-
- public static final String SPRING = "spring";
- public static final String FROM = "from";
- public static final String TO = "to";
- public static final String ROUTE = "route";
-
- private final ConfigTree config;
-
- public CamelGatewayConfig(ConfigTree config) {
- AssertArgument.isNotNull(config, "config");
- this.config = config;
- }
-
- public boolean isSpring() throws ConfigurationException {
- return config.getBooleanAttribute(SPRING, false);
- }
-
- public URI getFromURI() throws ConfigurationException {
- if ( !isSpring() ) {
- for (ConfigTree property: config.getChildren("property")) {
- if (FROM.equals(property.getRequiredAttribute("name"))) {
- URI fromURI = createURI(property.getRequiredAttribute("value"));
- if (fromURI != null) {
- return fromURI;
- }
- }
- }
- }
- return null;
- }
-
- public URI getToURI() throws ConfigurationException {
- if ( !isSpring() ) {
- for (ConfigTree property: config.getChildren("property")) {
- if (TO.equals(property.getRequiredAttribute("name"))) {
- URI toURI = createURI(property.getRequiredAttribute("value"));
- if (toURI != null) {
- return toURI;
- }
- }
- }
- }
- return null;
- }
-
- public String getCamelContextXML() throws ConfigurationException {
- StringBuilder sb = new StringBuilder();
- sb.append("<camelContext>");
- if (isSpring()) {
- sb.append("<routes>");
- for (ConfigTree property: config.getChildren("property")) {
- if (ROUTE.equals(property.getRequiredAttribute("name"))) {
- String xml = property.getRequiredAttribute("value");
- if (xml != null) {
- xml = xml.trim();
- if (xml.length() > 0) {
- sb.append(xml);
- }
- }
- }
- }
- sb.append("</routes>");
- }
- sb.append("</camelContext>");
- return sb.toString();
- }
-
- public static URI createURI(String str) throws ConfigurationException {
- if (str != null) {
- str = str.trim();
- if (str.length() > 0) {
- try {
- return new URI(str);
- } catch (URISyntaxException e) {
- throw new ConfigurationException("problem creating URI: " + str, e);
- }
- }
- }
- return null;
- }
-
-}
Modified: labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/samples/quickstarts/camel_helloworld/jboss-esb-unfiltered.xml
===================================================================
--- labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/samples/quickstarts/camel_helloworld/jboss-esb-unfiltered.xml 2010-05-21 18:38:52 UTC (rev 32998)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/samples/quickstarts/camel_helloworld/jboss-esb-unfiltered.xml 2010-05-21 19:51:12 UTC (rev 32999)
@@ -4,11 +4,11 @@
<!--
<providers>
<camel-provider name="provider1">
- <camel-bus busid="bus1" from="file://@INPUTDIR@?delete=true"/>
+ <camel-bus busid="bus1" from-uri="file://@INPUTDIR@?delete=true"/>
<camel-bus busid="bus2">
<route>
<from uri="file://@INPUTDIR@?delete=true"/>
- <to uri="log://camel_helloworld"/>
+ <to uri="log://camel_helloworld?level=INFO&showAll=true&multiline=true"/>
</route>
</camel-bus>
</camel-provider>
@@ -18,20 +18,24 @@
<services>
<service category="camel_helloworld" name="service1" description="Hello World" invmScope="GLOBAL">
<listeners>
- <camel-gateway name="gateway1" from="file://@INPUTDIR@?delete=true"/>
<!--
+ <camel-gateway name="gateway1" from-uri="file://@INPUTDIR@?delete=true"/>
<camel-gateway name="gateway2">
<route>
<from uri="file://@INPUTDIR@?delete=true"/>
- <to uri="log://camel_helloworld"/>
+ <to uri="log://camel_helloworld?level=INFO&showAll=true&multiline=true"/>
</route>
</camel-gateway>
<camel-gateway name="gateway3" busidref="bus1"/>
+ <camel-gateway name="gateway4" busidref="bus2"/>
-->
+ <camel-gateway name="gateway1" from-uri="file://@INPUTDIR@?delete=true"/>
</listeners>
<actions mep="OneWay">
<action name="action1" class="org.jboss.soa.esb.actions.SystemPrintln">
+ <!--
<property name="printfull" value="true"/>
+ -->
</action>
</actions>
</service>
More information about the jboss-svn-commits
mailing list