camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject camel git commit: CAMEL-9171 Also handle DefaultPacketExtension
Date Thu, 08 Oct 2015 13:21:34 GMT
Repository: camel
Updated Branches:
  refs/heads/master 3ebec4335 -> 1d9dc6220


CAMEL-9171 Also handle DefaultPacketExtension


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1d9dc622
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1d9dc622
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1d9dc622

Branch: refs/heads/master
Commit: 1d9dc62202c9e70267c9d5d4daaa9af7fba91664
Parents: 3ebec43
Author: Christian Schneider <chris@die-schneider.net>
Authored: Thu Oct 8 15:06:18 2015 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Thu Oct 8 15:06:18 2015 +0200

----------------------------------------------------------------------
 .../camel/component/xmpp/XmppBinding.java       | 34 ++++++++++++++++----
 .../camel/component/xmpp/XmppEndpoint.java      | 20 ++++++------
 2 files changed, 38 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1d9dc622/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java
b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java
index 1960540..ddb198b 100644
--- a/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java
+++ b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppBinding.java
@@ -24,9 +24,12 @@ import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultHeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.util.ObjectHelper;
+import org.jivesoftware.smack.packet.DefaultPacketExtension;
 import org.jivesoftware.smack.packet.Message;
 import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smack.packet.PacketExtension;
 import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
+import org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension;
 import org.jivesoftware.smackx.pubsub.packet.PubSub;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -131,13 +134,13 @@ public class XmppBinding {
     public Map<String, Object> extractHeadersFromXmpp(Packet xmppPacket, Exchange exchange)
{
         Map<String, Object> answer = new HashMap<String, Object>();
 
-        for (String name : JivePropertiesManager.getPropertiesNames(xmppPacket)) {
-            Object value = JivePropertiesManager.getProperty(xmppPacket, name);
-
-            if (!headerFilterStrategy.applyFilterToExternalHeaders(name, value, exchange))
{
-                answer.put(name, value);
-            }
+        PacketExtension jpe = xmppPacket.getExtension(JivePropertiesExtension.NAMESPACE);
+        if (jpe !=null && jpe instanceof JivePropertiesExtension) {
+            extractHeadersFrom((JivePropertiesExtension)jpe, exchange, answer);
         }
+        if (jpe !=null && jpe instanceof DefaultPacketExtension) {
+            extractHeadersFrom((DefaultPacketExtension)jpe, exchange, answer);
+    }
 
         if (xmppPacket instanceof Message) {
             Message xmppMessage = (Message) xmppPacket;
@@ -154,4 +157,23 @@ public class XmppBinding {
 
         return answer;
     }
+
+    private void extractHeadersFrom(JivePropertiesExtension jpe, Exchange exchange, Map<String,
Object> answer) {
+        for (String name : jpe.getPropertyNames()) {
+            Object value = jpe.getProperty(name);
+            if (!headerFilterStrategy.applyFilterToExternalHeaders(name, value, exchange))
{
+                answer.put(name, value);
+            }
+        }
+    }
+
+    private void extractHeadersFrom(DefaultPacketExtension jpe, Exchange exchange, Map<String,
Object> answer) {
+        for (String name : jpe.getNames()) {
+            Object value = jpe.getValue(name);
+            if (!headerFilterStrategy.applyFilterToExternalHeaders(name, value, exchange))
{
+                answer.put(name, value);
+            }
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/1d9dc622/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
index 11da25c..041c7c1 100644
--- a/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
+++ b/components/camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppEndpoint.java
@@ -150,21 +150,12 @@ public class XmppEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
     }
 
     public synchronized XMPPConnection createConnection() throws XMPPException, SmackException,
IOException {
-
         if (connection != null && connection.isConnected()) {
             return connection;
         }
 
         if (connection == null) {
-            if (port > 0) {
-                if (getServiceName() == null) {
-                    connection = new XMPPTCPConnection(new ConnectionConfiguration(host,
port));
-                } else {
-                    connection = new XMPPTCPConnection(new ConnectionConfiguration(host,
port, serviceName));
-                }
-            } else {
-                connection = new XMPPTCPConnection(host);
-            }
+            connection = createConnectionInternal();
         }
 
         connection.connect();
@@ -213,6 +204,15 @@ public class XmppEndpoint extends DefaultEndpoint implements HeaderFilterStrateg
         return connection;
     }
 
+    private XMPPTCPConnection createConnectionInternal() {
+        if (port == 0) {
+            port = 5222;
+        }
+        String sName = getServiceName() == null ? host : getServiceName();
+        ConnectionConfiguration conf = new ConnectionConfiguration(host, port, sName);
+        return new XMPPTCPConnection(conf);
+    }
+
     /*
      * If there is no "@" symbol in the room, find the chat service JID and
      * return fully qualified JID for the room as room@conference.server.domain


Mime
View raw message