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/06/05 08:46:02 UTC

svn commit: r663473 - in /labs/vysper/src: main/config/ main/java/org/apache/vysper/mina/ main/java/org/apache/vysper/spring/ main/java/org/apache/vysper/stanzasession/ main/java/org/apache/vysper/xmpp/security/ main/java/org/apache/vysper/xmpp/server/...

Author: berndf
Date: Wed Jun  4 23:46:02 2008
New Revision: 663473

URL: http://svn.apache.org/viewvc?rev=663473&view=rev
Log:
[vysper] an easily embeddable server class (LABS-128)

Added:
    labs/vysper/src/main/java/org/apache/vysper/mina/TCPEndpoint.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/security/FileBasedTLSContextFactory.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/server/Endpoint.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/server/XMPPServer.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/EqualityVerifier.java
Modified:
    labs/vysper/src/main/config/spring-config.xml
    labs/vysper/src/main/java/org/apache/vysper/spring/ServerMain.java
    labs/vysper/src/main/java/org/apache/vysper/stanzasession/StanzaSessionFactory.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/security/BogusTrustManagerFactory.java
    labs/vysper/src/test/java/org/apache/vysper/stanzasession/StanzaSessionTestCase.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=663473&r1=663472&r2=663473&view=diff
==============================================================================
--- labs/vysper/src/main/config/spring-config.xml (original)
+++ labs/vysper/src/main/config/spring-config.xml Wed Jun  4 23:46:02 2008
@@ -93,23 +93,23 @@
     </bean>
     
     <!--
-        MINA configuration
+        MINA configuration: XMPP/TCP endpoint
     -->
     
+    <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
+        <property name="customEditors">
+            <map>
+                <entry key="java.net.SocketAddress">
+                    <bean class="org.apache.mina.integration.spring.InetSocketAddressEditor" />
+                </entry>
+            </map>
+        </property>
+    </bean>
+
     <bean id="xmppHandler" class="org.apache.vysper.mina.XmppIoHandlerAdapter">
         <property name="serverRuntimeContext" ref="server"/>
     </bean>
-    
-    <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
-      <property name="customEditors">
-        <map>
-          <entry key="java.net.SocketAddress">
-            <bean class="org.apache.mina.integration.spring.InetSocketAddressEditor" />
-          </entry>
-        </map>
-      </property>
-    </bean>
-    
+
     <bean id="xmppCodec" class="org.apache.vysper.mina.codec.XMPPProtocolCodecFactory">
     </bean>
 
@@ -147,4 +147,4 @@
     </bean>
 
 
-</beans>
\ No newline at end of file
+</beans>

Added: labs/vysper/src/main/java/org/apache/vysper/mina/TCPEndpoint.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/TCPEndpoint.java?rev=663473&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/TCPEndpoint.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/TCPEndpoint.java Wed Jun  4 23:46:02 2008
@@ -0,0 +1,74 @@
+/***********************************************************************
+ * 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.mina;
+
+import org.apache.mina.common.DefaultIoFilterChainBuilder;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.filter.executor.ExecutorFilter;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
+import org.apache.vysper.mina.codec.XMPPProtocolCodecFactory;
+import org.apache.vysper.xmpp.server.Endpoint;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
+/**
+ */
+public class TCPEndpoint implements Endpoint {
+
+    private ServerRuntimeContext serverRuntimeContext;
+
+    private int port = 5222;
+
+    private SocketAcceptor acceptor;
+
+    public void setServerRuntimeContext(ServerRuntimeContext serverRuntimeContext) {
+        this.serverRuntimeContext = serverRuntimeContext;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+
+    public void start() throws IOException {
+        XmppIoHandlerAdapter adapter = new XmppIoHandlerAdapter();
+        adapter.setServerRuntimeContext(serverRuntimeContext);
+
+        XMPPProtocolCodecFactory xmppCodec = new XMPPProtocolCodecFactory();
+
+        DefaultIoFilterChainBuilder filterChainBuilder = new DefaultIoFilterChainBuilder();
+        filterChainBuilder.addLast("executorFilter", new ExecutorFilter());
+        filterChainBuilder.addLast("xmppCodec", new ProtocolCodecFilter(xmppCodec));
+        filterChainBuilder.addLast("loggingFilter", new LoggingFilter());
+
+        SocketAcceptorConfig socketAcceptorConfig = new SocketAcceptorConfig();
+        socketAcceptorConfig.setFilterChainBuilder(filterChainBuilder);
+        socketAcceptorConfig.setReuseAddress(true);
+
+        SocketAcceptor acceptor = new SocketAcceptor();
+        acceptor.setDefaultConfig(socketAcceptorConfig);
+        acceptor.bind(new InetSocketAddress(port), adapter);
+        this.acceptor = acceptor;
+    }
+
+    public void stop() {
+        acceptor.unbindAll();
+    }
+}

Modified: labs/vysper/src/main/java/org/apache/vysper/spring/ServerMain.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/spring/ServerMain.java?rev=663473&r1=663472&r2=663473&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/spring/ServerMain.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/spring/ServerMain.java Wed Jun  4 23:46:02 2008
@@ -16,7 +16,12 @@
  ***********************************************************************/
 package org.apache.vysper.spring;
 
-import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.apache.vysper.xmpp.server.XMPPServer;
+import org.apache.vysper.xmpp.authorization.SimpleUserAuthorization;
+import org.apache.vysper.mina.TCPEndpoint;
+import org.apache.vysper.stanzasession.StanzaSessionFactory;
+
+import java.io.File;
 
 /**
  * starts the server as a standalone application
@@ -29,7 +34,25 @@
      * @param args
      */
     public static void main(String[] args) {
-        new ClassPathXmlApplicationContext("spring-config.xml");
-        System.out.println("vysper server is running...");
+        //new ClassPathXmlApplicationContext("spring-config.xml");
+
+        SimpleUserAuthorization userAuthorization = new SimpleUserAuthorization();
+        userAuthorization.addUser("user1@vysper.org", "password1");
+        userAuthorization.addUser("user2@vysper.org", "password1");
+        userAuthorization.addUser("user3@vysper.org", "password1");
+
+        XMPPServer server = new XMPPServer("vysper.org");
+        server.addEndpoint(new TCPEndpoint());
+        server.addEndpoint(new StanzaSessionFactory());
+        server.setUserAuthorization(userAuthorization);
+        
+        server.setTLSCertificateInfo(new File("src/main/config/bogus_mina_tls.cert"), "boguspw");
+
+        try {
+            server.start();
+            System.out.println("vysper server is running...");
+        } catch (Exception e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
     }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/stanzasession/StanzaSessionFactory.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/stanzasession/StanzaSessionFactory.java?rev=663473&r1=663472&r2=663473&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/stanzasession/StanzaSessionFactory.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/stanzasession/StanzaSessionFactory.java Wed Jun  4 23:46:02 2008
@@ -19,17 +19,14 @@
 import org.apache.vysper.xmpp.protocol.SessionStateHolder;
 import org.apache.vysper.xmpp.server.ServerRuntimeContext;
 import org.apache.vysper.xmpp.server.SessionState;
+import org.apache.vysper.xmpp.server.Endpoint;
 
 /**
  */
-public class StanzaSessionFactory {
+public class StanzaSessionFactory implements Endpoint {
     
     private ServerRuntimeContext serverRuntimeContext;
 
-    public StanzaSessionFactory(ServerRuntimeContext serverRuntimeContext) {
-        this.serverRuntimeContext = serverRuntimeContext;
-    }
-
     /**
      * returns a new session for the server. the session behaves like a client, but lives within the server JVM  
      */
@@ -40,4 +37,16 @@
         StanzaSession session = new StanzaSession(sessionContext);
         return session;
     }
+
+    public void setServerRuntimeContext(ServerRuntimeContext serverRuntimeContext) {
+        this.serverRuntimeContext = serverRuntimeContext;
+    }
+
+    public void start() {
+        // nothing to do
+    }
+
+    public void stop() {
+        // nothing to do
+    }
 }

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/security/BogusTrustManagerFactory.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/security/BogusTrustManagerFactory.java?rev=663473&r1=663472&r2=663473&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/security/BogusTrustManagerFactory.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/security/BogusTrustManagerFactory.java Wed Jun  4 23:46:02 2008
@@ -38,7 +38,7 @@
  *
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  */
-class BogusTrustManagerFactory extends TrustManagerFactorySpi implements TrustManagerFactory {
+public class BogusTrustManagerFactory extends TrustManagerFactorySpi implements TrustManagerFactory {
 
     static final X509TrustManager X509 = new X509TrustManager() {
         public void checkClientTrusted(X509Certificate[] x509Certificates,
@@ -75,4 +75,4 @@
     public TrustManager[] getTrustManagers() {
         return X509_MANAGERS;
     }
-}
\ No newline at end of file
+}

Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/security/FileBasedTLSContextFactory.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/security/FileBasedTLSContextFactory.java?rev=663473&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/security/FileBasedTLSContextFactory.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/security/FileBasedTLSContextFactory.java Wed Jun  4 23:46:02 2008
@@ -0,0 +1,36 @@
+/***********************************************************************
+ * 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.security;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.FileInputStream;
+
+/**
+ */
+public class FileBasedTLSContextFactory extends AbstractTLSContextFactory {
+    private File file;
+
+    public FileBasedTLSContextFactory(File file) {
+        this.file = file;
+    }
+
+    protected InputStream getCertificateInputStream() throws IOException {
+        return new FileInputStream(file);
+    }
+}

Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/Endpoint.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/Endpoint.java?rev=663473&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/Endpoint.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/Endpoint.java Wed Jun  4 23:46:02 2008
@@ -0,0 +1,32 @@
+/***********************************************************************
+ * 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.server;
+
+import java.io.IOException;
+
+/**
+ * an endpoint is at the intersection between a transport (e.g. TCP/IP, HTTP) and the server.
+ */
+public interface Endpoint {
+    
+    void setServerRuntimeContext(ServerRuntimeContext serverRuntimeContext);
+    
+    void start() throws IOException;
+    
+    void stop();
+    
+}

Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/server/XMPPServer.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/server/XMPPServer.java?rev=663473&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/server/XMPPServer.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/server/XMPPServer.java Wed Jun  4 23:46:02 2008
@@ -0,0 +1,123 @@
+/***********************************************************************
+ * 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.server;
+
+import org.apache.vysper.xmpp.protocol.NamespaceHandlerDictionary;
+import org.apache.vysper.xmpp.resourcebinding.ResourceRegistry;
+import org.apache.vysper.xmpp.delivery.DeliveringStanzaRelay;
+import org.apache.vysper.xmpp.delivery.MasterStanzaRelay;
+import org.apache.vysper.xmpp.delivery.RecordingStanzaRelay;
+import org.apache.vysper.xmpp.authorization.Plain;
+import org.apache.vysper.xmpp.authorization.SASLMechanism;
+import org.apache.vysper.xmpp.authorization.UserAuthorization;
+import org.apache.vysper.xmpp.addressing.EntityImpl;
+import org.apache.vysper.xmpp.security.FileBasedTLSContextFactory;
+import org.apache.vysper.xmpp.security.BogusTrustManagerFactory;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.io.File;
+
+/**
+ */
+public class XMPPServer {
+
+    private final List<SASLMechanism> saslMechanisms = new ArrayList<SASLMechanism>();
+    private String serverDomain;
+    private DefaultServerRuntimeContext serverRuntimeContext;
+    private UserAuthorization userAuthorization;
+    private File tlsCertificateFile;
+    private String tlsCertificatePassword;
+    private final List<Endpoint> endpoints = new ArrayList<Endpoint>();
+
+    public XMPPServer(String domain) {
+        this.serverDomain = domain;
+
+        // default list of SASL mechanisms
+        saslMechanisms.add(new Plain());
+    }
+    
+    public void setSASLMechanisms(List<SASLMechanism> validMechanisms) {
+        saslMechanisms.addAll(validMechanisms);
+    }
+
+    public void setUserAuthorization(UserAuthorization userAuthorization) {
+        this.userAuthorization = userAuthorization;
+    }
+
+    public void setTLSCertificateInfo(File certificate, String password) {
+        tlsCertificateFile = certificate;
+        tlsCertificatePassword = password;
+    }
+
+    public void addEndpoint(Endpoint endpoint) {
+        endpoints.add(endpoint);
+    }
+    
+    public void start() throws Exception {
+
+        BogusTrustManagerFactory bogusTrustManagerFactory = new BogusTrustManagerFactory();
+        FileBasedTLSContextFactory tlsContextFactory = new FileBasedTLSContextFactory(tlsCertificateFile);
+        tlsContextFactory.setPassword(tlsCertificatePassword);
+        tlsContextFactory.setTrustManagerFactory(bogusTrustManagerFactory);
+
+        List<NamespaceHandlerDictionary> dictionaries = new ArrayList<NamespaceHandlerDictionary>();
+        addCoreDictionaries(dictionaries);
+        dictionaries.add(new org.apache.vysper.xmpp.modules.roster.RosterDictionary());
+
+        ResourceRegistry resourceRegistry = new ResourceRegistry();
+        
+        DeliveringStanzaRelay internalStanzaRelay = new DeliveringStanzaRelay(resourceRegistry);
+        RecordingStanzaRelay externalStanzaRelay = new RecordingStanzaRelay();
+
+        MasterStanzaRelay masterStanzaRelay = new MasterStanzaRelay();
+        masterStanzaRelay.setInternalRelay(internalStanzaRelay);
+        masterStanzaRelay.setExternalRelay(externalStanzaRelay);
+
+        ServerFeatures serverFeatures = new ServerFeatures();
+        serverFeatures.setAuthenticationMethods(saslMechanisms);
+
+        EntityImpl serverEntity = new EntityImpl(null, serverDomain, null);
+
+        serverRuntimeContext = new DefaultServerRuntimeContext(serverEntity, masterStanzaRelay, serverFeatures, dictionaries, resourceRegistry);
+        serverRuntimeContext.setUserAuthorization(userAuthorization);
+        serverRuntimeContext.setTlsContextFactory(tlsContextFactory);
+
+        masterStanzaRelay.setServerRuntimeContext(serverRuntimeContext);
+
+        if (endpoints.size() == 0) throw new IllegalStateException("server must have at least one endpoint");
+        for (Endpoint endpoint : endpoints) {
+            endpoint.setServerRuntimeContext(serverRuntimeContext);
+            endpoint.start();
+        }
+    }
+
+    public void stop() {
+        for (Endpoint endpoint : endpoints) {
+            endpoint.stop();
+        }
+    }
+    
+    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());
+        dictionaries.add(new org.apache.vysper.xmpp.modules.core.sasl.SASLStanzaDictionary());
+        dictionaries.add(new org.apache.vysper.xmpp.modules.core.bind.BindResourceDictionary());
+        dictionaries.add(new org.apache.vysper.xmpp.modules.core.session.SessionStanzaDictionary());
+        dictionaries.add(new org.apache.vysper.xmpp.modules.core.compatibility.jabber_iq_auth.JabberIQAuthDictionary());
+    }
+}

Added: labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/EqualityVerifier.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/EqualityVerifier.java?rev=663473&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/EqualityVerifier.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/xmlfragment/EqualityVerifier.java Wed Jun  4 23:46:02 2008
@@ -0,0 +1,87 @@
+/***********************************************************************
+ * 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.xmlfragment;
+
+import java.util.Comparator;
+import java.util.TreeSet;
+import java.util.List;
+
+/**
+ */
+public class EqualityVerifier {
+
+    private static AttributeComparator ATTRIBUTE_COMPARATOR = new AttributeComparator();
+
+    /**
+     * checks only name, namespace and attributes of both XMLElements for equality,
+     * but not inner elements
+     */
+    public boolean equalsElements_Shallow(XMLElement first, XMLElement second) {
+        if (first == null) return second == null;
+        if (second == null) return false;
+        
+        if (!first.getName().equals(second.getName())) return false;
+        if (!first.getNamespace().equals(second.getNamespace())) return false;
+
+        return equalsAttributes(first.getAttributes(), second.getAttributes());
+    }
+
+    /**
+     * additional to the shallow check, does check the inner elements. more precisely, it checks whether
+     * all inner elements at corresponding positions are equal. it does _not_ check whether inner elements
+     * are the same for some proper mutation. 
+     */
+    public boolean equalsElements_DeepSameOrder(XMLElement first, XMLElement second) {
+        if (first == null) return second == null;
+        if (second == null) return false;
+        
+        if (!first.getName().equals(second.getName())) return false;
+        if (!first.getNamespace().equals(second.getNamespace())) return false;
+
+        boolean attrEquals = equalsAttributes(first.getAttributes(), second.getAttributes());
+        if (!attrEquals) return false;
+
+        List<XMLElement> firstInnerElements = first.getInnerElements();
+        List<XMLElement> secondInnerElements = second.getInnerElements();
+        
+        if (firstInnerElements.size() != secondInnerElements.size()) return false;
+        for (int i = 0; i < firstInnerElements.size(); i++) {
+            if (!equalsElements_DeepSameOrder(firstInnerElements.get(0), secondInnerElements.get(0))) return false;
+        }
+        return true;
+    }
+
+    private boolean equalsAttributes(List<Attribute> firstAttrs, List<Attribute> secondAttrs) {
+        TreeSet<Attribute> attrSorted1 = new TreeSet<Attribute>(ATTRIBUTE_COMPARATOR);
+        attrSorted1.addAll(firstAttrs);
+
+        TreeSet<Attribute> attrSorted2 = new TreeSet<Attribute>(ATTRIBUTE_COMPARATOR);
+        attrSorted2.addAll(secondAttrs);
+
+        return attrSorted1.equals(attrSorted2);
+    }
+
+    static class AttributeComparator implements Comparator<Attribute> {
+
+        public int compare(Attribute attribute1, Attribute attribute2) {
+            if (attribute1.getName().equals(attribute2.getName())) {
+                return attribute1.getValue().compareTo(attribute2.getValue());
+            }
+            return attribute1.getName().compareTo(attribute2.getName());
+        }
+    }
+}

Modified: labs/vysper/src/test/java/org/apache/vysper/stanzasession/StanzaSessionTestCase.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/test/java/org/apache/vysper/stanzasession/StanzaSessionTestCase.java?rev=663473&r1=663472&r2=663473&view=diff
==============================================================================
--- labs/vysper/src/test/java/org/apache/vysper/stanzasession/StanzaSessionTestCase.java (original)
+++ labs/vysper/src/test/java/org/apache/vysper/stanzasession/StanzaSessionTestCase.java Wed Jun  4 23:46:02 2008
@@ -57,7 +57,8 @@
 
         relay.setServerRuntimeContext(serverContext);
 
-        sessionFactory = new StanzaSessionFactory(serverContext);
+        sessionFactory = new StanzaSessionFactory();
+        sessionFactory.setServerRuntimeContext(serverContext);
     }
     
     public void testHandshake() {



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