[jboss-svn-commits] JBL Code SVN: r33077 - 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
Tue May 25 16:33:26 EDT 2010
Author: dward
Date: 2010-05-25 16:33:26 -0400 (Tue, 25 May 2010)
New Revision: 33077
Added:
labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossPackageScanClassResolver.java
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/samples/quickstarts/camel_helloworld/jboss-esb-unfiltered.xml
Log:
1) All route from uri's (both attribute and element) are cummulative. 2) Fix put in for ESB on AS5. 3) Simplified quickstart.
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-25 16:17:53 UTC (rev 33076)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers130/CamelGatewayMapper.java 2010-05-25 20:33:26 UTC (rev 33077)
@@ -22,6 +22,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -31,6 +32,7 @@
import org.jboss.soa.esb.listeners.config.xbeanmodel130.CamelGatewayDocument;
import org.jboss.soa.esb.listeners.config.xbeanmodel130.CamelBusDocument.CamelBus;
import org.jboss.soa.esb.listeners.config.xbeanmodel130.FromDocument.From;
+import org.jboss.soa.esb.listeners.config.xbeanmodel130.PropertyDocument.Property;
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.JBossESBComponent;
@@ -47,6 +49,7 @@
final Element gatewayNode = YADOMUtil.addElement(root, "listener");
gatewayNode.setAttribute("name", gateway.getName());
+ gatewayNode.setAttribute("gatewayClass", CamelGateway.class.getName());
final CamelBus bus;
try {
@@ -59,18 +62,10 @@
URI toURI = createToURI(gateway, bus, model);
- // <camel-gateway from-uri="">
- URI gatewayFromURI;
- if (gateway.isSetFromUri()) {
- gatewayFromURI = createURI(gateway.getFromUri());
- } else {
- gatewayFromURI = null;
- }
-
if (bus != null) {
try {
- if (gatewayFromURI == null && bus.isSetFromUri()) {
- // <camel-bus from-uri="">
+ // <camel-bus from-uri="">
+ if (bus.isSetFromUri()) {
URI busFromURI = createURI(bus.getFromUri());
addRouteXML(busFromURI, toURI, routeXMLs);
}
@@ -84,7 +79,9 @@
}
}
- if (gatewayFromURI != null) {
+ // <camel-gateway from-uri="">
+ if (gateway.isSetFromUri()) {
+ URI gatewayFromURI = createURI(gateway.getFromUri());
addRouteXML(gatewayFromURI, toURI, routeXMLs);
}
// <camel-gateway><from uri="">*
@@ -97,18 +94,34 @@
MapperUtil.mapDefaultAttributes(gateway, gatewayNode, model);
// Map the <property> elements targeted at the listener - from the listener itself.
- MapperUtil.mapProperties(gateway.getPropertyList(), gatewayNode);
-
- gatewayNode.setAttribute("gatewayClass", CamelGateway.class.getName());
-
- // Map the route attribute
- for (String routeXML : routeXMLs) {
- Element propertyElement = gatewayNode.getOwnerDocument().createElement("property");
- propertyElement.setAttribute("name", CamelGateway.ROUTE);
- propertyElement.setAttribute("value", routeXML);
- gatewayNode.appendChild(propertyElement);
+ List<Property> propertyList = gateway.getPropertyList();
+ Iterator<Property> propertyIterator = propertyList.iterator();
+ while (propertyIterator.hasNext()) {
+ Property property = propertyIterator.next();
+ // Enforce adding routes the prescribed way
+ if (CamelGateway.ROUTES.equals(property.getName())) {
+ propertyIterator.remove();
+ }
}
+ MapperUtil.mapProperties(propertyList, gatewayNode);
+ // Map the routes <property>
+ if (routeXMLs.size() == 0) {
+ throw new ConfigurationException("no routes defined; add at least one route");
+ }
+ StringBuilder sb = new StringBuilder();
+ // Don't let the namespace fool you; there's no dependency on Spring at this level!
+ sb.append("<routes xmlns=\"http://camel.apache.org/schema/spring\">");
+ for (String routeXML : routeXMLs) {
+ sb.append(routeXML);
+ }
+ sb.append("</routes>");
+ String routesXML = sb.toString();
+ Element propertyElement = gatewayNode.getOwnerDocument().createElement("property");
+ propertyElement.setAttribute("name", CamelGateway.ROUTES);
+ propertyElement.setAttribute("value", routesXML);
+ gatewayNode.appendChild(propertyElement);
+
return gatewayNode;
}
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-25 16:17:53 UTC (rev 33076)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/CamelGateway.java 2010-05-25 20:33:26 UTC (rev 33077)
@@ -22,6 +22,8 @@
import java.io.StringReader;
import java.io.StringWriter;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
@@ -34,6 +36,7 @@
import org.dom4j.DocumentHelper;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
+import org.jboss.mx.util.MBeanServerLocator;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.lifecycle.AbstractManagedLifecycle;
@@ -46,42 +49,48 @@
*/
public class CamelGateway extends AbstractManagedLifecycle {
- public static final String ROUTE = "route";
+ public static final String ROUTES = "routes";
private static final Logger logger = Logger.getLogger(CamelGateway.class);
- private final String routesXML;
- private CamelContext camelContext;
+ private static final boolean isAS4;
+ static {
+ try {
+ MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
+ String versionNumber = (String)mbeanServer.getAttribute(new ObjectName("jboss.system:type=Server"), "VersionNumber");
+ isAS4 = (Integer.valueOf(versionNumber.substring(0, 1)).intValue() == 4);
+ } catch (Throwable t) {
+ throw new RuntimeException("problem detecting JBoss AS version", t);
+ }
+ }
+ private String routesXML = null;
+ private CamelContext camelContext = null;
+
public CamelGateway(ConfigTree config) throws ConfigurationException {
super(config);
- StringBuilder sb = new StringBuilder();
- // Don't let the namespace fool you; there's no dependency on Spring at this level!
- sb.append("<routes xmlns=\"http://camel.apache.org/schema/spring\">");
- 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();
- if (xml.length() > 0) {
- sb.append(xml);
- routesDefined = true;
- }
- }
+ if (ROUTES.equals(property.getRequiredAttribute("name"))) {
+ routesXML = property.getRequiredAttribute("value").trim();
+ break;
}
}
- if (!routesDefined) {
- throw new ConfigurationException("no routes defined; add at least one route");
+ if (routesXML == null || routesXML.length() == 0) {
+ throw new ConfigurationException("property [" + ROUTES + "] missing or empty");
+ } else {
+ routesXML = routesXML.replaceAll("&", "&");
}
- sb.append("</routes>");
- routesXML = sb.toString().replaceAll("&", "&");
}
@Override
protected void doInitialise() throws ManagedLifecycleException {
camelContext = new DefaultCamelContext(new SimpleRegistry());
camelContext.disableJMX();
+ if (!isAS4) {
+ // JBossESB on AS5+ needs this to handle VFS classloading URIs.
+ // JBossESB on AS4 will not work if we use this.
+ camelContext.setPackageScanClassResolver(new JBossPackageScanClassResolver());
+ }
camelContext.addComponent(JBossESBComponent.JBOSSESB, new JBossESBComponent());
if (logger.isInfoEnabled()) {
try {
@@ -92,7 +101,7 @@
logger.info("adding routes [" + sw.toString().replaceAll("&", "&") + "]");
} catch (Exception e) {
logger.warn("problem pretty-printing routes: " + e.getMessage());
- logger.info("adding routes [" + routesXML + "]");
+ logger.info("adding routes [" + routesXML.replaceAll("&", "&") + "]");
}
}
try {
Added: labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossPackageScanClassResolver.java
===================================================================
--- labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossPackageScanClassResolver.java (rev 0)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossPackageScanClassResolver.java 2010-05-25 20:33:26 UTC (rev 33077)
@@ -0,0 +1,100 @@
+/*
+ * =========================================================================
+ * == NOTICE file corresponding to the section 4 d of ==
+ * == the Apache License, Version 2.0, ==
+ * == in this case for the Apache Camel distribution. ==
+ * =========================================================================
+ *
+ * This product includes software developed by
+ * The Apache Software Foundation (http://www.apache.org/).
+ *
+ * Please read the different LICENSE files present in the licenses directory of
+ * this distribution
+ */
+package org.jboss.soa.esb.listeners.gateway.camel;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+
+import org.apache.camel.impl.DefaultPackageScanClassResolver;
+import org.apache.camel.spi.PackageScanFilter;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VisitorAttributes;
+import org.jboss.virtual.plugins.vfs.helpers.AbstractVirtualFileVisitor;
+
+/**
+ * JBoss specific package scan classloader to be used when Camel is running
+ * inside JBoss Application Server.
+ *
+ * <p>The camel-jboss jar is unavailable in the maven repository, so we have to build this class ourselves.</p>
+ * Explanation: http://camel.apache.org/camel-jboss.html<br/>
+ * Source: http://code.google.com/p/camel-extra/source/browse/trunk/components/camel-jboss/src/main/java/org/apache/camel/jboss/JBossPackageScanClassResolver.java<br/>
+ * NOTICE: http://code.google.com/p/camel-extra/source/browse/trunk/components/camel-jboss/src/main/resources/META-INF/NOTICE.txt<br/>
+ * LICENSE: http://code.google.com/p/camel-extra/source/browse/trunk/components/camel-jboss/src/main/resources/META-INF/LICENSE.txt
+ */
+public class JBossPackageScanClassResolver extends DefaultPackageScanClassResolver {
+
+ @Override
+ protected void find(PackageScanFilter test, String packageName, ClassLoader loader, Set<Class<?>> classes) {
+ if (log.isTraceEnabled()) {
+ log.trace("Searching for: " + test + " in package: " + packageName
+ + " using classloader: " + loader.getClass().getName());
+ }
+
+ Enumeration<URL> urls;
+ try {
+ urls = getResources(loader, packageName);
+ if (!urls.hasMoreElements()) {
+ log.trace("No URLs returned by classloader");
+ }
+ }
+ catch (IOException ioe) {
+ log.warn("Could not read package: " + packageName, ioe);
+ return;
+ }
+
+ while (urls.hasMoreElements()) {
+ URL url = null;
+ try {
+ url = urls.nextElement();
+ if (log.isTraceEnabled()) {
+ log.trace("URL from classloader: " + url);
+ }
+ VirtualFile root = VFS.getRoot(url);
+ root.visit(new MatchingClassVisitor(test, classes));
+ }
+ catch (IOException ioe) {
+ log.warn("Could not read entries in url: " + url, ioe);
+ }
+ }
+ }
+
+ private class MatchingClassVisitor extends AbstractVirtualFileVisitor {
+ private PackageScanFilter filter;
+ private Set<Class<?>> classes;
+
+ private MatchingClassVisitor(PackageScanFilter filter, Set<Class<?>> classes) {
+ super(VisitorAttributes.RECURSE_LEAVES_ONLY);
+ this.filter = filter;
+ this.classes = classes;
+ }
+
+ public void visit(VirtualFile file) {
+ if (file.getName().endsWith(".class")) {
+ String fqn = file.getPathName();
+ String qn;
+ if (fqn.indexOf("jar/") != -1) {
+ qn = fqn.substring(fqn.indexOf("jar/") + 4);
+ } else {
+ qn = fqn.substring(fqn.indexOf("/") + 1);
+ }
+
+ addIfMatching(filter, qn, classes);
+ }
+ }
+ }
+
+}
Property changes on: labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/camel/JBossPackageScanClassResolver.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
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-25 16:17:53 UTC (rev 33076)
+++ labs/jbossesb/workspace/dward/JBESB_4_8_Camel_Gateway/product/samples/quickstarts/camel_helloworld/jboss-esb-unfiltered.xml 2010-05-25 20:33:26 UTC (rev 33077)
@@ -1,30 +1,13 @@
<?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 uri="file://@INPUTDIR1@?delete=true"/>
- <from uri="file://@INPUTDIR2@?delete=true"/>
- </camel-bus>
- <!--
- <camel-bus busid="bus2" from-uri="file://@INPUTDIR1@?delete=true"/>
- -->
- </camel-provider>
- </providers>
-
<services>
<service category="camel_helloworld" name="service1" description="Hello World" invmScope="GLOBAL">
<listeners>
- <camel-gateway name="gateway1" busidref="bus1"/>
- <!--
- <camel-gateway name="gateway2" busidref="bus2"/>
- <camel-gateway name="gateway3">
+ <camel-gateway name="gateway1">
<from uri="file://@INPUTDIR1@?delete=true"/>
<from uri="file://@INPUTDIR2@?delete=true"/>
</camel-gateway>
- <camel-gateway name="gateway4" from-uri="file://@INPUTDIR1@?delete=true"/>
- -->
</listeners>
<actions mep="OneWay">
<action name="action1" class="org.jboss.soa.esb.actions.SystemPrintln"/>
More information about the jboss-svn-commits
mailing list