camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r743010 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/xml/ components/camel-spring/src/main/java/org/apache/camel/spring/handler/ components/camel-spring/src/test/java/org/apache/camel/spring/ components/camel-spring/...
Date Tue, 10 Feb 2009 16:29:51 GMT
Author: davsclaus
Date: Tue Feb 10 16:29:35 2009
New Revision: 743010

URL: http://svn.apache.org/viewvc?rev=743010&view=rev
Log:
CAMEL-1205: endpoints defined in the route in to/from with and id attribute is now also registered
in the registry as an endpoint.

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java
  (contents, props changed)
      - copied, changed from r742867, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/file/SpringFileAntPathMatcherFileFilterTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml
  (contents, props changed)
      - copied, changed from r742867, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/file/SpringFileAntPathMatcherFileFilterTest-context.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/Namespaces.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/Namespaces.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/Namespaces.java?rev=743010&r1=743009&r2=743010&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/Namespaces.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/Namespaces.java Tue
Feb 10 16:29:35 2009
@@ -140,6 +140,5 @@
      */
     public void configure(NamespaceAware namespaceAware) {
         namespaceAware.setNamespaces(getNamespaces());
-
     }
 }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=743010&r1=743009&r2=743010&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
Tue Feb 10 16:29:35 2009
@@ -24,13 +24,14 @@
 import javax.xml.bind.Binder;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
-
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.builder.xml.Namespaces;
+import org.apache.camel.model.FromType;
+import org.apache.camel.model.SendType;
 import org.apache.camel.model.dataformat.ArtixDSDataFormat;
 import org.apache.camel.model.dataformat.JaxbDataFormat;
 import org.apache.camel.model.dataformat.SerializationDataFormat;
@@ -69,12 +70,10 @@
     private JAXBContext jaxbContext;
     private Map<String, BeanDefinitionParser> parserMap = new HashMap<String, BeanDefinitionParser>();
 
-
     public ModelFileGenerator createModelFileGenerator() throws JAXBException {
         return new ModelFileGenerator(getJaxbContext());
     }
 
-
     public void init() {
         // remoting
         addBeanDefinitionParser("proxy", CamelProxyFactoryBean.class);
@@ -96,9 +95,10 @@
         // jmx agent
         addBeanDefinitionParser("jmxAgent", CamelJMXAgentType.class);
 
-        // TODO switch to use the above mechanism?
-        registerParser("endpoint", endpointParser);
+        // endpoint
+        addBeanDefinitionParser("endpoint", EndpointFactoryBean.class);
 
+        // camel context
         Class cl = CamelContextFactoryBean.class;
         try {
             cl = Class.forName("org.apache.camel.osgi.CamelContextFactoryBean");
@@ -125,8 +125,7 @@
         registerParser(elementName, new ScriptDefinitionParser(engineName));
     }
 
-    protected void registerParser(String name,
-                                  org.springframework.beans.factory.xml.BeanDefinitionParser
parser) {
+    protected void registerParser(String name, org.springframework.beans.factory.xml.BeanDefinitionParser
parser) {
         parserElementNames.add(name);
         registerBeanDefinitionParser(name, parser);
     }
@@ -139,11 +138,6 @@
         try {
             binder = getJaxbContext().createBinder();
             return binder.unmarshal(element);
-            /*
-             * Unmarshaller unmarshaller =
-             * getJaxbContext().createUnmarshaller(); return
-             * unmarshaller.unmarshal(element);
-             */
         } catch (JAXBException e) {
             throw new BeanDefinitionStoreException("Failed to parse JAXB element: " + e,
e);
         }
@@ -190,8 +184,7 @@
 
             String contextId = element.getAttribute("id");
 
-            // lets avoid folks having to explicitly give an ID to a camel
-            // context
+            // lets avoid folks having to explicitly give an ID to a camel context
             if (ObjectHelper.isEmpty(contextId)) {
                 contextId = "camelContext";
                 element.setAttribute("id", contextId);
@@ -225,16 +218,7 @@
                         createBeanPostProcessor(parserContext, contextId, childElement, builder);
                         createdBeanPostProcessor = true;
                     } else if (localName.equals("endpoint")) {
-                        BeanDefinition definition = endpointParser.parse(childElement, parserContext);
-                        String id = childElement.getAttribute("id");
-                        if (ObjectHelper.isNotEmpty(id)) {
-                            // TODO we can zap this?
-                            definition.getPropertyValues()
-                                .addPropertyValue("camelContext", new RuntimeBeanReference(contextId));
-                            // definition.getPropertyValues().addPropertyValue("context",
-                            // builder.getBeanDefinition());
-                            parserContext.registerComponent(new BeanComponentDefinition(definition,
id));
-                        }
+                        registerEndpoint(childElement, parserContext, contextId);
                     } else {
                         BeanDefinitionParser parser = parserMap.get(localName);
                         if (parser != null) {
@@ -251,6 +235,10 @@
                     }
                 }
             }
+
+            // inject endpoints defined in routes where we can have set an id in the from/to
types
+            injectWithinRoutesNodeIdsAsEndpoint(element, parserContext, contextId);
+
             // lets inject the namespaces into any namespace aware POJOs
             injectNamespaces(element);
             if (!createdBeanPostProcessor) {
@@ -282,4 +270,37 @@
             }
         }
     }
+
+    protected void injectWithinRoutesNodeIdsAsEndpoint(Element element, ParserContext parserContext,
String contextId) {
+        NodeList list = element.getChildNodes();
+        int size = list.getLength();
+        for (int i = 0; i < size; i++) {
+            Node child = list.item(i);
+            if (child instanceof Element) {
+                Element childElement = (Element)child;
+                Object object = binder.getJAXBNode(child);
+                // we only want from/to types to be registered as endpoints
+                if (object instanceof FromType || object instanceof SendType) {
+                    registerEndpoint(childElement, parserContext, contextId);
+                }
+                // recursive
+                injectWithinRoutesNodeIdsAsEndpoint(childElement, parserContext, contextId);
+            }
+        }
+    }
+
+    private void registerEndpoint(Element childElement, ParserContext parserContext, String
contextId) {
+        String id = childElement.getAttribute("id");
+        // must have an id to be registered
+        if (ObjectHelper.isNotEmpty(id)) {
+            BeanDefinition definition = endpointParser.parse(childElement, parserContext);
+            // TODO we can zap this?
+            definition.getPropertyValues()
+                .addPropertyValue("camelContext", new RuntimeBeanReference(contextId));
+            // definition.getPropertyValues().addPropertyValue("context",
+            // builder.getBeanDefinition());
+            parserContext.registerComponent(new BeanComponentDefinition(definition, id));
+        }
+    }
+    
 }

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java
(from r742867, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/file/SpringFileAntPathMatcherFileFilterTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/file/SpringFileAntPathMatcherFileFilterTest.java&r1=742867&r2=743010&rev=743010&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/file/SpringFileAntPathMatcherFileFilterTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java
Tue Feb 10 16:29:35 2009
@@ -14,13 +14,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.spring.file;
+package org.apache.camel.spring;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.ProducerTemplate;
-import org.apache.camel.TestSupport;
-import org.apache.camel.component.file.FileComponent;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
@@ -30,30 +28,24 @@
  * @version $Revision$
  */
 @ContextConfiguration
-public class SpringFileAntPathMatcherFileFilterTest extends AbstractJUnit38SpringContextTests
{
+public class NodeIdReferenceTest extends AbstractJUnit38SpringContextTests {
     protected String expectedBody = "Godday World";
+
     @Autowired
-    protected ProducerTemplate template;
-    @EndpointInject(name = "myFileEndpoint")
-    protected Endpoint inputFile;
+    protected ProducerTemplate producer;
+
+    @EndpointInject(name = "foo")
+    protected Endpoint start;
+
     @EndpointInject(uri = "mock:result")
     protected MockEndpoint result;
 
-    public void testAntPatchMatherFilter() throws Exception {
+    public void testNodeIdReference() throws Exception {
         result.expectedBodiesReceived(expectedBody);
 
-        template.sendBodyAndHeader(inputFile, "Hello World", FileComponent.HEADER_FILE_NAME,
"hello.txt");
-        template.sendBodyAndHeader(inputFile, "Bye World", FileComponent.HEADER_FILE_NAME,
"bye.xml");
-        template.sendBodyAndHeader(inputFile, expectedBody, FileComponent.HEADER_FILE_NAME,
"subfolder/foo/godday.txt");
-        template.sendBodyAndHeader(inputFile, "Bad world", FileComponent.HEADER_FILE_NAME,
"subfolder/badday.txt");
-        template.sendBodyAndHeader(inputFile, "Day world", FileComponent.HEADER_FILE_NAME,
"day.xml");
+        producer.sendBody(start, expectedBody);
 
         result.assertIsSatisfied();
     }
 
-    @Override
-    protected void setUp() throws Exception {
-        TestSupport.deleteDirectory("target/antpathmatcher");
-        super.setUp();
-    }
-}
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/NodeIdReferenceTest.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml
(from r742867, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/file/SpringFileAntPathMatcherFileFilterTest-context.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/file/SpringFileAntPathMatcherFileFilterTest-context.xml&r1=742867&r2=743010&rev=743010&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/file/SpringFileAntPathMatcherFileFilterTest-context.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml
Tue Feb 10 16:29:35 2009
@@ -22,26 +22,13 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-    <!-- START SNIPPET: example -->
     <camelContext xmlns="http://camel.apache.org/schema/spring">
         <template id="camelTemplate"/>
 
-        <!-- use myFilter as filter to allow setting ANT paths for which files to scan
for -->
-        <endpoint id="myFileEndpoint" uri="newfile://target/antpathmatcher?recursive=true&amp;filter=#myAntFilter"/>
-
         <route>
-            <from ref="myFileEndpoint"/>
+            <from id="foo" uri="direct:start"/>
             <to uri="mock:result"/>
         </route>
     </camelContext>
 
-    <!-- we use the antpath file filter to use ant paths for includes and exlucde -->
-    <bean id="myAntFilter" class="org.apache.camel.component.file.AntPathMatcherGenericFileFilter">
-        <!-- include and file in the subfolder that has day in the name -->
-        <property name="includes" value="**/subfolder/**/*day*"/>
-        <!-- exclude all files with bad in name or .xml files. Use comma to seperate multiple
excludes -->
-        <property name="excludes" value="**/*bad*,**/*.xml"/>
-    </bean>
-    <!-- END SNIPPET: example -->
-
 </beans>

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/NodeIdReferenceTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message