You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/12/16 08:35:28 UTC
svn commit: r891143 - in /camel/trunk/components/camel-irc/src:
main/java/org/apache/camel/component/irc/
test/java/org/apache/camel/component/irc/
Author: davsclaus
Date: Wed Dec 16 07:35:28 2009
New Revision: 891143
URL: http://svn.apache.org/viewvc?rev=891143&view=rev
Log:
CAMEL-2291: Applied patch with thanks to Tracy Snell. Added support for keys to irc component.
Added:
camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcConfigurationTest.java (with props)
Modified:
camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java
Modified: camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java?rev=891143&r1=891142&r2=891143&view=diff
==============================================================================
--- camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java (original)
+++ camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConfiguration.java Wed Dec 16 07:35:28 2009
@@ -30,6 +30,7 @@
public class IrcConfiguration implements Cloneable {
private String target;
private List<String> channels = new ArrayList<String>();
+ private List<String> keys = new ArrayList<String>();
private String hostname;
private String password;
private String nickname;
@@ -100,11 +101,11 @@
} else if (!uriStr.startsWith("irc://")) {
uriStr = uriStr.replace("irc:", "irc://");
}
-
+
if (uriStr.contains("?")) {
uriStr = ObjectHelper.before(uriStr, "?");
}
-
+
URI uri = new URI(uriStr);
setNickname(uri.getUserInfo());
@@ -141,6 +142,21 @@
}
}
+ public void setKeys(String keys) {
+ String[] s = keys.split(",");
+ for (String key : s) {
+ this.keys.add(key);
+ }
+ }
+
+ public void setKeys(List<String> keys) {
+ this.keys = keys;
+ }
+
+ public List<String> getKeys() {
+ return keys;
+ }
+
public void setTrustManager(SSLTrustManager trustManager) {
this.trustManager = trustManager;
}
Modified: camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java?rev=891143&r1=891142&r2=891143&view=diff
==============================================================================
--- camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java (original)
+++ camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcConsumer.java Wed Dec 16 07:35:28 2009
@@ -16,9 +16,12 @@
*/
package org.apache.camel.component.irc;
+import java.util.List;
+
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.impl.DefaultConsumer;
+import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.schwering.irc.lib.IRCConnection;
@@ -62,11 +65,30 @@
listener = new FilteredIRCEventAdapter();
connection.addIRCEventListener(listener);
- for (String channel : endpoint.getConfiguration().getChannels()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Joining: " + channel + " using " + connection.getClass().getName());
+ List<String> channels = endpoint.getConfiguration().getChannels();
+ for (String channel : channels) {
+
+ // find key for channel
+ int ndx = channels.indexOf(channel);
+ String key = null;
+ if (ndx >= 0) {
+ List<String> keys = endpoint.getConfiguration().getKeys();
+ if (keys.size() > 0 && ndx < keys.size()) {
+ key = keys.get(ndx);
+ }
+ }
+
+ if (ObjectHelper.isNotEmpty(key)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Joining: " + channel + " using " + connection.getClass().getName() + " with key " + key);
+ }
+ connection.doJoin(channel, key);
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Joining: " + channel + " using " + connection.getClass().getName());
+ }
+ connection.doJoin(channel);
}
- connection.doJoin(channel);
}
}
@@ -184,4 +206,5 @@
}
}
}
+
}
Modified: camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java?rev=891143&r1=891142&r2=891143&view=diff
==============================================================================
--- camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java (original)
+++ camel/trunk/components/camel-irc/src/main/java/org/apache/camel/component/irc/IrcProducer.java Wed Dec 16 07:35:28 2009
@@ -16,8 +16,11 @@
*/
package org.apache.camel.component.irc;
+import java.util.List;
+
import org.apache.camel.Exchange;
import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ObjectHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.schwering.irc.lib.IRCConnection;
@@ -65,11 +68,30 @@
protected void doStart() throws Exception {
super.doStart();
+ List<String> channels = endpoint.getConfiguration().getChannels();
for (String channel : endpoint.getConfiguration().getChannels()) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Joining: " + channel);
+
+ // find key for channel
+ int ndx = channels.indexOf(channel);
+ String key = null;
+ if (ndx >= 0) {
+ List<String> keys = endpoint.getConfiguration().getKeys();
+ if (keys.size() > 0 && ndx < keys.size()) {
+ key = keys.get(ndx);
+ }
+ }
+
+ if (ObjectHelper.isNotEmpty(key)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Joining: " + channel + " using " + connection.getClass().getName() + " with key " + key);
+ }
+ connection.doJoin(channel, key);
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Joining: " + channel + " using " + connection.getClass().getName());
+ }
+ connection.doJoin(channel);
}
- connection.doJoin(channel);
}
}
Added: camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcConfigurationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcConfigurationTest.java?rev=891143&view=auto
==============================================================================
--- camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcConfigurationTest.java (added)
+++ camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcConfigurationTest.java Wed Dec 16 07:35:28 2009
@@ -0,0 +1,143 @@
+/**
+ * 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 java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.Test;
+
+public class IrcConfigurationTest extends TestCase {
+
+ @Test
+ public void testConfigureFormat1() throws Exception {
+
+ CamelContext camel = new DefaultCamelContext();
+ IrcComponent component = new IrcComponent(camel);
+
+ // irc:nick@host[:port]/#room[?options]
+ IrcEndpoint endpoint = (IrcEndpoint) component.createEndpoint("irc://camelbot@irc.freenode.net/#camel");
+ IrcConfiguration conf = endpoint.getConfiguration();
+ assertEquals("camelbot", conf.getNickname());
+ assertEquals("irc.freenode.net", conf.getHostname());
+ List<String> channels = conf.getChannels();
+ assertEquals(1, channels.size());
+ assertEquals("#camel", channels.get(0));
+ }
+
+ @Test
+ public void testConfigureFormat2() throws Exception {
+
+ CamelContext camel = new DefaultCamelContext();
+ IrcComponent component = new IrcComponent(camel);
+
+ // irc:nick@host[:port]/#room[?options]
+ IrcEndpoint endpoint = (IrcEndpoint) component.createEndpoint("irc://camelbot@irc.freenode.net?channels=#camel");
+
+ IrcConfiguration conf = endpoint.getConfiguration();
+ assertEquals("camelbot", conf.getNickname());
+ assertEquals("irc.freenode.net", conf.getHostname());
+ List<String> channels = conf.getChannels();
+ assertEquals(1, channels.size());
+ assertEquals("#camel", channels.get(0));
+ }
+
+ @Test
+ public void testConfigureFormat3() throws Exception {
+
+ CamelContext camel = new DefaultCamelContext();
+ IrcComponent component = new IrcComponent(camel);
+
+ // irc:nick@host[:port]/#room[?options]
+ IrcEndpoint endpoint = (IrcEndpoint) component.createEndpoint("irc://irc.freenode.net?channels=#camel&nickname=camelbot");
+
+ IrcConfiguration conf = endpoint.getConfiguration();
+ assertEquals("camelbot", conf.getNickname());
+ assertEquals("irc.freenode.net", conf.getHostname());
+ List<String> channels = conf.getChannels();
+ assertEquals(1, channels.size());
+ assertEquals("#camel", channels.get(0));
+ }
+
+ @Test
+ public void testConfigureFormat4() throws Exception {
+
+ CamelContext camel = new DefaultCamelContext();
+ IrcComponent component = new IrcComponent(camel);
+
+ // irc:nick@host[:port]/#room[?options]
+ IrcEndpoint endpoint = (IrcEndpoint) component.createEndpoint("irc://irc.freenode.net?keys=,foo&channels=#camel,#smx&nickname=camelbot");
+
+ IrcConfiguration conf = endpoint.getConfiguration();
+ assertEquals("camelbot", conf.getNickname());
+ assertEquals("irc.freenode.net", conf.getHostname());
+ List<String> channels = conf.getChannels();
+ assertEquals(2, channels.size());
+ assertEquals("#camel", channels.get(0));
+ List<String> keys = conf.getKeys();
+ assertEquals(2, keys.size());
+ assertEquals("foo", keys.get(1));
+ }
+
+ @Test
+ public void testConfigureFormat5() throws Exception {
+
+ CamelContext camel = new DefaultCamelContext();
+ IrcComponent component = new IrcComponent(camel);
+
+ // irc:nick@host[:port]/#room[?options]
+ IrcEndpoint endpoint = (IrcEndpoint) component.
+ createEndpoint("irc://badnick@irc.freenode.net?keys=foo,&channels=#camel,#smx&realname=Camel Bot&nickname=camelbot");
+
+ IrcConfiguration conf = endpoint.getConfiguration();
+ assertEquals("camelbot", conf.getNickname());
+ assertEquals("irc.freenode.net", conf.getHostname());
+ List<String> channels = conf.getChannels();
+ assertEquals(2, channels.size());
+ assertEquals("#camel", channels.get(0));
+ List<String> keys = conf.getKeys();
+ assertEquals(1, keys.size());
+ assertEquals("foo", keys.get(0));
+ assertEquals("Camel Bot", conf.getRealname());
+ }
+
+ @Test
+ public void testConfigureFormat6() throws Exception {
+
+ CamelContext camel = new DefaultCamelContext();
+ IrcComponent component = new IrcComponent(camel);
+
+ // irc:nick@host[:port]/#room[?options]
+ IrcEndpoint endpoint = (IrcEndpoint) component.
+ createEndpoint("irc://badnick@irc.freenode.net?keys=foo,bar&channels=#camel,#smx&realname=Camel Bot&nickname=camelbot");
+
+ IrcConfiguration conf = endpoint.getConfiguration();
+ assertEquals("camelbot", conf.getNickname());
+ assertEquals("irc.freenode.net", conf.getHostname());
+ List<String> channels = conf.getChannels();
+ assertEquals(2, channels.size());
+ assertEquals("#camel", channels.get(0));
+ List<String> keys = conf.getKeys();
+ assertEquals(2, keys.size());
+ assertEquals("foo", keys.get(0));
+ assertEquals("bar", keys.get(1));
+ assertEquals("Camel Bot", conf.getRealname());
+ }
+
+}
Propchange: camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcConfigurationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-irc/src/test/java/org/apache/camel/component/irc/IrcConfigurationTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date