You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/09/13 09:35:40 UTC
svn commit: r814274 [1/2] - in /camel/trunk: components/
components/camel-cache/ components/camel-cache/src/
components/camel-cache/src/main/ components/camel-cache/src/main/java/
components/camel-cache/src/main/java/org/ components/camel-cache/src/mai...
Author: ningjiang
Date: Sun Sep 13 07:35:39 2009
New Revision: 814274
URL: http://svn.apache.org/viewvc?rev=814274&view=rev
Log:
CAMEL-1868 applied patch with thanks to Ashwin
Added:
camel/trunk/components/camel-cache/
camel/trunk/components/camel-cache/pom.xml (with props)
camel/trunk/components/camel-cache/src/
camel/trunk/components/camel-cache/src/main/
camel/trunk/components/camel-cache/src/main/java/
camel/trunk/components/camel-cache/src/main/java/org/
camel/trunk/components/camel-cache/src/main/java/org/apache/
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java (with props)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java (with props)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java (with props)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java (with props)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java (with props)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java (with props)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java (with props)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java (with props)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java (with props)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java (with props)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java (with props)
camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java (with props)
camel/trunk/components/camel-cache/src/main/resources/
camel/trunk/components/camel-cache/src/main/resources/META-INF/
camel/trunk/components/camel-cache/src/main/resources/META-INF/LICENSE.txt (with props)
camel/trunk/components/camel-cache/src/main/resources/META-INF/NOTICE.txt (with props)
camel/trunk/components/camel-cache/src/main/resources/META-INF/services/
camel/trunk/components/camel-cache/src/main/resources/META-INF/services/org/
camel/trunk/components/camel-cache/src/main/resources/META-INF/services/org/apache/
camel/trunk/components/camel-cache/src/main/resources/META-INF/services/org/apache/camel/
camel/trunk/components/camel-cache/src/main/resources/META-INF/services/org/apache/camel/component/
camel/trunk/components/camel-cache/src/main/resources/META-INF/services/org/apache/camel/component/cache (with props)
camel/trunk/components/camel-cache/src/main/resources/ehcache.xml (with props)
camel/trunk/components/camel-cache/src/main/resources/xpathreplacer.xsl (with props)
camel/trunk/components/camel-cache/src/test/
camel/trunk/components/camel-cache/src/test/java/
camel/trunk/components/camel-cache/src/test/java/org/
camel/trunk/components/camel-cache/src/test/java/org/apache/
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheConsumerTest.java (with props)
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java (with props)
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedBodyReplacerTest.java (with props)
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedTokenReplacerTest.java (with props)
camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedXPathElementReplacerTest.java (with props)
camel/trunk/components/camel-cache/src/test/resources/
camel/trunk/components/camel-cache/src/test/resources/log4j.properties (with props)
camel/trunk/components/camel-cache/src/test/resources/test.txt (with props)
camel/trunk/components/camel-cache/src/test/resources/updatedtest.txt (with props)
Modified:
camel/trunk/components/pom.xml
camel/trunk/parent/pom.xml
Added: camel/trunk/components/camel-cache/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/pom.xml?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/pom.xml (added)
+++ camel/trunk/components/camel-cache/pom.xml Sun Sep 13 07:35:39 2009
@@ -0,0 +1,166 @@
+<?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>components</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-cache</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: Cache</name>
+ <description>Camel Cache support based on ehCache</description>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.cache.*</camel.osgi.export.pkg>
+ </properties>
+
+ <repositories>
+ <repository>
+ <id>servicemix</id>
+ <name>Apache ServiceMix Repository</name>
+ <url>http://svn.apache.org/repos/asf/servicemix/m2-repo</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache</artifactId>
+ <version>1.6.0</version>
+ </dependency>
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>${xalan-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>${xerces-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>jsch</groupId> <!-- com.jcraft -->
+ <artifactId>jsch</artifactId>
+ <version>0.1.40</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- to allow Spring annotations (jmx) to be tested -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <optional>true</optional>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <optional>true</optional>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>ftp.enable</name>
+ <value>${ftp.enable}</value>
+ </property>
+ <property>
+ <name>ftp.server</name>
+ <value>${ftp.url}</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-clean-plugin</artifactId>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>${basedir}/res</directory>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: camel/trunk/components/camel-cache/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/pom.xml
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/pom.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-cache/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,50 @@
+/**
+ * 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.cache;
+
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+public class CacheComponent extends DefaultComponent {
+ CacheConfiguration config;
+
+ public CacheComponent() {
+ config = new CacheConfiguration();
+ }
+
+ public CacheComponent(CamelContext context) {
+ super(context);
+ config = new CacheConfiguration();
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining,
+ Map parameters) throws Exception {
+ config.parseURI(new URI(uri));
+
+ CacheEndpoint cacheEndpoint = new CacheEndpoint(uri, this, config);
+ setProperties(cacheEndpoint.getConfig(), parameters);
+ return cacheEndpoint;
+ }
+
+
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,173 @@
+/**
+ * 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.cache;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+
+import net.sf.ehcache.event.RegisteredEventListeners;
+import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
+
+import org.apache.camel.util.URISupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CacheConfiguration {
+ private static final transient Log LOG = LogFactory.getLog(CacheConfiguration.class);
+ private URI uri;
+ private String cacheName;
+ private int maxElementsInMemory = 1000;
+ private MemoryStoreEvictionPolicy memoryStoreEvictionPolicy = MemoryStoreEvictionPolicy.LFU;
+ private boolean overflowToDisk = true;
+ private String diskStorePath;
+ private boolean eternal;
+ private long timeToLiveSeconds = 300;
+ private long timeToIdleSeconds = 300;
+ private boolean diskPersistent;
+ private long diskExpiryThreadIntervalSeconds;
+ private Map cacheSettings;
+
+ public CacheConfiguration() {
+ }
+
+ public CacheConfiguration(URI uri) throws Exception {
+ parseURI(uri);
+
+ }
+
+ public void parseURI(URI uri) throws Exception {
+ String protocol = uri.getScheme();
+
+ if (!protocol.equalsIgnoreCase("cache")) {
+ throw new IllegalArgumentException("Unrecognized Cache protocol: " + protocol + " for uri: " + uri);
+ }
+
+ setCacheName(uri.getHost());
+
+ cacheSettings = URISupport.parseParameters(uri);
+ if (cacheSettings.containsKey("maxElementsInMemory")) {
+ setMaxElementsInMemory(Integer.valueOf((String) cacheSettings.get("maxElementsInMemory")).intValue());
+ }
+ if (cacheSettings.containsKey("overflowToDisk")) {
+ setOverflowToDisk(Boolean.valueOf((String) cacheSettings.get("overflowToDisk")));
+ if (cacheSettings.containsKey("diskStorePath")) {
+ setDiskStorePath((String)cacheSettings.get("diskStorePath"));
+ }
+ }
+ if (cacheSettings.containsKey("eternal")) {
+ setEternal(Boolean.valueOf((String) cacheSettings.get("eternal")));
+ }
+ if (cacheSettings.containsKey("timeToLiveSeconds")) {
+ setTimeToLiveSeconds(Long.valueOf((String) cacheSettings.get("timeToLiveSeconds")).longValue());
+ }
+ if (cacheSettings.containsKey("timeToIdleSeconds")) {
+ setTimeToLiveSeconds(Long.valueOf((String) cacheSettings.get("timeToIdleSeconds")).longValue());
+ }
+ if (cacheSettings.containsKey("diskPersistent")) {
+ setEternal(Boolean.valueOf((String) cacheSettings.get("diskPersistent")));
+ }
+ if (cacheSettings.containsKey("diskExpiryThreadIntervalSeconds")) {
+ setTimeToLiveSeconds(Long.valueOf((String) cacheSettings.get("diskExpiryThreadIntervalSeconds")).longValue());
+ }
+
+ }
+
+ public String getCacheName() {
+ return cacheName;
+ }
+
+ public void setCacheName(String cacheName) {
+ this.cacheName = cacheName;
+ }
+
+ public int getMaxElementsInMemory() {
+ return maxElementsInMemory;
+ }
+
+ public void setMaxElementsInMemory(int maxElementsInMemory) {
+ this.maxElementsInMemory = maxElementsInMemory;
+ }
+
+ public MemoryStoreEvictionPolicy getMemoryStoreEvictionPolicy() {
+ return memoryStoreEvictionPolicy;
+ }
+
+ public void setMemoryStoreEvictionPolicy(
+ MemoryStoreEvictionPolicy memoryStoreEvictionPolicy) {
+ this.memoryStoreEvictionPolicy = memoryStoreEvictionPolicy;
+ }
+
+ public boolean isOverflowToDisk() {
+ return overflowToDisk;
+ }
+
+ public void setOverflowToDisk(boolean overflowToDisk) {
+ this.overflowToDisk = overflowToDisk;
+ }
+
+ public String getDiskStorePath() {
+ return diskStorePath;
+ }
+
+ public void setDiskStorePath(String diskStorePath) {
+ this.diskStorePath = diskStorePath;
+ }
+
+ public boolean isEternal() {
+ return eternal;
+ }
+
+ public void setEternal(boolean eternal) {
+ this.eternal = eternal;
+ }
+
+ public long getTimeToLiveSeconds() {
+ return timeToLiveSeconds;
+ }
+
+ public void setTimeToLiveSeconds(long timeToLiveSeconds) {
+ this.timeToLiveSeconds = timeToLiveSeconds;
+ }
+
+ public long getTimeToIdleSeconds() {
+ return timeToIdleSeconds;
+ }
+
+ public void setTimeToIdleSeconds(long timeToIdleSeconds) {
+ this.timeToIdleSeconds = timeToIdleSeconds;
+ }
+
+ public boolean isDiskPersistent() {
+ return diskPersistent;
+ }
+
+ public void setDiskPersistent(boolean diskPersistent) {
+ this.diskPersistent = diskPersistent;
+ }
+
+ public long getDiskExpiryThreadIntervalSeconds() {
+ return diskExpiryThreadIntervalSeconds;
+ }
+
+ public void setDiskExpiryThreadIntervalSeconds(
+ long diskExpiryThreadIntervalSeconds) {
+ this.diskExpiryThreadIntervalSeconds = diskExpiryThreadIntervalSeconds;
+ }
+
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,97 @@
+/**
+ * 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.cache;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Ehcache;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.component.cache.factory.CacheManagerFactory;
+import org.apache.camel.impl.DefaultConsumer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CacheConsumer extends DefaultConsumer {
+
+ private static final transient Log LOG = LogFactory.getLog(CacheConsumer.class);
+ CacheEndpoint endpoint;
+ CacheConfiguration config;
+ Ehcache cache;
+ CacheManager cacheManager;
+
+ public CacheConsumer(Endpoint endpoint, Processor processor, CacheConfiguration config) {
+ super(endpoint, processor);
+ this.endpoint = (CacheEndpoint) endpoint;
+ this.config = config;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ // TODO Auto-generated method stub
+ super.doStart();
+ createConsumerCacheConnection();
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ // TODO Auto-generated method stub
+ super.doStop();
+ removeConsumerCacheConnection();
+ }
+
+ @Override
+ public CacheEndpoint getEndpoint() {
+ return endpoint;
+ }
+
+ private void createConsumerCacheConnection() {
+ cacheManager = new CacheManagerFactory().instantiateCacheManager();
+ CacheEventListener cacheEventListener = new CacheEventListenerFactory().createCacheEventListener(null);
+ cacheEventListener.setCacheConsumer(this);
+
+ if (cacheManager.cacheExists(config.getCacheName())) {
+ cache = cacheManager.getCache(config.getCacheName());
+ cache.getCacheEventNotificationService().registerListener(cacheEventListener);
+ } else {
+ cache = new Cache(config.getCacheName(),
+ config.getMaxElementsInMemory(),
+ config.getMemoryStoreEvictionPolicy(),
+ config.isOverflowToDisk(),
+ config.getDiskStorePath(),
+ config.isEternal(),
+ config.getTimeToLiveSeconds(),
+ config.getTimeToIdleSeconds(),
+ config.isDiskPersistent(),
+ config.getDiskExpiryThreadIntervalSeconds(),
+ null);
+ cache.getCacheEventNotificationService().registerListener(cacheEventListener);
+ cacheManager.addCache(cache);
+ LOG.info("Added a new cache: " + cache.getName());
+ }
+ }
+
+ private void removeConsumerCacheConnection() {
+ cacheManager.removeCache(config.getCacheName());
+ if (cacheManager.getCacheNames().length == 0) {
+ cacheManager.shutdown();
+ }
+ }
+
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,72 @@
+/**
+ * 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.cache;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.impl.DefaultMessage;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CacheEndpoint extends DefaultEndpoint {
+ private static final transient Log LOG = LogFactory.getLog(CacheEndpoint.class);
+ CacheConfiguration config;
+
+ public CacheEndpoint(String endpointUri, Component component, CacheConfiguration config) {
+ super(endpointUri, component);
+ this.config = config;
+ }
+
+ public Consumer createConsumer(Processor processor) throws Exception {
+ return new CacheConsumer(this, processor, config);
+ }
+
+ public Producer createProducer() throws Exception {
+ return new CacheProducer(this, config);
+ }
+
+ public boolean isSingleton() {
+ return false;
+ }
+
+ public CacheConfiguration getConfig() {
+ return config;
+ }
+
+ public void setConfig(CacheConfiguration config) {
+ this.config = config;
+ }
+
+ public Exchange createCacheExchange(String operation, String key, Object value) {
+ DefaultExchange exchange = new DefaultExchange(this.getCamelContext(), getExchangePattern());
+ DefaultMessage message = new DefaultMessage();
+ message.setHeader("CACHE_OPERATION", operation);
+ message.setHeader("CACHE_KEY", key);
+ message.setBody(value);
+ exchange.setIn(message);
+ return exchange;
+
+
+ }
+
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,109 @@
+/**
+ * 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.cache;
+
+import net.sf.ehcache.CacheException;
+import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.Element;
+
+import org.apache.camel.Exchange;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public class CacheEventListener implements net.sf.ehcache.event.CacheEventListener {
+
+ private static final transient Log LOG = LogFactory.getLog(CacheEventListener.class);
+ CacheConsumer cacheConsumer;
+
+
+ public CacheEventListener() {
+ super();
+ }
+
+ public CacheEventListener(CacheConsumer cacheConsumer) {
+ super();
+ this.cacheConsumer = cacheConsumer;
+ }
+
+ public void notifyElementEvicted(Ehcache cache, Element element) {
+ LOG.info("Element" + element.toString() + " is being evicted from cache " + cache.getName());
+
+ }
+
+ public void notifyElementExpired(Ehcache cache, Element element) {
+ LOG.info("Element" + element.toString() + " has expired in cache " + cache.getName());
+ }
+
+ public void notifyElementPut(Ehcache cache, Element element)
+ throws CacheException {
+ LOG.info("Element" + element.toString() + " has just been added/put in cache " + cache.getName());
+ dispatchExchange(cache, element, "ADD");
+ }
+
+ public void notifyElementRemoved(Ehcache cache, Element element)
+ throws CacheException {
+ LOG.info("Element" + element.toString() + " has just been removed from cache " + cache.getName());
+ dispatchExchange(cache, element, "DELETE");
+ }
+
+ public void notifyElementUpdated(Ehcache cache, Element element)
+ throws CacheException {
+ LOG.info("Element" + element.toString() + " has just been updated in cache " + cache.getName());
+ dispatchExchange(cache, element, "UPDATE");
+ }
+
+ public void notifyRemoveAll(Ehcache cache) {
+ LOG.info("Cache " + cache.getName() + " is being emptied and all elements removed");
+ dispatchExchange(cache, null, "DELETEALL");
+
+ }
+
+ private void dispatchExchange(Ehcache cache, Element element, String operation) {
+ Exchange exchange;
+
+ LOG.info("Consumer Dispatching the Exchange containing the Element " + element.toString() + " in cache " + cache.getName());
+ if (element == null) {
+ exchange = cacheConsumer.getEndpoint().createCacheExchange(operation, "", "");
+ } else {
+ exchange = cacheConsumer.getEndpoint().createCacheExchange(operation, (String) element.getObjectKey(), element.getObjectValue());
+ }
+ try {
+ cacheConsumer.getProcessor().process(exchange);
+ } catch (Exception e) {
+ throw new CacheException("Error in consumer while dispatching exchange containing Key " + (String) element.getObjectKey() + " for further processing ", e);
+ }
+ }
+
+ public CacheConsumer getCacheConsumer() {
+ return cacheConsumer;
+ }
+
+ public void setCacheConsumer(CacheConsumer cacheConsumer) {
+ this.cacheConsumer = cacheConsumer;
+ }
+
+ public void dispose() {
+
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,28 @@
+/**
+ * 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.cache;
+
+import java.util.Properties;
+
+public class CacheEventListenerFactory extends net.sf.ehcache.event.CacheEventListenerFactory {
+
+ public CacheEventListener createCacheEventListener(Properties properties) {
+ return new CacheEventListener();
+ }
+
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,125 @@
+/**
+ * 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.cache;
+
+import java.io.InputStream;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheException;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Ehcache;
+import net.sf.ehcache.Element;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.cache.factory.CacheManagerFactory;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CacheProducer extends DefaultProducer {
+ private static final transient Log LOG = LogFactory.getLog(CacheProducer.class);
+ Endpoint endpoint;
+ CacheConfiguration config;
+ CacheManager cacheManager;
+ Ehcache cache;
+
+ public CacheProducer(Endpoint endpoint, CacheConfiguration config) throws Exception {
+ super(endpoint);
+ this.endpoint = endpoint;
+ this.config = config;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ LOG.info("In CacheProducer.start()");
+ super.doStart();
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ LOG.info("In CacheProducer.stop()");
+ super.doStop();
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ LOG.info("In CacheProducer.process()");
+ Object body = exchange.getIn().getBody();
+ InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, body);
+
+ // Read InputStream into a byte[] buffer
+ byte[] buffer = new byte[is.available()];
+ int n = is.available();
+ for (int j = 0; j < n; j++) {
+ buffer[j] = (byte)is.read();
+ }
+
+ // Cache the buffer to the specified Cache against the specified key
+ cacheManager = new CacheManagerFactory().instantiateCacheManager();
+
+ LOG.info("Cache Name: " + config.getCacheName());
+ if (cacheManager.cacheExists(config.getCacheName())) {
+ LOG.info("Found an existing cache: " + config.getCacheName());
+ LOG.info("Cache " + config.getCacheName() + " currently contains " + cacheManager.getCache(config.getCacheName()).getSize() + " elements");
+ cache = cacheManager.getCache(config.getCacheName());
+ } else {
+ cache = new Cache(config.getCacheName(),
+ config.getMaxElementsInMemory(),
+ config.getMemoryStoreEvictionPolicy(),
+ config.isOverflowToDisk(),
+ config.getDiskStorePath(),
+ config.isEternal(),
+ config.getTimeToLiveSeconds(),
+ config.getTimeToIdleSeconds(),
+ config.isDiskPersistent(),
+ config.getDiskExpiryThreadIntervalSeconds(),
+ null);
+ cacheManager.addCache(cache);
+ LOG.info("Added a new cache: " + cache.getName());
+ }
+
+
+ String key = (String) exchange.getIn().getHeader("CACHE_KEY");
+ String operation = (String) exchange.getIn().getHeader("CACHE_OPERATION");
+ if (operation == null) {
+ throw new CacheException("Operation property is not specified in the incoming exchange header."
+ + "A valid Operation property must be set to ADD, UPDATE, DELETE, DELETEALL");
+ }
+ if ((key == null) && (!operation.equalsIgnoreCase("DELETEALL"))) {
+ throw new CacheException("Cache Key is not specified in exchange either header or URL. Unable to add objects to the cache without a Key");
+ }
+
+ performCacheOperation(operation, key, buffer);
+ }
+
+ private void performCacheOperation(String operation, String key, byte[] buffer) {
+ if (operation.equalsIgnoreCase("DELETEALL")) {
+ LOG.info("Deleting All elements from the Cache");
+ cache.removeAll();
+ } else if (operation.equalsIgnoreCase("ADD")) {
+ LOG.info("Adding an element with key " + key + " into the Cache");
+ cache.put(new Element(key, buffer), true);
+ } else if (operation.equalsIgnoreCase("UPDATE")) {
+ LOG.info("Updating an element with key " + key + " into the Cache");
+ cache.put(new Element(key, buffer), true);
+ } else if (operation.equalsIgnoreCase("DELETE")) {
+ LOG.info("Deleting an element with key " + key + " into the Cache");
+ cache.remove(key, true);
+ }
+ }
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,32 @@
+/**
+ * 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.cache.factory;
+
+import net.sf.ehcache.CacheManager;
+
+public class CacheManagerFactory {
+ public CacheManager cacheManager;
+
+ public CacheManager instantiateCacheManager() {
+ if (cacheManager == null) {
+ cacheManager = CacheManager.getInstance();
+ }
+
+ return cacheManager;
+ }
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,64 @@
+package org.apache.camel.processor.cache;
+
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Ehcache;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.cache.factory.CacheManagerFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CacheBasedMessageBodyReplacer extends CacheValidate implements Processor {
+ private static final transient Log LOG = LogFactory.getLog(CacheBasedMessageBodyReplacer.class);
+ private String cacheName;
+ private String key;
+ CacheManager cacheManager;
+ Ehcache cache;
+
+ public CacheBasedMessageBodyReplacer(String cacheName, String key) {
+ super();
+ if (cacheName.contains("cache://")) {
+ this.setCacheName(cacheName.replace("cache://", ""));
+ } else {
+ this.setCacheName(cacheName);
+ }
+ this.setKey(key);
+ }
+
+
+ public void process(Exchange exchange) throws Exception {
+ // Cache the buffer to the specified Cache against the specified key
+ cacheManager = new CacheManagerFactory().instantiateCacheManager();
+
+ if (isValid(cacheManager, cacheName, key)) {
+ cache = cacheManager.getCache(cacheName);
+ LOG.info("Replacing Message Body from CacheName " + cacheName + " for key " + key);
+ exchange.getIn().setHeader("CACHE_KEY", key);
+ exchange.getIn().setBody(cache.get(key).getObjectValue());
+ }
+
+ }
+
+
+ public String getCacheName() {
+ return cacheName;
+ }
+
+
+ public void setCacheName(String cacheName) {
+ this.cacheName = cacheName;
+ }
+
+
+ public String getKey() {
+ return key;
+ }
+
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,88 @@
+package org.apache.camel.processor.cache;
+
+import java.io.InputStream;
+
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Ehcache;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.cache.factory.CacheManagerFactory;
+import org.apache.camel.converter.IOConverter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CacheBasedTokenReplacer extends CacheValidate implements Processor {
+ private static final transient Log LOG = LogFactory.getLog(CacheBasedTokenReplacer.class);
+ private String cacheName;
+ private String key;
+ private String replacementToken;
+ private CacheManager cacheManager;
+ private Ehcache cache;
+
+
+ public CacheBasedTokenReplacer(String cacheName, String key, String replacementToken) {
+ super();
+ if (cacheName.contains("cache://")) {
+ this.setCacheName(cacheName.replace("cache://", ""));
+ } else {
+ this.setCacheName(cacheName);
+ }
+ this.setKey(key);
+ this.setReplacementToken(replacementToken);
+ }
+
+
+ public void process(Exchange exchange) throws Exception {
+ // Cache the buffer to the specified Cache against the specified key
+ cacheManager = new CacheManagerFactory().instantiateCacheManager();
+
+ if (isValid(cacheManager, cacheName, key)) {
+ cache = cacheManager.getCache(cacheName);
+ LOG.info("Replacing Token " + replacementToken + "in Message with value stored against key " + key + " in CacheName " + cacheName);
+ exchange.getIn().setHeader("CACHE_KEY", key);
+ Object body = exchange.getIn().getBody();
+ InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, body);
+
+ byte[] buffer = IOConverter.toBytes(is);
+ is.close();
+
+ //Note: The value in the cache must be a String
+ String cacheValue = exchange.getContext().getTypeConverter().convertTo(String.class, cache.get(key).getObjectValue());
+ String replacedTokenString = new String(buffer).replaceAll(replacementToken, cacheValue);
+ LOG.debug("replacedTokenString = " + replacedTokenString);
+ exchange.getIn().setBody(replacedTokenString.getBytes());
+ }
+ }
+
+
+ public String getCacheName() {
+ return cacheName;
+ }
+
+
+ public void setCacheName(String cacheName) {
+ this.cacheName = cacheName;
+ }
+
+
+ public String getKey() {
+ return key;
+ }
+
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+
+ public String getReplacementToken() {
+ return replacementToken;
+ }
+
+
+ public void setReplacementToken(String replacementToken) {
+ this.replacementToken = replacementToken;
+ }
+
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,112 @@
+package org.apache.camel.processor.cache;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.StringReader;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Ehcache;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.cache.factory.CacheManagerFactory;
+import org.apache.camel.converter.IOConverter;
+import org.apache.camel.converter.jaxp.XmlConverter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Document;
+
+public class CacheBasedXPathReplacer extends CacheValidate implements Processor {
+ private static final transient Log LOG = LogFactory.getLog(CacheBasedXPathReplacer.class);
+ private String cacheName;
+ private String key;
+ private String xpath;
+ private CacheManager cacheManager;
+ private Ehcache cache;
+ private Document document;
+ private DOMSource source;
+ private DOMResult result;
+
+ public CacheBasedXPathReplacer(String cacheName, String key, String xpath) {
+ super();
+ if (cacheName.contains("cache://")) {
+ this.setCacheName(cacheName.replace("cache://", ""));
+ } else {
+ this.setCacheName(cacheName);
+ }
+ this.key = key;
+ this.xpath = xpath;
+ }
+
+
+ public void process(Exchange exchange) throws Exception {
+ // Cache the buffer to the specified Cache against the specified key
+ cacheManager = new CacheManagerFactory().instantiateCacheManager();
+
+ if (isValid(cacheManager, cacheName, key)) {
+ cache = cacheManager.getCache(cacheName);
+ LOG.info("Replacing XPath value " + xpath + "in Message with value stored against key " + key + " in CacheName " + cacheName);
+ exchange.getIn().setHeader("CACHE_KEY", key);
+ Object body = exchange.getIn().getBody();
+ InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, body);
+ try {
+ document = exchange.getContext().getTypeConverter().convertTo(Document.class, exchange, is);
+ } finally {
+ is.close();
+ }
+
+ InputStream cis = exchange.getContext().getTypeConverter().convertTo(InputStream.class, cache.get(key).getObjectValue());
+ try {
+ Document cacheValueDocument = exchange.getContext().getTypeConverter().convertTo(Document.class, exchange, cis);
+
+ //Create/setup the Transformer
+ XmlConverter xmlConverter = new XmlConverter();
+ String xslString = IOConverter.toString(new File("./src/main/resources/xpathreplacer.xsl"));
+ xslString = xslString.replace("##match_token##", xpath);
+ Source xslSource = xmlConverter.toStreamSource(new StringReader(xslString));
+ TransformerFactory transformerFactory = xmlConverter.createTransformerFactory();
+ Transformer transformer = transformerFactory.newTransformer(xslSource);
+ source = xmlConverter.toSource(document);
+ result = new DOMResult();
+
+ transformer.setParameter("cacheValue", cacheValueDocument);
+ transformer.transform(source, result);
+ } finally {
+ cis.close();
+ }
+ }
+
+ exchange.getIn().setBody(IOConverter.toBytes(IOConverter.toInputStrean(new DOMSource(result.getNode()))));
+ }
+
+ public String getCacheName() {
+ return cacheName;
+ }
+
+ public void setCacheName(String cacheName) {
+ this.cacheName = cacheName;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getXpath() {
+ return xpath;
+ }
+
+ public void setXpath(String xpath) {
+ this.xpath = xpath;
+ }
+
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java (added)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java Sun Sep 13 07:35:39 2009
@@ -0,0 +1,32 @@
+package org.apache.camel.processor.cache;
+
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Ehcache;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CacheValidate {
+ private static final transient Log LOG = LogFactory.getLog(CacheValidate.class);
+
+ public boolean isValid(CacheManager cacheManager, String cacheName, String key) {
+ LOG.info("Cache Name: " + cacheName);
+ if (!cacheManager.cacheExists(cacheName)) {
+ LOG.info("No existing Cache found with name: " + cacheName + ". Please ensure a cache is first instantiated using a Cache Consumer or Cache Producer");
+ LOG.info("Replacement will not be performed since the cache " + cacheName + "does not presently exist");
+ return false;
+ }
+
+ LOG.info("Found an existing cache: " + cacheName);
+ LOG.info("Cache " + cacheName + " currently contains " + cacheManager.getCache(cacheName).getSize() + " elements");
+ Ehcache cache = cacheManager.getCache(cacheName);
+ if (!cache.isKeyInCache(key)) {
+ LOG.info("No Key with name: " + key + "presently exists in the cache. It is also possible that the key may have expired in the cache");
+ LOG.info("Replacement will not be performed until an appropriate key/value pair is added to (or) found in the cache.");
+ return false;
+
+ }
+
+ return true;
+ }
+}
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-cache/src/main/resources/META-INF/LICENSE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/resources/META-INF/LICENSE.txt?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/resources/META-INF/LICENSE.txt (added)
+++ camel/trunk/components/camel-cache/src/main/resources/META-INF/LICENSE.txt Sun Sep 13 07:35:39 2009
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
Propchange: camel/trunk/components/camel-cache/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-cache/src/main/resources/META-INF/NOTICE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/resources/META-INF/NOTICE.txt?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/resources/META-INF/NOTICE.txt (added)
+++ camel/trunk/components/camel-cache/src/main/resources/META-INF/NOTICE.txt Sun Sep 13 07:35:39 2009
@@ -0,0 +1,11 @@
+ =========================================================================
+ == 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.
Propchange: camel/trunk/components/camel-cache/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-cache/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
svn:executable = *
Propchange: camel/trunk/components/camel-cache/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: camel/trunk/components/camel-cache/src/main/resources/META-INF/services/org/apache/camel/component/cache
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/resources/META-INF/services/org/apache/camel/component/cache?rev=814274&view=auto
==============================================================================
--- camel/trunk/components/camel-cache/src/main/resources/META-INF/services/org/apache/camel/component/cache (added)
+++ camel/trunk/components/camel-cache/src/main/resources/META-INF/services/org/apache/camel/component/cache Sun Sep 13 07:35:39 2009
@@ -0,0 +1,17 @@
+# 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.cache.CacheComponent
Propchange: camel/trunk/components/camel-cache/src/main/resources/META-INF/services/org/apache/camel/component/cache
------------------------------------------------------------------------------
svn:executable = *