You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2012/05/29 16:48:45 UTC
svn commit: r1343758 - in /camel/trunk/components/camel-netty/src:
main/java/org/apache/camel/component/netty/NettyConverter.java
test/java/org/apache/camel/component/netty/NettyConverterTest.java
Author: davsclaus
Date: Tue May 29 14:48:45 2012
New Revision: 1343758
URL: http://svn.apache.org/viewvc?rev=1343758&view=rev
Log:
CAMEL-5317: Fixed potential NPE in netty converter. Thanks to Lukasz for the patch.
Added:
camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyConverterTest.java (with props)
Modified:
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java
Modified: camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java?rev=1343758&r1=1343757&r2=1343758&view=diff
==============================================================================
--- camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java (original)
+++ camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java Tue May 29 14:48:45 2012
@@ -48,7 +48,10 @@ public final class NettyConverter {
public static String toString(ChannelBuffer buffer, Exchange exchange) {
byte[] bytes = toByteArray(buffer);
// use type converter as it can handle encoding set on the Exchange
- return exchange.getContext().getTypeConverter().convertTo(String.class, exchange, bytes);
+ if (exchange != null) {
+ return exchange.getContext().getTypeConverter().convertTo(String.class, exchange, bytes);
+ }
+ return new String(bytes);
}
@Converter
Added: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyConverterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyConverterTest.java?rev=1343758&view=auto
==============================================================================
--- camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyConverterTest.java (added)
+++ camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyConverterTest.java Tue May 29 14:48:45 2012
@@ -0,0 +1,60 @@
+/**
+ * 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.netty;
+
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.DynamicChannelBuffer;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Utility test to verify netty type converter.
+ */
+public class NettyConverterTest extends CamelTestSupport {
+
+ /**
+ * Test payload to send.
+ */
+ private static final String PAYLOAD = "Test Message";
+
+ private ChannelBuffer buf;
+
+ @Before
+ public void startUp() {
+ byte[] bytes = PAYLOAD.getBytes();
+ buf = new DynamicChannelBuffer(bytes.length);
+ buf.writeBytes(bytes);
+ }
+
+ @Test
+ public void testConversionWithExchange() {
+ String result = context.getTypeConverter().convertTo(String.class, new DefaultExchange(context), buf);
+ assertNotNull(result);
+ assertEquals(PAYLOAD, result);
+ }
+
+
+ @Test
+ public void testConversionWithoutExchange() {
+ String result = context.getTypeConverter().convertTo(String.class, buf);
+ assertNotNull(result);
+ assertEquals(PAYLOAD, result);
+ }
+
+}
Propchange: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyConverterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyConverterTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date