Author: janstey
Date: Wed Dec 31 10:03:37 2008
New Revision: 730436

URL: http://svn.apache.org/viewvc?rev=730436&view=rev
Log:
CAMEL-1209 - get xmpp working with google talk

Added:
    
activemq/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/GoogleTalkTest.java
   (with props)
Modified:
    activemq/camel/trunk/components/camel-xmpp/pom.xml
    
activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
    
activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java
    
activemq/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/UriConfigurationTest.java

Modified: activemq/camel/trunk/components/camel-xmpp/pom.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-xmpp/pom.xml?rev=730436&r1=730435&r2=730436&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-xmpp/pom.xml (original)
+++ activemq/camel/trunk/components/camel-xmpp/pom.xml Wed Dec 31 10:03:37 2008
@@ -52,6 +52,12 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-core</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
 
     <dependency>
       <groupId>commons-logging</groupId>

Modified: 
activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java?rev=730436&r1=730435&r2=730436&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
 (original)
+++ 
activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
 Wed Dec 31 10:03:37 2008
@@ -53,6 +53,7 @@
     private String room;
     private String participant;
     private String nickname;
+    private String serviceName;
 
     public XmppEndpoint(String uri, XmppComponent component) {
         super(uri, component);
@@ -193,6 +194,14 @@
         this.nickname = nickname;
     }
 
+    public void setServiceName(String serviceName) {
+        this.serviceName = serviceName;
+    }
+
+    public String getServiceName() {
+        return serviceName;
+    }    
+    
     public XMPPConnection getConnection() throws XMPPException {
         if (connection == null) {
             connection = createConnection();
@@ -208,8 +217,12 @@
     // 
-------------------------------------------------------------------------
     protected XMPPConnection createConnection() throws XMPPException {
         XMPPConnection connection;
-        if (port > 0) {
-            connection = new XMPPConnection(new ConnectionConfiguration(host, 
port));
+        if (port > 0) {            
+            if (getServiceName() == null) {
+                connection = new XMPPConnection(new 
ConnectionConfiguration(host, port));
+            } else {
+                connection = new XMPPConnection(new 
ConnectionConfiguration(host, port, getServiceName()));
+            }
         } else {
             connection = new XMPPConnection(host);
         }
@@ -271,5 +284,4 @@
     public boolean isSingleton() {
         return true;
     }
-
 }

Modified: 
activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java?rev=730436&r1=730435&r2=730436&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java
 (original)
+++ 
activemq/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java
 Wed Dec 31 10:03:37 2008
@@ -21,6 +21,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jivesoftware.smack.Chat;
+import org.jivesoftware.smack.ChatManager;
 import org.jivesoftware.smack.MessageListener;
 import org.jivesoftware.smack.XMPPException;
 import org.jivesoftware.smack.packet.Message;
@@ -47,10 +48,11 @@
         String threadId = exchange.getExchangeId();
 
         try {
-            Chat chat = 
endpoint.getConnection().getChatManager().getThreadChat(threadId);
+            ChatManager chatManager = 
endpoint.getConnection().getChatManager();
+            Chat chat = chatManager.getThreadChat(threadId);
 
             if (chat == null) {
-                chat = 
endpoint.getConnection().getChatManager().createChat(getParticipant(), 
threadId, new MessageListener() {
+                chat = chatManager.createChat(getParticipant(), threadId, new 
MessageListener() {
                     public void processMessage(Chat chat, Message message) {
                         // not here to do conversation
                     }
@@ -60,7 +62,6 @@
             // TODO it would be nice if we could reuse the message from the 
exchange
             Message message = new Message();
             message.setTo(participant);
-            message.setFrom(endpoint.getUser());
             message.setThread(threadId);
             message.setType(Message.Type.normal);
 

Added: 
activemq/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/GoogleTalkTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/GoogleTalkTest.java?rev=730436&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/GoogleTalkTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/GoogleTalkTest.java
 Wed Dec 31 10:03:37 2008
@@ -0,0 +1,45 @@
+/**
+ * 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.xmpp;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+public class GoogleTalkTest extends ContextTestSupport {
+    // a disabled test... before enabling you must fill in your own gmail 
credentials in the route below
+    public void xtestSendToGTalk() throws Exception {
+        MockEndpoint result = getMockEndpoint("mock:result");
+        template.sendBody("direct:start", "Hi!");
+        result.assertIsSatisfied();
+    }
+    
+    // get around junit warning
+    public void testNothing() throws Exception {        
+    }
+
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                // send a message from [email protected] to [email protected]
+                from("direct:start").
+                    
to("xmpp://talk.google.com:5222/[email protected]?servicename=gmail.com&user=fromuser&password=secret").
+                    to("mock:result");
+            }
+        };
+    }
+}

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

Modified: 
activemq/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/UriConfigurationTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/UriConfigurationTest.java?rev=730436&r1=730435&r2=730436&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/UriConfigurationTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/UriConfigurationTest.java
 Wed Dec 31 10:03:37 2008
@@ -29,7 +29,7 @@
     protected CamelContext context = new DefaultCamelContext();
 
     public void testPrivateChatConfiguration() throws Exception {
-        Endpoint endpoint = 
context.getEndpoint("xmpp://camel-u...@localhost:123/test-u...@localhost?password=secret");
+        Endpoint endpoint = 
context.getEndpoint("xmpp://camel-u...@localhost:123/test-u...@localhost?password=secret&serviceName=someCoolChat");
         assertTrue("Endpoint not an XmppEndpoint: " + endpoint, endpoint 
instanceof XmppEndpoint);
         XmppEndpoint xmppEndpoint = (XmppEndpoint) endpoint;
 
@@ -39,6 +39,7 @@
         assertEquals("camel-user", xmppEndpoint.getUser());
         assertEquals("test-u...@localhost", xmppEndpoint.getParticipant());
         assertEquals("secret", xmppEndpoint.getPassword());
+        assertEquals("someCoolChat", xmppEndpoint.getServiceName());
     }
 
     public void testGroupChatConfiguration() throws Exception {


Reply via email to