[jboss-svn-commits] JBL Code SVN: r32990 - in labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/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 May 20 18:40:44 EDT 2010
Author: dward
Date: 2010-05-20 18:40:44 -0400 (Thu, 20 May 2010)
New Revision: 32990
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/gateway/camel/CamelGateway.java
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/JBossESBComponent.java
labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossESBProcessor.java
labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/ServiceProcessor.java
labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/samples/quickstarts/camel_helloworld/jboss-esb-unfiltered.xml
Log:
rework and cleanup; getting closer to spring
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-20 22:16:54 UTC (rev 32989)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapper.java 2010-05-20 22:40:44 UTC (rev 32990)
@@ -21,21 +21,24 @@
import java.net.URI;
import java.util.ArrayList;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
-import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.dom.YADOMUtil;
import org.jboss.soa.esb.listeners.config.xbeanmodel130.CamelGatewayDocument;
-import org.jboss.soa.esb.listeners.config.xbeanmodel130.RouteDocument;
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;
/**
- * TODO
+ * CamelGatewayMapper.
*
* @author dward at jboss.org
*/
@@ -46,16 +49,18 @@
listenerNode.setAttribute("name", listener.getName());
- List<RouteDocument> routeDocs = new ArrayList<RouteDocument>();
+ URI toURI = createToURI(listener, model);
+ List<String> routeXMLs = new ArrayList<String>();
+
// <camel-gateway from="">
URI fromURI = CamelGatewayConfig.createURI(listener.getFrom());
- addRouteDocument(listener.getFrom(), routeDocs);
+ addRouteXML(fromURI, toURI, routeXMLs);
// <camel-gateway><route>
boolean spring = false;
for (XmlObject route : listener.getRouteList()) {
- if (addRouteDocument(route, routeDocs)) {
+ if (addRouteXML(route, toURI, routeXMLs)) {
spring = true;
}
}
@@ -72,12 +77,12 @@
// <camel-bus from="">
if (fromURI == null) {
fromURI = CamelGatewayConfig.createURI(bus.getFrom());
- addRouteDocument(bus.getFrom(), routeDocs);
+ addRouteXML(fromURI, toURI, routeXMLs);
}
// <camel-bus><route>
for (XmlObject route : bus.getRouteList()) {
- if (addRouteDocument(route, routeDocs)) {
+ if (addRouteXML(route, toURI, routeXMLs)) {
spring = true;
}
}
@@ -94,60 +99,84 @@
listenerNode.setAttribute("gatewayClass", CamelGateway.class.getName());
- // Map the async attribute
- listenerNode.setAttribute(CamelGatewayConfig.ASYNC, String.valueOf(listener.getAsync()));
-
- // Map the timeout attribute
- listenerNode.setAttribute(CamelGatewayConfig.TIMEOUT, String.valueOf(listener.getTimeout()));
-
// 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);
}
- for (RouteDocument routeDoc : routeDocs) {
+
+ 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);
- propertyElement.setNodeValue(routeDoc.xmlText());
+ propertyElement.setAttribute("value", routeXML);
listenerNode.appendChild(propertyElement);
}
return listenerNode;
}
- private static boolean addRouteDocument(String from, List<RouteDocument> routeDocs) throws ConfigurationException {
- boolean added = false;
- URI uri = CamelGatewayConfig.createURI(from);
- if (uri != null) {
- try {
- StringBuilder sb = new StringBuilder();
- sb.append("<jesb:route xmlns:jesb=\"");
- sb.append("http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd");
- sb.append("\"><from uri=\"");
- sb.append(uri);
- sb.append("\"/></jesb:route>");
- routeDocs.add(RouteDocument.Factory.parse(sb.toString()));
- added = true;
- } catch (XmlException e) {
- throw new ConfigurationException("problem creating route document from URI: " + uri, e);
- }
+ private 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>");
+ routeXMLs.add(sb.toString());
}
- return added;
}
- private static boolean addRouteDocument(XmlObject route, List<RouteDocument> routeDocs) {
+ private static boolean addRouteXML(XmlObject route, URI toURI, List<String> routeXMLs) {
boolean added = false;
if (route != null) {
- RouteDocument routeDoc = RouteDocument.Factory.newInstance();
- routeDoc.set(route);
- routeDocs.add(routeDoc);
+ XmlOptions xo = new XmlOptions();
+ xo.setSaveOuter();
+ xo.setSavePrettyPrint();
+ String routeXML = route.xmlText(xo);
+ routeXML = routeXML.replaceAll(" xmlns=\".*\"", "");
+ routeXML = routeXML.replaceAll(" ", "");
+ routeXML = routeXML.replaceAll("\\n", "");
+ StringBuilder sb = new StringBuilder();
+ sb.append("<to uri=\"");
+ sb.append(toURI);
+ 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-20 22:16:54 UTC (rev 32989)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java 2010-05-20 22:40:44 UTC (rev 32990)
@@ -20,8 +20,6 @@
package org.jboss.soa.esb.listeners.gateway.camel;
import java.net.URI;
-import java.util.LinkedHashMap;
-import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
@@ -34,7 +32,7 @@
import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleException;
/**
- * TODO
+ * CamelGateway.
*
* @author dward at jboss.org
*/
@@ -42,12 +40,9 @@
private static final Logger logger = Logger.getLogger(CamelGateway.class);
- private final String serviceCategory;
- private final String serviceName;
- private final boolean async;
- private final long timeout;
private final boolean spring;
private final URI fromURI;
+ private final URI toURI;
private final String camelContextXML;
private CamelContext camelContext;
@@ -55,20 +50,14 @@
public CamelGateway(ConfigTree config) throws ConfigurationException {
super(config);
CamelGatewayConfig camelConfig = new CamelGatewayConfig(config);
- serviceCategory = camelConfig.getServiceCategory();
- serviceName = camelConfig.getServiceName();
- async = camelConfig.isAsync();
- timeout = camelConfig.getTimeout();
spring = camelConfig.isSpring();
fromURI = camelConfig.getFromURI();
+ toURI = camelConfig.getToURI();
camelContextXML = camelConfig.getCamelContextXML();
if (logger.isDebugEnabled()) {
- logger.debug("serviceCategory: " + serviceCategory);
- logger.debug("serviceName: " + serviceName);
- logger.debug("async: " + async);
- logger.debug("timeout: " + timeout);
logger.debug("spring: " + spring);
logger.debug("fromURI: " + fromURI);
+ logger.debug("toURI: " + toURI);
logger.debug("camelContextXML: " + camelContextXML);
}
}
@@ -81,14 +70,6 @@
camelContext.disableJMX();
camelContext.addComponent(JBossESBComponent.JBOSSESB, new JBossESBComponent());
try {
- Map<String,Object> toParams = new LinkedHashMap<String,Object>();
- toParams.put(JBossESBComponent.CATEGORY, serviceCategory);
- toParams.put(JBossESBComponent.NAME, serviceName);
- toParams.put(JBossESBComponent.ASYNC, async);
- if (!async) {
- toParams.put(JBossESBComponent.TIMEOUT, timeout);
- }
- final URI toURI = JBossESBComponent.createEndpointURI(JBossESBComponent.SERVICE, toParams);
logger.info("adding route from [" + fromURI + "] to [" + toURI + "]");
camelContext.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
@@ -105,6 +86,7 @@
camelContext = new DefaultCamelContext(new SimpleRegistry());
camelContext.disableJMX();
camelContext.addComponent(JBossESBComponent.JBOSSESB, new JBossESBComponent());
+ logger.info("camelContextXML: " + camelContextXML);
}
}
Modified: 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-20 22:16:54 UTC (rev 32989)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGatewayConfig.java 2010-05-20 22:40:44 UTC (rev 32990)
@@ -25,20 +25,18 @@
import org.jboss.internal.soa.esb.assertion.AssertArgument;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.ListenerTagNames;
/**
- * TODO
+ * CamelGatewayConfig.
*
* @author dward at jboss.org
*/
public class CamelGatewayConfig {
- public static final String ASYNC = JBossESBComponent.ASYNC;
- public static final String TIMEOUT = JBossESBComponent.TIMEOUT;
+ public static final String SPRING = "spring";
public static final String FROM = "from";
+ public static final String TO = "to";
public static final String ROUTE = "route";
- public static final String SPRING = "spring";
private final ConfigTree config;
@@ -47,22 +45,6 @@
this.config = config;
}
- public String getServiceCategory() throws ConfigurationException {
- return config.getRequiredAttribute(ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG);
- }
-
- public String getServiceName() throws ConfigurationException {
- return config.getRequiredAttribute(ListenerTagNames.TARGET_SERVICE_NAME_TAG);
- }
-
- public boolean isAsync() throws ConfigurationException {
- return config.getBooleanAttribute(ASYNC, true);
- }
-
- public long getTimeout() throws ConfigurationException {
- return config.getLongAttribute(TIMEOUT, 30000L);
- }
-
public boolean isSpring() throws ConfigurationException {
return config.getBooleanAttribute(SPRING, false);
}
@@ -81,6 +63,20 @@
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>");
Modified: labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossESBComponent.java
===================================================================
--- labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossESBComponent.java 2010-05-20 22:16:54 UTC (rev 32989)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossESBComponent.java 2010-05-20 22:40:44 UTC (rev 32990)
@@ -30,7 +30,7 @@
import org.jboss.soa.esb.Service;
/**
- * TODO
+ * JBossESBComponent.
*
* @author dward at jboss.org
*/
Modified: labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossESBProcessor.java
===================================================================
--- labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossESBProcessor.java 2010-05-20 22:16:54 UTC (rev 32989)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossESBProcessor.java 2010-05-20 22:40:44 UTC (rev 32990)
@@ -35,7 +35,7 @@
import org.jboss.soa.esb.util.Util;
/**
- * TODO
+ * JBossESBProcessor.
*
* @author dward at jboss.org
*/
Modified: labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/ServiceProcessor.java
===================================================================
--- labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/ServiceProcessor.java 2010-05-20 22:16:54 UTC (rev 32989)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/ServiceProcessor.java 2010-05-20 22:40:44 UTC (rev 32990)
@@ -25,7 +25,7 @@
import org.jboss.soa.esb.message.Message;
/**
- * TODO
+ * ServiceProcessor.
*
* @author dward at jboss.org
*/
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-20 22:16:54 UTC (rev 32989)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/samples/quickstarts/camel_helloworld/jboss-esb-unfiltered.xml 2010-05-20 22:40:44 UTC (rev 32990)
@@ -1,10 +1,33 @@
<?xml version = "1.0" encoding = "UTF-8"?>
<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd" parameterReloadSecs="5">
+ <!--
+ <providers>
+ <camel-provider name="provider1">
+ <camel-bus busid="bus1" from="file://@INPUTDIR@?delete=true"/>
+ <camel-bus busid="bus2">
+ <route>
+ <from uri="file://@INPUTDIR@?delete=true"/>
+ <to uri="log://camel_helloworld"/>
+ </route>
+ </camel-bus>
+ </camel-provider>
+ </providers>
+ -->
+
<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="gateway2">
+ <route>
+ <from uri="file://@INPUTDIR@?delete=true"/>
+ <to uri="log://camel_helloworld"/>
+ </route>
+ </camel-gateway>
+ <camel-gateway name="gateway3" busidref="bus1"/>
+ -->
</listeners>
<actions mep="OneWay">
<action name="action1" class="org.jboss.soa.esb.actions.SystemPrintln">
More information about the jboss-svn-commits
mailing list