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/02/23 05:19:07 UTC
svn commit: r746876 - in /camel/branches/camel-1.x: ./
camel-core/src/main/java/org/apache/camel/converter/stream/
camel-core/src/main/java/org/apache/camel/processor/interceptor/
camel-core/src/test/java/org/apache/camel/converter/stream/ camel-core/s...
Author: ningjiang
Date: Mon Feb 23 04:19:06 2009
New Revision: 746876
URL: http://svn.apache.org/viewvc?rev=746876&view=rev
Log:
Merged revisions 746872 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r746872 | ningjiang | 2009-02-23 11:52:43 +0800 (Mon, 23 Feb 2009) | 1 line
CAMEL-1370 caching the StreamSource by caching the inputStream or reader
........
Modified:
camel/branches/camel-1.x/ (props changed)
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCaching.java
camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/converter/stream/StreamCacheConverterTest.java
camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/interceptor/StreamCachingInterceptorTest.java
Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb 23 04:19:06 2009
@@ -1 +1 @@
-/camel/trunk:739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269
+/camel/trunk:739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872
Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java?rev=746876&r1=746875&r2=746876&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java Mon Feb 23 04:19:06 2009
@@ -45,18 +45,18 @@
private XmlConverter converter = new XmlConverter();
@Converter
- public StreamCache convertToStreamCache(StreamSource source) throws TransformerException {
- return new SourceCache(converter.toString(source));
+ public StreamCache convertToStreamCache(StreamSource source) throws IOException {
+ return new StreamSourceCache(source);
}
@Converter
- public StreamCache convertToStreamCache(StringSource source) throws TransformerException {
+ public StreamCache convertToStreamCache(StringSource source) {
//no need to do stream caching for a StringSource
return null;
}
@Converter
- public StreamCache convertToStreamCache(BytesSource source) throws TransformerException {
+ public StreamCache convertToStreamCache(BytesSource source) {
//no need to do stream caching for a BytesSource
return null;
}
@@ -95,6 +95,35 @@
}
}
+
+ /*
+ * {@link StreamCache} implementation for Cache the StreamSource {@link StreamSource}s
+ */
+ private class StreamSourceCache extends StreamSource implements StreamCache {
+ InputStreamCache inputStreamCache;
+ ReaderCache readCache;
+
+ public StreamSourceCache(StreamSource source) throws IOException {
+ if (source.getInputStream() != null) {
+ inputStreamCache = new InputStreamCache(IOConverter.toBytes(source.getInputStream()));
+ setInputStream(inputStreamCache);
+ setSystemId(source.getSystemId());
+ }
+ if (source.getReader() != null) {
+ readCache = new ReaderCache(IOConverter.toString(source.getReader()));
+ setReader(readCache);
+ }
+ }
+ public void reset() {
+ if (inputStreamCache != null) {
+ inputStreamCache.reset();
+ }
+ if (readCache != null) {
+ readCache.reset();
+ }
+ }
+
+ }
private class InputStreamCache extends ByteArrayInputStream implements StreamCache {
Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCaching.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCaching.java?rev=746876&r1=746875&r2=746876&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCaching.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCaching.java Mon Feb 23 04:19:06 2009
@@ -54,4 +54,18 @@
}
context.addInterceptStrategy(new StreamCaching());
}
+
+ /**
+ * Enable stream caching for a RouteContext
+ *
+ * @param context the route context
+ */
+ public static void disable(RouteContext context) {
+ for (InterceptStrategy strategy : context.getInterceptStrategies()) {
+ if (strategy instanceof StreamCaching) {
+ context.getInterceptStrategies().remove(strategy);
+ return;
+ }
+ }
+ }
}
Modified: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/converter/stream/StreamCacheConverterTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/converter/stream/StreamCacheConverterTest.java?rev=746876&r1=746875&r2=746876&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/converter/stream/StreamCacheConverterTest.java (original)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/converter/stream/StreamCacheConverterTest.java Mon Feb 23 04:19:06 2009
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
+import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;
@@ -42,13 +43,14 @@
this.converter = new StreamCacheConverter();
}
- public void testConvertToStreamCacheStreamSource() throws TransformerException, FileNotFoundException {
+ public void testConvertToStreamCacheStreamSource() throws IOException, FileNotFoundException, TransformerException {
StreamSource source = new StreamSource(getTestFileStream());
- StreamSource cache = (StreamSource) converter.convertToStreamCache(source);
+ StreamCache cache = converter.convertToStreamCache(source);
//assert re-readability of the cached StreamSource
XmlConverter converter = new XmlConverter();
- assertNotNull(converter.toString(cache));
- assertNotNull(converter.toString(cache));
+ assertNotNull(converter.toString((Source)cache));
+ cache.reset();
+ assertNotNull(converter.toString((Source)cache));
}
public void testConvertToStreamCacheInputStream() throws IOException {
Modified: camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/interceptor/StreamCachingInterceptorTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/interceptor/StreamCachingInterceptorTest.java?rev=746876&r1=746875&r2=746876&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/interceptor/StreamCachingInterceptorTest.java (original)
+++ camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/interceptor/StreamCachingInterceptorTest.java Mon Feb 23 04:19:06 2009
@@ -81,7 +81,7 @@
template.sendBody("direct:b", message);
assertMockEndpointsSatisfied();
- assertTrue(b.assertExchangeReceived(0).getIn().getBody() instanceof StreamCache);
+ assertTrue(b.assertExchangeReceived(0).getIn().getBody() instanceof StreamCache);
assertEquals(b.assertExchangeReceived(0).getIn().getBody(String.class), MESSAGE);
}