You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by jo...@apache.org on 2010/11/08 23:18:40 UTC

svn commit: r1032767 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/model/ camel-core/src/main/java/org/apache/camel/model/dataformat/ camel-core/src/main/resources/org/apache/camel/model...

Author: joed
Date: Mon Nov  8 22:18:38 2010
New Revision: 1032767

URL: http://svn.apache.org/viewvc?rev=1032767&view=rev
Log:
Camel :: Syslog  - RFC3164 compatible marshal and unmarshal of messages.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/SyslogDataFormat.java
    camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java
    camel/trunk/components/camel-netty/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
    camel/trunk/components/camel-syslog/
    camel/trunk/components/camel-syslog/pom.xml
    camel/trunk/components/camel-syslog/src/
    camel/trunk/components/camel-syslog/src/main/
    camel/trunk/components/camel-syslog/src/main/java/
    camel/trunk/components/camel-syslog/src/main/java/org/
    camel/trunk/components/camel-syslog/src/main/java/org/apache/
    camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/
    camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/
    camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/
    camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/Rfc3164SyslogConverter.java
    camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/Rfc3164SyslogDataFormat.java
    camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogConstants.java
    camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogFacility.java
    camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogMessage.java
    camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogSeverity.java
    camel/trunk/components/camel-syslog/src/main/resources/
    camel/trunk/components/camel-syslog/src/main/resources/META-INF/
    camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/
    camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/
    camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/
    camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/
    camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
    camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/dataformat/
    camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/dataformat/syslog
    camel/trunk/components/camel-syslog/src/test/
    camel/trunk/components/camel-syslog/src/test/java/
    camel/trunk/components/camel-syslog/src/test/java/org/
    camel/trunk/components/camel-syslog/src/test/java/org/apache/
    camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/
    camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/
    camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/
    camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/MinaDataFormatTest.java
    camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/MinaManyUDPMessagesTest.java
    camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyDataFormatTest.java
    camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyManyUDPMessagesTest.java
    camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogEnumsTest.java
    camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogSpringMinaTest.java
    camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogSpringNettyTest.java
    camel/trunk/components/camel-syslog/src/test/resources/
    camel/trunk/components/camel-syslog/src/test/resources/log4j.properties
    camel/trunk/components/camel-syslog/src/test/resources/org/
    camel/trunk/components/camel-syslog/src/test/resources/org/apache/
    camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/
    camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/
    camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/syslog/
    camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/syslog/applicationContext-Mina.xml
    camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/syslog/applicationContext-Netty.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
    camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
    camel/trunk/components/pom.xml

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java?rev=1032767&r1=1032766&r2=1032767&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataFormatClause.java Mon Nov  8 22:18:38 2010
@@ -18,6 +18,7 @@ package org.apache.camel.builder;
 
 import java.util.zip.Deflater;
 
+import org.apache.camel.model.dataformat.SyslogDataFormat;
 import org.w3c.dom.Node;
 
 import org.apache.camel.model.DataFormatDefinition;
@@ -266,7 +267,15 @@ public class DataFormatClause<T extends 
     }
 
     /**
-     * Return WellFormed HTML (an XML Document) either 
+     * Uses the Syslog data format
+     */
+    public T syslog() {
+        return dataFormat(new SyslogDataFormat());
+    }
+
+
+    /**
+     * Return WellFormed HTML (an XML Document) either
      * {@link java.lang.String} or {@link org.w3c.dom.Node}
      */
     public T tidyMarkup(Class<?> dataObjectType) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java?rev=1032767&r1=1032766&r2=1032767&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalDefinition.java Mon Nov  8 22:18:38 2010
@@ -36,6 +36,7 @@ import org.apache.camel.model.dataformat
 import org.apache.camel.model.dataformat.RssDataFormat;
 import org.apache.camel.model.dataformat.SerializationDataFormat;
 import org.apache.camel.model.dataformat.StringDataFormat;
+import org.apache.camel.model.dataformat.SyslogDataFormat;
 import org.apache.camel.model.dataformat.XMLBeansDataFormat;
 import org.apache.camel.model.dataformat.XMLSecurityDataFormat;
 import org.apache.camel.model.dataformat.XStreamDataFormat;
@@ -69,6 +70,7 @@ public class MarshalDefinition extends O
     @XmlElement(required = false, name = "secureXML", type = XMLSecurityDataFormat.class),
     @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
     @XmlElement(required = false, name = "string", type = StringDataFormat.class),
+    @XmlElement(required = false, name = "syslog", type = SyslogDataFormat.class),
     @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
     @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),
     @XmlElement(required = false, name = "zip", type = ZipDataFormat.class)}

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java?rev=1032767&r1=1032766&r2=1032767&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalDefinition.java Mon Nov  8 22:18:38 2010
@@ -36,6 +36,7 @@ import org.apache.camel.model.dataformat
 import org.apache.camel.model.dataformat.RssDataFormat;
 import org.apache.camel.model.dataformat.SerializationDataFormat;
 import org.apache.camel.model.dataformat.StringDataFormat;
+import org.apache.camel.model.dataformat.SyslogDataFormat;
 import org.apache.camel.model.dataformat.TidyMarkupDataFormat;
 import org.apache.camel.model.dataformat.XMLBeansDataFormat;
 import org.apache.camel.model.dataformat.XMLSecurityDataFormat;
@@ -70,6 +71,7 @@ public class UnmarshalDefinition extends
     @XmlElement(required = false, name = "secureXML", type = XMLSecurityDataFormat.class),
     @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
     @XmlElement(required = false, name = "string", type = StringDataFormat.class),
+    @XmlElement(required = false, name = "syslog", type = SyslogDataFormat.class),
     @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class),
     @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
     @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java?rev=1032767&r1=1032766&r2=1032767&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatsDefinition.java Mon Nov  8 22:18:38 2010
@@ -52,6 +52,7 @@ public class DataFormatsDefinition {
         @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
         @XmlElement(required = false, name = "soapjaxb", type = SoapJaxbDataFormat.class),
         @XmlElement(required = false, name = "string", type = StringDataFormat.class),
+        @XmlElement(required = false, name = "syslog", type = SyslogDataFormat.class),
         @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class),
         @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
         @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/SyslogDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/SyslogDataFormat.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/SyslogDataFormat.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/SyslogDataFormat.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,38 @@
+/**
+ * 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.model.dataformat;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.DataFormatDefinition;
+
+/**
+ * Represents a <a href="http://camel.apache.org/syslog.html">Syslog</a> {@link org.apache.camel.spi.DataFormat}.
+ *
+ * @version $Revision$
+ */
+@XmlRootElement(name = "syslog")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class SyslogDataFormat extends DataFormatDefinition {
+
+    public SyslogDataFormat() {
+        super("syslog");
+    }
+}

Modified: camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index?rev=1032767&r1=1032766&r2=1032767&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index (original)
+++ camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index Mon Nov  8 22:18:38 2010
@@ -30,6 +30,7 @@ ProtobufDataFormat
 RssDataFormat
 SerializationDataFormat
 StringDataFormat
+SyslogDataFormat
 TidyMarkupDataFormat
 XMLBeansDataFormat
 XStreamDataFormat

Added: 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=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java (added)
+++ camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,73 @@
+/**
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectInputStream;
+
+import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBufferInputStream;
+import org.jboss.netty.buffer.DynamicChannelBuffer;
+
+/**
+ * A set of converter methods for working with Netty types
+ *
+ * @version $Revision$
+ */
+@Converter
+public final class NettyConverter {
+
+    private NettyConverter() {
+        //Utility Class
+    }
+
+    @Converter
+    public static byte[] toByteArray(ChannelBuffer buffer) {
+        return buffer.array();
+    }
+
+    @Converter
+    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);
+    }
+
+    @Converter
+    public static InputStream toInputStream(ChannelBuffer buffer) {
+        return new ChannelBufferInputStream(buffer);
+    }
+
+    @Converter
+    public static ObjectInput toObjectInput(ChannelBuffer buffer) throws IOException {
+        InputStream is = toInputStream(buffer);
+        return new ObjectInputStream(is);
+    }
+
+    @Converter
+    public static ChannelBuffer toByteBuffer(byte[] bytes) {
+        ChannelBuffer buf = new DynamicChannelBuffer(bytes.length);
+
+        buf.writeBytes(bytes);
+        return buf;
+    }
+}

Added: camel/trunk/components/camel-netty/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-netty/src/main/resources/META-INF/services/org/apache/camel/TypeConverter (added)
+++ camel/trunk/components/camel-netty/src/main/resources/META-INF/services/org/apache/camel/TypeConverter Mon Nov  8 22:18:38 2010
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.camel.component.netty
\ No newline at end of file

Added: camel/trunk/components/camel-syslog/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/pom.xml?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/pom.xml (added)
+++ camel/trunk/components/camel-syslog/pom.xml Mon Nov  8 22:18:38 2010
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-parent</artifactId>
+        <version>2.6-SNAPSHOT</version>
+        <relativePath>../../parent</relativePath>
+    </parent>
+
+    <artifactId>camel-syslog</artifactId>
+    <packaging>bundle</packaging>
+    <name>Camel :: Syslog</name>
+    <description>Camel Syslog support</description>
+
+    <properties>
+        <camel.osgi.export.pkg>org.apache.camel.component.syslog.*</camel.osgi.export.pkg>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+
+        <!-- testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core-xml</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-spring</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-spring</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-mina</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-netty</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <!-- to allow Spring annotations (jmx) to be tested -->
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <optional>true</optional>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-aop</artifactId>
+            <optional>true</optional>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file

Added: camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/Rfc3164SyslogConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/Rfc3164SyslogConverter.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/Rfc3164SyslogConverter.java (added)
+++ camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/Rfc3164SyslogConverter.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,267 @@
+/**
+ * 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.syslog;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.Converter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class Rfc3164SyslogConverter {
+
+    private static final transient Log LOG = LogFactory.getLog(Rfc3164SyslogConverter.class);
+
+    private static enum MONTHS {
+        jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec
+    }
+
+    private final static Map<String, MONTHS> MONTH_VALUE_MAP = new HashMap<String, MONTHS>() {
+        {
+            put("jan", MONTHS.jan);
+            put("feb", MONTHS.feb);
+            put("mar", MONTHS.mar);
+            put("apr", MONTHS.apr);
+            put("may", MONTHS.may);
+            put("jun", MONTHS.jun);
+            put("jul", MONTHS.jul);
+            put("aug", MONTHS.aug);
+            put("sep", MONTHS.sep);
+            put("oct", MONTHS.oct);
+            put("nov", MONTHS.nov);
+            put("dec", MONTHS.dec);
+        }
+    };
+
+    @Converter
+    public static String toString(SyslogMessage message) {
+        StringBuilder sbr = new StringBuilder();
+        sbr.append("<");
+        if (message.getFacility() == null) {
+            message.setFacility(SyslogFacility.USER);
+        }
+        if (message.getSeverity() == null) {
+            message.setSeverity(SyslogSeverity.INFO);
+        }
+        if (message.getHostname() == null) {
+            //This is massively ugly..
+            try {
+                message.setHostname(InetAddress.getLocalHost().toString());
+            } catch (UnknownHostException e) {
+                message.setHostname("UNKNOWN_HOST");
+            }
+        }
+        sbr.append(message.getFacility().ordinal() * 8 + message.getSeverity().ordinal());
+        sbr.append(">");
+        if (message.getTimestamp() == null) {
+            message.setTimestamp(new Date());
+        }
+
+        //SDF isn't going to help much here.
+
+        Calendar cal = GregorianCalendar.getInstance();
+        cal.setTime(message.getTimestamp());
+
+        String firstLetter = MONTHS.values()[cal.get(Calendar.MONTH)].toString().substring(0, 1);  // Get first letter
+        String remainder = MONTHS.values()[cal.get(Calendar.MONTH)].toString()
+            .substring(1);    // Get remainder of word.
+        String capitalized = firstLetter.toUpperCase() + remainder.toLowerCase();
+
+        sbr.append(capitalized);
+        sbr.append(" ");
+
+        if (cal.get(Calendar.DAY_OF_MONTH) < 10) {
+            sbr.append(" ").append(cal.get(Calendar.DAY_OF_MONTH));
+        } else {
+            sbr.append(cal.get(Calendar.DAY_OF_MONTH));
+        }
+
+        sbr.append(" ");
+
+        if (cal.get(Calendar.HOUR_OF_DAY) < 10) {
+            sbr.append("0").append(cal.get(Calendar.HOUR_OF_DAY));
+        } else {
+            sbr.append(cal.get(Calendar.HOUR_OF_DAY));
+        }
+        sbr.append(":");
+
+        if (cal.get(Calendar.MINUTE) < 10) {
+            sbr.append("0").append(cal.get(Calendar.MINUTE));
+        } else {
+            sbr.append(cal.get(Calendar.MINUTE));
+        }
+        sbr.append(":");
+
+        if (cal.get(Calendar.SECOND) < 10) {
+            sbr.append("0").append(cal.get(Calendar.SECOND));
+        } else {
+            sbr.append(cal.get(Calendar.SECOND));
+        }
+        sbr.append(" ");
+
+        sbr.append(message.getHostname());
+        sbr.append(" ");
+        sbr.append(message.getLogMessage());
+        return sbr.toString();
+    }
+
+    @Converter
+    public static SyslogMessage toSyslogMessage(String body) {
+        return parseMessage(body.getBytes());
+    }
+
+    public final static SyslogMessage parseMessage(byte[] bytes) {
+        ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
+        byteBuffer.put(bytes);
+        byteBuffer.rewind();
+
+        SyslogMessage syslogMessage = new SyslogMessage();
+        Character charFound = (char) byteBuffer.get();
+
+        while (charFound != '<') {
+            //Ignore noise in beginning of message.
+            charFound = (char) byteBuffer.get();
+        }
+        char priChar = 0;
+        if (charFound == '<') {
+            int facility = 0;
+
+            while (Character.isDigit(priChar = (char) (byteBuffer.get() & 0xff))) {
+                facility *= 10;
+                facility += Character.digit(priChar, 10);
+            }
+            syslogMessage.setFacility(SyslogFacility.values()[facility >> 3]);
+            syslogMessage.setSeverity(SyslogSeverity.values()[facility & 0x07]);
+        }
+
+        if (priChar != '>') {
+            //Invalid character - this is not a well defined syslog message.
+            LOG.error("Invalid syslog message, missing a > in the Facility/Priority part");
+        }
+
+        //Done parsing severity and facility
+        //<169>Oct 22 10:52:01 TZ-6 scapegoat.dmz.example.org 10.1.2.3 sched[0]: That's All Folks!
+        //Need to parse the date.
+
+        /**
+         The TIMESTAMP field is the local time and is in the format of "Mmm dd
+         hh:mm:ss" (without the quote marks) where:
+
+         Mmm is the English language abbreviation for the month of the
+         year with the first character in uppercase and the other two
+         characters in lowercase.  The following are the only acceptable
+         values:
+
+         Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
+
+         dd is the day of the month.  If the day of the month is less
+         than 10, then it MUST be represented as a space and then the
+         number.  For example, the 7th day of August would be
+         represented as "Aug  7", with two spaces between the "g" and
+         the "7".
+
+         hh:mm:ss is the local time.  The hour (hh) is represented in a
+         24-hour format.  Valid entries are between 00 and 23,
+         inclusive.  The minute (mm) and second (ss) entries are between
+         00 and 59 inclusive.
+
+
+         */
+
+        char[] month = new char[3];
+        for (int i = 0; i < 3; i++) {
+            month[i] = (char) (byteBuffer.get() & 0xff);
+        }
+        charFound = (char) byteBuffer.get();
+        if (charFound != ' ') {
+            //Invalid Message - missing mandatory space.
+            LOG.error("Invalid syslog message, missing a mandatory space after month");
+        }
+        charFound = (char) (byteBuffer.get() & 0xff);
+
+        int day = 0;
+        if (charFound == ' ') {
+            //Extra space for the day - this is okay.
+            //Just ignored per the spec.
+        } else {
+            day *= 10;
+            day += Character.digit(charFound, 10);
+        }
+
+        while (Character.isDigit(charFound = (char) (byteBuffer.get() & 0xff))) {
+            day *= 10;
+            day += Character.digit(charFound, 10);
+        }
+
+        int hour = 0;
+        while (Character.isDigit(charFound = (char) (byteBuffer.get() & 0xff))) {
+            hour *= 10;
+            hour += Character.digit(charFound, 10);
+        }
+
+        int minute = 0;
+        while (Character.isDigit(charFound = (char) (byteBuffer.get() & 0xff))) {
+            minute *= 10;
+            minute += Character.digit(charFound, 10);
+        }
+
+        int second = 0;
+        while (Character.isDigit(charFound = (char) (byteBuffer.get() & 0xff))) {
+            second *= 10;
+            second += Character.digit(charFound, 10);
+        }
+
+        //The host is the char sequence until the next ' '
+
+        StringBuilder host = new StringBuilder();
+        while ((charFound = (char) (byteBuffer.get() & 0xff)) != ' ') {
+            host.append(charFound);
+        }
+
+        syslogMessage.setHostname(host.toString());
+
+        StringBuilder msg = new StringBuilder();
+        while (byteBuffer.hasRemaining()) {
+            charFound = (char) (byteBuffer.get() & 0xff);
+            msg.append(charFound);
+        }
+
+        Calendar calendar = new GregorianCalendar();
+        calendar.set(Calendar.MONTH, MONTH_VALUE_MAP.get((String.valueOf(month).toLowerCase())).ordinal());
+        calendar.set(Calendar.DAY_OF_MONTH, day);
+        calendar.set(Calendar.HOUR_OF_DAY, hour);
+        calendar.set(Calendar.MINUTE, minute);
+        calendar.set(Calendar.SECOND, second);
+
+        syslogMessage.setTimestamp(calendar.getTime());
+
+        syslogMessage.setLogMessage(msg.toString());
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Syslog message : " + syslogMessage.toString());
+        }
+
+        return syslogMessage;
+    }
+}

Added: camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/Rfc3164SyslogDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/Rfc3164SyslogDataFormat.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/Rfc3164SyslogDataFormat.java (added)
+++ camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/Rfc3164SyslogDataFormat.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,63 @@
+/**
+ * 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.syslog;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.util.ExchangeHelper;
+
+public class Rfc3164SyslogDataFormat implements DataFormat {
+    public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception {
+        SyslogMessage message = ExchangeHelper.convertToMandatoryType(exchange, SyslogMessage.class, body);
+        stream.write(Rfc3164SyslogConverter.toString(message).getBytes());
+    }
+
+    public Object unmarshal(Exchange exchange, InputStream inputStream) throws Exception {
+
+        String body = ExchangeHelper.convertToMandatoryType(exchange, String.class, inputStream);
+        SyslogMessage message = Rfc3164SyslogConverter.parseMessage(body.getBytes());
+
+        exchange.getOut().setHeader(SyslogConstants.SYSLOG_FACILITY, message.getFacility());
+        exchange.getOut().setHeader(SyslogConstants.SYSLOG_SEVERITY, message.getSeverity());
+        exchange.getOut().setHeader(SyslogConstants.SYSLOG_HOSTNAME, message.getHostname());
+        exchange.getOut().setHeader(SyslogConstants.SYSLOG_TIMESTAMP, message.getTimestamp());
+
+        //Since we are behind the fact of being in an Endpoint...
+        //We need to pull in the remote/local via either Mina or Netty.
+
+        if (exchange.getIn().getHeader("CamelMinaLocalAddress") != null) {
+            message.setLocalAddress(exchange.getIn().getHeader("CamelMinaLocalAddress", String.class));
+            exchange.getOut().setHeader(SyslogConstants.SYSLOG_LOCAL_ADDRESS, message.getLocalAddress());
+        }
+
+        if (exchange.getIn().getHeader("CamelMinaRemoteAddress") != null) {
+            message.setRemoteAddress(exchange.getIn().getHeader("CamelMinaRemoteAddress", String.class));
+            exchange.getOut().setHeader(SyslogConstants.SYSLOG_REMOTE_ADDRESS, message.getRemoteAddress());
+        }
+
+        if (exchange.getIn().getHeader("CamelNettyRemoteAddress") != null) {
+            message.setRemoteAddress(exchange.getIn().getHeader("CamelMinaRemoteAddress", String.class));
+            exchange.getOut().setHeader(SyslogConstants.SYSLOG_REMOTE_ADDRESS, message.getRemoteAddress());
+        }
+
+        return message;
+    }
+}

Added: camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogConstants.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogConstants.java (added)
+++ camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogConstants.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,54 @@
+/**
+ * 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.syslog;
+
+public class SyslogConstants {
+
+    /**
+     * The socket address of local machine that received the message.
+     */
+    public static final transient String SYSLOG_LOCAL_ADDRESS = "CamelSyslogLocalAddress";
+    /**
+     * The socket address of the remote machine that send the message.
+     */
+    public static final transient String SYSLOG_REMOTE_ADDRESS = "CamelSyslogRemoteAddress";
+
+    /**
+     * The Sylog message Facility
+     */
+    public static final transient String SYSLOG_FACILITY = "CamelSyslogFacility";
+
+    /**
+     * The Syslog severity
+     */
+    public static final transient String SYSLOG_SEVERITY = "CamelSyslogSeverity";
+
+    /**
+     * The hostname in the syslog message
+     */
+    public static final transient String SYSLOG_HOSTNAME = "CamelSyslogHostname";
+
+    /**
+     * The syslog timestamp
+     */
+    public static final transient String SYSLOG_TIMESTAMP = "CamelSyslogTimestamp";
+
+    private SyslogConstants() {
+        // Utility class
+    }
+}

Added: camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogFacility.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogFacility.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogFacility.java (added)
+++ camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogFacility.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,47 @@
+/**
+ * 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.syslog;
+
+public enum SyslogFacility {
+    KERN,
+    USER,
+    MAIL,
+    DAEMON,
+    AUTH,
+    SYSLOG,
+    LPR,
+    NEWS,
+    UUCP,
+    CRON,
+    AUTHPRIV,
+    FTP,
+    RESERVED_12,
+    RESERVED_13,
+    RESERVED_14,
+    RESERVED_15,
+    LOCAL0,
+    LOCAL1,
+    LOCAL2,
+    LOCAL3,
+    LOCAL4,
+    LOCAL5,
+    LOCAL6,
+    LOCAL7,;
+
+}
+

Added: camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogMessage.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogMessage.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogMessage.java (added)
+++ camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogMessage.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,93 @@
+/**
+ * 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.syslog;
+
+import java.util.Date;
+
+public class SyslogMessage {
+
+    private SyslogFacility facility;
+    private SyslogSeverity severity;
+    private String remoteAddress;
+    private String localAddress;
+    private String hostname;
+    private String logMessage;
+
+    private Date timestamp;
+
+    public String getLogMessage() {
+        return logMessage;
+    }
+
+    public void setLogMessage(String logMessage) {
+        this.logMessage = logMessage;
+    }
+
+    public String getLocalAddress() {
+        return localAddress;
+    }
+
+    public void setLocalAddress(String localAddress) {
+        this.localAddress = localAddress;
+    }
+
+    public SyslogFacility getFacility() {
+        return facility;
+    }
+
+    public void setFacility(SyslogFacility facility) {
+        this.facility = facility;
+    }
+
+    public Date getTimestamp() {
+        return timestamp;
+    }
+
+    public void setTimestamp(Date timestamp) {
+        this.timestamp = timestamp;
+    }
+
+    public SyslogSeverity getSeverity() {
+        return severity;
+    }
+
+    public void setSeverity(SyslogSeverity severity) {
+        this.severity = severity;
+    }
+
+    public String getRemoteAddress() {
+        return remoteAddress;
+    }
+
+    public void setRemoteAddress(String remoteAddress) {
+        this.remoteAddress = remoteAddress;
+    }
+
+    public String getHostname() {
+        return hostname;
+    }
+
+    public void setHostname(String hostname) {
+        this.hostname = hostname;
+    }
+
+    @Override
+    public String toString() {
+        return "SyslogMessage{" + "content='" + logMessage + '\'' + ", facility=" + facility + ", severity=" + severity + ", remoteAddress='" + remoteAddress + '\'' + ", localAddress='" + localAddress + '\'' + ", hostname='" + hostname + '\'' + ", messageTime=" + timestamp + '}';
+    }
+}

Added: camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogSeverity.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogSeverity.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogSeverity.java (added)
+++ camel/trunk/components/camel-syslog/src/main/java/org/apache/camel/component/syslog/SyslogSeverity.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,29 @@
+/**
+ * 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.syslog;
+
+public enum SyslogSeverity {
+    EMERG,
+    ALERT,
+    CRIT,
+    ERR,
+    WARNING,
+    NOTICE,
+    INFO,
+    DEBUG,;
+}

Added: camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/TypeConverter?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/TypeConverter (added)
+++ camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/TypeConverter Mon Nov  8 22:18:38 2010
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.camel.component.syslog
\ No newline at end of file

Added: camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/dataformat/syslog
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/dataformat/syslog?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/dataformat/syslog (added)
+++ camel/trunk/components/camel-syslog/src/main/resources/META-INF/services/org/apache/camel/dataformat/syslog Mon Nov  8 22:18:38 2010
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.syslog.Rfc3164SyslogDataFormat
\ No newline at end of file

Added: camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/MinaDataFormatTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/MinaDataFormatTest.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/MinaDataFormatTest.java (added)
+++ camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/MinaDataFormatTest.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,87 @@
+/**
+ * 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.syslog;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+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.spi.DataFormat;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class MinaDataFormatTest extends CamelTestSupport {
+
+    private final int serverPort = 10514;
+    private final int messageCount = 1;
+    private final String message = "<165>Aug  4 05:34:00 mymachine myproc[10]: %% It's\n         time to make the do-nuts.  %%  Ingredients: Mix=OK, Jelly=OK #\n" + "         Devices: Mixer=OK, Jelly_Injector=OK, Frier=OK # Transport:\n" + "         Conveyer1=OK, Conveyer2=OK # %%";
+
+    @Test
+    public void testSendingRawUDP() throws IOException, InterruptedException {
+
+        MockEndpoint mock = getMockEndpoint("mock:syslogReceiver");
+        MockEndpoint mock2 = getMockEndpoint("mock:syslogReceiver2");
+        mock.expectedMessageCount(1);
+        mock2.expectedMessageCount(1);
+        mock2.expectedBodiesReceived(message);
+        DatagramSocket ds = new DatagramSocket();
+
+        DatagramSocket socket = new DatagramSocket();
+        try {
+            InetAddress address = InetAddress.getByName("127.0.0.1");
+            for (int i = 0; i < messageCount; i++) {
+
+                byte[] data = message.getBytes();
+
+                DatagramPacket packet = new DatagramPacket(data, data.length, address, serverPort);
+                socket.send(packet);
+                Thread.sleep(100);
+            }
+        } finally {
+            socket.close();
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+
+                //context.setTracing(true);
+                DataFormat syslogDataFormat = new Rfc3164SyslogDataFormat();
+
+                // we setup a Syslog  listener on a random port.
+                from("mina:udp://127.0.0.1:" + serverPort)
+
+                    .unmarshal(syslogDataFormat).process(new Processor() {
+                    public void process(Exchange ex) {
+                        assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
+                    }
+                }).to("mock:syslogReceiver").
+                    marshal(syslogDataFormat).to("mock:syslogReceiver2");
+            }
+        };
+    }
+}

Added: camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/MinaManyUDPMessagesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/MinaManyUDPMessagesTest.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/MinaManyUDPMessagesTest.java (added)
+++ camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/MinaManyUDPMessagesTest.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,83 @@
+/**
+ * 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.syslog;
+
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+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.spi.DataFormat;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class MinaManyUDPMessagesTest extends CamelTestSupport {
+
+    private final int serverPort = 10514;
+    private final int messageCount = 100;
+    private final String message = "<165>Aug  4 05:34:00 mymachine myproc[10]: %% It's\n         time to make the do-nuts.  %%  Ingredients: Mix=OK, Jelly=OK #\n" + "         Devices: Mixer=OK, Jelly_Injector=OK, Frier=OK # Transport:\n" + "         Conveyer1=OK, Conveyer2=OK # %%";
+
+    @Test
+    public void testSendingManyMessages() throws Exception, InterruptedException {
+        MockEndpoint stop1 = getMockEndpoint("mock:stop1");
+        MockEndpoint stop2 = getMockEndpoint("mock:stop2");
+        stop2.expectedMessageCount(messageCount);
+        stop1.expectedMessageCount(messageCount);
+
+        DatagramSocket socket = new DatagramSocket();
+        try {
+            InetAddress address = InetAddress.getByName("127.0.0.1");
+            for (int i = 0; i < messageCount; i++) {
+
+                byte[] data = message.getBytes();
+
+                DatagramPacket packet = new DatagramPacket(data, data.length, address, serverPort);
+                socket.send(packet);
+                Thread.sleep(100);
+            }
+        } finally {
+            socket.close();
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+
+                //context.setTracing(true);
+                DataFormat syslogDataFormat = new Rfc3164SyslogDataFormat();
+
+                // we setup a Syslog  listener on a random port.
+                from("mina:udp://127.0.0.1:" + serverPort)
+
+                    .unmarshal(syslogDataFormat).process(new Processor() {
+                    public void process(Exchange ex) {
+                        assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
+                    }
+                }).to("mock:stop1").
+                    marshal(syslogDataFormat).to("mock:stop2");
+            }
+        };
+    }
+}

Added: camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyDataFormatTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyDataFormatTest.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyDataFormatTest.java (added)
+++ camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyDataFormatTest.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,87 @@
+/**
+ * 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.syslog;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+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.spi.DataFormat;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class NettyDataFormatTest extends CamelTestSupport {
+
+    private final int serverPort = 10514;
+    private final int messageCount = 1;
+    private final String message = "<165>Aug  4 05:34:00 mymachine myproc[10]: %% It's\n         time to make the do-nuts.  %%  Ingredients: Mix=OK, Jelly=OK #\n" + "         Devices: Mixer=OK, Jelly_Injector=OK, Frier=OK # Transport:\n" + "         Conveyer1=OK, Conveyer2=OK # %%";
+
+    @Test
+    public void testSendingRawUDP() throws IOException, InterruptedException {
+
+        MockEndpoint mock = getMockEndpoint("mock:syslogReceiver");
+        MockEndpoint mock2 = getMockEndpoint("mock:syslogReceiver2");
+        mock.expectedMessageCount(1);
+        mock2.expectedMessageCount(1);
+        mock2.expectedBodiesReceived(message);
+        DatagramSocket ds = new DatagramSocket();
+
+        DatagramSocket socket = new DatagramSocket();
+        try {
+            InetAddress address = InetAddress.getByName("127.0.0.1");
+            for (int i = 0; i < messageCount; i++) {
+
+                byte[] data = message.getBytes();
+
+                DatagramPacket packet = new DatagramPacket(data, data.length, address, serverPort);
+                socket.send(packet);
+                Thread.sleep(100);
+            }
+        } finally {
+            socket.close();
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+
+                context.setTracing(true);
+                DataFormat syslogDataFormat = new Rfc3164SyslogDataFormat();
+
+                // we setup a Syslog  listener on a random port.
+                from("netty:udp://127.0.0.1:" + serverPort + "?sync=false&allowDefaultCodec=false")
+
+                    .unmarshal(syslogDataFormat).process(new Processor() {
+                    public void process(Exchange ex) {
+                        assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
+                    }
+                }).to("mock:syslogReceiver").
+                    marshal(syslogDataFormat).to("mock:syslogReceiver2");
+            }
+        };
+    }
+}

Added: camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyManyUDPMessagesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyManyUDPMessagesTest.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyManyUDPMessagesTest.java (added)
+++ camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/NettyManyUDPMessagesTest.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,83 @@
+/**
+ * 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.syslog;
+
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+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.spi.DataFormat;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class NettyManyUDPMessagesTest extends CamelTestSupport {
+
+    private final int serverPort = 10514;
+    private final int messageCount = 100;
+    private final String message = "<165>Aug  4 05:34:00 mymachine myproc[10]: %% It's\n         time to make the do-nuts.  %%  Ingredients: Mix=OK, Jelly=OK #\n" + "         Devices: Mixer=OK, Jelly_Injector=OK, Frier=OK # Transport:\n" + "         Conveyer1=OK, Conveyer2=OK # %%";
+
+    @Test
+    public void testSendingManyMessages() throws Exception, InterruptedException {
+        MockEndpoint stop1 = getMockEndpoint("mock:stop1");
+        MockEndpoint stop2 = getMockEndpoint("mock:stop2");
+        stop2.expectedMessageCount(messageCount);
+        stop1.expectedMessageCount(messageCount);
+
+        DatagramSocket socket = new DatagramSocket();
+        try {
+            InetAddress address = InetAddress.getByName("127.0.0.1");
+            for (int i = 0; i < messageCount; i++) {
+
+                byte[] data = message.getBytes();
+
+                DatagramPacket packet = new DatagramPacket(data, data.length, address, serverPort);
+                socket.send(packet);
+                Thread.sleep(100);
+            }
+        } finally {
+            socket.close();
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+
+                //context.setTracing(true);
+                DataFormat syslogDataFormat = new Rfc3164SyslogDataFormat();
+
+                // we setup a Syslog  listener on a random port.
+                from("netty:udp://127.0.0.1:" + serverPort + "?sync=false&allowDefaultCodec=false")
+
+                    .unmarshal(syslogDataFormat).process(new Processor() {
+                    public void process(Exchange ex) {
+                        assertTrue(ex.getIn().getBody() instanceof SyslogMessage);
+                    }
+                }).to("mock:stop1").
+                    marshal(syslogDataFormat).to("mock:stop2");
+            }
+        };
+    }
+}

Added: camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogEnumsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogEnumsTest.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogEnumsTest.java (added)
+++ camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogEnumsTest.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,62 @@
+/**
+ * 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.syslog;
+
+import junit.framework.TestCase;
+import org.junit.Test;
+
+public class SyslogEnumsTest extends TestCase {
+
+    @Test
+    public void testFacilityConstants() {
+
+        assertEquals("KERN", SyslogFacility.values()[(0 >> 3)].name());
+        assertEquals("USER", SyslogFacility.values()[((1 >> 3 / 8))].name());
+        assertEquals("MAIL", SyslogFacility.values()[((2 >> 3 / 8))].name());
+        assertEquals("DAEMON", SyslogFacility.values()[((3 >> 3 / 8))].name());
+        assertEquals("AUTH", SyslogFacility.values()[((4 >> 3 / 8))].name());
+        assertEquals("SYSLOG", SyslogFacility.values()[((5 >> 3 / 8))].name());
+        assertEquals("LPR", SyslogFacility.values()[(((6 >> 3 / 8)))].name());
+        assertEquals("NEWS", SyslogFacility.values()[(((7 >> 3 / 8)))].name());
+        assertEquals("UUCP", SyslogFacility.values()[(((8 >> 3 / 8)))].name());
+        assertEquals("CRON", SyslogFacility.values()[(((9 >> 3 / 8)))].name());
+        assertEquals("AUTHPRIV", SyslogFacility.values()[((10 >> 3 / 8))].name());
+        assertEquals("FTP", SyslogFacility.values()[((11 >> 3 / 8))].name());
+        /**
+         RESERVED_12,
+         RESERVED_13,
+         RESERVED_14,
+         RESERVED_15,
+         */
+        assertEquals("LOCAL0", SyslogFacility.values()[((16 >> 3 / 8))].name());
+        assertEquals("LOCAL1", SyslogFacility.values()[((17 >> 3 / 8))].name());
+        assertEquals("LOCAL2", SyslogFacility.values()[((18 >> 3 / 8))].name());
+        assertEquals("LOCAL3", SyslogFacility.values()[((19 >> 3 / 8))].name());
+        assertEquals("LOCAL4", SyslogFacility.values()[((20 >> 3 / 8))].name());
+        assertEquals("LOCAL5", SyslogFacility.values()[((21 >> 3 / 8))].name());
+        assertEquals("LOCAL6", SyslogFacility.values()[((22 >> 3 / 8))].name());
+        assertEquals("LOCAL7", SyslogFacility.values()[((23 >> 3 / 8))].name());
+    }
+
+    @Test
+    public void testSeverity() {
+        assertEquals("EMERG", SyslogSeverity.values()[0 & 0x07].name());
+        assertEquals("ALERT", SyslogSeverity.values()[1 & 0x07].name());
+        assertEquals("DEBUG", SyslogSeverity.values()[7 & 0x07].name());
+    }
+}

Added: camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogSpringMinaTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogSpringMinaTest.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogSpringMinaTest.java (added)
+++ camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogSpringMinaTest.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,69 @@
+/**
+ * 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.syslog;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SyslogSpringMinaTest extends CamelSpringTestSupport {
+
+    private final int serverPort = 10514;
+    private final int messageCount = 1;
+    private final String message = "<165>Aug  4 05:34:00 mymachine myproc[10]: %% It's\n         time to make the do-nuts.  %%  Ingredients: Mix=OK, Jelly=OK #\n" + "         Devices: Mixer=OK, Jelly_Injector=OK, Frier=OK # Transport:\n" + "         Conveyer1=OK, Conveyer2=OK # %%";
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/syslog/applicationContext-Mina.xml");
+    }
+
+    @Test
+    public void testSendingRawUDP() throws IOException, InterruptedException {
+
+        MockEndpoint mock = getMockEndpoint("mock:stop1");
+        MockEndpoint mock2 = getMockEndpoint("mock:stop2");
+        mock.expectedMessageCount(1);
+        mock2.expectedMessageCount(1);
+        mock2.expectedBodiesReceived(message);
+        DatagramSocket ds = new DatagramSocket();
+
+        DatagramSocket socket = new DatagramSocket();
+        try {
+            InetAddress address = InetAddress.getByName("127.0.0.1");
+            for (int i = 0; i < messageCount; i++) {
+
+                byte[] data = message.getBytes();
+
+                DatagramPacket packet = new DatagramPacket(data, data.length, address, serverPort);
+                socket.send(packet);
+                Thread.sleep(100);
+            }
+        } finally {
+            socket.close();
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+}

Added: camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogSpringNettyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogSpringNettyTest.java?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogSpringNettyTest.java (added)
+++ camel/trunk/components/camel-syslog/src/test/java/org/apache/camel/component/syslog/SyslogSpringNettyTest.java Mon Nov  8 22:18:38 2010
@@ -0,0 +1,68 @@
+/**
+ * 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.syslog;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SyslogSpringNettyTest extends CamelSpringTestSupport {
+    private final int serverPort = 10514;
+    private final int messageCount = 1;
+    private final String message = "<165>Aug  4 05:34:00 mymachine myproc[10]: %% It's\n         time to make the do-nuts.  %%  Ingredients: Mix=OK, Jelly=OK #\n" + "         Devices: Mixer=OK, Jelly_Injector=OK, Frier=OK # Transport:\n" + "         Conveyer1=OK, Conveyer2=OK # %%";
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/syslog/applicationContext-Netty.xml");
+    }
+
+    @Test
+    public void testSendingRawUDP() throws IOException, InterruptedException {
+
+        MockEndpoint mock = getMockEndpoint("mock:stop1");
+        MockEndpoint mock2 = getMockEndpoint("mock:stop2");
+        mock.expectedMessageCount(1);
+        mock2.expectedMessageCount(1);
+        mock2.expectedBodiesReceived(message);
+        DatagramSocket ds = new DatagramSocket();
+
+        DatagramSocket socket = new DatagramSocket();
+        try {
+            InetAddress address = InetAddress.getByName("127.0.0.1");
+            for (int i = 0; i < messageCount; i++) {
+
+                byte[] data = message.getBytes();
+
+                DatagramPacket packet = new DatagramPacket(data, data.length, address, serverPort);
+                socket.send(packet);
+                Thread.sleep(100);
+            }
+        } finally {
+            socket.close();
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+}

Added: camel/trunk/components/camel-syslog/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/test/resources/log4j.properties?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/test/resources/log4j.properties (added)
+++ camel/trunk/components/camel-syslog/src/test/resources/log4j.properties Mon Nov  8 22:18:38 2010
@@ -0,0 +1,35 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=INFO, file
+
+# CONSOLE appender not used by default
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d %-5p %c{1} - %m %n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d %-5p %c{1} - %m %n
+log4j.appender.file.file=target/camel-syslog-test.log
+
+# debug loging for Camel
+log4j.logger.org.apache.camel.component.syslog=DEBUG

Added: camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/syslog/applicationContext-Mina.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/syslog/applicationContext-Mina.xml?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/syslog/applicationContext-Mina.xml (added)
+++ camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/syslog/applicationContext-Mina.xml Mon Nov  8 22:18:38 2010
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+    <bean id="myMinaFactory" class="org.apache.camel.component.mina.MinaComponent">
+        <!-- we must provide a camel context so we refer to it by its id -->
+        <constructor-arg index="0" ref="myCamel"/>
+    </bean>
+
+    <bean id="minaSyslog"
+          factory-bean="myMinaFactory"
+          factory-method="createEndpoint">
+        <!-- and here we can pass it our configuration -->
+        <constructor-arg index="0" ref="minaSyslogConfig"/>
+    </bean>
+
+    <!-- this is our mina configuration with plain properties -->
+    <bean id="minaSyslogConfig" class="org.apache.camel.component.mina.MinaConfiguration">
+        <property name="protocol" value="udp"/>
+        <property name="host" value="localhost"/>
+        <property name="port" value="10514"/>
+        <property name="sync" value="false"/>
+    </bean>
+
+    <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
+
+        <dataFormats>
+            <syslog id="mySyslog"/>
+        </dataFormats>
+
+        <route>
+            <from ref="minaSyslog"/>
+            <unmarshal ref="mySyslog"/>
+            <to uri="mock:stop1"/>
+            <marshal ref="mySyslog"/>
+            <to uri="mock:stop2"/>
+        </route>
+
+    </camelContext>
+
+</beans>

Added: camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/syslog/applicationContext-Netty.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/syslog/applicationContext-Netty.xml?rev=1032767&view=auto
==============================================================================
--- camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/syslog/applicationContext-Netty.xml (added)
+++ camel/trunk/components/camel-syslog/src/test/resources/org/apache/camel/component/syslog/applicationContext-Netty.xml Mon Nov  8 22:18:38 2010
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+
+    <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring">
+
+        <dataFormats>
+            <syslog id="mySyslog"/>
+        </dataFormats>
+
+        <route>
+            <from uri="netty:udp://localhost:10514?sync=false&amp;allowDefaultCodec=false"/>
+            <unmarshal ref="mySyslog"/>
+            <to uri="mock:stop1"/>
+            <marshal ref="mySyslog"/>
+            <to uri="mock:stop2"/>
+        </route>
+
+    </camelContext>
+
+</beans>

Modified: camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/pom.xml?rev=1032767&r1=1032766&r2=1032767&view=diff
==============================================================================
--- camel/trunk/components/pom.xml (original)
+++ camel/trunk/components/pom.xml Mon Nov  8 22:18:38 2010
@@ -110,6 +110,7 @@
     <module>camel-sql</module>
     <module>camel-stringtemplate</module>
     <module>camel-stream</module>
+    <module>camel-syslog</module>
     <module>camel-tagsoup</module>
     <module>camel-test</module>
     <module>camel-velocity</module>