In StanzaHandler, use StanzaBroker.writeToSession instead of SessionContext.getResponseWriter
diff --git a/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java b/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java
index 34e7c02..4958685 100644
--- a/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java
+++ b/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/MessageHandler.java
@@ -124,10 +124,8 @@
// TODO return error stanza
e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates.
}
- } else if (sessionContext != null) {
- sessionContext.getResponseWriter().write(stanza);
} else {
- throw new IllegalStateException("handling offline messages not implemented");
+ stanzaBroker.writeToSession(stanza);
}
return null;
}
diff --git a/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/RelayingIQHandler.java b/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/RelayingIQHandler.java
index 95bdf77..7604c90 100644
--- a/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/RelayingIQHandler.java
+++ b/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/RelayingIQHandler.java
@@ -114,7 +114,7 @@
stanza, StanzaErrorType.CANCEL, null, null, null));
}
- sessionContext.getResponseWriter().write(stanza);
+ stanzaBroker.writeToSession(stanza);
}
return Collections.emptyList();
diff --git a/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/async/ResponseFuture.java b/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/async/ResponseFuture.java
index eae552b..6bbf6e6 100644
--- a/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/async/ResponseFuture.java
+++ b/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/base/handler/async/ResponseFuture.java
@@ -44,9 +44,4 @@
this.sessionContext = sessionContext;
}
- protected void sendResponse(T response) throws DeliveryException {
- StanzaWriter stanzaWriter = sessionContext.getResponseWriter();
- stanzaWriter.write(response);
- }
-
}
diff --git a/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java b/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
index f014023..38b34c5 100644
--- a/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
+++ b/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceAvailabilityHandler.java
@@ -455,12 +455,9 @@
// TODO ?check if user has blocked contact?
- // write inbound stanza to the user
- sessionContext.getResponseWriter().write(stanza);
-
logger.info("{} has become available", stanza.getFrom().getFullQualifiedName());
- return null;
+ return stanza;
}
private void relayTo(Entity from, List<Entity> tos, PresenceStanza original, StanzaBroker stanzaBroker) {
diff --git a/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java b/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java
index be0ee1f..2a2d39c 100644
--- a/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java
+++ b/server/core/src/main/java/org/apache/vysper/xmpp/modules/core/im/handler/PresenceSubscriptionHandler.java
@@ -487,7 +487,7 @@
// TODO check if user has blocked contact
// write inbound subscription request to the user
- sessionContext.getResponseWriter().write(stanza);
+ stanzaBroker.writeToSession(stanza);
return null;
}
diff --git a/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0220_server_dailback/DbVerifyHandler.java b/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0220_server_dailback/DbVerifyHandler.java
index 75865a4..ec4fad2 100644
--- a/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0220_server_dailback/DbVerifyHandler.java
+++ b/server/core/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0220_server_dailback/DbVerifyHandler.java
@@ -116,7 +116,7 @@
builder.addAttribute("to", otherServer.getDomain());
builder.addAttribute("type", resultType);
- dialbackSessionContext.getResponseWriter().write(builder.build());
+ stanzaBroker.writeToSession(builder.build());
// }
// close this session as we are now done checking dialback
diff --git a/server/core/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandler.java b/server/core/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandler.java
index a498704..639cf07 100644
--- a/server/core/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandler.java
+++ b/server/core/src/main/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandler.java
@@ -192,7 +192,7 @@
logger.warn("relaying IQ failed", e);
}
} else {
- sessionContext.getResponseWriter().write(stanza);
+ stanzaBroker.writeToSession(stanza);
}
}
}
diff --git a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandler.java b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandler.java
index a2df28a..19ae032 100644
--- a/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandler.java
+++ b/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandler.java
@@ -52,7 +52,6 @@
/**
* verifies if the stanza is processed by this handler
*
- * @param stanza
* @return true, if it is processed, false otherwise
*/
boolean verify(Stanza stanza);
@@ -71,7 +70,7 @@
* false, if the session is receiving the stanza targeted to the
* session's client.
*/
- void execute(Stanza stanza, ServerRuntimeContext serverRuntimeContext,
- boolean isOutboundStanza, SessionContext sessionContext, SessionStateHolder sessionStateHolder,
- StanzaBroker stanzaBroker) throws ProtocolException;
+ void execute(Stanza stanza, ServerRuntimeContext serverRuntimeContext, boolean isOutboundStanza,
+ SessionContext sessionContext, SessionStateHolder sessionStateHolder, StanzaBroker stanzaBroker)
+ throws ProtocolException;
}
diff --git a/server/core/src/main/java/org/apache/vysper/xmpp/server/SessionContext.java b/server/core/src/main/java/org/apache/vysper/xmpp/server/SessionContext.java
index 0d1668c..f6d4b48 100644
--- a/server/core/src/main/java/org/apache/vysper/xmpp/server/SessionContext.java
+++ b/server/core/src/main/java/org/apache/vysper/xmpp/server/SessionContext.java
@@ -31,11 +31,11 @@
*/
public interface SessionContext {
- static final String SESSION_ATTRIBUTE_MESSAGE_STANZA_NO_RECEIVE = "stanza.message.no_receive";
+ String SESSION_ATTRIBUTE_MESSAGE_STANZA_NO_RECEIVE = "stanza.message.no_receive";
- static final String SESSION_ATTRIBUTE_PRESENCE_STANZA_NO_RECEIVE = "stanza.presence.no_receive";
+ String SESSION_ATTRIBUTE_PRESENCE_STANZA_NO_RECEIVE = "stanza.presence.no_receive";
- public enum SessionTerminationCause {
+ enum SessionTerminationCause {
/**
* underlying connection is broken
*/
@@ -49,8 +49,8 @@
*/
SERVER_SHUTDOWN,
/**
- * the server signalled a stream error to the client and subsequently needs
- * to close the session down
+ * the server signalled a stream error to the client and subsequently needs to
+ * close the session down
*/
STREAM_ERROR;
@@ -68,23 +68,21 @@
ServerRuntimeContext getServerRuntimeContext();
/**
- * FALSE iff _this_ server has initiated the connection (to another server),
- * and _not_ the remote side (client/server) initiated the session. for
- * common client/server connections this returns TRUE.
- *
- * @return
+ * FALSE iff _this_ server has initiated the connection (to another server), and
+ * _not_ the remote side (client/server) initiated the session. for common
+ * client/server connections this returns TRUE.
*/
boolean isRemotelyInitiatedSession();
/**
- * @return the initiating {@link Entity}. For c2s, this is the client {@link Entity}. For s2s, this is the server {@link Entity}
+ * @return the initiating {@link Entity}. For c2s, this is the client
+ * {@link Entity}. For s2s, this is the server {@link Entity}
*/
Entity getInitiatingEntity();
/**
- * Sets the initiating entity. For c2s, this is the client {@link Entity}. For s2s, this is the server {@link Entity}
- *
- * @param entity
+ * Sets the initiating entity. For c2s, this is the client {@link Entity}. For
+ * s2s, this is the server {@link Entity}
*/
void setInitiatingEntity(Entity entity);
@@ -110,8 +108,8 @@
SessionState getState();
/**
- * Returns the id for this session, which is unique inside a server instance
- * and across all hosted services.
+ * Returns the id for this session, which is unique inside a server instance and
+ * across all hosted services.
*
* @return this session's id
*/
@@ -136,7 +134,9 @@
/**
* Ends this session and the underlying TCP connection.
- * @param give the logical cause for the session's end
+ *
+ * @param terminationCause
+ * give the logical cause for the session's end
*/
void endSession(SessionTerminationCause terminationCause);
@@ -154,9 +154,8 @@
/**
* this method signals that from now on a new <stream:stream>... xml stream
- * begins. this is used at the very beginning of the session, then again
- * after encryption and after authentication. see RFC3920.7.5.7 and
- * RFC3920.6.2
+ * begins. this is used at the very beginning of the session, then again after
+ * encryption and after authentication. see RFC3920.7.5.7 and RFC3920.6.2
*/
void setIsReopeningXMLStream();
@@ -176,17 +175,23 @@
/**
* put arbitrary object into the session
- * @param key identifier used to retrieve the object
- * @param value NULL to not store an object with the key
+ *
+ * @param key
+ * identifier used to retrieve the object
+ * @param value
+ * NULL to not store an object with the key
* @return previous stored value object, or NULL
*/
Object putAttribute(String key, Object value);
/**
* retrieve object
- * @param key retrieve a previously stored attribute
+ *
+ * @param key
+ * retrieve a previously stored attribute
* @return stored object for the given key, or NULL
- * @see org.apache.vysper.xmpp.server.SessionContext#putAttribute(String, Object)
+ * @see org.apache.vysper.xmpp.server.SessionContext#putAttribute(String,
+ * Object)
*/
Object getAttribute(String key);
diff --git a/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/base/handler/RelayingIQHandlerTestCase.java b/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/base/handler/RelayingIQHandlerTestCase.java
index 8db7188..f004403 100644
--- a/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/base/handler/RelayingIQHandlerTestCase.java
+++ b/server/core/src/test/java/org/apache/vysper/xmpp/modules/core/base/handler/RelayingIQHandlerTestCase.java
@@ -87,8 +87,8 @@
relayingIQHandler.execute(iqStanza, sessionContext.getServerRuntimeContext(), false, sessionContext, null,
stanzaBroker/* don't we have as sessionStateHolder? */);
- assertFalse(stanzaBroker.hasStanzaWrittenToSession());
- Stanza deliveredStanza = sessionContext.getNextRecordedResponse();
+ Stanza deliveredStanza = stanzaBroker.getUniqueStanzaWrittenToSession();
+ assertNotNull(deliveredStanza);
assertTrue(deliveredStanza.getVerifier().onlySubelementEquals("mandatory", NamespaceURIs.JABBER_CLIENT));
assertEquals(initiatingUser.getEntityFQ(), deliveredStanza.getTo());
}
diff --git a/server/core/src/test/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandlerTestCase.java b/server/core/src/test/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandlerTestCase.java
index 8a005e5..253588c 100644
--- a/server/core/src/test/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandlerTestCase.java
+++ b/server/core/src/test/java/org/apache/vysper/xmpp/modules/servicediscovery/handler/DiscoInfoIQHandlerTestCase.java
@@ -228,7 +228,7 @@
Assert.assertNull(response);
- verify(stanzaWriter).write(stanza);
+ verify(stanzaBroker).writeToSession(stanza);
}
@Test
@@ -333,7 +333,7 @@
Assert.assertNull(response);
- verify(stanzaWriter).write(stanza);
+ verify(stanzaBroker).writeToSession(stanza);
}
private Stanza createErrorResponse(Entity from, String error) {