labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ber...@apache.org
Subject svn commit: r659976 - in /labs/vysper/src/main/java/org/apache/vysper/xmpp: delivery/ delivery/failure/ modules/core/base/handler/ resourcebinding/ server/response/ stanza/
Date Sun, 25 May 2008 12:30:00 GMT
Author: berndf
Date: Sun May 25 05:29:59 2008
New Revision: 659976

URL: http://svn.apache.org/viewvc?rev=659976&view=rev
Log:
[vysper] - adjust failure strategy process() signature
- returning error message stanza for unavailable entities now actually works
- store priority from presence in resource registry (needed for stanza propagation, see for
example draft-saintandre-rfc3921bis-04#8.3.1.1)

Modified:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveringStanzaRelay.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveryFailureStrategy.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaReceiverRelay.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/IgnoreFailureStrategy.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/ReturnErrorToSenderFailureStrategy.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.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/main/java/org/apache/vysper/xmpp/server/response/ServerErrorResponses.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/PresenceStanza.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/StanzaBuilder.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=659976&r1=659975&r2=659976&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 Sun
May 25 05:29:59 2008
@@ -86,7 +86,7 @@
         private RelayResult runFailureStrategy(RelayResult relayResult) {
             if (deliveryFailureStrategy != null) {
                 try {
-                    deliveryFailureStrategy.process(stanza, null, relayResult.getProcessingError());
+                    deliveryFailureStrategy.process(stanza, relayResult.getProcessingError());
                 } catch (DeliveryException e) {
                     return new RelayResult(e);
                 } catch (RuntimeException e) {

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveryFailureStrategy.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveryFailureStrategy.java?rev=659976&r1=659975&r2=659976&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveryFailureStrategy.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/DeliveryFailureStrategy.java
Sun May 25 05:29:59 2008
@@ -16,9 +16,8 @@
  
 ***********************************************************************/
 package org.apache.vysper.xmpp.delivery;
- 
+
 import org.apache.vysper.xmpp.stanza.Stanza;
-import org.apache.vysper.xmpp.server.ServerRuntimeContext;
  
 /**
  * there are many reasons why a stanza may fail to deliver: remote server not answering,
local addressee has
@@ -28,7 +27,13 @@
  * notified. 
  */
 public interface DeliveryFailureStrategy {
- 
-    public void process(Stanza failedToDeliverStanza, ServerRuntimeContext serverRuntimeContext,
DeliveryException deliveryException) throws DeliveryException;
+
+    /**
+     * 
+     * @param failedToDeliverStanza - stanza which could not be delivered
+     * @param deliveryException - optional: exception which occured during the failed delivery
+     * @throws DeliveryException - exception which occured during failure strategy execution.
+     */
+    public void process(Stanza failedToDeliverStanza, DeliveryException deliveryException)
throws DeliveryException;
     
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaReceiverRelay.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaReceiverRelay.java?rev=659976&r1=659975&r2=659976&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaReceiverRelay.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/StanzaReceiverRelay.java Sun
May 25 05:29:59 2008
@@ -47,7 +47,7 @@
         if (receiverMap.get(receiver) == null) {
 
             if (deliveryFailureStrategy != null && exploitFailureStrategy) {
-                deliveryFailureStrategy.process(stanza, serverRuntimeContext, null);
+                deliveryFailureStrategy.process(stanza, null);
             }
 
             throw new LocalRecipientNotReachableException("cannot find receiver" + receiver.getFullQualifiedName());

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/IgnoreFailureStrategy.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/IgnoreFailureStrategy.java?rev=659976&r1=659975&r2=659976&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/IgnoreFailureStrategy.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/IgnoreFailureStrategy.java
Sun May 25 05:29:59 2008
@@ -20,7 +20,6 @@
 import org.apache.vysper.xmpp.delivery.DeliveryFailureStrategy;
 import org.apache.vysper.xmpp.delivery.DeliveryException;
 import org.apache.vysper.xmpp.stanza.Stanza;
-import org.apache.vysper.xmpp.server.ServerRuntimeContext;
 
 /**
  */
@@ -28,7 +27,7 @@
 
     public final static IgnoreFailureStrategy IGNORE_FAILURE_STRATEGY = new IgnoreFailureStrategy();
     
-    public void process(Stanza failedToDeliverStanza, ServerRuntimeContext serverRuntimeContext,
DeliveryException deliveryException) {
+    public void process(Stanza failedToDeliverStanza, DeliveryException deliveryException)
{
         // do nothing                                                                   
                       
     }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/ReturnErrorToSenderFailureStrategy.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/ReturnErrorToSenderFailureStrategy.java?rev=659976&r1=659975&r2=659976&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/ReturnErrorToSenderFailureStrategy.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/failure/ReturnErrorToSenderFailureStrategy.java
Sun May 25 05:29:59 2008
@@ -16,19 +16,26 @@
  ***********************************************************************/
 package org.apache.vysper.xmpp.delivery.failure;
 
-import org.apache.vysper.xmpp.delivery.DeliveryFailureStrategy;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.addressing.EntityImpl;
 import org.apache.vysper.xmpp.delivery.DeliveryException;
+import org.apache.vysper.xmpp.delivery.DeliveryFailureStrategy;
 import org.apache.vysper.xmpp.delivery.LocalRecipientNotReachableException;
-import org.apache.vysper.xmpp.stanza.*;
-import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.apache.vysper.xmpp.delivery.StanzaRelay;
 import org.apache.vysper.xmpp.server.response.ServerErrorResponses;
-import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.stanza.*;
 
 /**
  */
 public class ReturnErrorToSenderFailureStrategy implements DeliveryFailureStrategy {
+    
+    private StanzaRelay stanzaRelay;
+
+    public ReturnErrorToSenderFailureStrategy(StanzaRelay stanzaRelay) {
+        this.stanzaRelay = stanzaRelay;
+    }
 
-    public void process(Stanza failedToDeliverStanza, ServerRuntimeContext serverRuntimeContext,
DeliveryException deliveryException) throws DeliveryException {
+    public void process(Stanza failedToDeliverStanza, DeliveryException deliveryException)
throws DeliveryException {
 
         StanzaErrorCondition stanzaErrorCondition = StanzaErrorCondition.SERVICE_UNAVAILABLE;
         StanzaErrorType errorType = StanzaErrorType.CANCEL;
@@ -50,10 +57,8 @@
                 }
             }
         }
-        
-        Entity from = failedCoreStanza.getFrom();
 
-        Stanza error = ServerErrorResponses.getInstance().getStanzaError(stanzaErrorCondition,
failedCoreStanza, errorType, "stanza could not be delivered", "en", null);
-        serverRuntimeContext.getStanzaRelay().relay(from, error, IgnoreFailureStrategy.IGNORE_FAILURE_STRATEGY);
+        XMPPCoreStanza error = XMPPCoreStanza.getWrapper(ServerErrorResponses.getInstance().getStanzaError(stanzaErrorCondition,
failedCoreStanza, errorType, "stanza could not be delivered", "en", null));
+        stanzaRelay.relay(error.getTo(), error, IgnoreFailureStrategy.IGNORE_FAILURE_STRATEGY);
     }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java?rev=659976&r1=659975&r2=659976&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java
Sun May 25 05:29:59 2008
@@ -80,7 +80,7 @@
         
         StanzaRelay stanzaRelay = sessionContext.getServerRuntimeContext().getStanzaRelay();
         try {
-            stanzaRelay.relay(to, stanza, new ReturnErrorToSenderFailureStrategy());
+            stanzaRelay.relay(to, stanza, new ReturnErrorToSenderFailureStrategy(stanzaRelay));
         } catch (Exception e) {
             // TODO return error stanza
             e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.

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=659976&r1=659975&r2=659976&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
Sun May 25 05:29:59 2008
@@ -173,6 +173,7 @@
 
     private void handleOutboundPresenceUpdate(PresenceStanza stanza, SessionContext sessionContext,

                                               ResourceRegistry registry, Entity initiatingEntity)
{
+        updateResourcePriority(registry, initiatingEntity, stanza.getPrioritySafe());
         System.out.println("C: has updated his presence");
     }
 
@@ -468,6 +469,7 @@
 	@SpecCompliant(spec = "RFC3921bis-04", section = "4.2.3")
 	private void handleInboundInitialPresence(PresenceStanza stanza,
                                            SessionContext sessionContext, ResourceRegistry
registry) {
+        updateResourcePriority(registry, sessionContext.getInitiatingEntity(), stanza.getPrioritySafe());
 		Entity user = stanza.getTo();
 		List<String> resources = registry.getAvailableResources(user);
 
@@ -477,7 +479,12 @@
 		}
 	}
 
-	private PresenceStanza buildPresenceStanza(Entity from, Entity to,
+    private void updateResourcePriority(ResourceRegistry registry, Entity initiatingEntity,
int priority) {
+        if (initiatingEntity == null || initiatingEntity.getResource() == null) return;
+        registry.setResourcePriority(initiatingEntity.getResource(), priority);
+    }
+
+    private PresenceStanza buildPresenceStanza(Entity from, Entity to,
 			String type) {
 		StanzaBuilder builder = new StanzaBuilder("presence");
 		builder.addAttribute("from", from.getFullQualifiedName());

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=659976&r1=659975&r2=659976&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
Sun May 25 05:29:59 2008
@@ -33,23 +33,29 @@
  * assigns and holds resource ids and their related session
  */
 public class ResourceRegistry {
+    private static class SessionData {
 
-	private static class SessionData {
-		SessionData(SessionContext context, ResourceState status) {
+        private final SessionContext context;
+
+        private ResourceState state;
+
+        private Integer priority;
+
+        SessionData(SessionContext context, ResourceState status, Integer priority) {
 			this.context = context;
 			this.state = status;
-		}
+            this.priority = priority == null ? 0 : priority;
+        }
 
-		private final SessionContext context;
-		private ResourceState state;
-	}
+    }
+
+    private UUIDGenerator resourceIdGenerator = new JVMBuiltinUUIDGenerator();
 
-	private UUIDGenerator resourceIdGenerator = new JVMBuiltinUUIDGenerator();
+    protected final Map<String, SessionData> boundResources = new HashMap<String,
SessionData>();
 
-	protected final Map<String, SessionData> boundResources = new HashMap<String, SessionData>();
-	protected final Map<Entity, List<String>> entityResources = new HashMap<Entity,
List<String>>();
+    protected final Map<Entity, List<String>> entityResources = new HashMap<Entity,
List<String>>();
 
-	public String bindSession(SessionContext sessionContext) {
+    public String bindSession(SessionContext sessionContext) {
 		if (sessionContext == null) {
 			throw new IllegalArgumentException("session context cannot be NULL");
 		}
@@ -62,7 +68,7 @@
 		synchronized (boundResources) {
 			synchronized (entityResources) {
 				boundResources.put(resourceId, new SessionData(sessionContext,
-						ResourceState.CONNECTED));
+						ResourceState.CONNECTED, 0));
 
 				Entity initiatingEntity = sessionContext.getInitiatingEntity();
 				List<String> resourceList = getResourceList(initiatingEntity);
@@ -78,11 +84,11 @@
 		return resourceId;
 	}
 
-	public Iterator<String> boundResources() {
+    public Iterator<String> boundResources() {
 		return Collections.unmodifiableSet(boundResources.keySet()).iterator();
 	}
 
-	public void unbindResource(String resourceId) {
+    public void unbindResource(String resourceId) {
 		synchronized (boundResources) {
 			synchronized (entityResources) {
 				SessionContext sessionContext = getSessionContext(resourceId);
@@ -94,7 +100,7 @@
 		}
 	}
 
-	public void unbindSession(SessionContext unbindingSessionContext) {
+    public void unbindSession(SessionContext unbindingSessionContext) {
 		if (unbindingSessionContext == null)
 			return;
 
@@ -118,12 +124,12 @@
 		}
 	}
 
-	public String getFirstResourceForSession(SessionContext sessionContext) {
+    public String getFirstResourceForSession(SessionContext sessionContext) {
         List<String> list = getResourcesForSession(sessionContext);
         if (list != null && list.size() > 0) return list.get(0);
         return null;
     }
-    
+
     public List<String> getResourcesForSession(SessionContext sessionContext) {
 		if (sessionContext == null) return null;
 
@@ -141,21 +147,21 @@
 		return resourceIds;
 	}
 
-	public SessionContext getSessionContext(String resourceId) {
+    public SessionContext getSessionContext(String resourceId) {
 		SessionData data = boundResources.get(resourceId);
 		if (data == null)
 			return null;
 		return data.context;
 	}
 
-	private Entity getBareEntity(Entity entity) {
+    private Entity getBareEntity(Entity entity) {
         if (entity == null) return null;
         if (!entity.isResourceSet())
 			return entity; // bare already
 		return new EntityImpl(entity.getNode(), entity.getDomain(), null);
 	}
 
-	/**
+    /**
 	 * @param entity
 	 * @return all resources bound to this entity modulo the entity's resource
 	 *         (if given)
@@ -164,14 +170,14 @@
 		return entityResources.get(getBareEntity(entity));
 	}
 
-	/**
+    /**
 	 * retrieve IDs of all bound resources for this entity
 	 */
 	public List<String> getBoundResources(Entity entity) {
 		return getBoundResources(entity, true);
 	}
 
-	/**
+    /**
 	 * retrieve IDs of all bound resources for this entity
 	 */
 	public List<String> getBoundResources(Entity entity, boolean considerBareID) {
@@ -190,7 +196,7 @@
 		return Collections.singletonList(entity.getResource());
 	}
 
-	public List<SessionContext> getSessions(Entity entity) {
+    public List<SessionContext> getSessions(Entity entity) {
 		List<SessionContext> sessionContexts = new ArrayList<SessionContext>();
 
 		List<String> boundResources = getBoundResources(entity, false);
@@ -201,7 +207,7 @@
 		return sessionContexts;
 	}
 
-	/**
+    /**
 	 * Sets the {@link ResourceState} for the given resource.
 	 * 
 	 * @param resourceId
@@ -217,7 +223,7 @@
 		data.state = state;
 	}
 
-	/**
+    /**
 	 * Gets the {@link ResourceState} of the given resource.
 	 * 
 	 * @param resourceId
@@ -231,7 +237,14 @@
 		return data.state;
 	}
 
-	/**
+    public void setResourcePriority(String resource, int priority) {
+        if (resource == null) return;
+        SessionData data = boundResources.get(resource);
+		if (data == null) return;
+		data.priority = priority;
+    }
+
+    /**
 	 * Checks whether the given resource is connected.
 	 * 
 	 * @param resourceId
@@ -242,7 +255,7 @@
 		return ResourceState.CONNECTED.equals(getResourceState(resourceId));
 	}
 
-	/**
+    /**
 	 * Checks whether the given resource is available.
 	 * 
 	 * @param resourceId

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerErrorResponses.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerErrorResponses.java?rev=659976&r1=659975&r2=659976&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerErrorResponses.java
(original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/response/ServerErrorResponses.java
Sun May 25 05:29:59 2008
@@ -98,12 +98,7 @@
                                                                "cannot respond to IQ stanza
of type error with the same", null);
         }
 
-        StanzaBuilder responseBuilder = new StanzaBuilder(stanza.getName(), stanza.getNamespace());
-
-        String id = stanza.getID();
-        if (id != null) responseBuilder.addAttribute("id", id);
-
-        responseBuilder.addAttribute("type", "error");
+        StanzaBuilder responseBuilder = StanzaBuilder.createDirectReply(stanza, true, "error");
 
         fillErrorStanza(stanza, type, errorCondition, errorText, errorLang, errorConditionElement,
responseBuilder);
 

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/PresenceStanza.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/PresenceStanza.java?rev=659976&r1=659975&r2=659976&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/PresenceStanza.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/PresenceStanza.java Sun May 25
05:29:59 2008
@@ -97,4 +97,11 @@
         return priorityValue;
     } 
     
+    public int getPrioritySafe() {
+        try {
+            return getPriority();
+        } catch (XMLSemanticError xmlSemanticError) {
+            return 0; // default
+        }
+    }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/StanzaBuilder.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/StanzaBuilder.java?rev=659976&r1=659975&r2=659976&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/StanzaBuilder.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/stanza/StanzaBuilder.java Sun May 25
05:29:59 2008
@@ -23,6 +23,7 @@
 import org.apache.vysper.xmpp.xmlfragment.XMLText;
 import org.apache.vysper.xmpp.xmlfragment.NamespaceAttribute;
 import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.addressing.EntityImpl;
 
 import java.util.Stack;
 import java.util.List;
@@ -63,6 +64,24 @@
         return stanzaBuilder;        
     }
     
+    public static StanzaBuilder createDirectReply(XMPPCoreStanza original, boolean fromIsServerOnly,
String type) {
+        StanzaBuilder stanzaBuilder = new StanzaBuilder(original.getName(), original.getNamespace());
+        // reverse to and from
+        Entity newTo = original.getFrom();
+        if (newTo != null) {
+            stanzaBuilder.addAttribute("to", newTo.getFullQualifiedName());
+        }
+        Entity newFrom = original.getTo();
+        if (newFrom != null) {
+            if (fromIsServerOnly) newFrom = new EntityImpl(null, newFrom.getDomain(), null);
+            stanzaBuilder.addAttribute("from", newFrom.getFullQualifiedName());
+        }
+        stanzaBuilder.addAttribute("type", type);
+        if (original.getID() != null) stanzaBuilder.addAttribute("id", original.getID());
+        
+        return stanzaBuilder;
+    }
+    
     class ElementStruct {
         public ElementStruct parentElement = null;
         public XMLElement element = null;



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


Mime
View raw message