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/13 23:00:05 UTC
svn commit: r575449 - in /labs/vysper/src/main: config/spring-config.xml
java/org/apache/vysper/mina/MinaBackedSessionContext.java
java/org/apache/vysper/mina/XmppIoHandlerAdapter.java
java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java
Author: berndf
Date: Thu Sep 13 14:00:05 2007
New Revision: 575449
URL: http://svn.apache.org/viewvc?rev=575449&view=rev
Log:
[vysper] Spring config file; session creation; trying to have a continuous xml stream (but failing)
Added:
labs/vysper/src/main/config/spring-config.xml
labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java
Modified:
labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java
labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java
Added: labs/vysper/src/main/config/spring-config.xml
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/config/spring-config.xml?rev=575449&view=auto
==============================================================================
--- labs/vysper/src/main/config/spring-config.xml (added)
+++ labs/vysper/src/main/config/spring-config.xml Thu Sep 13 14:00:05 2007
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
+
+<!--
+ ! 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. !
+ -->
+
+<beans>
+
+ <!--
+ Vysper Server singletons
+ -->
+ <bean id="stanzaRelay" class="org.apache.vysper.xmpp.delivery.RecordingStanzaRelay" />
+
+ <bean id="server" class="org.apache.vysper.xmpp.server.DefaultServerRuntimeContext" >
+ <constructor-arg >
+ <bean class="org.apache.vysper.xmpp.addressing.EntityImpl" >
+ <constructor-arg value="vysper"/>
+ <constructor-arg value="org"/>
+ <constructor-arg value="server"/>
+ </bean>
+ </constructor-arg>
+ <constructor-arg ref="stanzaRelay"/>
+ </bean>
+
+ <!--
+ MINA configuration
+ -->
+
+ <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>
+
+ <!-- The filter chain. Adds an SSLFilter, a TextLineCodec and a LoggingFilter -->
+ <bean id="filterChainBuilder" class="org.apache.mina.integration.spring.DefaultIoFilterChainBuilderFactoryBean">
+ <property name="filters">
+ <list>
+ <bean class="org.apache.mina.filter.executor.ExecutorFilter" />
+ <!--<bean class="org.apache.mina.filter.SSLFilter">
+ <constructor-arg ref="sslContext"/>
+ </bean>-->
+ <bean class="org.apache.mina.filter.codec.ProtocolCodecFilter">
+ <constructor-arg>
+ <!-- UNUSED, REMOVE <bean class="org.apache.mina.filter.codec.textline.TextLineCodecFactory" /> -->
+ <bean class="org.apache.vysper.mina.codec.XMPPProtocolCodecFactory" />
+ </constructor-arg>
+ </bean>
+ <bean class="org.apache.mina.filter.LoggingFilter" />
+ </list>
+ </property>
+ </bean>
+
+ <!-- socket based xmpp: IoAcceptor binding to xmpp port 5222 -->
+ <bean id="ioAcceptor" class="org.apache.mina.integration.spring.IoAcceptorFactoryBean">
+ <property name="target">
+ <bean class="org.apache.mina.transport.socket.nio.SocketAcceptor" />
+ </property>
+ <property name="bindings">
+ <list>
+ <bean class="org.apache.mina.integration.spring.Binding">
+ <property name="address" value=":5222" />
+ <property name="handler" ref="xmppHandler" />
+ <property name="serviceConfig">
+ <bean class="org.apache.mina.transport.socket.nio.SocketAcceptorConfig">
+ <property name="filterChainBuilder" ref="filterChainBuilder" />
+ <property name="reuseAddress" value="true" />
+ </bean>
+ </property>
+ </bean>
+ </list>
+ </property>
+ </bean>
+
+
+</beans>
\ No newline at end of file
Added: labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java
URL: http://svn.apache.org/viewvc/labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java?rev=575449&view=auto
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java (added)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/MinaBackedSessionContext.java Thu Sep 13 14:00:05 2007
@@ -0,0 +1,34 @@
+package org.apache.vysper.mina;
+
+import org.apache.vysper.xmpp.server.DefaultSessionContext;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.apache.vysper.xmpp.protocol.SessionStateHolder;
+import org.apache.vysper.xmpp.writer.StanzaWriter;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.mina.common.IoSession;
+
+/**
+ */
+public class MinaBackedSessionContext extends DefaultSessionContext implements StanzaWriter {
+ private IoSession minaSession;
+
+ public MinaBackedSessionContext(
+ ServerRuntimeContext serverRuntimeContext,
+ SessionStateHolder sessionStateHolder,
+ IoSession minaSession) {
+ super(serverRuntimeContext, sessionStateHolder);
+ this.minaSession = minaSession;
+ }
+
+ public StanzaWriter getResponseWriter() {
+ return this;
+ }
+
+ public void write(Stanza stanza) {
+ minaSession.write(stanza);
+ }
+
+ public void close() {
+ minaSession.getCloseFuture().setClosed();
+ }
+}
Modified: 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=575449&r1=575448&r2=575449&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/XmppIoHandlerAdapter.java Thu Sep 13 14:00:05 2007
@@ -16,35 +16,66 @@
***********************************************************************/
package org.apache.vysper.mina;
-import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoHandler;
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 {
+public class XmppIoHandlerAdapter implements IoHandler {
- ProtocolWorker protocolWorker = new ProtocolWorker();
+ public static final String ATTRIBUTE_VYSPER_SESSION = "vysperSession";
+
+ private ServerRuntimeContext serverRuntimeContext;
+ ProtocolWorker protocolWorker = new ProtocolWorker();
+
+ public void setServerRuntimeContext(ServerRuntimeContext serverRuntimeContext) {
+ this.serverRuntimeContext = serverRuntimeContext;
+ }
+
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);
+ SessionContext session = extractSession(ioSession);
+ protocolWorker.processStanza(session, stanza, new SessionStateHolder());
+ }
+
+ private SessionContext extractSession(IoSession ioSession) {
+ return (SessionContext) ioSession.getAttribute(ATTRIBUTE_VYSPER_SESSION);
+ }
+
+ public void messageSent(IoSession ioSession, Object o) throws Exception {
+ // TODO implement
+ }
+
+ public void sessionCreated(IoSession ioSession) throws Exception {
+ SessionContext sessionContext = new MinaBackedSessionContext(serverRuntimeContext, new SessionStateHolder(), ioSession);
+ ioSession.setAttribute(ATTRIBUTE_VYSPER_SESSION, sessionContext);
+ }
+
+ public void sessionOpened(IoSession ioSession) throws Exception {
+ // TODO implement
+ }
+
+ public void sessionClosed(IoSession ioSession) throws Exception {
+ // TODO implement
+ }
+
+ public void sessionIdle(IoSession ioSession, IdleStatus idleStatus) throws Exception {
+ // TODO implement
+ }
+
+ public void exceptionCaught(IoSession ioSession, Throwable throwable) throws Exception {
+ // TODO implement
}
}
Modified: 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=575449&r1=575448&r2=575449&view=diff
==============================================================================
--- labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java (original)
+++ labs/vysper/src/main/java/org/apache/vysper/mina/codec/XMPPProtocolDecoder.java Thu Sep 13 14:00:05 2007
@@ -28,10 +28,20 @@
*/
public class XMPPProtocolDecoder implements ProtocolDecoder {
+ public static final String ATTRIBUTE_VYSPER_XLM_PARSER = "vysperXMLParser";
+
public void decode(IoSession ioSession, ByteBuffer byteBuffer, ProtocolDecoderOutput protocolDecoderOutput) throws Exception {
- Parser parser = new Parser(byteBuffer);
+
+ Parser parser = (Parser) ioSession.getAttribute(ATTRIBUTE_VYSPER_XLM_PARSER);
+ if (parser == null) {
+ parser = new Parser();
+ ioSession.setAttribute(ATTRIBUTE_VYSPER_XLM_PARSER, parser);
+ }
+
+ parser.copyLatest(byteBuffer);
+
Stanza nextStanza = parser.getNextStanza();
- protocolDecoderOutput.write(nextStanza);
+ if (nextStanza != null) protocolDecoderOutput.write(nextStanza);
}
public void finishDecode(IoSession ioSession, ProtocolDecoderOutput protocolDecoderOutput) throws Exception {
@@ -45,14 +55,18 @@
// this is not a lightweight implementation!! should be replaced by something more seamless
class Parser extends AbstractNekopullStreamParser {
- private ByteBuffer byteBuffer;
+ private ByteBuffer permanentByteBuffer;
- Parser(ByteBuffer byteBuffer) {
- this.byteBuffer = byteBuffer;
+ public Parser() {
+ this.permanentByteBuffer = ByteBuffer.allocate(16).setAutoExpand(true);
}
protected XMLInputSource getInputSource() {
- return new XMLInputSource(null, null, null, byteBuffer.asInputStream(), null);
+ return new XMLInputSource(null, null, null, permanentByteBuffer.asInputStream(), null);
+ }
+
+ public void copyLatest(ByteBuffer byteBuffer) {
+ permanentByteBuffer.put(byteBuffer);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org