You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2007/09/14 11:40:25 UTC
svn commit: r575600 - in /activemq/camel/trunk:
camel-core/src/main/java/org/apache/camel/
camel-core/src/main/java/org/apache/camel/impl/
camel-core/src/main/java/org/apache/camel/management/
camel-core/src/main/java/org/apache/camel/util/ components/...
Author: jstrachan
Date: Fri Sep 14 02:40:19 2007
New Revision: 575600
URL: http://svn.apache.org/viewvc?rev=575600&view=rev
Log:
added velocity component along with some useful base classes in camel-core/camel-spring to make it easier to create a Processor based or Resource based endpoint for CAMEL-147
Added:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeExchangeException.java
- copied, changed from r574905, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelExchangeException.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/EventDrivenPollingConsumer.java (contents, props changed)
- copied, changed from r574905, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumer.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorPollingConsumer.java (with props)
activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedEndpoint.java
- copied, changed from r574905, activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedComponent.java
activemq/camel/trunk/components/camel-velocity/
activemq/camel/trunk/components/camel-velocity/pom.xml (with props)
activemq/camel/trunk/components/camel-velocity/src/
activemq/camel/trunk/components/camel-velocity/src/main/
activemq/camel/trunk/components/camel-velocity/src/main/java/
activemq/camel/trunk/components/camel-velocity/src/main/java/org/
activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/
activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/
activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/
activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/
activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java (with props)
activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java (with props)
activemq/camel/trunk/components/camel-velocity/src/main/resources/
activemq/camel/trunk/components/camel-velocity/src/main/resources/META-INF/
activemq/camel/trunk/components/camel-velocity/src/main/resources/META-INF/services/
activemq/camel/trunk/components/camel-velocity/src/main/resources/META-INF/services/org/
activemq/camel/trunk/components/camel-velocity/src/main/resources/META-INF/services/org/apache/
activemq/camel/trunk/components/camel-velocity/src/main/resources/META-INF/services/org/apache/camel/
activemq/camel/trunk/components/camel-velocity/src/main/resources/META-INF/services/org/apache/camel/component/
activemq/camel/trunk/components/camel-velocity/src/main/resources/META-INF/services/org/apache/camel/component/velocity
activemq/camel/trunk/components/camel-velocity/src/test/
activemq/camel/trunk/components/camel-velocity/src/test/java/
activemq/camel/trunk/components/camel-velocity/src/test/java/org/
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/
activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java (with props)
activemq/camel/trunk/components/camel-velocity/src/test/resources/
activemq/camel/trunk/components/camel-velocity/src/test/resources/log4j.properties (with props)
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/
activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm
Removed:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumer.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingEndpoint.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorEndpoint.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
activemq/camel/trunk/components/camel-spring/pom.xml
activemq/camel/trunk/components/pom.xml
Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeExchangeException.java (from r574905, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelExchangeException.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeExchangeException.java?p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeExchangeException.java&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelExchangeException.java&r1=574905&r2=575600&rev=575600&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelExchangeException.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeExchangeException.java Fri Sep 14 02:40:19 2007
@@ -17,19 +17,24 @@
package org.apache.camel;
/**
- * An exception caused by a specific message {@ilnk Exchange}
+ * A runtime exception caused by a specific message {@ilnk Exchange}
*
* @version $Revision: 1.1 $
*/
-public class CamelExchangeException extends CamelException {
+public class RuntimeExchangeException extends RuntimeCamelException {
private static final long serialVersionUID = -8721487431101572630L;
private final Exchange exchange;
- public CamelExchangeException(String message, Exchange exchange) {
+ public RuntimeExchangeException(String message, Exchange exchange) {
super(message + " on the exchange: " + exchange);
this.exchange = exchange;
}
+ public RuntimeExchangeException(Exception e, Exchange exchange) {
+ super(e.getMessage(), e);
+ this.exchange = exchange;
+ }
+
/**
* Returns the exchange which caused the exception
*
@@ -39,4 +44,4 @@
return exchange;
}
-}
+}
\ No newline at end of file
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java?rev=575600&r1=575599&r2=575600&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java Fri Sep 14 02:40:19 2007
@@ -106,7 +106,7 @@
}
public PollingConsumer<E> createPollingConsumer() throws Exception {
- return new DefaultPollingConsumer<E>(this);
+ return new EventDrivenPollingConsumer<E>(this);
}
/**
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingEndpoint.java?rev=575600&r1=575599&r2=575600&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingEndpoint.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingEndpoint.java Fri Sep 14 02:40:19 2007
@@ -35,6 +35,10 @@
super(endpointUri, component);
}
+ protected DefaultPollingEndpoint(String endpointUri, CamelContext context) {
+ super(endpointUri, context);
+ }
+
public Consumer<E> createConsumer(Processor processor) throws Exception {
DefaultScheduledPollConsumer result = new DefaultScheduledPollConsumer(this, processor);
configureConsumer(result);
Copied: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/EventDrivenPollingConsumer.java (from r574905, activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumer.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/EventDrivenPollingConsumer.java?p2=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/EventDrivenPollingConsumer.java&p1=activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumer.java&r1=574905&r2=575600&rev=575600&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumer.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/EventDrivenPollingConsumer.java Fri Sep 14 02:40:19 2007
@@ -37,18 +37,18 @@
*
* @version $Revision: 1.1 $
*/
-public class DefaultPollingConsumer<E extends Exchange> extends PollingConsumerSupport<E> implements
+public class EventDrivenPollingConsumer<E extends Exchange> extends PollingConsumerSupport<E> implements
Processor {
- private static final transient Log LOG = LogFactory.getLog(DefaultPollingConsumer.class);
+ private static final transient Log LOG = LogFactory.getLog(EventDrivenPollingConsumer.class);
private BlockingQueue<E> queue;
private ExceptionHandler interuptedExceptionHandler = new LoggingExceptionHandler(new Logger(LOG));
private Consumer<E> consumer;
- public DefaultPollingConsumer(Endpoint<E> endpoint) {
+ public EventDrivenPollingConsumer(Endpoint<E> endpoint) {
this(endpoint, new ArrayBlockingQueue<E>(1000));
}
- public DefaultPollingConsumer(Endpoint<E> endpoint, BlockingQueue<E> queue) {
+ public EventDrivenPollingConsumer(Endpoint<E> endpoint, BlockingQueue<E> queue) {
super(endpoint);
this.queue = queue;
}
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/EventDrivenPollingConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorEndpoint.java?rev=575600&r1=575599&r2=575600&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorEndpoint.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorEndpoint.java Fri Sep 14 02:40:19 2007
@@ -23,6 +23,7 @@
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.ExchangePattern;
+import org.apache.camel.PollingConsumer;
/**
* An endpoint which allows exchanges to be sent into it which just invokes a
@@ -31,7 +32,7 @@
*
* @version $Revision: 1.1 $
*/
-public class ProcessorEndpoint extends DefaultEndpoint<Exchange> {
+public class ProcessorEndpoint extends DefaultPollingEndpoint<Exchange> {
private final Processor processor;
public ProcessorEndpoint(String endpointUri, CamelContext context, Processor processor) {
@@ -53,11 +54,19 @@
};
}
- public Consumer<Exchange> createConsumer(Processor processor) throws Exception {
- throw new UnsupportedOperationException("You cannot consume from this endpoint!");
+ @Override
+ public PollingConsumer<Exchange> createPollingConsumer() throws Exception {
+ return new ProcessorPollingConsumer(this, getProcessor());
}
public Processor getProcessor() {
+ if (processor == null) {
+ return new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ onExchange(exchange);
+ }
+ };
+ }
return processor;
}
Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorPollingConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorPollingConsumer.java?rev=575600&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorPollingConsumer.java (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorPollingConsumer.java Fri Sep 14 02:40:19 2007
@@ -0,0 +1,68 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.Processor;
+import org.apache.camel.RuntimeExchangeException;
+import org.apache.camel.util.ServiceHelper;
+
+/**
+ * A simple implementation of {@link PollingConsumer} which just uses
+ * a {@link Processor}. This implementation does not support timeout based
+ * receive methods such as {@link #receive(long)}
+ *
+ * @version $Revision: 1.1 $
+ */
+public class ProcessorPollingConsumer extends PollingConsumerSupport {
+ private Processor processor;
+
+ public ProcessorPollingConsumer(Endpoint endpoint, Processor processor) {
+ super(endpoint);
+ this.processor = processor;
+ }
+
+ protected void doStart() throws Exception {
+ ServiceHelper.startService(processor);
+ }
+
+ protected void doStop() throws Exception {
+ ServiceHelper.stopService(processor);
+ }
+
+ public Exchange receive() {
+ Exchange exchange = getEndpoint().createExchange();
+ try {
+ processor.process(exchange);
+ }
+ catch (Exception e) {
+ throw new RuntimeExchangeException(e, exchange);
+ }
+ return exchange;
+ }
+
+ public Exchange receiveNoWait() {
+ return receive();
+ }
+
+ public Exchange receive(long timeout) {
+ return receive();
+ }
+}
Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ProcessorPollingConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java?rev=575600&r1=575599&r2=575600&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java Fri Sep 14 02:40:19 2007
@@ -20,6 +20,7 @@
import org.apache.camel.Consumer;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
+import org.apache.camel.CamelContext;
import org.apache.camel.util.IntrospectionSupport;
import java.util.Map;
@@ -34,6 +35,10 @@
protected ScheduledPollEndpoint(String endpointUri, Component component) {
super(endpointUri, component);
+ }
+
+ protected ScheduledPollEndpoint(String endpointUri, CamelContext context) {
+ super(endpointUri, context);
}
public Map getConsumerProperties() {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java?rev=575600&r1=575599&r2=575600&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java Fri Sep 14 02:40:19 2007
@@ -25,6 +25,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.lang.management.ManagementFactory;
import javax.management.InstanceAlreadyExistsException;
import javax.management.JMException;
@@ -85,7 +86,10 @@
}
public MBeanServer getMBeanServer() {
- return server;
+ if (server == null) {
+ server = ManagementFactory.getPlatformMBeanServer();
+ }
+ return server;
}
public void register(Object obj, ObjectName name) throws JMException {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=575600&r1=575599&r2=575600&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java Fri Sep 14 02:40:19 2007
@@ -16,6 +16,9 @@
*/
package org.apache.camel.util;
+import java.util.Map;
+import java.util.HashMap;
+
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
@@ -203,5 +206,47 @@
public static boolean isOutCapable(Exchange exchange) {
ExchangePattern pattern = exchange.getPattern();
return pattern != null && pattern.isOutCapable();
+ }
+
+ /**
+ * Creates a new instance of the given type from the injector
+ */
+ public static <T> T newInstance(Exchange exchange, Class<T> type) {
+ return exchange.getContext().getInjector().newInstance(type);
+ }
+
+ /**
+ * Creates a Map of the variables which are made available to a script or template
+ *
+ * @param exchange the exchange to make available
+ * @return a Map populated with the require dvariables
+ */
+ public static Map createVariableMap(Exchange exchange) {
+ Map answer = new HashMap();
+ populateVariableMap(exchange, answer);
+ return answer;
+ }
+
+ /**
+ * Populates the Map with the variables which are made available to a script or template
+ *
+ * @param exchange the exchange to make available
+ * @param map the map to populate
+ * @return a Map populated with the require dvariables
+ */
+ public static void populateVariableMap(Exchange exchange, Map map) {
+ map.put("exchange", exchange);
+ Message in = exchange.getIn();
+ map.put("in", in);
+ map.put("request", in);
+ map.put("headers", in.getHeaders());
+ map.put("body", in.getBody())
+ ;
+ if (isOutCapable(exchange)) {
+ Message out = exchange.getOut(true);
+ map.put("out", out);
+ map.put("response", out);
+ }
+ map.put("camelContext", exchange.getContext());
}
}
Modified: activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java?rev=575600&r1=575599&r2=575600&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java (original)
+++ activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java Fri Sep 14 02:40:19 2007
@@ -17,16 +17,16 @@
*/
package org.apache.camel.component.jetty;
+import java.net.URI;
+import java.net.URISyntaxException;
+
import org.apache.camel.Consumer;
import org.apache.camel.PollingConsumer;
import org.apache.camel.Processor;
import org.apache.camel.component.http.HttpConsumer;
import org.apache.camel.component.http.HttpEndpoint;
import org.apache.camel.component.http.HttpExchange;
-import org.apache.camel.impl.DefaultPollingConsumer;
-
-import java.net.URI;
-import java.net.URISyntaxException;
+import org.apache.camel.impl.EventDrivenPollingConsumer;
/**
* @version $Revision: 1.1 $
@@ -51,7 +51,7 @@
@Override
public PollingConsumer<HttpExchange> createPollingConsumer() throws Exception {
- return new DefaultPollingConsumer(this);
+ return new EventDrivenPollingConsumer(this);
}
@Override
Modified: activemq/camel/trunk/components/camel-spring/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/pom.xml?rev=575600&r1=575599&r2=575600&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/pom.xml (original)
+++ activemq/camel/trunk/components/camel-spring/pom.xml Fri Sep 14 02:40:19 2007
@@ -245,6 +245,7 @@
</plugin>
+<!--
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
@@ -259,17 +260,19 @@
<mainClass>org.apache.camel.spring.Main</mainClass>
</configuration>
</plugin>
+-->
</plugins>
</build>
+<!--
<reporting>
<plugins>
- <!-- lets generate nice PNG / SVG diagrams from our example routes -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
+-->
</project>
Copied: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedEndpoint.java (from r574905, activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedComponent.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedEndpoint.java?p2=activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedEndpoint.java&p1=activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedComponent.java&r1=574905&r2=575600&rev=575600&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedComponent.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/component/ResourceBasedEndpoint.java Fri Sep 14 02:40:19 2007
@@ -16,22 +16,42 @@
*/
package org.apache.camel.component;
+import org.apache.camel.Component;
import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
import org.apache.camel.component.validator.ValidatorComponent;
-import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.impl.ProcessorEndpoint;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
/**
+ * A useful base class for endpoints which depend on a resource
+ * such as things like Velocity or XQuery based components
+ *
* @version $Revision: 1.1 $
*/
-public abstract class ResourceBasedComponent extends DefaultComponent<Exchange> {
+public abstract class ResourceBasedEndpoint extends ProcessorEndpoint {
protected static final transient Log LOG = LogFactory.getLog(ValidatorComponent.class);
private ResourceLoader resourceLoader = new DefaultResourceLoader();
+ private final String resourceUri;
+ private Resource resource;
+
+ public ResourceBasedEndpoint(String endpointUri, Component component, String resourceUri, Processor processor) {
+ super(endpointUri, component, processor);
+ this.resourceUri = resourceUri;
+ }
+ public Resource getResource() {
+ if (resource == null) {
+ resource = getResourceLoader().getResource(resourceUri);
+ if (resource == null) {
+ throw new IllegalArgumentException("Could not find resource for URI: " + resourceUri + " using: " + getResourceLoader());
+ }
+ }
+ return resource;
+ }
public ResourceLoader getResourceLoader() {
return resourceLoader;
@@ -40,14 +60,4 @@
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
-
- protected Resource resolveMandatoryResource(String uri) {
- Resource resource = getResourceLoader().getResource(uri);
- if (resource == null) {
- throw new IllegalArgumentException("Could not find resource for URI: " + uri + " using: " + getResourceLoader());
- } else {
- return resource;
- }
-
- }
-}
+}
\ No newline at end of file
Added: activemq/camel/trunk/components/camel-velocity/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/pom.xml?rev=575600&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-velocity/pom.xml (added)
+++ activemq/camel/trunk/components/camel-velocity/pom.xml Fri Sep 14 02:40:19 2007
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>1.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-velocity</artifactId>
+ <name>Camel :: Velocity</name>
+ <description>Camel Velocity support</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>velocity</groupId>
+ <artifactId>velocity</artifactId>
+ <version>1.4</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
+
+
Propchange: activemq/camel/trunk/components/camel-velocity/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java?rev=575600&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java (added)
+++ activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java Fri Sep 14 02:40:19 2007
@@ -0,0 +1,43 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.velocity;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.velocity.app.VelocityEngine;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class VelocityComponent extends DefaultComponent {
+ private VelocityEngine velocityEngine = new VelocityEngine();
+
+ public VelocityEngine getVelocityEngine() {
+ return velocityEngine;
+ }
+
+ public void setVelocityEngine(VelocityEngine velocityEngine) {
+ this.velocityEngine = velocityEngine;
+ }
+
+ protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
+ return new VelocityEndpoint(uri, this, remaining, parameters);
+ }
+}
Propchange: activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java?rev=575600&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java (added)
+++ activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java Fri Sep 14 02:40:19 2007
@@ -0,0 +1,89 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.velocity;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.component.ResourceBasedEndpoint;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.impl.PollingConsumerSupport;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class VelocityEndpoint extends ResourceBasedEndpoint {
+ private final VelocityComponent component;
+ private VelocityEngine velocityEngine;
+
+ public VelocityEndpoint(String uri, VelocityComponent component, String resourceUri, Map parameters) {
+ super(uri, component, resourceUri, null);
+ this.component = component;
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+ @Override
+ public ExchangePattern getExchangePattern() {
+ return ExchangePattern.InOut;
+ }
+
+ public VelocityEngine getVelocityEngine() {
+ if (velocityEngine == null) {
+ velocityEngine = component.getVelocityEngine();
+ }
+ return velocityEngine;
+ }
+
+ public void setVelocityEngine(VelocityEngine velocityEngine) {
+ this.velocityEngine = velocityEngine;
+ }
+
+ @Override
+ protected void onExchange(Exchange exchange) throws Exception {
+ Reader reader = new InputStreamReader(getResource().getInputStream());
+ StringWriter buffer = new StringWriter();
+ String logTag = getClass().getName();
+ Context velocityContext = new VelocityContext(ExchangeHelper.createVariableMap(exchange));
+ getVelocityEngine().evaluate(velocityContext, buffer, logTag, reader);
+
+ // now lets output the results to the exchange
+ Message out = exchange.getOut(true);
+ out.setBody(buffer.toString());
+ out.setHeader("org.apache.camel.velocity.resource", getResource());
+ }
+}
Propchange: activemq/camel/trunk/components/camel-velocity/src/main/java/org/apache/camel/component/velocity/VelocityEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-velocity/src/main/resources/META-INF/services/org/apache/camel/component/velocity
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/main/resources/META-INF/services/org/apache/camel/component/velocity?rev=575600&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-velocity/src/main/resources/META-INF/services/org/apache/camel/component/velocity (added)
+++ activemq/camel/trunk/components/camel-velocity/src/main/resources/META-INF/services/org/apache/camel/component/velocity Fri Sep 14 02:40:19 2007
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class=org.apache.camel.component.velocity.VelocityComponent
Added: activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java?rev=575600&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java (added)
+++ activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java Fri Sep 14 02:40:19 2007
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.velocity;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import static org.apache.camel.language.simple.SimpleLanguage.simple;
+import org.apache.camel.util.ExchangeHelper;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class VelocityTest extends ContextTestSupport {
+
+ public void testReceivesFooResponse() throws Exception {
+ assertRespondsWith("foo", "<hello>foo</hello>");
+ }
+
+ public void testReceivesBarResponse() throws Exception {
+ assertRespondsWith("bar", "<hello>bar</hello>");
+ }
+
+ protected void assertRespondsWith(final String value, String containedText) throws InvalidPayloadException {
+ Exchange response = template.request("direct:a", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ in.setBody("answer");
+ in.setHeader("cheese", value);
+ }
+ });
+
+ assertNotNull("Should receive a response!", response);
+
+ System.out.println("Received response: " + response + " with out: " + response.getOut());
+
+ String text = ExchangeHelper.getMandatoryOutBody(response, String.class);
+ log.info("Received: " + text);
+ assertStringContains(text, containedText);
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // START SNIPPET: example
+ from("direct:a").
+ to("velocity:org/apache/camel/component/velocity/example.vm");
+ // END SNIPPET: example
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-velocity/src/test/java/org/apache/camel/component/velocity/VelocityTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-velocity/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/resources/log4j.properties?rev=575600&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-velocity/src/test/resources/log4j.properties (added)
+++ activemq/camel/trunk/components/camel-velocity/src/test/resources/log4j.properties Fri Sep 14 02:40:19 2007
@@ -0,0 +1,35 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, out
+
+log4j.logger.org.apache.activemq.spring=WARN
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.out.file=target/camel-test.log
+log4j.appender.out.append=true
Propchange: activemq/camel/trunk/components/camel-velocity/src/test/resources/log4j.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm?rev=575600&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm (added)
+++ activemq/camel/trunk/components/camel-velocity/src/test/resources/org/apache/camel/component/velocity/example.vm Fri Sep 14 02:40:19 2007
@@ -0,0 +1 @@
+<hello>${headers.cheese}</hello>
\ No newline at end of file
Modified: activemq/camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/pom.xml?rev=575600&r1=575599&r2=575600&view=diff
==============================================================================
--- activemq/camel/trunk/components/pom.xml (original)
+++ activemq/camel/trunk/components/pom.xml Fri Sep 14 02:40:19 2007
@@ -38,7 +38,7 @@
<module>camel-bam</module>
<module>camel-cxf</module>
<module>camel-ftp</module>
- <!--<module>camel-groovy</module>-->
+ <module>camel-groovy</module>
<module>camel-http</module>
<module>camel-ibatis</module>
<module>camel-irc</module>
@@ -61,6 +61,7 @@
<module>camel-saxon</module>
<module>camel-script</module>
<module>camel-spring</module>
+ <!-- <module>camel-velocity</module> -->
<module>camel-xmlbeans</module>
<module>camel-xmpp</module>
</modules>