[jboss-svn-commits] JBL Code SVN: r24232 - in labs/jbossesb/workspace/sandbox: iplistener and 20 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Dec 4 04:32:32 EST 2008


Author: tfennelly
Date: 2008-12-04 04:32:32 -0500 (Thu, 04 Dec 2008)
New Revision: 24232

Added:
   labs/jbossesb/workspace/sandbox/iplistener/
   labs/jbossesb/workspace/sandbox/iplistener/lib/
   labs/jbossesb/workspace/sandbox/iplistener/lib/test-util.jar
   labs/jbossesb/workspace/sandbox/iplistener/pom.xml
   labs/jbossesb/workspace/sandbox/iplistener/src/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/ActionPipelineDispatcher.java
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/DefaultMessageHandler.java
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/MessageDispatcher.java
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/MessageHandler.java
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/UDPListener.java
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/soa/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/soa/esb/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/soa/esb/listeners/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/soa/esb/listeners/gateway/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/soa/esb/listeners/gateway/scripts/
   labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/soa/esb/listeners/gateway/scripts/UDPListener.groovy
   labs/jbossesb/workspace/sandbox/iplistener/src/main/resources/
   labs/jbossesb/workspace/sandbox/iplistener/src/test/
   labs/jbossesb/workspace/sandbox/iplistener/src/test/java/
   labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/
   labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/
   labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/
   labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/iplistener/
   labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/iplistener/UDPListenerTest.java
   labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/iplistener/jboss-esb.xml
   labs/jbossesb/workspace/sandbox/iplistener/src/test/resources/
   labs/jbossesb/workspace/sandbox/iplistener/src/test/resources/log4j.xml
Log:
IP listener

Added: labs/jbossesb/workspace/sandbox/iplistener/lib/test-util.jar
===================================================================
(Binary files differ)


Property changes on: labs/jbossesb/workspace/sandbox/iplistener/lib/test-util.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/jbossesb/workspace/sandbox/iplistener/pom.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/iplistener/pom.xml	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/iplistener/pom.xml	2008-12-04 09:32:32 UTC (rev 24232)
@@ -0,0 +1,193 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+    <name>IP Listener</name>
+    <groupId>org.jboss.jbossesb</groupId>
+    <artifactId>iplistener</artifactId>
+    <version>1.0</version>
+
+    <!-- ===================================================================================================
+             Need to set the "soaserver.home" in the following <properties> section.  Set this to the
+             home dir of your local SOA Server (get this from the CSP).
+         =================================================================================================== -->
+
+    <properties>
+        <soaserver.home>H:/Jboss/ESB/branches/JBESB_4_4_SOA_4_3_GA/product/build/soa-server-4.3.0</soaserver.home>
+        <jbossesb.version>SOA_4_3_GA</jbossesb.version>
+        <jbossesb.lib>${soaserver.home}/server/default/deploy/jbossesb.sar/lib</jbossesb.lib>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.mina</groupId>
+            <artifactId>mina-core</artifactId>
+            <version>1.1.7</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.mina</groupId>
+            <artifactId>mina-filter-ssl</artifactId>
+            <version>1.1.7</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.codehaus.groovy</groupId>
+            <artifactId>groovy-all</artifactId>
+            <version>1.5.0</version>
+        </dependency>
+
+        <dependency>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-api</artifactId>
+          <version>1.4.3</version>
+        </dependency>
+
+        <dependency>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-simple</artifactId>
+          <version>1.4.3</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>1.4.3</version>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-net</groupId>
+            <artifactId>commons-net</artifactId>
+            <version>1.4.1</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>jboss</groupId>
+            <artifactId>jbossesb-rosetta</artifactId>
+            <version>${jbossesb.version}</version>
+            <scope>system</scope>
+            <systemPath>${jbossesb.lib}/jbossesb-rosetta.jar</systemPath>
+        </dependency>
+
+        <dependency>
+            <groupId>jboss</groupId>
+            <artifactId>jbossts-common</artifactId>
+            <version>1.0</version>
+            <scope>system</scope>
+            <systemPath>${jbossesb.lib}/jbossts-common.jar</systemPath>
+        </dependency>
+
+        <dependency>
+            <groupId>jboss</groupId>
+            <artifactId>jbossesb-config-model</artifactId>
+            <version>${jbossesb.version}</version>
+            <scope>system</scope>
+            <systemPath>${jbossesb.lib}/jbossesb-config-model-1.0.1.jar</systemPath>
+        </dependency>
+
+        <dependency>
+            <groupId>jboss</groupId>
+            <artifactId>jbossesb-rosetta-test-utils</artifactId>
+            <version>${jbossesb.version}</version>
+            <scope>system</scope>
+            <systemPath>${basedir}/lib/test-util.jar</systemPath>
+        </dependency>
+
+        <dependency>
+            <groupId>jboss</groupId>
+            <artifactId>jmx-client</artifactId>
+            <version>1.0</version>
+            <scope>system</scope>
+            <systemPath>${soaserver.home}/client/jmx-client.jar</systemPath>
+        </dependency>
+
+        <dependency>
+            <groupId>xmlbeans</groupId>
+            <artifactId>xbean</artifactId>
+            <version>2.2.0</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>apache-commons</groupId>
+            <artifactId>commons-codec</artifactId>
+            <version>1.0</version>
+            <scope>system</scope>
+            <systemPath>${soaserver.home}/lib/commons-codec.jar</systemPath>
+        </dependency>
+
+        <dependency>
+            <groupId>xmlbeans</groupId>
+            <artifactId>xmlbeans-jsr173-api</artifactId>
+            <version>2.0-dev</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>3.8.1</version>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>src/main/java</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </resource>
+            <resource>
+                <directory>src/main/resources</directory>
+            </resource>
+        </resources>
+        <testResources>
+            <testResource>
+                <directory>src/test/java</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </testResource>
+            <testResource>
+                <directory>src/test/resources</directory>
+            </testResource>
+        </testResources>
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-dependencies</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}</outputDirectory>
+                            <overWriteReleases>false</overWriteReleases>
+                            <overWriteSnapshots>true</overWriteSnapshots>
+                            <excludeTransitive>true</excludeTransitive>
+                            <excludeArtifactIds>
+                                groovy-all,junit,log4j,jbossesb-rosetta,jbossesb-rosetta-xmlbeans,jbossts-common,jbossesb-rosetta-test-utils,commons-net,commons-codec,jbossesb-config-model,jmx-client,xbean,xmlbeans-jsr173-api
+                            </excludeArtifactIds>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
\ No newline at end of file


Property changes on: labs/jbossesb/workspace/sandbox/iplistener/pom.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/ActionPipelineDispatcher.java
===================================================================
--- labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/ActionPipelineDispatcher.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/ActionPipelineDispatcher.java	2008-12-04 09:32:32 UTC (rev 24232)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.iplistener;
+
+import org.jboss.soa.esb.listeners.message.ActionProcessingPipeline;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Pipeline executor.
+ * 
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class ActionPipelineDispatcher implements MessageDispatcher {
+
+    private ActionProcessingPipeline pipeline;
+
+    public ActionPipelineDispatcher(ActionProcessingPipeline pipeline) {
+        this.pipeline = pipeline;
+    }
+
+    public boolean dispatch(Message message) {
+        return pipeline.process(message);
+    }    
+}


Property changes on: labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/ActionPipelineDispatcher.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/DefaultMessageHandler.java
===================================================================
--- labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/DefaultMessageHandler.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/DefaultMessageHandler.java	2008-12-04 09:32:32 UTC (rev 24232)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.iplistener;
+
+import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.transport.socket.nio.SocketSessionConfig;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+/**
+ * Default handler.
+ * 
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class DefaultMessageHandler extends IoHandlerAdapter implements MessageHandler {
+
+    private MessageDispatcher dispatcher;
+
+    public final void setDispatcher(final MessageDispatcher dispatcher) {
+        this.dispatcher = dispatcher;
+    }
+
+    public void sessionCreated(final IoSession session) {
+        if (session.getTransportType() == TransportType.SOCKET) {
+            ((SocketSessionConfig) session.getConfig()).setReceiveBufferSize(2048);
+        }
+        session.setIdleTime(IdleStatus.BOTH_IDLE, 10);
+    }
+
+    public void exceptionCaught(final IoSession session, final Throwable cause) {
+        session.close();
+        // TODO: Handle reconnect.
+    }
+
+    public void messageReceived(final IoSession session, final Object message) throws Exception {
+        if (!(message instanceof ByteBuffer)) {
+            return;
+        }
+
+        ByteBuffer byteBuffer = (ByteBuffer) message;
+        Message esbMessage = MessageFactory.getInstance().getMessage();
+        byte[] bytes = new byte[byteBuffer.remaining()];
+
+        byteBuffer.get(bytes);
+        esbMessage.getBody().add(bytes);
+        dispatcher.dispatch(esbMessage);
+    }
+}


Property changes on: labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/DefaultMessageHandler.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/MessageDispatcher.java
===================================================================
--- labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/MessageDispatcher.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/MessageDispatcher.java	2008-12-04 09:32:32 UTC (rev 24232)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.iplistener;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Message Dispatcher.
+ * <p/>
+ * Dispatch the message to the configured ESB Action Pipeline.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public interface MessageDispatcher {
+
+    /**
+     * Dispatch the message to the action pipline.
+     * @param message The message.
+     */
+    boolean dispatch(Message message);
+}


Property changes on: labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/MessageDispatcher.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/MessageHandler.java
===================================================================
--- labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/MessageHandler.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/MessageHandler.java	2008-12-04 09:32:32 UTC (rev 24232)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.iplistener;
+
+import org.apache.mina.common.IoHandler;
+
+/**
+ * Message handler.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public interface MessageHandler extends IoHandler {
+
+    /**
+     * Set the {@link MessageDispatcher} instance to be used
+     * to dispatch messages to the action pipeline.
+     *
+     * @param dispatcher The dispatcher instance.
+     */
+    void setDispatcher(MessageDispatcher dispatcher);
+}


Property changes on: labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/MessageHandler.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/UDPListener.java
===================================================================
--- labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/UDPListener.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/UDPListener.java	2008-12-04 09:32:32 UTC (rev 24232)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.iplistener;
+
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.transport.socket.nio.DatagramAcceptor;
+import org.apache.mina.transport.socket.nio.DatagramSessionConfig;
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.ActionProcessingPipeline;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+/**
+ * UDP Listener class.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class UDPListener {
+
+    private ConfigTree config;
+    private SocketAddress address;
+    private IoAcceptor datagramAcceptor;
+    private ActionProcessingPipeline pipeline;
+
+    /**
+     * Public constructor.
+     * @param config The Listener config. 
+     */
+    public UDPListener(final ConfigTree config) throws ConfigurationException {
+        AssertArgument.isNotNull(config, "config");
+        this.config = config;
+
+        String portParam = config.getRequiredAttribute("port").trim();
+        try {
+            int port = Integer.parseInt(portParam);
+            address = new InetSocketAddress(port);
+        } catch (NumberFormatException e) {
+            throw new ConfigurationException("Invalid 'port' config value '" + portParam + "'.  Must be an integer value.");
+        }
+    }
+
+    /**
+     * Start the listener.
+     * @throws IOException Failed to bind to configured address.
+     * @throws ConfigurationException Invalid listener/pipeline configuration.
+     */
+    public final void start() throws IOException, ConfigurationException {
+        datagramAcceptor = new DatagramAcceptor();
+        ((DatagramSessionConfig) datagramAcceptor.getDefaultConfig().getSessionConfig()).setReuseAddress(true);
+
+        MessageHandler handler = getHandler(config);
+
+        pipeline = new ActionProcessingPipeline(config);
+        handler.setDispatcher(new ActionPipelineDispatcher(pipeline));
+        pipeline.initialise();
+
+        datagramAcceptor.bind(address, handler);
+    }
+
+    /**
+     * Stop the listener.
+     */
+    public final void stop() {
+        try {
+            if(pipeline != null) {
+                pipeline.destroy() ;
+            }
+        } finally {
+            if(address != null) {
+                datagramAcceptor.unbind(address);
+            }
+        }
+    }
+
+    /**
+     * Get the configured {@link MessageHandler} instance.
+     * <p/>
+     * Defaults to {@link DefaultMessageHandler}.
+     *
+     * @param config The listener configuration.
+     * @return The MessageHandler implementation.
+     * @throws ConfigurationException Unable to create the configured {@link MessageHandler} instance.
+     */
+    private MessageHandler getHandler(final ConfigTree config) throws ConfigurationException {
+        String handlerClass = config.getAttribute("handlerClass", DefaultMessageHandler.class.getName()).trim();
+
+        try {
+            return (MessageHandler) ClassUtil.forName(handlerClass, getClass()).newInstance();
+        } catch (ClassCastException e) {
+            throw new ConfigurationException("Class '" + handlerClass + "' must implement '" + MessageHandler.class.getName() + "'.");
+        } catch (InstantiationException e) {
+            throw new ConfigurationException("Failed to create an instance of MessagHandler implementation '" + handlerClass + "'.", e);
+        } catch (IllegalAccessException e) {
+            throw new ConfigurationException("Failed to create an instance of MessagHandler implementation '" + handlerClass + "'.", e);
+        } catch (ClassNotFoundException e) {
+            throw new ConfigurationException("Failed to create an instance of MessagHandler implementation '" + handlerClass + "'.", e);
+        }
+    }
+}


Property changes on: labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/esb/iplistener/UDPListener.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/soa/esb/listeners/gateway/scripts/UDPListener.groovy
===================================================================
--- labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/soa/esb/listeners/gateway/scripts/UDPListener.groovy	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/iplistener/src/main/java/org/jboss/soa/esb/listeners/gateway/scripts/UDPListener.groovy	2008-12-04 09:32:32 UTC (rev 24232)
@@ -0,0 +1,15 @@
+import org.jboss.esb.iplistener.UDPListener;
+
+UDPListener udpListener = new UDPListener(config);
+
+// Start the listener...
+udpListener.start();
+
+// Wait until the Groovy Gateway is signaled to stop...
+def stopped = false;
+while(!stopped) {
+    stopped = gateway.waitUntilStopping(200);
+}
+
+// Now stop the listener...
+udpListener.stop();
\ No newline at end of file

Added: labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/iplistener/UDPListenerTest.java
===================================================================
--- labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/iplistener/UDPListenerTest.java	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/iplistener/UDPListenerTest.java	2008-12-04 09:32:32 UTC (rev 24232)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.iplistener;
+
+import junit.framework.TestCase;
+import org.apache.commons.net.EchoUDPClient;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.mock.MockAction;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.testutils.ESBConfigUtil;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.net.InetAddress;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class UDPListenerTest extends TestCase {
+
+    public void test() throws IOException, SAXException, ConfigurationException, InterruptedException {
+        
+        ESBConfigUtil configUtil = new ESBConfigUtil(getClass().getResourceAsStream("jboss-esb.xml"));
+        ConfigTree listenerConfig = configUtil.getListenerConfig("UDP-2222");
+        UDPListener listener = new UDPListener(listenerConfig);
+
+        listener.start();
+        try
+        {
+            EchoUDPClient client = new EchoUDPClient();
+            client.open();
+            try {
+                byte[] writeBuffer = "Hello Edgar".getBytes();
+                client.setSoTimeout(3000);
+                client.send(writeBuffer, writeBuffer.length, InetAddress.getByName(null), 2222);
+            } finally {
+                client.close();
+            }
+
+            Thread.sleep(1000);
+
+            assertEquals("Hello Edgar", new String((byte[]) MockAction.message.getBody().get()));
+        } finally {
+            listener.stop();
+        }
+    }        
+}


Property changes on: labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/iplistener/UDPListenerTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/iplistener/jboss-esb.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/iplistener/jboss-esb.xml	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/iplistener/jboss-esb.xml	2008-12-04 09:32:32 UTC (rev 24232)
@@ -0,0 +1,22 @@
+<?xml version = "1.0" encoding = "UTF-8"?>
+<jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd" parameterReloadSecs="5">
+
+    <services>
+
+        <service category="Aircraft" name="brazil.Track" description="UDP Listener example">
+
+            <listeners>
+                <groovy-listener name="UDP-2222" script="UDPListener">
+                    <property name="port" value="2222"/>
+                </groovy-listener>
+            </listeners>
+            
+            <actions>
+                <action name="myaction" class="org.jboss.soa.esb.mock.MockAction"/>
+            </actions>
+
+        </service>
+
+    </services>
+
+</jbossesb>


Property changes on: labs/jbossesb/workspace/sandbox/iplistener/src/test/java/org/jboss/esb/iplistener/jboss-esb.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: labs/jbossesb/workspace/sandbox/iplistener/src/test/resources/log4j.xml
===================================================================
--- labs/jbossesb/workspace/sandbox/iplistener/src/test/resources/log4j.xml	                        (rev 0)
+++ labs/jbossesb/workspace/sandbox/iplistener/src/test/resources/log4j.xml	2008-12-04 09:32:32 UTC (rev 24232)
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!--                                                                       -->
+<!--  Log4j Configuration                                                  -->
+<!--                                                                       -->
+<!-- ===================================================================== -->
+
+<!-- $Id: log4j.xml,v 1.26.2.5 2005/09/15 09:31:02 dimitris Exp $ -->
+
+<!--
+   | For more configuration infromation and examples see the Jakarta Log4j
+   | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+    <!-- ============================== -->
+    <!-- Append messages to the console -->
+    <!-- ============================== -->
+
+    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+        <param name="Target" value="System.out"/>
+        <param name="Threshold" value="INFO"/>
+
+        <layout class="org.apache.log4j.PatternLayout">
+            <!-- The default pattern: Date Priority [Category] Message\n -->
+            <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%t][%c{1}] %m%n"/>
+        </layout>
+    </appender>
+
+    <!-- ================ -->
+    <!-- Limit categories -->
+
+    <category name="org.jboss">
+        <priority value="info"/>
+    </category>
+
+    <!-- ======================= -->
+    <!-- Setup the Root category -->
+    <!-- ======================= -->
+
+    <root>
+        <appender-ref ref="CONSOLE"/>
+    </root>
+
+</log4j:configuration>
+


Property changes on: labs/jbossesb/workspace/sandbox/iplistener/src/test/resources/log4j.xml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list