camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r550572 - in /activemq/camel/trunk/components/camel-irc/src: main/java/org/apache/camel/component/irc/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/camel/ test/java/org/apache/camel/component/ test/java/org/apa...
Date Mon, 25 Jun 2007 18:44:50 GMT
Author: jstrachan
Date: Mon Jun 25 11:44:49 2007
New Revision: 550572

URL: http://svn.apache.org/viewvc?view=rev&rev=550572
Log:
added an integration test case along with removing some System.out statements and adding some
debug logging

Added:
    activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcErrorLogger.java
  (with props)
    activemq/camel/trunk/components/camel-irc/src/test/
    activemq/camel/trunk/components/camel-irc/src/test/java/
    activemq/camel/trunk/components/camel-irc/src/test/java/org/
    activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/
    activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/
    activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/
    activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/
    activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/CodehausIrcChat.java
  (with props)
    activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcRouteIntegration.java
  (with props)
    activemq/camel/trunk/components/camel-irc/src/test/resources/
    activemq/camel/trunk/components/camel-irc/src/test/resources/log4j.properties
      - copied, changed from r550438, activemq/camel/trunk/components/camel-jms/src/test/resources/log4j.properties
Modified:
    activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcBinding.java
    activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java
    activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
    activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
    activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java
    activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java
    activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java
    activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java

Modified: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcBinding.java?view=diff&rev=550572&r1=550571&r2=550572
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcBinding.java
(original)
+++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcBinding.java
Mon Jun 25 11:44:49 2007
@@ -18,7 +18,14 @@
 package org.apache.camel.component.irc;
 
 public class IrcBinding {
-    public Object extractBodyFromIrc(IrcExchange exchange, String message) {
-        return message;
+    public Object extractBodyFromIrc(IrcExchange exchange, IrcMessage message) {
+        String type = message.getMessageType();
+        String text = message.getMessage();
+        if (text != null) {
+            return text;
+        }
+        else {
+            return type;
+        }
     }
 }

Modified: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java?view=diff&rev=550572&r1=550571&r2=550572
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java
(original)
+++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcComponent.java
Mon Jun 25 11:44:49 2007
@@ -18,18 +18,25 @@
 package org.apache.camel.component.irc;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.impl.DefaultComponent;
 import org.apache.camel.util.IntrospectionSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.schwering.irc.lib.IRCConnection;
 
-import java.io.IOException;
 import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
 
 public class IrcComponent extends DefaultComponent<IrcExchange> {
-
+    private static final transient Log log = LogFactory.getLog(IrcComponent.class);
     private IrcConfiguration configuration;
+    private final Map<String, IRCConnection> connectionCache = new HashMap<String,
IRCConnection>();
+
+    public static IrcComponent ircComponent() {
+        return new IrcComponent();
+    }
 
     public IrcComponent() {
         configuration = new IrcConfiguration();
@@ -44,10 +51,6 @@
         configuration = new IrcConfiguration();
     }
 
-    public static IrcComponent ircComponent() {
-        return new IrcComponent();
-    }
-
     protected IrcEndpoint createEndpoint(String uri, String remaining, Map parameters) throws
Exception {
         IrcConfiguration config = getConfiguration().copy();
         config.configure(new URI(uri));
@@ -67,14 +70,15 @@
         this.configuration = configuration;
     }
 
-    final Map<String, IRCConnection> connectionCache = new HashMap<String, IRCConnection>();
-
     public synchronized IRCConnection getIRCConnection(IrcConfiguration configuration) {
         final IRCConnection connection;
         if (connectionCache.containsKey(configuration.getCacheKey())) {
-            System.out.println("Returning Cached Connection to " + configuration.getHostname()
+ " " + configuration.getTarget());
+            if (log.isDebugEnabled()) {
+                log.debug("Returning Cached Connection to " + configuration.getHostname()
+ " " + configuration.getTarget());
+            }
             connection = connectionCache.get(configuration.getCacheKey());
-        } else {
+        }
+        else {
             connection = createConnection(configuration);
             connectionCache.put(configuration.getCacheKey(), connection);
         }
@@ -82,7 +86,8 @@
     }
 
     protected IRCConnection createConnection(IrcConfiguration configuration) {
-        System.out.println("Creating Connection to " + configuration.getHostname() + " "
+ configuration.getTarget());
+        log.debug("Creating Connection to " + configuration.getHostname() + " destination:
" + configuration.getTarget()
+                + " nick: " + configuration.getNickname() + " user: " + configuration.getUsername());
 
         final IRCConnection conn = new IRCConnection(configuration.getHostname(), configuration.getPorts(),
configuration.getPassword(), configuration.getNickname(), configuration.getUsername(), configuration.getRealname());
         conn.setEncoding("UTF-8");
@@ -92,8 +97,12 @@
 
         try {
             conn.connect();
-        } catch (IOException e) {
-            e.printStackTrace();
+        }
+        catch (Exception e) {
+            log.error("Failed to connect: " + e, e);
+
+            // TODO use checked exceptions?
+            throw new RuntimeCamelException(e);
         }
         return conn;
     }
@@ -102,16 +111,18 @@
         try {
             connection.doQuit();
             connection.close();
-        } catch (Exception e) {
+        }
+        catch (Exception e) {
             e.printStackTrace();
-        } finally {
-            connectionCache.remove(key); // TODO this is probably bad in the for each
         }
     }
 
     @Override
-    protected void doStop() throws Exception {
-        for (Map.Entry<String, IRCConnection> entry : connectionCache.entrySet()) {
+    protected synchronized void doStop() throws Exception {
+        // lets use a copy so we can clear the connections eagerly in case of exceptions
+        Map<String, IRCConnection> map = new HashMap<String, IRCConnection>(connectionCache);
+        connectionCache.clear();
+        for (Map.Entry<String, IRCConnection> entry : map.entrySet()) {
             closeConnection(entry.getKey(), entry.getValue());
         }
         super.doStop();

Modified: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java?view=diff&rev=550572&r1=550571&r2=550572
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
(original)
+++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
Mon Jun 25 11:44:49 2007
@@ -20,10 +20,8 @@
 import org.apache.camel.RuntimeCamelException;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 
 public class IrcConfiguration implements Cloneable {
-
     String target;
     String hostname;
     String password;
@@ -41,7 +39,7 @@
     boolean onTopic = true;
     boolean onPrivmsg = true;
     int[] ports = {6667, 6668, 6669};
-    
+
     public IrcConfiguration() {
     }
 
@@ -74,14 +72,13 @@
     public String getCacheKey() {
         return hostname + ":" + nickname;
     }
-    
+
     public void configure(URI uri) {
         setNickname(uri.getUserInfo());
         setUsername(uri.getUserInfo());
         setRealname(uri.getUserInfo());
         setHostname(uri.getHost());
         setTarget(uri.getPath().substring(1));
-
     }
 
     public String getHostname() {

Modified: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java?view=diff&rev=550572&r1=550571&r2=550572
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
(original)
+++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
Mon Jun 25 11:44:49 2007
@@ -19,12 +19,15 @@
 
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultConsumer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.schwering.irc.lib.IRCConnection;
 import org.schwering.irc.lib.IRCEventAdapter;
 import org.schwering.irc.lib.IRCModeParser;
 import org.schwering.irc.lib.IRCUser;
 
 public class IrcConsumer extends DefaultConsumer<IrcExchange> {
+    private static final transient Log log = LogFactory.getLog(IrcConsumer.class);
     final private IrcEndpoint endpoint;
     final private IRCConnection connection;
     final IrcConfiguration configuration;
@@ -37,18 +40,24 @@
         configuration = endpoint.getConfiguration();
     }
 
-
     @Override
     protected void doStop() throws Exception {
-        connection.doPart(endpoint.getConfiguration().getTarget());
+        String target = endpoint.getConfiguration().getTarget();
+        connection.doPart(target);
         connection.removeIRCEventListener(listener);
+
+        super.doStop();
     }
 
     @Override
     protected void doStart() throws Exception {
-        connection.addIRCEventListener(new FilteredIRCEventAdapter(endpoint.getConfiguration().getTarget()));
-        connection.doJoin(endpoint.getConfiguration().getTarget());
         super.doStart();
+
+        String target = endpoint.getConfiguration().getTarget();
+        connection.addIRCEventListener(new FilteredIRCEventAdapter(target));
+
+        log.debug("joining: " + target);
+        connection.doJoin(target);
     }
 
     public IRCConnection getConnection() {
@@ -62,14 +71,14 @@
             this.target = target;
         }
 
-
         @Override
         public void onNick(IRCUser user, String newNick) {
             if (configuration.isOnNick()) {
                 IrcExchange exchange = endpoint.createOnNickExchange(user, newNick);
                 try {
                     getProcessor().process(exchange);
-                } catch (Exception e) {
+                }
+                catch (Exception e) {
                     // TODO: what should we do when a processing failure occurs??
                     e.printStackTrace();
                 }
@@ -82,7 +91,8 @@
                 IrcExchange exchange = endpoint.createOnQuitExchange(user, msg);
                 try {
                     getProcessor().process(exchange);
-                } catch (Exception e) {
+                }
+                catch (Exception e) {
                     // TODO: what should we do when a processing failure occurs??
                     e.printStackTrace();
                 }
@@ -96,7 +106,8 @@
                     IrcExchange exchange = endpoint.createOnJoinExchange(channel, user);
                     try {
                         getProcessor().process(exchange);
-                    } catch (Exception e) {
+                    }
+                    catch (Exception e) {
                         // TODO: what should we do when a processing failure occurs??
                         e.printStackTrace();
                     }
@@ -111,7 +122,8 @@
                     IrcExchange exchange = endpoint.createOnKickExchange(channel, user, passiveNick,
msg);
                     try {
                         getProcessor().process(exchange);
-                    } catch (Exception e) {
+                    }
+                    catch (Exception e) {
                         // TODO: what should we do when a processing failure occurs??
                         e.printStackTrace();
                     }
@@ -126,7 +138,8 @@
                     IrcExchange exchange = endpoint.createOnModeExchange(channel, user, modeParser);
                     try {
                         getProcessor().process(exchange);
-                    } catch (Exception e) {
+                    }
+                    catch (Exception e) {
                         // TODO: what should we do when a processing failure occurs??
                         e.printStackTrace();
                     }
@@ -141,7 +154,8 @@
                     IrcExchange exchange = endpoint.createOnPartExchange(channel, user, msg);
                     try {
                         getProcessor().process(exchange);
-                    } catch (Exception e) {
+                    }
+                    catch (Exception e) {
                         // TODO: what should we do when a processing failure occurs??
                         e.printStackTrace();
                     }
@@ -156,7 +170,8 @@
                     IrcExchange exchange = endpoint.createOnTopicExchange(channel, user,
topic);
                     try {
                         getProcessor().process(exchange);
-                    } catch (Exception e) {
+                    }
+                    catch (Exception e) {
                         // TODO: what should we do when a processing failure occurs??
                         e.printStackTrace();
                     }
@@ -171,13 +186,13 @@
                     IrcExchange exchange = endpoint.createOnPrivmsgExchange(target, user,
msg);
                     try {
                         getProcessor().process(exchange);
-                    } catch (Exception e) {
+                    }
+                    catch (Exception e) {
                         // TODO: what should we do when a processing failure occurs??
                         e.printStackTrace();
                     }
                 }
             }
         }
-
     }
 }

Modified: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java?view=diff&rev=550572&r1=550571&r2=550572
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java
(original)
+++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcEndpoint.java
Mon Jun 25 11:44:49 2007
@@ -19,14 +19,10 @@
 
 import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultEndpoint;
-import org.schwering.irc.lib.IRCConnection;
 import org.schwering.irc.lib.IRCModeParser;
 import org.schwering.irc.lib.IRCUser;
 
-import java.io.IOException;
-
 public class IrcEndpoint extends DefaultEndpoint<IrcExchange> {
-
     private IrcBinding binding;
     private IrcConfiguration configuration;
     private IrcComponent component;
@@ -38,7 +34,7 @@
     }
 
     public boolean isSingleton() {
-        return false;
+        return true;
     }
 
     public IrcExchange createExchange() {
@@ -111,88 +107,5 @@
     public void setConfiguration(IrcConfiguration configuration) {
         this.configuration = configuration;
     }
-
-    public static void main(String[] args) throws InterruptedException {
-        final IrcConfiguration config = new IrcConfiguration("irc.codehaus.org", "camel-irc",
"Camel IRC Component", "#camel-irc");
-        final IRCConnection conn = new IRCConnection(config.getHostname(), config.getPorts(),
config.getPassword(), config.getNickname(), config.getUsername(), config.getRealname());
-//        conn.addIRCEventListener(new IRCEventAdapter() {
-//
-//            @Override
-//            public void onRegistered() {
-//                super.onRegistered();
-//                System.out.println("onRegistered");
-//            }
-//
-//            @Override
-//            public void onDisconnected() {
-//                super.onDisconnected();
-//                System.out.println("onDisconnected");
-//            }
-//
-//            @Override
-//            public void onMode(String string, IRCUser ircUser, IRCModeParser ircModeParser)
{
-//                super.onMode(string, ircUser, ircModeParser);
-//                System.out.println("onMode.string = " + string);
-//                System.out.println("onMode.ircUser = " + ircUser);
-//                System.out.println("onMode.ircModeParser = " + ircModeParser);
-//            }
-//
-//            @Override
-//            public void onMode(IRCUser ircUser, String string, String string1) {
-//                super.onMode(ircUser, string, string1);
-//                System.out.println("onMode.ircUser = " + ircUser);
-//                System.out.println("onMode.string = " + string);
-//                System.out.println("onMode.string1 = " + string1);
-//            }
-//
-//            @Override
-//            public void onPing(String string) {
-//                super.onPing(string);
-//                System.out.println("onPing.string = " + string);
-//            }
-//
-//            @Override
-//            public void onError(String string) {
-//                System.out.println("onError.string = " + string);
-//            }
-//
-//            @Override
-//            public void onError(int i, String string) {
-//                super.onError(i, string);
-//                System.out.println("onError.i = " + i);
-//                System.out.println("onError.string = " + string);
-//            }
-//
-//            @Override
-//            public void unknown(String string, String string1, String string2, String string3)
{
-//                super.unknown(string, string1, string2, string3);
-//                System.out.println("unknown.string = " + string);
-//                System.out.println("unknown.string1 = " + string1);
-//                System.out.println("unknown.string2 = " + string2);
-//                System.out.println("unknown.string3 = " + string3);
-//            }
-//        });
-        conn.setEncoding("UTF-8");
-        conn.setDaemon(true);
-        conn.setColors(false);
-        conn.setPong(true);
-
-        try {
-            conn.connect();
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-//        while (!conn.isConnected()) {
-//            Thread.sleep(1000);
-//            System.out.println("Sleeping");
-//        }
-        System.out.println("Connected");
-//        conn.send("/JOIN #CAMEL");
-//        conn.doPrivmsg("nnordrum", "hi!");
-//        System.out.println("Joining Channel");
-        conn.doJoin(config.getTarget());
-        Thread.sleep(Integer.MAX_VALUE);
-    }
-
 }
 

Added: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcErrorLogger.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcErrorLogger.java?view=auto&rev=550572
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcErrorLogger.java
(added)
+++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcErrorLogger.java
Mon Jun 25 11:44:49 2007
@@ -0,0 +1,91 @@
+/**
+ *
+ * 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.irc;
+
+import org.apache.commons.logging.Log;
+import org.schwering.irc.lib.IRCEventAdapter;
+import org.schwering.irc.lib.IRCModeParser;
+import org.schwering.irc.lib.IRCUser;
+
+/**
+ * A helper class which logs errors
+ *
+ * @version $Revision: 1.1 $
+ */
+public class IrcErrorLogger extends IRCEventAdapter {
+    private Log log;
+
+    public IrcErrorLogger(Log log) {
+        this.log = log;
+    }
+
+    @Override
+    public void onRegistered() {
+        super.onRegistered();
+        log.info("onRegistered");
+    }
+
+    @Override
+    public void onDisconnected() {
+        super.onDisconnected();
+        log.info("onDisconnected");
+    }
+
+    @Override
+    public void onMode(String string, IRCUser ircUser, IRCModeParser ircModeParser) {
+        super.onMode(string, ircUser, ircModeParser);
+        log.info("onMode.string = " + string);
+        log.info("onMode.ircUser = " + ircUser);
+        log.info("onMode.ircModeParser = " + ircModeParser);
+    }
+
+    @Override
+    public void onMode(IRCUser ircUser, String string, String string1) {
+        super.onMode(ircUser, string, string1);
+        log.info("onMode.ircUser = " + ircUser);
+        log.info("onMode.string = " + string);
+        log.info("onMode.string1 = " + string1);
+    }
+
+    @Override
+    public void onPing(String string) {
+        super.onPing(string);
+        log.info("onPing.string = " + string);
+    }
+
+    @Override
+    public void onError(String string) {
+        log.info("onError.string = " + string);
+    }
+
+    @Override
+    public void onError(int i, String string) {
+        super.onError(i, string);
+        log.error("onError.i = " + i);
+        log.error("onError.string = " + string);
+    }
+
+    @Override
+    public void unknown(String string, String string1, String string2, String string3) {
+        super.unknown(string, string1, string2, string3);
+        log.error("unknown.string = " + string);
+        log.error("unknown.string1 = " + string1);
+        log.error("unknown.string2 = " + string2);
+        log.error("unknown.string3 = " + string3);
+    }
+}

Propchange: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcErrorLogger.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java?view=diff&rev=550572&r1=550571&r2=550572
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java
(original)
+++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcExchange.java
Mon Jun 25 11:44:49 2007
@@ -17,11 +17,8 @@
  */
 package org.apache.camel.component.irc;
 
-import org.apache.camel.impl.DefaultExchange;
 import org.apache.camel.CamelContext;
-import org.apache.camel.Message;
-import org.apache.camel.Exchange;
-import org.schwering.irc.lib.IRCUser;
+import org.apache.camel.impl.DefaultExchange;
 
 public class IrcExchange extends DefaultExchange {
     private IrcBinding binding;
@@ -32,7 +29,7 @@
     }
 
     public IrcExchange(CamelContext context, IrcBinding binding, IrcMessage inMessage) {
-        this(context,  binding);
+        this(context, binding);
         setIn(inMessage);
     }
 

Modified: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java?view=diff&rev=550572&r1=550571&r2=550572
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java
(original)
+++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcMessage.java
Mon Jun 25 11:44:49 2007
@@ -21,7 +21,6 @@
 import org.schwering.irc.lib.IRCUser;
 
 import java.util.Map;
-import java.util.HashMap;
 
 public class IrcMessage extends DefaultMessage {
     private String messageType;
@@ -109,7 +108,7 @@
     protected Object createBody() {
         IrcExchange ircExchange = getExchange();
         IrcBinding binding = ircExchange.getBinding();
-        return binding.extractBodyFromIrc(ircExchange, message);
+        return binding.extractBodyFromIrc(ircExchange, this);
     }
 
     @Override
@@ -138,7 +137,8 @@
     public String toString() {
         if (message != null) {
             return "IrcMessage: " + message;
-        } else {
+        }
+        else {
             return "IrcMessage: " + getBody();
         }
     }

Modified: activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java?view=diff&rev=550572&r1=550571&r2=550572
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java
(original)
+++ activemq/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java
Mon Jun 25 11:44:49 2007
@@ -20,11 +20,16 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.impl.DefaultProducer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.schwering.irc.lib.IRCConnection;
+import org.schwering.irc.lib.IRCEventListener;
 
 public class IrcProducer extends DefaultProducer<IrcExchange> {
+    private static final transient Log log = LogFactory.getLog(IrcProducer.class);
     private IRCConnection connection;
     private IrcEndpoint endpoint;
+    private IRCEventListener ircErrorLogger;
 
     public IrcProducer(IrcEndpoint endpoint, IRCConnection connection) {
         super(endpoint);
@@ -37,15 +42,43 @@
             final String msg = exchange.getIn().getBody(String.class);
             if (isMessageACommand(msg)) {
                 connection.send(msg);
-            } else {
+            }
+            else {
                 final String target = endpoint.getConfiguration().getTarget();
+
+                if (log.isDebugEnabled()) {
+                    log.debug("sending to: " + target + " message: " + msg);
+                }
+
                 connection.doPrivmsg(target, msg);
             }
-        } catch (Exception e) {
+        }
+        catch (Exception e) {
             throw new RuntimeCamelException(e);
         }
     }
 
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        ircErrorLogger = createIrcErrorLogger();
+        connection.addIRCEventListener(ircErrorLogger);
+
+        final String target = endpoint.getConfiguration().getTarget();
+
+        log.debug("joining: " + target);
+        connection.doJoin(target);
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+        if (connection != null) {
+            connection.removeIRCEventListener(ircErrorLogger);
+        }
+    }
+
     protected boolean isMessageACommand(String msg) {
         for (String command : commands) {
             if (msg.startsWith(command)) {
@@ -55,6 +88,10 @@
         return false;
     }
 
+    protected IRCEventListener createIrcErrorLogger() {
+        return new IrcErrorLogger(log);
+    }
+
     public final String[] commands = new String[]{
             "AWAY", "INVITE", "ISON", "JOIN",
             "KICK", "LIST", "NAMES", "PRIVMSG",
@@ -62,5 +99,4 @@
             "PONG", "QUIT", "TOPIC", "WHO",
             "WHOIS", "WHOWAS", "USERHOST"
     };
-
 }

Added: activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/CodehausIrcChat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/CodehausIrcChat.java?view=auto&rev=550572
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/CodehausIrcChat.java
(added)
+++ activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/CodehausIrcChat.java
Mon Jun 25 11:44:49 2007
@@ -0,0 +1,116 @@
+/**
+ *
+ * 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.irc;
+
+import org.schwering.irc.lib.IRCConnection;
+import org.schwering.irc.lib.IRCEventAdapter;
+import org.schwering.irc.lib.IRCUser;
+import org.schwering.irc.lib.IRCModeParser;
+
+import java.io.IOException;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class CodehausIrcChat {
+    public static void main(String[] args) throws InterruptedException {
+        final IrcConfiguration config = new IrcConfiguration("irc.codehaus.org", "camel-irc",
"Camel IRC Component", "#camel-test");
+
+        final IRCConnection conn = new IRCConnection(config.getHostname(), config.getPorts(),
config.getPassword(), config.getNickname(), config.getUsername(), config.getRealname());
+
+        conn.addIRCEventListener(new IRCEventAdapter() {
+
+            @Override
+            public void onRegistered() {
+                super.onRegistered();
+                System.out.println("onRegistered");
+            }
+
+            @Override
+            public void onDisconnected() {
+                super.onDisconnected();
+                System.out.println("onDisconnected");
+            }
+
+            @Override
+            public void onMode(String string, IRCUser ircUser, IRCModeParser ircModeParser)
{
+                super.onMode(string, ircUser, ircModeParser);
+                System.out.println("onMode.string = " + string);
+                System.out.println("onMode.ircUser = " + ircUser);
+                System.out.println("onMode.ircModeParser = " + ircModeParser);
+            }
+
+            @Override
+            public void onMode(IRCUser ircUser, String string, String string1) {
+                super.onMode(ircUser, string, string1);
+                System.out.println("onMode.ircUser = " + ircUser);
+                System.out.println("onMode.string = " + string);
+                System.out.println("onMode.string1 = " + string1);
+            }
+
+            @Override
+            public void onPing(String string) {
+                super.onPing(string);
+                System.out.println("onPing.string = " + string);
+            }
+
+            @Override
+            public void onError(String string) {
+                System.out.println("onError.string = " + string);
+            }
+
+            @Override
+            public void onError(int i, String string) {
+                super.onError(i, string);
+                System.out.println("onError.i = " + i);
+                System.out.println("onError.string = " + string);
+            }
+
+            @Override
+            public void unknown(String string, String string1, String string2, String string3)
{
+                super.unknown(string, string1, string2, string3);
+                System.out.println("unknown.string = " + string);
+                System.out.println("unknown.string1 = " + string1);
+                System.out.println("unknown.string2 = " + string2);
+                System.out.println("unknown.string3 = " + string3);
+            }
+        });
+        conn.setEncoding("UTF-8");
+        //conn.setDaemon(true);
+        conn.setColors(false);
+        conn.setPong(true);
+
+        try {
+            conn.connect();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+//        while (!conn.isConnected()) {
+//            Thread.sleep(1000);
+//            System.out.println("Sleeping");
+//        }
+        System.out.println("Connected");
+        //conn.send("/JOIN #camel-test");
+
+        //System.out.println("Joining Channel: " + config.getTarget());
+        conn.doJoin(config.getTarget());
+
+        conn.doPrivmsg("#camel-test", "hi!");
+        Thread.sleep(Integer.MAX_VALUE);
+    }
+}

Propchange: activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/CodehausIrcChat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcRouteIntegration.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcRouteIntegration.java?view=auto&rev=550572
==============================================================================
--- activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcRouteIntegration.java
(added)
+++ activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcRouteIntegration.java
Mon Jun 25 11:44:49 2007
@@ -0,0 +1,84 @@
+/**
+ *
+ * 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.irc;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+import java.util.List;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class IrcRouteIntegration extends ContextTestSupport {
+    protected MockEndpoint resultEndpoint;
+    protected String body1 = "Message One";
+    protected String body2 = "Message Two";
+    private boolean sentMessages;
+
+    public void testIrcMessages() throws Exception {
+        resultEndpoint = (MockEndpoint) context.getEndpoint("mock:result");
+        resultEndpoint.expectedBodiesReceived(body1, body2);
+
+        resultEndpoint.assertIsSatisfied();
+        //Thread.sleep(10000);
+
+        List<Exchange> list = resultEndpoint.getReceivedExchanges();
+        for (Exchange exchange : list) {
+            log.info("Received exchange: " + exchange + " headers: " + exchange.getIn().getHeaders());
+        }
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("irc://camel-con@irc.codehaus.org:6667/%23camel-test").
+                        choice().
+                        when(header("irc.messageType").isEqualTo("PRIVMSG")).to("mock:result").
+                        when(header("irc.messageType").isEqualTo("JOIN")).to("queue:consumerJoined");
+
+                // TODO this causes errors on shutdown...
+                //otherwise().to("mock:otherIrcCommands");
+
+                from("queue:consumerJoined").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        sendMessages();
+                    }
+                });
+            }
+        };
+    }
+
+    /**
+     * Lets send messages once the consumer has joined
+     */
+    protected void sendMessages() {
+        if (!sentMessages) {
+            sentMessages = true;
+
+            // now the consumer has joined, lets send some messages
+            String sendUri = "irc://camel-prd@irc.codehaus.org:6667/%23camel-test";
+
+            template.sendBody(sendUri, body1);
+            template.sendBody(sendUri, body2);
+        }
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcRouteIntegration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: activemq/camel/trunk/components/camel-irc/src/test/resources/log4j.properties (from
r550438, activemq/camel/trunk/components/camel-jms/src/test/resources/log4j.properties)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-irc/src/test/resources/log4j.properties?view=diff&rev=550572&p1=activemq/camel/trunk/components/camel-jms/src/test/resources/log4j.properties&r1=550438&p2=activemq/camel/trunk/components/camel-irc/src/test/resources/log4j.properties&r2=550572
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/resources/log4j.properties (original)
+++ activemq/camel/trunk/components/camel-irc/src/test/resources/log4j.properties Mon Jun
25 11:44:49 2007
@@ -20,7 +20,6 @@
 #
 log4j.rootLogger=INFO, out
 
-log4j.logger.org.apache.activemq=WARN
 #log4j.logger.org.apache.camel=DEBUG
 
 # CONSOLE appender not used by default



Mime
View raw message