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 2014/09/07 09:22:47 UTC
[2/6] git commit: Used wrong rfc number
Used wrong rfc number
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c3663ef6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c3663ef6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c3663ef6
Branch: refs/heads/master
Commit: c3663ef6e665daf9595bc35e7b8a532f6a71eaf5
Parents: 372ab5b
Author: svenrienstra <sv...@topicus.nl>
Authored: Fri May 30 11:31:57 2014 +0200
Committer: svenrienstra <sv...@topicus.nl>
Committed: Fri May 30 11:31:57 2014 +0200
----------------------------------------------------------------------
.../component/syslog/netty/Rfc5425Encoder.java | 38 +++++++
.../syslog/netty/Rfc5425FrameDecoder.java | 100 +++++++++++++++++++
.../component/syslog/netty/Rfc5426Encoder.java | 38 -------
.../syslog/netty/Rfc5426FrameDecoder.java | 100 -------------------
.../syslog/NettyRfc5426LongMessageTest.java | 10 +-
.../component/syslog/NettyRfc5426Test.java | 10 +-
6 files changed, 148 insertions(+), 148 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c3663ef6/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5425Encoder.java
----------------------------------------------------------------------
diff --git a/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5425Encoder.java b/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5425Encoder.java
new file mode 100644
index 0000000..d353725
--- /dev/null
+++ b/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5425Encoder.java
@@ -0,0 +1,38 @@
+/**
+ *
+ */
+package org.apache.camel.component.syslog.netty;
+
+import static org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer;
+
+import java.nio.charset.Charset;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandler.Sharable;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
+
+/**
+ * @author svenrienstra
+ */
+@Sharable
+public class Rfc5425Encoder extends OneToOneEncoder {
+
+ @Override
+ protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
+ if (!(msg instanceof ChannelBuffer)) {
+ return msg;
+ }
+
+ ChannelBuffer src = (ChannelBuffer)msg;
+ int length = src.readableBytes();
+
+ String headerString = length + " ";
+
+ ChannelBuffer header = channel.getConfig().getBufferFactory().getBuffer(src.order(), headerString.getBytes(Charset.forName("UTF8")).length);
+ header.writeBytes(headerString.getBytes(Charset.forName("UTF8")));
+
+ return wrappedBuffer(header, src);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c3663ef6/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5425FrameDecoder.java
----------------------------------------------------------------------
diff --git a/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5425FrameDecoder.java b/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5425FrameDecoder.java
new file mode 100644
index 0000000..3c7a67a
--- /dev/null
+++ b/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5425FrameDecoder.java
@@ -0,0 +1,100 @@
+/**
+ *
+ */
+package org.apache.camel.component.syslog.netty;
+
+import org.apache.camel.component.netty.ChannelHandlerFactory;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandler;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.handler.codec.frame.FrameDecoder;
+
+/**
+ * @author svenrienstra
+ */
+public class Rfc5425FrameDecoder extends FrameDecoder implements ChannelHandlerFactory {
+
+ private Integer currentFramelength;
+
+ /**
+ * @see org.jboss.netty.handler.codec.frame.FrameDecoder#decode(org.jboss.netty.channel.ChannelHandlerContext,
+ * org.jboss.netty.channel.Channel,
+ * org.jboss.netty.buffer.ChannelBuffer)
+ */
+ @Override
+ protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
+ if (currentFramelength == null) {
+ // find index of the first space, it should be after the length
+ // field
+ int index = indexOf(buffer, ChannelBuffers.wrappedBuffer(new byte[] {' '}));
+
+ // Read part until the first space, if we have found one
+ StringBuffer lengthbuffer = new StringBuffer();
+ if (index > -1) {
+ lengthbuffer.append(new String(buffer.readBytes(index).array()));
+ }
+
+ int length;
+ try {
+ // add one because we have to take in account the space after
+ // the length field
+ length = Integer.parseInt(lengthbuffer.toString()) + 1;
+ } catch (NumberFormatException e) {
+ length = -1;
+ }
+
+ // We have not found the length field, reset the buffer so we can
+ // retry next time
+ if (length < 0) {
+ buffer.resetReaderIndex();
+ return null;
+ }
+ currentFramelength = length;
+ }
+
+ // Buffer does not contain enough data yet, wait until it does
+ if (buffer.readableBytes() < currentFramelength) {
+ return null;
+ }
+
+ // read the message
+ int lengthToRead = currentFramelength;
+ currentFramelength = null;
+ return buffer.readBytes(lengthToRead);
+ }
+
+ /**
+ * Borrowed from the DelimiterBasedFrameDecoder Returns the number of bytes
+ * between the readerIndex of the haystack and the first needle found in the
+ * haystack. -1 is returned if no needle is found in the haystack.
+ */
+ private static int indexOf(ChannelBuffer haystack, ChannelBuffer needle) {
+ for (int i = haystack.readerIndex(); i < haystack.writerIndex(); i++) {
+ int haystackIndex = i;
+ int needleIndex;
+ for (needleIndex = 0; needleIndex < needle.capacity(); needleIndex++) {
+ if (haystack.getByte(haystackIndex) != needle.getByte(needleIndex)) {
+ break;
+ } else {
+ haystackIndex++;
+ if (haystackIndex == haystack.writerIndex() && needleIndex != needle.capacity() - 1) {
+ return -1;
+ }
+ }
+ }
+
+ if (needleIndex == needle.capacity()) {
+ // Found the needle from the haystack!
+ return i - haystack.readerIndex();
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public ChannelHandler newChannelHandler() {
+ return new Rfc5425FrameDecoder();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c3663ef6/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5426Encoder.java
----------------------------------------------------------------------
diff --git a/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5426Encoder.java b/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5426Encoder.java
deleted file mode 100644
index 7dce437..0000000
--- a/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5426Encoder.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- *
- */
-package org.apache.camel.component.syslog.netty;
-
-import static org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer;
-
-import java.nio.charset.Charset;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandler.Sharable;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
-
-/**
- * @author svenrienstra
- */
-@Sharable
-public class Rfc5426Encoder extends OneToOneEncoder {
-
- @Override
- protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
- if (!(msg instanceof ChannelBuffer)) {
- return msg;
- }
-
- ChannelBuffer src = (ChannelBuffer)msg;
- int length = src.readableBytes();
-
- String headerString = length + " ";
-
- ChannelBuffer header = channel.getConfig().getBufferFactory().getBuffer(src.order(), headerString.getBytes(Charset.forName("UTF8")).length);
- header.writeBytes(headerString.getBytes(Charset.forName("UTF8")));
-
- return wrappedBuffer(header, src);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c3663ef6/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5426FrameDecoder.java
----------------------------------------------------------------------
diff --git a/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5426FrameDecoder.java b/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5426FrameDecoder.java
deleted file mode 100644
index e3bbf10..0000000
--- a/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/netty/Rfc5426FrameDecoder.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/**
- *
- */
-package org.apache.camel.component.syslog.netty;
-
-import org.apache.camel.component.netty.ChannelHandlerFactory;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandler;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-/**
- * @author svenrienstra
- */
-public class Rfc5426FrameDecoder extends FrameDecoder implements ChannelHandlerFactory {
-
- private Integer currentFramelength;
-
- /**
- * @see org.jboss.netty.handler.codec.frame.FrameDecoder#decode(org.jboss.netty.channel.ChannelHandlerContext,
- * org.jboss.netty.channel.Channel,
- * org.jboss.netty.buffer.ChannelBuffer)
- */
- @Override
- protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
- if (currentFramelength == null) {
- // find index of the first space, it should be after the length
- // field
- int index = indexOf(buffer, ChannelBuffers.wrappedBuffer(new byte[] {' '}));
-
- // Read part until the first space, if we have found one
- StringBuffer lengthbuffer = new StringBuffer();
- if (index > -1) {
- lengthbuffer.append(new String(buffer.readBytes(index).array()));
- }
-
- int length;
- try {
- // add one because we have to take in account the space after
- // the length field
- length = Integer.parseInt(lengthbuffer.toString()) + 1;
- } catch (NumberFormatException e) {
- length = -1;
- }
-
- // We have not found the length field, reset the buffer so we can
- // retry next time
- if (length < 0) {
- buffer.resetReaderIndex();
- return null;
- }
- currentFramelength = length;
- }
-
- // Buffer does not contain enough data yet, wait until it does
- if (buffer.readableBytes() < currentFramelength) {
- return null;
- }
-
- // read the message
- int lengthToRead = currentFramelength;
- currentFramelength = null;
- return buffer.readBytes(lengthToRead);
- }
-
- /**
- * Borrowed from the DelimiterBasedFrameDecoder Returns the number of bytes
- * between the readerIndex of the haystack and the first needle found in the
- * haystack. -1 is returned if no needle is found in the haystack.
- */
- private static int indexOf(ChannelBuffer haystack, ChannelBuffer needle) {
- for (int i = haystack.readerIndex(); i < haystack.writerIndex(); i++) {
- int haystackIndex = i;
- int needleIndex;
- for (needleIndex = 0; needleIndex < needle.capacity(); needleIndex++) {
- if (haystack.getByte(haystackIndex) != needle.getByte(needleIndex)) {
- break;
- } else {
- haystackIndex++;
- if (haystackIndex == haystack.writerIndex() && needleIndex != needle.capacity() - 1) {
- return -1;
- }
- }
- }
-
- if (needleIndex == needle.capacity()) {
- // Found the needle from the haystack!
- return i - haystack.readerIndex();
- }
- }
- return -1;
- }
-
- @Override
- public ChannelHandler newChannelHandler() {
- return new Rfc5426FrameDecoder();
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c3663ef6/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyRfc5426LongMessageTest.java
----------------------------------------------------------------------
diff --git a/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyRfc5426LongMessageTest.java b/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyRfc5426LongMessageTest.java
index 5f029a3..859efdd 100644
--- a/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyRfc5426LongMessageTest.java
+++ b/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyRfc5426LongMessageTest.java
@@ -21,8 +21,8 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.component.syslog.netty.Rfc5426Encoder;
-import org.apache.camel.component.syslog.netty.Rfc5426FrameDecoder;
+import org.apache.camel.component.syslog.netty.Rfc5425Encoder;
+import org.apache.camel.component.syslog.netty.Rfc5425FrameDecoder;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.test.AvailablePortFinder;
@@ -46,8 +46,8 @@ public class NettyRfc5426LongMessageTest extends CamelTestSupport {
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();
- jndi.bind("decoder", new Rfc5426FrameDecoder());
- jndi.bind("encoder", new Rfc5426Encoder());
+ jndi.bind("decoder", new Rfc5425FrameDecoder());
+ jndi.bind("encoder", new Rfc5425Encoder());
return jndi;
}
@@ -67,7 +67,7 @@ public class NettyRfc5426LongMessageTest extends CamelTestSupport {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
- context().getRegistry(JndiRegistry.class).bind("rfc5426FrameDecoder", new Rfc5426FrameDecoder());
+ context().getRegistry(JndiRegistry.class).bind("rfc5426FrameDecoder", new Rfc5425FrameDecoder());
return new RouteBuilder() {
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/c3663ef6/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyRfc5426Test.java
----------------------------------------------------------------------
diff --git a/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyRfc5426Test.java b/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyRfc5426Test.java
index 179988c..22b22bd 100644
--- a/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyRfc5426Test.java
+++ b/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyRfc5426Test.java
@@ -21,8 +21,8 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.component.syslog.netty.Rfc5426Encoder;
-import org.apache.camel.component.syslog.netty.Rfc5426FrameDecoder;
+import org.apache.camel.component.syslog.netty.Rfc5425Encoder;
+import org.apache.camel.component.syslog.netty.Rfc5425FrameDecoder;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.test.AvailablePortFinder;
@@ -48,8 +48,8 @@ public class NettyRfc5426Test extends CamelTestSupport {
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();
- jndi.bind("decoder", new Rfc5426FrameDecoder());
- jndi.bind("encoder", new Rfc5426Encoder());
+ jndi.bind("decoder", new Rfc5425FrameDecoder());
+ jndi.bind("encoder", new Rfc5425Encoder());
return jndi;
}
@@ -70,7 +70,7 @@ public class NettyRfc5426Test extends CamelTestSupport {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
- context().getRegistry(JndiRegistry.class).bind("rfc5426FrameDecoder", new Rfc5426FrameDecoder());
+ context().getRegistry(JndiRegistry.class).bind("rfc5426FrameDecoder", new Rfc5425FrameDecoder());
return new RouteBuilder() {
@Override