You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bv...@apache.org on 2012/02/14 16:30:42 UTC
svn commit: r1243995 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/impl/ZipDataFormat.java
test/java/org/apache/camel/impl/ZipDataFormatTest.java
Author: bvahdat
Date: Tue Feb 14 15:30:42 2012
New Revision: 1243995
URL: http://svn.apache.org/viewvc?rev=1243995&view=rev
Log:
ZipDataFormat.marshal() should better ask for a mandatory conversion to avoid possible NPE.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java?rev=1243995&r1=1243994&r2=1243995&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java Tue Feb 14 15:30:42 2012
@@ -41,7 +41,8 @@ public class ZipDataFormat implements Da
}
public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
- InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, graph);
+ // ask for a mandatoy type converter to avoid a possible NPE beforehand as we do copy from the InputStream
+ InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, graph);
DeflaterOutputStream zipOutput = new DeflaterOutputStream(stream, new Deflater(compressionLevel));
try {
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatTest.java?rev=1243995&r1=1243994&r2=1243995&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatTest.java Tue Feb 14 15:30:42 2012
@@ -23,9 +23,11 @@ import java.util.zip.Inflater;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
+import org.apache.camel.NoTypeConversionAvailableException;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.DataFormat;
/**
* Unit test of the zip data format.
@@ -50,6 +52,17 @@ public class ZipDataFormatTest extends C
return false;
}
+ public void testMarshalMandatoryConversionFailed() throws Exception {
+ DataFormat dataFormat = new ZipDataFormat();
+
+ try {
+ dataFormat.marshal(new DefaultExchange(new DefaultCamelContext()), new Object(), new ByteArrayOutputStream());
+ fail("Should have thrown an exception");
+ } catch (NoTypeConversionAvailableException e) {
+ // expected
+ }
+ }
+
private void sendText() throws Exception {
template.send("direct:start", new Processor() {
public void process(Exchange exchange) throws Exception {