You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by be...@apache.org on 2008/04/09 15:51:36 UTC
svn commit: r646348 - in /labs/vysper/src/main: config/
java/org/apache/vysper/xmpp/delivery/ java/org/apache/vysper/xmpp/modules/
java/org/apache/vysper/xmpp/protocol/ java/org/apache/vysper/xmpp/server/
Author: berndf
Date: Wed Apr 9 06:51:34 2008
New Revision: 646348
URL: http://svn.apache.org/viewvc?rev=646348&view=rev
Log:
[vysper] make resource registry available on the ServerRuntimeContext level (LABS-94)
add license header to modules package files (LABS-115)
handle messages (LABS-100)
Added:
labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/MasterStanzaRelay.java
Modified:
labs/vysper/src/main/config/spring-config.xml
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ModuleRegistry.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ServerRuntimeContextService.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ServiceDiscoveryInfo.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/SessionStateHolder.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java
labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerRuntimeContext.java
Modified: labs/vysper/src/main/config/spring-config.xml
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/config/spring-config.xml?rev=646348&r1=646347&r2=646348&view=diff
==============================================================================
--- labs/vysper/src/main/config/spring-config.xml (original)
+++ labs/vysper/src/main/config/spring-config.xml Wed Apr 9 06:51:34 2008
@@ -33,7 +33,11 @@
<!--
Vysper Server singletons
-->
- <bean id="stanzaRelay" class="org.apache.vysper.xmpp.delivery.RecordingStanzaRelay" />
+ <bean name="resourceRegistry" class="org.apache.vysper.xmpp.resourcebinding.ResourceRegistry" />
+
+ <bean id="stanzaRelay" class="org.apache.vysper.xmpp.delivery.MasterStanzaRelay" >
+ <constructor-arg ref="resourceRegistry"/>
+ </bean>
<bean id="serverFeatures" class="org.apache.vysper.xmpp.server.ServerFeatures">
<constructor-arg value="true" />
@@ -65,13 +69,13 @@
<bean class="org.apache.vysper.xmpp.modules.core.compatibility.jabber_iq_auth.JabberIQAuthDictionary"/>
</list>
</constructor-arg>
+ <constructor-arg ref="resourceRegistry"/>
<property name="tlsContextFactory" ref="tlsContextFactory" />
<property name="userAuthorization" >
<bean class="org.apache.vysper.xmpp.authorization.SimpleUserAuthorization">
<constructor-arg index="0">
<map>
<entry key="user1@vysper.org" value="password1" />
- <entry key="user1@localhost" value="password1" />
</map>
</constructor-arg>
</bean>
Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/MasterStanzaRelay.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/MasterStanzaRelay.java?rev=646348&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/MasterStanzaRelay.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/delivery/MasterStanzaRelay.java Wed Apr 9 06:51:34 2008
@@ -0,0 +1,79 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.delivery;
+
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.resourcebinding.ResourceRegistry;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.server.SessionContext;
+import org.apache.vysper.xmpp.writer.StanzaWriter;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.List;
+
+/**
+ * relays stanzas to internal or external servers
+ * TODO: but right now, it only delivers to internal sessions
+ */
+public class MasterStanzaRelay implements StanzaRelay {
+
+ protected ResourceRegistry resourceRegistry;
+ protected final ExecutorService executor = Executors.newSingleThreadExecutor();
+
+ public MasterStanzaRelay(ResourceRegistry resourceRegistry) {
+ this.resourceRegistry = resourceRegistry;
+ }
+
+ public void relay(Entity receiver, Stanza stanza) throws DeliveryException {
+ executor.submit(new Relay(receiver, stanza));
+ }
+
+ public boolean receiverExists(Entity receiver) {
+ // TODO this is a temp solution, since we only check for 'online' users yet
+ return !resourceRegistry.getSessions(receiver).isEmpty();
+ }
+
+ private class Relay implements Callable<Boolean> {
+ private Entity receiver;
+ private Stanza stanza;
+
+ Relay(Entity receiver, Stanza stanza) {
+ this.receiver = receiver;
+ this.stanza = stanza;
+ }
+
+ public Entity getReceiver() {
+ return receiver;
+ }
+
+ public Stanza getStanza() {
+ return stanza;
+ }
+
+ public Boolean call() throws Exception {
+ List<SessionContext> receivingSessions = resourceRegistry.getSessions(receiver);
+ for (SessionContext sessionContext : receivingSessions) {
+ StanzaWriter stanzaWriter = sessionContext.getResponseWriter();
+ stanzaWriter.write(stanza);
+ }
+ return Boolean.TRUE;
+ }
+ }
+
+}
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ModuleRegistry.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ModuleRegistry.java?rev=646348&r1=646347&r2=646348&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ModuleRegistry.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ModuleRegistry.java Wed Apr 9 06:51:34 2008
@@ -1,3 +1,19 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.modules;
/**
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ServerRuntimeContextService.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ServerRuntimeContextService.java?rev=646348&r1=646347&r2=646348&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ServerRuntimeContextService.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ServerRuntimeContextService.java Wed Apr 9 06:51:34 2008
@@ -1,3 +1,19 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.modules;
/**
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ServiceDiscoveryInfo.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ServiceDiscoveryInfo.java?rev=646348&r1=646347&r2=646348&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ServiceDiscoveryInfo.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/modules/ServiceDiscoveryInfo.java Wed Apr 9 06:51:34 2008
@@ -1,3 +1,19 @@
+/***********************************************************************
+ * Copyright (c) 2006-2007 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.modules;
/**
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/SessionStateHolder.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/SessionStateHolder.java?rev=646348&r1=646347&r2=646348&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/SessionStateHolder.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/SessionStateHolder.java Wed Apr 9 06:51:34 2008
@@ -33,5 +33,9 @@
public void setState(SessionState newState) {
currentState = newState;
System.err.println("session state changed to = " + newState);
+if (currentState == SessionState.CLOSED) {
+ currentState = SessionState.AUTHENTICATED;
+}
+ System.err.println("session state changed to = " + newState);
}
}
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java?rev=646348&r1=646347&r2=646348&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/AbstractSessionContext.java Wed Apr 9 06:51:34 2008
@@ -36,7 +36,6 @@
protected String xmlLang;
protected SessionStateHolder sessionStateHolder;
protected Entity serverEntity;
- protected ResourceRegistry registry = new ResourceRegistry();
private Entity initiatingEntity;
private boolean serverToServer = false;
@@ -108,6 +107,6 @@
// TODO we should impose a hard limit on the number of bound resources per session (in ServerConfiguration)
// TODO to avoid DoS attacks based on resource binding and to shield against clients running berserk
- return registry.bindSession(this);
+ return getServerRuntimeContext().getResourceRegistry().bindSession(this);
}
}
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java?rev=646348&r1=646347&r2=646348&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/DefaultServerRuntimeContext.java Wed Apr 9 06:51:34 2008
@@ -22,19 +22,26 @@
import org.apache.vysper.xmpp.protocol.NamespaceHandlerDictionary;
import org.apache.vysper.xmpp.protocol.StanzaHandler;
import org.apache.vysper.xmpp.protocol.StanzaHandlerLookup;
+import org.apache.vysper.xmpp.protocol.HandlerDictionary;
import org.apache.vysper.xmpp.security.TLSContextFactory;
import org.apache.vysper.xmpp.stanza.Stanza;
import org.apache.vysper.xmpp.uuid.JVMBuiltinUUIDGenerator;
import org.apache.vysper.xmpp.uuid.UUIDGenerator;
import org.apache.vysper.xmpp.authorization.UserAuthorization;
import org.apache.vysper.xmpp.authorization.SimpleUserAuthorization;
+import org.apache.vysper.xmpp.modules.ModuleRegistry;
+import org.apache.vysper.xmpp.modules.Module;
+import org.apache.vysper.xmpp.modules.ServerRuntimeContextService;
+import org.apache.vysper.xmpp.resourcebinding.ResourceRegistry;
import javax.net.ssl.SSLContext;
import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
/**
*/
-public class DefaultServerRuntimeContext implements ServerRuntimeContext {
+public class DefaultServerRuntimeContext implements ServerRuntimeContext, ModuleRegistry {
private StanzaHandlerLookup stanzaHandlerLookup = new StanzaHandlerLookup();
private Entity serverEntity;
@@ -43,6 +50,8 @@
private SSLContext sslContext = null;
private UUIDGenerator resourceIdGenerator = new JVMBuiltinUUIDGenerator();
private UserAuthorization userAuthorization = new SimpleUserAuthorization();
+ private ResourceRegistry resourceRegistry;
+ final private Map<String, ServerRuntimeContextService> serverRuntimeContextServiceMap = new HashMap<String, ServerRuntimeContextService>();
public DefaultServerRuntimeContext(Entity serverEntity, StanzaRelay stanzaRelay) {
@@ -53,9 +62,11 @@
public DefaultServerRuntimeContext(Entity serverEntity,
StanzaRelay stanzaRelay,
ServerFeatures serverFeatures,
- List<NamespaceHandlerDictionary> dictionaries) {
+ List<NamespaceHandlerDictionary> dictionaries,
+ ResourceRegistry resourceRegistry) {
this(serverEntity, stanzaRelay);
this.serverFeatures = serverFeatures;
+ this.resourceRegistry = resourceRegistry;
addDictionaries(dictionaries);
}
@@ -110,7 +121,53 @@
return userAuthorization;
}
+ public ResourceRegistry getResourceRegistry() {
+ return resourceRegistry;
+ }
+
public void setUserAuthorization(UserAuthorization userAuthorization) {
this.userAuthorization = userAuthorization;
+ }
+
+ public void registerServerRuntimeContextService(ServerRuntimeContextService service) {
+ if (service == null) throw new IllegalStateException("service must not be null");
+ if (serverRuntimeContextServiceMap.get(service.getName()) == null) {
+ throw new IllegalStateException("service already registered: " + service.getName());
+ }
+ serverRuntimeContextServiceMap.put(service.getName(), service);
+ }
+
+ public ServerRuntimeContextService getServerRuntimeContextService(String name) {
+ return serverRuntimeContextServiceMap.get(name);
+ }
+
+ public void setModules(List<Module> modules) {
+ for (Module module : modules) {
+ addModule(module);
+ }
+ }
+
+ public void addModule(Module module) {
+
+ List<ServerRuntimeContextService> serviceList = module.getServerServices();
+ if (serviceList != null) {
+ for (ServerRuntimeContextService serverRuntimeContextService : serviceList) {
+ registerServerRuntimeContextService(serverRuntimeContextService);
+ }
+ }
+
+ // TODO not yet implemented: use module.getServiceDiscoveryInfos()
+
+ List<HandlerDictionary> handlerDictionaryList = module.getHandlerDictionaries();
+ if (handlerDictionaryList != null) {
+ for (HandlerDictionary handlerDictionary : handlerDictionaryList) {
+ if (handlerDictionary instanceof NamespaceHandlerDictionary) {
+ addDictionary((NamespaceHandlerDictionary) handlerDictionary);
+ } else {
+ throw new RuntimeException("arbitrary HandlerDictionary implementations not supported yet, only NamespaceHandlerDictionary.");
+ }
+ }
+ }
+
}
}
Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerRuntimeContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerRuntimeContext.java?rev=646348&r1=646347&r2=646348&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerRuntimeContext.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/ServerRuntimeContext.java Wed Apr 9 06:51:34 2008
@@ -22,6 +22,8 @@
import org.apache.vysper.xmpp.protocol.StanzaHandler;
import org.apache.vysper.xmpp.stanza.Stanza;
import org.apache.vysper.xmpp.authorization.UserAuthorization;
+import org.apache.vysper.xmpp.modules.ServerRuntimeContextService;
+import org.apache.vysper.xmpp.resourcebinding.ResourceRegistry;
import javax.net.ssl.SSLContext;
@@ -44,4 +46,10 @@
SSLContext getSslContext();
UserAuthorization getUserAuthorization();
+
+ ResourceRegistry getResourceRegistry();
+
+ void registerServerRuntimeContextService(ServerRuntimeContextService service);
+
+ ServerRuntimeContextService getServerRuntimeContextService(String name);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org