You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/08/25 15:58:40 UTC
svn commit: r807636 - in /camel/trunk/components/camel-xmpp/src:
main/java/org/apache/camel/component/xmpp/
test/java/org/apache/camel/component/xmpp/
Author: ningjiang
Date: Tue Aug 25 13:58:40 2009
New Revision: 807636
URL: http://svn.apache.org/viewvc?rev=807636&view=rev
Log:
CAMEL-1914 applied patch with thanks to Stan
Modified:
camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppConsumer.java
camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java
camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java
Modified: camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppConsumer.java?rev=807636&r1=807635&r2=807636&view=diff
==============================================================================
--- camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppConsumer.java (original)
+++ camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppConsumer.java Tue Aug 25 13:58:40 2009
@@ -44,6 +44,7 @@
private static final transient Log LOG = LogFactory.getLog(XmppConsumer.class);
private final XmppEndpoint endpoint;
private MultiUserChat muc;
+ private Chat privateChat;
private XMPPConnection connection;
public XmppConsumer(XmppEndpoint endpoint, Processor processor) {
@@ -59,7 +60,7 @@
// if an existing chat session has been opened (for example by a producer) let's
// just add a listener to that chat
- Chat privateChat = connection.getChatManager().getThreadChat(endpoint.getParticipant());
+ privateChat = connection.getChatManager().getThreadChat(endpoint.getParticipant());
if (privateChat != null) {
LOG.debug("Adding listener to existing chat opened to " + privateChat.getParticipant());
@@ -106,13 +107,13 @@
public void processPacket(Packet packet) {
if (packet instanceof Message) {
- processMessage(null, (Message) packet);
+ processMessage(null, (Message)packet);
}
}
public void processMessage(Chat chat, Message message) {
if (LOG.isDebugEnabled()) {
- LOG.debug("Recieved XMPP message: " + message.getBody());
+ LOG.debug("Received XMPP message for " + endpoint.getUser() + " from " + endpoint.getParticipant() + " : " + message.getBody());
}
Exchange exchange = endpoint.createExchange(message);
@@ -122,5 +123,4 @@
exchange.setException(e);
}
}
-
}
Modified: camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java?rev=807636&r1=807635&r2=807636&view=diff
==============================================================================
--- camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java (original)
+++ camel/trunk/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppPrivateChatProducer.java Tue Aug 25 13:58:40 2009
@@ -84,14 +84,14 @@
endpoint.getBinding().populateXmppMessage(message, exchange);
if (LOG.isDebugEnabled()) {
- LOG.debug("Sending XMPP message: " + message.getBody());
+ LOG.debug("Sending XMPP message to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message.getBody());
}
chat.sendMessage(message);
} catch (XMPPException xmppe) {
- throw new RuntimeExchangeException("Cannot send XMPP message: " + message
+ throw new RuntimeExchangeException("Cannot send XMPP message: to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
+ " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, xmppe);
} catch (Exception e) {
- throw new RuntimeExchangeException("Cannot send XMPP message: " + message
+ throw new RuntimeExchangeException("Cannot send XMPP message to " + endpoint.getParticipant() + " from " + endpoint.getUser() + " : " + message
+ " to: " + XmppEndpoint.getConnectionMessage(connection), exchange, e);
}
}
Modified: camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java?rev=807636&r1=807635&r2=807636&view=diff
==============================================================================
--- camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java (original)
+++ camel/trunk/components/camel-xmpp/src/test/java/org/apache/camel/component/xmpp/XmppRouteChatTest.java Tue Aug 25 13:58:40 2009
@@ -21,6 +21,9 @@
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import org.jivesoftware.smack.packet.Message;
import org.junit.Test;
@@ -28,6 +31,7 @@
* @version $Revision$
*/
public class XmppRouteChatTest extends CamelTestSupport {
+ private static final transient Log LOG = LogFactory.getLog(XmppRouteChatTest.class);
protected MockEndpoint consumerEndpoint;
protected MockEndpoint producerEndpoint;
protected String body1 = "the first message";
@@ -35,24 +39,39 @@
@Test
- public void testXmppChat() {
- producerEndpoint = (MockEndpoint)context.getEndpoint("mock:fromProducer");
- consumerEndpoint = (MockEndpoint)context.getEndpoint("mock:fromConsumer");
+ public void testXmppChat() throws Exception {
+ consumerEndpoint = (MockEndpoint)context.getEndpoint("mock:out1");
+ producerEndpoint = (MockEndpoint)context.getEndpoint("mock:out2");
- //will send chat messages to the consumer
- template.sendBody("direct:toProducer", body1);
- template.sendBody("direct:toProducer", body2);
consumerEndpoint.expectedBodiesReceived(body1, body2);
-
+ producerEndpoint.expectedBodiesReceived(body1, body2);
+
+ //will send chat messages to the consumer
template.sendBody("direct:toConsumer", body1);
template.sendBody("direct:toConsumer", body2);
- consumerEndpoint.expectedBodiesReceived(body1, body2);
+
+ template.sendBody("direct:toProducer", body1);
+ template.sendBody("direct:toProducer", body2);
+
+ consumerEndpoint.assertIsSatisfied();
+ producerEndpoint.assertIsSatisfied();
+
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
+ Processor stringConverter = new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ XmppMessage xmppMessage = (XmppMessage)exchange.getIn();
+ Message message = xmppMessage.getXmppMessage();
+ String body = message.getBody();
+ LOG.debug("Converting message - " + body);
+ exchange.getIn().setBody(body);
+ }
+ };
+
from("direct:toConsumer")
.to(getConsumerUri());
@@ -60,31 +79,22 @@
.to(getProducerUri());
from(getConsumerUri())
- .to("mock:fromConsumer");
+ .process(stringConverter)
+ .to("mock:out1");
from(getProducerUri())
- .to("mock:fromProducer");
-
- from("direct:getString")
- .process(new Processor() {
- public void process(Exchange exchange) throws Exception {
- XmppMessage xmppMessage = (XmppMessage)exchange.getIn();
- Message message = xmppMessage.getXmppMessage();
- exchange.getIn().setBody(message.getBody());
- }
- })
- .to("direct:getStringResult");
-
+ .process(stringConverter)
+ .to("mock:out2");
}
};
}
protected String getProducerUri() {
- return "xmpp://camel_producer@jabber.org:5222/camel_consumer@jabber.org?user=camel_producer&password=secret&serviceName=jabber.org";
+ return "xmpp://jabber.org:5222/camel_consumer?user=camel_producer&password=secret&serviceName=jabber.org";
}
protected String getConsumerUri() {
- return "xmpp://camel_consumer@jabber.org:5222/camel_producer@jabber.org?user=camel_consumer&password=secret&serviceName=jabber.org";
+ return "xmpp://jabber.org:5222/camel_producer?user=camel_consumer&password=secret&serviceName=jabber.org";
}
}