You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2012/03/31 20:04:48 UTC
svn commit: r1307865 - in /camel/branches/camel-2.9.x: ./
camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatTest.java
Author: hadrian
Date: Sat Mar 31 18:04:48 2012
New Revision: 1307865
URL: http://svn.apache.org/viewvc?rev=1307865&view=rev
Log:
Merged revisions 1243995 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r1243995 | bvahdat | 2012-02-14 10:30:42 -0500 (Tue, 14 Feb 2012) | 1 line
ZipDataFormat.marshal() should better ask for a mandatory conversion to avoid possible NPE.
........
Modified:
camel/branches/camel-2.9.x/ (props changed)
camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatTest.java
Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java?rev=1307865&r1=1307864&r2=1307865&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java (original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java Sat Mar 31 18:04:48 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/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatTest.java?rev=1307865&r1=1307864&r2=1307865&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatTest.java (original)
+++ camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/impl/ZipDataFormatTest.java Sat Mar 31 18:04:48 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 {