labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r657983 - in /labs/vysper/src: main/java/org/apache/vysper/xmpp/delivery/ main/java/org/apache/vysper/xmpp/modules/core/base/handler/ main/java/org/apache/vysper/xmpp/resourcebinding/ test/java/org/apache/vysper/smack/
Date Mon, 19 May 2008 21:15:40 GMT
Author: berndf
Date: Mon May 19 14:15:40 2008
New Revision: 657983

URL: http://svn.apache.org/viewvc?rev=657983&view=rev
Log:
[vysper] make stanza delivery more robust, catch missing recipient

Added:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachable.java
Modified:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelay.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
    labs/vysper/src/test/java/org/apache/vysper/smack/BasicClient.java

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelay.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelay.java?rev=657983&r1=657982&r2=657983&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelay.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelay.java Mon
May 19 14:15:40 2008
@@ -72,15 +72,23 @@
         }
 
         public RelayResult call() {
-            List<SessionContext> receivingSessions = resourceRegistry.getSessions(receiver);
-            for (SessionContext sessionContext : receivingSessions) {
-                StanzaWriter stanzaWriter = null;
-                try {
-                    stanzaWriter = sessionContext.getResponseWriter();
-                } catch (Exception e) {
-                    return new RelayResult(e);
+            try {
+                List<SessionContext> receivingSessions = resourceRegistry.getSessions(receiver);
+                if (receivingSessions == null || receivingSessions.size() == 0) {
+                    System.out.println("S: #E# cannot relay to " + receiver.getFullQualifiedName());
+                    return new RelayResult(new LocalRecipientNotReachable());
                 }
-                stanzaWriter.write(stanza);
+                for (SessionContext sessionContext : receivingSessions) {
+                    StanzaWriter stanzaWriter = null;
+                    try {
+                        stanzaWriter = sessionContext.getResponseWriter();
+                    } catch (Exception e) {
+                        return new RelayResult(e);
+                    }
+                    stanzaWriter.write(stanza);
+                }
+            } catch (RuntimeException e) {
+                return new RelayResult(e);
             }
             return new RelayResult();
         }
@@ -107,4 +115,4 @@
             return relayed;
         }
     }
-}
\ No newline at end of file
+}

Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachable.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachable.java?rev=657983&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachable.java
(added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/LocalRecipientNotReachable.java
Mon May 19 14:15:40 2008
@@ -0,0 +1,21 @@
+package org.apache.vysper.xmpp.delivery;
+
+/**
+ */
+public class LocalRecipientNotReachable extends DeliveryException {
+    public LocalRecipientNotReachable() {
+        super();
+    }
+
+    public LocalRecipientNotReachable(String string) {
+        super(string);
+    }
+
+    public LocalRecipientNotReachable(String string, Throwable throwable) {
+        super(string, throwable);
+    }
+
+    public LocalRecipientNotReachable(Throwable throwable) {
+        super(throwable);
+    }
+}

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java?rev=657983&r1=657982&r2=657983&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/PresenceHandler.java
Mon May 19 14:15:40 2008
@@ -64,6 +64,7 @@
         boolean hasFrom = verifier.attributePresent("from");
         boolean hasTo = verifier.attributePresent("to");
         boolean hasType = verifier.attributePresent("type");
+        boolean isOutbound = !hasFrom && hasTo && !sessionContext.isServerToServer();
         PresenceStanzaType type = presenceStanza.getPresenceType();
 
         if (!hasTo && !hasType) {
@@ -77,7 +78,7 @@
                 handleOutboundInitialPresence(presenceStanza, sessionContext, registry, initiatingEntity);
             }
 
-        } else if (hasType && hasTo && !hasFrom && !sessionContext.isServerToServer())
{
+        } else if (isOutbound && hasType) {
 			// this is an outbound subscription
 			// request/approval/cancellation/unsubscription
 			// stamp it with the bare JID of the user
@@ -159,8 +160,8 @@
             }
 
 		} else if (hasFrom && hasTo) {
-            throw new RuntimeException("unhandled presence stanza");
-        } else if (!hasFrom && hasType && type == PresenceStanzaType.UNAVAILABLE)
{
+            throw new RuntimeException("unhandled direct presence stanza");
+        } else if (hasType && type == PresenceStanzaType.UNAVAILABLE) {
             handleInboundUnavailable(presenceStanza, sessionContext);
         } else {
             System.err.println("unhandled presence case");

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java?rev=657983&r1=657982&r2=657983&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/resourcebinding/ResourceRegistry.java
Mon May 19 14:15:40 2008
@@ -125,8 +125,7 @@
     }
     
     public List<String> getResourcesForSession(SessionContext sessionContext) {
-		if (sessionContext == null)
-			return null;
+		if (sessionContext == null) return null;
 
 		List<String> resourceIds = new ArrayList<String>();
 		for (String resourceId : boundResources.keySet()) {
@@ -150,7 +149,8 @@
 	}
 
 	private Entity getBareEntity(Entity entity) {
-		if (!entity.isResourceSet())
+        if (entity == null) return null;
+        if (!entity.isResourceSet())
 			return entity; // bare already
 		return new EntityImpl(entity.getNode(), entity.getDomain(), null);
 	}
@@ -176,12 +176,12 @@
 	 */
 	public List<String> getBoundResources(Entity entity, boolean considerBareID) {
 		// all resources for the entity
-		List<String> resourceList = Collections
-				.unmodifiableList(getResourceList(entity));
+		List<String> resourceList = getResourceList(entity);
+        if (resourceList == null) return Collections.emptyList();
 
-		// if resource should not be considered, return all resources
+        // if resource should not be considered, return all resources
 		if (considerBareID || entity.getResource() == null)
-			return resourceList;
+			return Collections.unmodifiableList(resourceList);
 		// resource not contained, result is empty
 		if (!resourceList.contains(entity.getResource())) {
 			return Collections.emptyList();

Modified: labs/vysper/src/test/java/org/apache/vysper/smack/BasicClient.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/smack/BasicClient.java?rev=657983&r1=657982&r2=657983&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/smack/BasicClient.java (original)
+++ labs/vysper/src/test/java/org/apache/vysper/smack/BasicClient.java Mon May 19 14:15:40
2008
@@ -33,8 +33,8 @@
 public class BasicClient {
     public static void main(String[] args) throws XMPPException {
 
-        String me = args[0];
-        String to = args.length > 0 ? null : args[1];
+        String me = args.length > 0 ? args[0] : "user1";
+        String to = args.length < 1 ? null : args[1];
         
         try {
             ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("localhost");
@@ -51,7 +51,7 @@
 
             SASLAuthentication saslAuthentication = connection.getSASLAuthentication();
 //            saslAuthentication.authenticateAnonymously();
-//            saslAuthentication.authenticate("user1@localhost", "password1", "test");
+//            saslAuthentication.authenticate("user1@vysper.org", "password1", "test");
 
 //            if (!saslAuthentication.isAuthenticated()) return;
             
@@ -75,5 +75,6 @@
         } catch (Throwable e) {
             e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
         }
+        System.exit(0);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message