Author: ngn
Date: Tue Aug 11 20:13:13 2009
New Revision: 803275
URL: http://svn.apache.org/viewvc?rev=803275&view=rev
Log:
Add support for letting modules register for subdomains (e.g.
pubsub.vysper.org) on which all stanzas will be routed to that handler if the
"to" attribute matches the subdomain (VYSPER-172)
Added:
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/AbstractHandlerDictionary.java
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/SubdomainHandlerDictionary.java
mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/TestUtil.java
- copied, changed from r802586,
mina/sandbox/vysper/trunk/server/extensions/xep0045-muc/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/TestUtil.java
Modified:
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/ModuleRegistry.java
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/NamespaceHandlerDictionary.java
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookup.java
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/XMPPServer.java
mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookupTestCase.java
Modified:
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/ModuleRegistry.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/ModuleRegistry.java?rev=803275&r1=803274&r2=803275&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/ModuleRegistry.java
(original)
+++
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/modules/ModuleRegistry.java
Tue Aug 11 20:13:13 2009
@@ -30,5 +30,5 @@
void addModule(Module module);
- void setModules(List<Module> modules);
+ void addModules(List<Module> modules);
}
Added:
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/AbstractHandlerDictionary.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/AbstractHandlerDictionary.java?rev=803275&view=auto
==============================================================================
---
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/AbstractHandlerDictionary.java
(added)
+++
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/AbstractHandlerDictionary.java
Tue Aug 11 20:13:13 2009
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.vysper.xmpp.protocol;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.vysper.xmpp.stanza.Stanza;
+
+/**
+ * Abstract class for implementations of {...@link HandlerDictionary}
+ *
+ * @author The Apache MINA Project ([email protected])
+ */
+public abstract class AbstractHandlerDictionary implements HandlerDictionary {
+
+ private List<StanzaHandler> handlerList = new ArrayList<StanzaHandler>();
+ private boolean sealed = false;
+
+ public AbstractHandlerDictionary() {
+ }
+
+ public AbstractHandlerDictionary(List<StanzaHandler> handlerList) {
+ if (handlerList != null) {
+ for (StanzaHandler stanzaHandler : handlerList) {
+ register(stanzaHandler);
+ }
+ }
+ seal();
+ }
+
+ public AbstractHandlerDictionary(StanzaHandler stanzaHandler) {
+ register(stanzaHandler);
+ seal();
+ }
+
+ public void register(StanzaHandler stanzaHandler) {
+ if (sealed) throw new IllegalStateException("stanza directory is
sealed. registering denied.");
+ if (stanzaHandler == null || stanzaHandler.getName() == null) throw
new IllegalArgumentException("stanza handler not complete");
+
+ if (handlerList.contains(stanzaHandler)) throw new
IllegalStateException("stanza handler already in handlerList: " +
stanzaHandler.getName());
+ handlerList.add(stanzaHandler);
+ }
+
+ public void seal() {
+ sealed = true;
+ }
+
+ /**
+ * returns the first handler whose verify method returns true for the
given stanza
+ * @param stanza
+ */
+ public StanzaHandler get(Stanza stanza) {
+ for (StanzaHandler stanzaHandler : handlerList) {
+ if (stanzaHandler.verify(stanza)) return stanzaHandler;
+ }
+ return null;
+ }
+}
Modified:
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/NamespaceHandlerDictionary.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/NamespaceHandlerDictionary.java?rev=803275&r1=803274&r2=803275&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/NamespaceHandlerDictionary.java
(original)
+++
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/NamespaceHandlerDictionary.java
Tue Aug 11 20:13:13 2009
@@ -19,9 +19,6 @@
*/
package org.apache.vysper.xmpp.protocol;
-import org.apache.vysper.xmpp.stanza.Stanza;
-
-import java.util.ArrayList;
import java.util.List;
/**
@@ -29,56 +26,25 @@
*
* @author The Apache MINA Project ([email protected])
*/
-public class NamespaceHandlerDictionary implements HandlerDictionary {
+public class NamespaceHandlerDictionary extends AbstractHandlerDictionary {
private String namespaceURI;
- private List<StanzaHandler> handlerList = new ArrayList<StanzaHandler>();
- private boolean sealed = false;
public NamespaceHandlerDictionary(String namespaceURI) {
this.namespaceURI = namespaceURI;
}
public NamespaceHandlerDictionary(String namespaceURI, List<StanzaHandler>
handlerList) {
+ super(handlerList);
this.namespaceURI = namespaceURI;
- if (handlerList != null) {
- for (StanzaHandler stanzaHandler : handlerList) {
- register(stanzaHandler);
- }
- }
- seal();
}
public NamespaceHandlerDictionary(String namespaceURI, StanzaHandler
stanzaHandler) {
+ super(stanzaHandler);
this.namespaceURI = namespaceURI;
- register(stanzaHandler);
- seal();
}
public String getNamespaceURI() {
return namespaceURI;
}
-
- public void register(StanzaHandler stanzaHandler) {
- if (sealed) throw new IllegalStateException("stanza directory is
sealed. registering denied.");
- if (stanzaHandler == null || stanzaHandler.getName() == null) throw
new IllegalArgumentException("stanza handler not complete");
-
- if (handlerList.contains(stanzaHandler)) throw new
IllegalStateException("stanza handler already in handlerList: " +
stanzaHandler.getName());
- handlerList.add(stanzaHandler);
- }
-
- public void seal() {
- sealed = true;
- }
-
- /**
- * returns the first handler whose verify method returns true for the
given stanza
- * @param stanza
- */
- public StanzaHandler get(Stanza stanza) {
- for (StanzaHandler stanzaHandler : handlerList) {
- if (stanzaHandler.verify(stanza)) return stanzaHandler;
- }
- return null;
- }
}
Modified:
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookup.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookup.java?rev=803275&r1=803274&r2=803275&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookup.java
(original)
+++
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookup.java
Tue Aug 11 20:13:13 2009
@@ -19,6 +19,10 @@
*/
package org.apache.vysper.xmpp.protocol;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.apache.vysper.xmpp.addressing.Entity;
import org.apache.vysper.xmpp.modules.core.base.handler.IQHandler;
import org.apache.vysper.xmpp.modules.core.base.handler.MessageHandler;
import org.apache.vysper.xmpp.modules.core.base.handler.StreamStartHandler;
@@ -28,9 +32,6 @@
import org.apache.vysper.xmpp.stanza.XMPPCoreStanza;
import org.apache.vysper.xmpp.xmlfragment.XMLElement;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
/**
* for effeciently looking up the right handler for a stanza. at first this
class tries to determine the stanza's
* specific namespace which uniquely brings up a NamespaceHandlerDictionary.
then, all handlers in this directory
@@ -42,19 +43,48 @@
*/
public class StanzaHandlerLookup {
- private Map<String, NamespaceHandlerDictionary> dictionaries = new
LinkedHashMap<String, NamespaceHandlerDictionary>();
+ private Map<String, SubdomainHandlerDictionary> subdomainDictionaries =
new LinkedHashMap<String, SubdomainHandlerDictionary>();
+ private Map<String, NamespaceHandlerDictionary> namespaceDictionaries =
new LinkedHashMap<String, NamespaceHandlerDictionary>();
private IQHandler iqHandler = new IQHandler();
private MessageHandler messageHandler = new MessageHandler();
private PresenceHandler presenceHandler = new PresenceHandler();
private static final ServiceUnavailableStanzaErrorHandler
SERVICE_UNAVAILABLE_STANZA_ERROR_HANDLER = new
ServiceUnavailableStanzaErrorHandler();
+ private Entity serverEntity;
+
+ public StanzaHandlerLookup(Entity serverEntity) {
+ this.serverEntity = serverEntity;
+ }
+
public void addDictionary(NamespaceHandlerDictionary
namespaceHandlerDictionary) {
String namespace = namespaceHandlerDictionary.getNamespaceURI();
- if (dictionaries.containsKey(namespace)) throw new
IllegalArgumentException("dictionary already exists covering namespace " +
namespace);
- dictionaries.put(namespace, namespaceHandlerDictionary);
+ if (namespaceDictionaries.containsKey(namespace)) throw new
IllegalArgumentException("dictionary already exists covering namespace " +
namespace);
+ namespaceDictionaries.put(namespace, namespaceHandlerDictionary);
}
+ public void addDictionary(SubdomainHandlerDictionary
subdomainHandlerDictionary) {
+ Entity domain = subdomainHandlerDictionary.getDomain();
+ if(domain == null || domain.getDomain() == null) throw new
IllegalArgumentException("subdomain dictionary can not be added with null
domain");
+ if(domain.getDomain().equals(serverEntity.getDomain())) throw new
IllegalArgumentException("a module can not register for the server domain " +
domain);
+ if (subdomainDictionaries.containsKey(domain)) throw new
IllegalArgumentException("dictionary already exists covering the domain " +
domain);
+ subdomainDictionaries.put(domain.getDomain(),
subdomainHandlerDictionary);
+ }
+
+ private boolean forSubDomain(Stanza stanza) {
+ Entity to = stanza.getTo();
+
+ if(to != null) {
+ String stanzaDomain = to.getDomain();
+ String serverDomain = serverEntity.getDomain();
+
+ return stanzaDomain.endsWith(serverDomain) &&
!serverDomain.equals(stanzaDomain);
+ } else {
+ // no "to" attribute
+ return false;
+ }
+ }
+
/**
* looks into the stanza to see which handler is responsible, if any
* @param stanza
@@ -64,6 +94,13 @@
if (stanza == null) return null;
String name = stanza.getName();
+
+ // check if this stanza is for a subdomain, and if so, if we got a
module for it
+ if(forSubDomain(stanza)) {
+ StanzaHandler handler = getHandlerForSubdomain(stanza);
+ if(handler != null) return handler;
+ }
+
if ("xml".equals(name)) return new XMLPrologHandler();
else if ("stream".equals(name)) return new StreamStartHandler();
else if (iqHandler.verify(stanza)) return getIQHandler(stanza);
@@ -82,6 +119,26 @@
}
}
+ private StanzaHandler getHandlerForSubdomain(Stanza stanza) {
+ // check if we got a handler for this subdomain
+ HandlerDictionary handlerDic =
subdomainDictionaries.get(stanza.getTo().getDomain());
+ if(handlerDic != null) {
+ // a module has registered for this domain
+ StanzaHandler handler = handlerDic.get(stanza);
+ if(handler != null) {
+ // found a handler, return
+ return handler;
+ } else {
+ // all messages for a subdomain must be handled by the module
which has
+ // registered for the domain, or we return unsupported stanza
+ return SERVICE_UNAVAILABLE_STANZA_ERROR_HANDLER;
+ }
+ } else {
+ // no module has registered for this subdomain
+ return null;
+ }
+ }
+
private StanzaHandler getPresenceHandler(Stanza stanza) {
return getHandler(stanza, presenceHandler);
}
@@ -115,12 +172,12 @@
private StanzaHandler getHandlerForElement(Stanza stanza, XMLElement
xmlElement) {
String namespace = xmlElement.getNamespaceURI();
- NamespaceHandlerDictionary namespaceHandlerDictionary =
dictionaries.get(namespace);
+ NamespaceHandlerDictionary namespaceHandlerDictionary =
namespaceDictionaries.get(namespace);
// another try to get a dictionary
if (namespaceHandlerDictionary == null) {
namespace = xmlElement.getNamespacePrefix();
- namespaceHandlerDictionary = dictionaries.get(namespace);
+ namespaceHandlerDictionary = namespaceDictionaries.get(namespace);
}
if (namespaceHandlerDictionary != null) return
namespaceHandlerDictionary.get(stanza);
Added:
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/SubdomainHandlerDictionary.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/SubdomainHandlerDictionary.java?rev=803275&view=auto
==============================================================================
---
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/SubdomainHandlerDictionary.java
(added)
+++
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/protocol/SubdomainHandlerDictionary.java
Tue Aug 11 20:13:13 2009
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.vysper.xmpp.protocol;
+
+import java.util.List;
+
+import org.apache.vysper.xmpp.addressing.Entity;
+
+/**
+ * holds all stanza handlers for a distinct subdomain
+ *
+ * @author The Apache MINA Project ([email protected])
+ */
+public class SubdomainHandlerDictionary extends AbstractHandlerDictionary {
+
+ private Entity domain;
+
+ public SubdomainHandlerDictionary(Entity domin) {
+ this.domain = domin;
+ }
+
+ public SubdomainHandlerDictionary(Entity domin, List<StanzaHandler>
handlerList) {
+ super(handlerList);
+ this.domain = domin;
+ }
+
+ public SubdomainHandlerDictionary(Entity domin, StanzaHandler
stanzaHandler) {
+ super(stanzaHandler);
+ this.domain = domin;
+ }
+
+ public Entity getDomain() {
+ return domain;
+ }
+}
Modified:
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java?rev=803275&r1=803274&r2=803275&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java
(original)
+++
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java
Tue Aug 11 20:13:13 2009
@@ -20,6 +20,12 @@
package org.apache.vysper.xmpp.server;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.net.ssl.SSLContext;
+
import org.apache.vysper.storage.OpenStorageProviderRegistry;
import org.apache.vysper.storage.StorageProvider;
import org.apache.vysper.storage.StorageProviderRegistry;
@@ -36,6 +42,7 @@
import org.apache.vysper.xmpp.protocol.StanzaHandler;
import org.apache.vysper.xmpp.protocol.StanzaHandlerLookup;
import org.apache.vysper.xmpp.protocol.StanzaProcessor;
+import org.apache.vysper.xmpp.protocol.SubdomainHandlerDictionary;
import org.apache.vysper.xmpp.stanza.Stanza;
import org.apache.vysper.xmpp.state.presence.LatestPresenceCache;
import org.apache.vysper.xmpp.state.presence.SimplePresenceCache;
@@ -45,11 +52,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.net.ssl.SSLContext;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
/**
*
* @author The Apache MINA Project ([email protected])
@@ -63,7 +65,7 @@
/**
* directory where all available processors for incoming stanzas are
located
*/
- private StanzaHandlerLookup stanzaHandlerLookup = new
StanzaHandlerLookup();
+ private StanzaHandlerLookup stanzaHandlerLookup;
/**
* the 'domain' the server is directly serving for
@@ -121,6 +123,7 @@
this.serverEntity = serverEntity;
this.stanzaRelay = stanzaRelay;
this.resourceRegistry = new ResourceRegistry();
+ this.stanzaHandlerLookup = new StanzaHandlerLookup(serverEntity);
}
public DefaultServerRuntimeContext(Entity serverEntity, StanzaRelay
stanzaRelay, StorageProviderRegistry storageProviderRegistry) {
@@ -182,6 +185,10 @@
stanzaHandlerLookup.addDictionary(namespaceHandlerDictionary);
}
+ public void addDictionary(SubdomainHandlerDictionary
subdomainHandlerDictionary) {
+ stanzaHandlerLookup.addDictionary(subdomainHandlerDictionary);
+ }
+
protected void addDictionaries(List<NamespaceHandlerDictionary>
dictionaries) {
for (NamespaceHandlerDictionary dictionary : dictionaries) {
addDictionary(dictionary);
@@ -236,7 +243,7 @@
return storageProviderRegistry.retrieve(clazz);
}
- public void setModules(List<Module> modules) {
+ public void addModules(List<Module> modules) {
for (Module module : modules) {
addModuleInternal(module);
}
@@ -269,13 +276,29 @@
List<HandlerDictionary> handlerDictionaryList =
module.getHandlerDictionaries();
if (handlerDictionaryList != null) {
+ boolean addedNamespaceHandler = false;
+ boolean addedSubdomainHandler = false;
+
for (HandlerDictionary handlerDictionary : handlerDictionaryList) {
if (handlerDictionary instanceof NamespaceHandlerDictionary) {
addDictionary((NamespaceHandlerDictionary)
handlerDictionary);
+ addedNamespaceHandler = true;
+ } else if (handlerDictionary instanceof
SubdomainHandlerDictionary) {
+ addDictionary((SubdomainHandlerDictionary)
handlerDictionary);
+ addedSubdomainHandler = true;
} else {
- throw new RuntimeException("arbitrary HandlerDictionary
implementations not supported yet, only NamespaceHandlerDictionary.");
+ throw new RuntimeException("arbitrary HandlerDictionary
implementations not supported yet, " +
+ "only NamespaceHandlerDictionary and
SubdomainHandlerDictionary.");
}
}
+
+ // make sure that a module does not add both namespace and
subdomain handlers
+ if(addedNamespaceHandler && addedSubdomainHandler) {
+ throw new RuntimeException("Module adding both " +
+ " NamespaceHandlerDictionary and
SubdomainHandlerDictionary. Only one type is" +
+ "allowed per module");
+
+ }
}
}
}
Modified:
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/XMPPServer.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/XMPPServer.java?rev=803275&r1=803274&r2=803275&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/XMPPServer.java
(original)
+++
mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/server/XMPPServer.java
Tue Aug 11 20:13:13 2009
@@ -19,7 +19,12 @@
*/
package org.apache.vysper.xmpp.server;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.vysper.storage.StorageProviderRegistry;
+import org.apache.vysper.xmpp.addressing.Entity;
import org.apache.vysper.xmpp.addressing.EntityImpl;
import org.apache.vysper.xmpp.authorization.AccountManagement;
import org.apache.vysper.xmpp.authorization.Plain;
@@ -33,12 +38,9 @@
import org.apache.vysper.xmpp.modules.roster.RosterModule;
import org.apache.vysper.xmpp.modules.servicediscovery.ServiceDiscoveryModule;
import org.apache.vysper.xmpp.protocol.NamespaceHandlerDictionary;
+import org.apache.vysper.xmpp.protocol.SubdomainHandlerDictionary;
import org.apache.vysper.xmpp.state.resourcebinding.ResourceRegistry;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* this class is able to boot a standalone XMPP server.
* <code>
@@ -135,11 +137,9 @@
}
public void addModule(Module module) {
- ArrayList<Module> list = new ArrayList<Module>();
- list.add(module);
- serverRuntimeContext.setModules(list);
+ serverRuntimeContext.addModule(module);
}
-
+
private void addCoreDictionaries(List<NamespaceHandlerDictionary>
dictionaries) {
dictionaries.add(new
org.apache.vysper.xmpp.modules.core.base.BaseStreamStanzaDictionary());
dictionaries.add(new
org.apache.vysper.xmpp.modules.core.starttls.StartTLSStanzaDictionary());
Copied:
mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/TestUtil.java
(from r802586,
mina/sandbox/vysper/trunk/server/extensions/xep0045-muc/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/TestUtil.java)
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/TestUtil.java?p2=mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/TestUtil.java&p1=mina/sandbox/vysper/trunk/server/extensions/xep0045-muc/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/TestUtil.java&r1=802586&r2=803275&rev=803275&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/server/extensions/xep0045-muc/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0045_muc/TestUtil.java
(original)
+++
mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/TestUtil.java
Tue Aug 11 20:13:13 2009
@@ -17,7 +17,7 @@
* under the License.
*
*/
-package org.apache.vysper.xmpp.modules.extension.xep0045_muc;
+package org.apache.vysper;
import junit.framework.TestCase;
Modified:
mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookupTestCase.java
URL:
http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookupTestCase.java?rev=803275&r1=803274&r2=803275&view=diff
==============================================================================
---
mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookupTestCase.java
(original)
+++
mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/protocol/StanzaHandlerLookupTestCase.java
Tue Aug 11 20:13:13 2009
@@ -21,6 +21,8 @@
import junit.framework.TestCase;
+import org.apache.vysper.TestUtil;
+import org.apache.vysper.xmpp.addressing.Entity;
import org.apache.vysper.xmpp.modules.core.base.BaseStreamStanzaDictionary;
import org.apache.vysper.xmpp.modules.core.base.handler.IQHandler;
import org.apache.vysper.xmpp.modules.core.base.handler.MessageHandler;
@@ -35,6 +37,9 @@
*/
public class StanzaHandlerLookupTestCase extends TestCase {
+ private static final Entity SERVER_ENTITY =
TestUtil.parseUnchecked("vysper.org");
+ private static final Entity SUBDOMAIN_ENTITY =
TestUtil.parseUnchecked("sub.vysper.org");
+
public void testDictionaryHierarchy() {
NamespaceHandlerDictionary upperNamespaceHandlerDictionary = new
NamespaceHandlerDictionary("testNSURI1");
CallTestStanzaHandler upperStanzaHandler = new
CallTestStanzaHandler("testDictionaryHierarchy", "testNSURI1");
@@ -45,7 +50,7 @@
lowerNamespaceHandlerDictionary.register(lowerStanzaHandler);
- StanzaHandlerLookup stanzaHandlerLookup = new StanzaHandlerLookup();
+ StanzaHandlerLookup stanzaHandlerLookup = new
StanzaHandlerLookup(SERVER_ENTITY);
stanzaHandlerLookup.addDictionary(upperNamespaceHandlerDictionary);
stanzaHandlerLookup.addDictionary(lowerNamespaceHandlerDictionary);
@@ -70,7 +75,7 @@
}
public void testLookupCoreHandlerClientNS() {
- StanzaHandlerLookup stanzaHandlerLookup = new StanzaHandlerLookup();
+ StanzaHandlerLookup stanzaHandlerLookup = new
StanzaHandlerLookup(SERVER_ENTITY);
stanzaHandlerLookup.addDictionary(new BaseStreamStanzaDictionary());
Stanza stanza = new StanzaBuilder("iq",
NamespaceURIs.JABBER_CLIENT).getFinalStanza();
@@ -82,7 +87,7 @@
}
public void testLookupCoreHandlerServerNS() {
- StanzaHandlerLookup stanzaHandlerLookup = new StanzaHandlerLookup();
+ StanzaHandlerLookup stanzaHandlerLookup = new
StanzaHandlerLookup(SERVER_ENTITY);
stanzaHandlerLookup.addDictionary(new BaseStreamStanzaDictionary());
Stanza stanza = new StanzaBuilder("iq",
NamespaceURIs.JABBER_SERVER).getFinalStanza();
@@ -94,7 +99,7 @@
}
public void testLookupCoreHandlerWrongNamespace() {
- StanzaHandlerLookup stanzaHandlerLookup = new StanzaHandlerLookup();
+ StanzaHandlerLookup stanzaHandlerLookup = new
StanzaHandlerLookup(SERVER_ENTITY);
stanzaHandlerLookup.addDictionary(new BaseStreamStanzaDictionary());
Stanza stanza = new StanzaBuilder("iq",
"arbitraryNamespace").getFinalStanza();
@@ -104,7 +109,7 @@
}
public void testLookupPresenceHandler() {
- StanzaHandlerLookup stanzaHandlerLookup = new StanzaHandlerLookup();
+ StanzaHandlerLookup stanzaHandlerLookup = new
StanzaHandlerLookup(SERVER_ENTITY);
stanzaHandlerLookup.addDictionary(new BaseStreamStanzaDictionary());
Stanza stanza = new StanzaBuilder("presence",
NamespaceURIs.JABBER_CLIENT).getFinalStanza();
@@ -115,7 +120,7 @@
}
public void testLookupMessageHandler() {
- StanzaHandlerLookup stanzaHandlerLookup = new StanzaHandlerLookup();
+ StanzaHandlerLookup stanzaHandlerLookup = new
StanzaHandlerLookup(SERVER_ENTITY);
stanzaHandlerLookup.addDictionary(new BaseStreamStanzaDictionary());
Stanza stanza = new StanzaBuilder("message",
NamespaceURIs.JABBER_CLIENT).getFinalStanza();
@@ -126,7 +131,7 @@
}
public void testLookupSpecializedIQHandler() {
- StanzaHandlerLookup stanzaHandlerLookup = new StanzaHandlerLookup();
+ StanzaHandlerLookup stanzaHandlerLookup = new
StanzaHandlerLookup(SERVER_ENTITY);
stanzaHandlerLookup.addDictionary(new BaseStreamStanzaDictionary());
NamespaceHandlerDictionary testDictionary = new
NamespaceHandlerDictionary("test:namespace:OK");
@@ -145,14 +150,34 @@
handler = stanzaHandlerLookup.getHandler(stanza);
assertNotNull("handler found", handler);
assertTrue("test handler",
TestIQHandler.class.equals(handler.getClass()));
+ }
+
+ public void testLookupSubdomain() {
+ StanzaHandlerLookup stanzaHandlerLookup = new
StanzaHandlerLookup(SERVER_ENTITY);
+
+ SubdomainHandlerDictionary testDictionary = new
SubdomainHandlerDictionary(SUBDOMAIN_ENTITY);
+ testDictionary.register(new TestIQHandler("test", "test:namespace"));
+ stanzaHandlerLookup.addDictionary(testDictionary);
+
+ Stanza stanza = buildStanza("test", "test:namespace",
"[email protected]");
+ StanzaHandler handler = stanzaHandlerLookup.getHandler(stanza);
+ assertNotNull("handler found", handler);
+ assertTrue("test handler",
TestIQHandler.class.equals(handler.getClass()));
}
private Stanza buildStanza(String name, String namespaceURI) {
+ return buildStanza(name, namespaceURI, null);
+ }
+
+ private Stanza buildStanza(String name, String namespaceURI, String to) {
StanzaBuilder stanzaBuilder = new StanzaBuilder("iq",
NamespaceURIs.JABBER_CLIENT);
stanzaBuilder.addAttribute("id", "1");
stanzaBuilder.addAttribute("type", "get");
+ if(to != null) {
+ stanzaBuilder.addAttribute("to", to);
+ }
stanzaBuilder.startInnerElement(name, namespaceURI).endInnerElement();
Stanza stanza = stanzaBuilder.getFinalStanza();
return stanza;