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 2007/09/11 15:41:09 UTC

svn commit: r574597 - in /labs/vysper: ./ src/main/java/org/apache/vysper/mina/ src/main/java/org/apache/vysper/mina/codec/ src/main/java/org/apache/vysper/spring/ src/main/java/org/apache/vysper/xmpp/applicationdomains/base/ src/main/java/org/apache/v...

Author: berndf
Date: Tue Sep 11 06:41:08 2007
New Revision: 574597

URL: http://svn.apache.org/viewvc?rev=574597&view=rev
Log:
[vysper] introduce MINA, use Spring and have a basic standalone Server actually receiving something

Added:
    labs/vysper/src/main/java/org/apache/vysper/mina/
    labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java
    labs/vysper/src/main/java/org/apache/vysper/mina/codec/
    labs/vysper/src/main/java/org/apache/vysper/mina/codec/StanzaWriterProtocolEncoder.java
    labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolCodecFactory.java
    labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java
    labs/vysper/src/main/java/org/apache/vysper/spring/
    labs/vysper/src/main/java/org/apache/vysper/spring/ServerMain.java
Removed:
    labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/base/StanzaErrorCondition.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/applicationdomains/base/StanzaErrorType.java
Modified:
    labs/vysper/NOTICE.txt
    labs/vysper/src/main/java/org/apache/vysper/xmpp/parser/AbstractNekopullStreamParser.java
    labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java

Modified: labs/vysper/NOTICE.txt
URL: http://svn.apache.org/viewvc/labs/vysper/NOTICE.txt?rev=574597&r1=574596&r2=574597&view=diff
==============================================================================
--- labs/vysper/NOTICE.txt (original)
+++ labs/vysper/NOTICE.txt Tue Sep 11 06:41:08 2007
@@ -8,14 +8,23 @@
    This product includes software developed at
    The Apache Software Foundation (http://www.apache.org/).
 
-   This product also includes software developed by :
-     - TBD JUnit
-     - TBD springframework.org
+   This product also includes software developed by
+     Spring Framework (http://www.springframework.org/).
+
+   This product also includes software developed by
+     The Legends of the Bouncy Castle (http://www.bouncycastle.org).
+
+   This product also includes software developed by
+     Erich Gamma, Kent Beck and the JUnit Team (http://junit.sourceforge.org)
+   under The Common Public License 1.0.
+
+   This product also includes software developed at
+     slf4j.org (http://slf4j.org).
+   under the MIT License
 
    This product also includes software ("nekopull") developed by Andy Clark
    under The CyberNeko Software License, Version 1.0
    NekoPull is used with kind permission of Andy Clark (andyc at a. o.). Thanks, Andy!
-   TBD add link to Nekopull
- 
-   Please read the LICENSE.txt and README.txt files in the root directory of 
+   
+   Please read the LICENSE.txt and ABOUT.txt files in the root directory of 
    this distribution.

Added: labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java?rev=574597&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java Tue Sep 11 06:41:08 2007
@@ -0,0 +1,50 @@
+/***********************************************************************
+ * 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.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.vysper.xmpp.protocol.ProtocolWorker;
+import org.apache.vysper.xmpp.protocol.SessionStateHolder;
+import org.apache.vysper.xmpp.server.DefaultServerRuntimeContext;
+import org.apache.vysper.xmpp.server.DefaultSessionContext;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.apache.vysper.xmpp.server.SessionContext;
+import org.apache.vysper.xmpp.stanza.Stanza;
+
+/**
+ */
+public class XmppIoHandlerAdapter extends IoHandlerAdapter {
+    
+    ProtocolWorker protocolWorker = new ProtocolWorker();
+    
+    public void messageReceived(IoSession ioSession, Object message) throws Exception {
+        if (!(message instanceof Stanza)) {
+            throw new IllegalArgumentException("xmpp handler only accepts Stanza-typed messages");
+        }
+
+        Stanza stanza = (Stanza) message;
+
+        ServerRuntimeContext mockedRuntimeContext = new DefaultServerRuntimeContext(null, null);
+        SessionStateHolder mockedstateHolder = new SessionStateHolder();
+        SessionContext mockedSessionContext = new DefaultSessionContext(mockedRuntimeContext, mockedstateHolder);
+        
+        protocolWorker.processStanza(mockedSessionContext, stanza, mockedstateHolder);
+        
+        super.messageReceived(ioSession, message);
+    }
+}

Added: labs/vysper/src/main/java/org/apache/vysper/mina/codec/StanzaWriterProtocolEncoder.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/codec/StanzaWriterProtocolEncoder.java?rev=574597&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/codec/StanzaWriterProtocolEncoder.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/codec/StanzaWriterProtocolEncoder.java Tue Sep 11 06:41:08 2007
@@ -0,0 +1,46 @@
+/***********************************************************************
+ * 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.codec;
+
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.mina.common.IoSession;
+import org.apache.vysper.xmpp.writer.StanzaWriter;
+import org.apache.vysper.xmpp.stanza.Stanza;
+
+/**
+ * connects MINA low level protocol and session stanza writer
+ */
+public class StanzaWriterProtocolEncoder implements ProtocolEncoder, StanzaWriter {
+    
+    public void encode(IoSession ioSession, Object o, ProtocolEncoderOutput protocolEncoderOutput) throws Exception {
+
+    }
+
+    public void dispose(IoSession ioSession) throws Exception {
+
+    }
+
+    public void write(Stanza stanza) {
+
+    }
+
+    public void close() {
+
+    }
+    
+}

Added: labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolCodecFactory.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolCodecFactory.java?rev=574597&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolCodecFactory.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolCodecFactory.java Tue Sep 11 06:41:08 2007
@@ -0,0 +1,41 @@
+/***********************************************************************
+ * 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.codec;
+
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+
+/**
+ */
+public class XMPPProtocolCodecFactory implements ProtocolCodecFactory {
+    private StanzaWriterProtocolEncoder encoder;
+    private ProtocolDecoder decoder;
+
+    public XMPPProtocolCodecFactory() {
+        encoder = new StanzaWriterProtocolEncoder();
+        decoder = new XMPPProtocolDecoder();
+    }
+
+    public ProtocolEncoder getEncoder() throws Exception {
+        return encoder;
+    }
+
+    public ProtocolDecoder getDecoder() throws Exception {
+        return decoder;
+    }
+}

Added: labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java?rev=574597&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java Tue Sep 11 06:41:08 2007
@@ -0,0 +1,60 @@
+/***********************************************************************
+ * 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.codec;
+
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.ByteBuffer;
+import org.apache.vysper.xmpp.parser.AbstractNekopullStreamParser;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.xerces.xni.parser.XMLInputSource;
+
+/**
+ */
+public class XMPPProtocolDecoder implements ProtocolDecoder {
+    
+    public void decode(IoSession ioSession, ByteBuffer byteBuffer, ProtocolDecoderOutput protocolDecoderOutput) throws Exception {
+        Parser parser = new Parser(byteBuffer);
+        Stanza nextStanza = parser.getNextStanza();
+        protocolDecoderOutput.write(nextStanza);
+    }
+
+    public void finishDecode(IoSession ioSession, ProtocolDecoderOutput protocolDecoderOutput) throws Exception {
+
+    }
+
+    public void dispose(IoSession ioSession) throws Exception {
+
+    }
+
+    // this is not a lightweight implementation!! should be replaced by something more seamless
+    class Parser extends AbstractNekopullStreamParser {
+
+        private ByteBuffer byteBuffer;
+
+        Parser(ByteBuffer byteBuffer) {
+            this.byteBuffer = byteBuffer;
+        }
+
+        protected XMLInputSource getInputSource() {
+            return new XMLInputSource(null, null, null, byteBuffer.asInputStream(), null);
+        }
+    }
+    
+    
+}

Added: 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=574597&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/spring/ServerMain.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/spring/ServerMain.java Tue Sep 11 06:41:08 2007
@@ -0,0 +1,33 @@
+/***********************************************************************
+ * 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.spring;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ */
+public class ServerMain {
+
+    /**
+     * boots the server as a standalone application according to the spring-config.xml file
+     * found on the classpath
+     * @param args
+     */
+    public static void main(String[] args) {
+        new ClassPathXmlApplicationContext("spring-config.xml");
+    }
+}

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/parser/AbstractNekopullStreamParser.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/parser/AbstractNekopullStreamParser.java?rev=574597&r1=574596&r2=574597&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/parser/AbstractNekopullStreamParser.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/parser/AbstractNekopullStreamParser.java Tue Sep 11 06:41:08 2007
@@ -81,6 +81,11 @@
         if (event.type != XMLEvent.DOCUMENT) throw new ParsingException("XML document event expected, but was type = " + event.type);
     }
 
+    /**
+     * blocking operation until next stanza is ready
+     * @return
+     * @throws ParsingException
+     */
     public Stanza getNextStanza() throws ParsingException {
         if (parser == null) open();
 

Modified: labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java?rev=574597&r1=574596&r2=574597&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/xmpp/protocol/ProtocolWorker.java Tue Sep 11 06:41:08 2007
@@ -60,7 +60,7 @@
     }
 
     /**
-     * reads next stanza from stream
+     * reads next stanza from stream, if the worker is used in a pull szenario (testing).
      * @param sessionContext
      * @param streamParser
      * @return new stanza



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