You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ra...@apache.org on 2019/09/01 09:29:54 UTC
[mina-vysper] branch master updated: In StanzaHandler,
use StanzaBroker.writeToSession instead of
SessionContext.getResponseWriter
This is an automated email from the ASF dual-hosted git repository.
ralaoui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-vysper.git
The following commit(s) were added to refs/heads/master by this push:
new ffce856 In StanzaHandler, use StanzaBroker.writeToSession instead of SessionContext.getResponseWriter
ffce856 is described below
commit ffce856c812c2ad6fadc86e1ba68198ab216e038
Author: RĂ©da Housni Alaoui <re...@gmail.com>
AuthorDate: Sun Sep 1 11:29:42 2019 +0200
In StanzaHandler, use StanzaBroker.writeToSession instead of SessionContext.getResponseWriter
---
.../modules/core/base/handler/MessageHandler.java | 4 +-
.../core/base/handler/RelayingIQHandler.java | 2 +-
.../core/base/handler/async/ResponseFuture.java | 5 --
.../im/handler/PresenceAvailabilityHandler.java | 5 +-
.../im/handler/PresenceSubscriptionHandler.java | 2 +-
.../xep0220_server_dailback/DbVerifyHandler.java | 2 +-
.../handler/DiscoInfoIQHandler.java | 2 +-
.../apache/vysper/xmpp/protocol/StanzaHandler.java | 7 ++-
.../apache/vysper/xmpp/server/SessionContext.java | 53 ++++++++++++----------
.../base/handler/RelayingIQHandlerTestCase.java | 4 +-
.../handler/DiscoInfoIQHandlerTestCase.java | 4 +-
11 files changed, 42 insertions(+), 48 deletions(-)
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 @@ public class MessageHandler extends XMPPCoreStanzaHandler {
// 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 @@ public class RelayingIQHandler extends IQHandler {
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 @@ abstract public class ResponseFuture<T extends XMPPCoreStanza> implements Runnab
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 @@ public class PresenceAvailabilityHandler extends AbstractPresenceSpecializedHand
// 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 @@ public class PresenceSubscriptionHandler extends AbstractPresenceSpecializedHand
// 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 @@ public class DbVerifyHandler implements StanzaHandler {
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 @@ public class DiscoInfoIQHandler extends DefaultIQHandler {
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 @@ public interface StanzaHandler {
/**
* 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 @@ public interface StanzaHandler {
* 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 @@ import org.apache.vysper.xmpp.writer.StanzaWriter;
*/
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 @@ public interface SessionContext {
*/
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 @@ public interface SessionContext {
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 @@ public interface SessionContext {
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 @@ public interface SessionContext {
/**
* 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 @@ public interface SessionContext {
/**
* 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 @@ public interface SessionContext {
/**
* 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 @@ public class RelayingIQHandlerTestCase extends PresenceHandlerBaseTestCase {
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 @@ public class DiscoInfoIQHandlerTestCase extends Mockito {
Assert.assertNull(response);
- verify(stanzaWriter).write(stanza);
+ verify(stanzaBroker).writeToSession(stanza);
}
@Test
@@ -333,7 +333,7 @@ public class DiscoInfoIQHandlerTestCase extends Mockito {
Assert.assertNull(response);
- verify(stanzaWriter).write(stanza);
+ verify(stanzaBroker).writeToSession(stanza);
}
private Stanza createErrorResponse(Entity from, String error) {