directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nik...@apache.org
Subject svn commit: r448667 - in /directory/trunks/mina/example: ./ src/main/java/org/apache/mina/example/chat/ src/main/java/org/apache/mina/example/chat/client/
Date Thu, 21 Sep 2006 20:36:48 GMT
Author: niklas
Date: Thu Sep 21 13:36:47 2006
New Revision: 448667

URL: http://svn.apache.org/viewvc?view=rev&rev=448667
Log:
Added SSL and JMX support to chat server example (DIRMINA-227).

Added:
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ConnectDialog.java
  (with props)
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/jmxContext.xml
  (with props)
Modified:
    directory/trunks/mina/example/pom.xml
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/ChatProtocolHandler.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/Main.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/SpringMain.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ChatClientSupport.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/SwingChatClient.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/serverContext.xml

Modified: directory/trunks/mina/example/pom.xml
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/pom.xml?view=diff&rev=448667&r1=448666&r2=448667
==============================================================================
--- directory/trunks/mina/example/pom.xml (original)
+++ directory/trunks/mina/example/pom.xml Thu Sep 21 13:36:47 2006
@@ -34,7 +34,13 @@
       <artifactId>spring-context</artifactId>
       <version>1.2.8</version>
     </dependency>
-        
+    
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-support</artifactId>
+      <version>1.2.8</version>
+    </dependency>
+    
     <dependency>
       <groupId>commons-net</groupId>
       <artifactId>commons-net</artifactId>

Modified: directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/ChatProtocolHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/ChatProtocolHandler.java?view=diff&rev=448667&r1=448666&r2=448667
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/ChatProtocolHandler.java
(original)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/ChatProtocolHandler.java
Thu Sep 21 13:36:47 2006
@@ -148,4 +148,26 @@
     {
         return users.contains( name );
     }
+    
+    public int getNumberOfUsers()
+    {
+        return users.size();
+    }
+    
+    public void kick( String name )
+    {
+        synchronized( sessions )
+        {
+            Iterator iter = sessions.iterator();
+            while( iter.hasNext() )
+            {
+                IoSession s = ( IoSession ) iter.next();
+                if( name.equals( s.getAttribute( "user" ) ) )
+                {
+                    s.close();
+                    break;
+                }
+            }
+        }
+    }    
 }

Modified: directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/Main.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/Main.java?view=diff&rev=448667&r1=448666&r2=448667
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/Main.java (original)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/Main.java Thu
Sep 21 13:36:47 2006
@@ -24,7 +24,9 @@
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoAcceptorConfig;
+import org.apache.mina.example.echoserver.ssl.BogusSSLContextFactory;
 import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.SSLFilter;
 import org.apache.mina.filter.codec.ProtocolCodecFilter;
 import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
@@ -41,12 +43,21 @@
     /** Choose your favorite port number. */
     private static final int PORT = 1234;
     
+    /** Set this to true if you want to make the server SSL */
+    private static final boolean USE_SSL = false;
+    
     public static void main( String[] args ) throws Exception
     {
         IoAcceptor acceptor = new SocketAcceptor();
         IoAcceptorConfig config = new SocketAcceptorConfig();
         DefaultIoFilterChainBuilder chain = config.getFilterChain();
         
+        // Add SSL filter if SSL is enabled.
+        if( USE_SSL )
+        {
+            addSSLSupport( chain  );
+        }
+        
         chain.addLast( "codec", new ProtocolCodecFilter( new TextLineCodecFactory() ) );
         
         addLogger( chain );
@@ -59,6 +70,16 @@
 
         System.out.println( "Listening on port " + PORT );
     }
+    
+    private static void addSSLSupport( DefaultIoFilterChainBuilder chain )
+            throws Exception
+    {
+        SSLFilter sslFilter = new SSLFilter( BogusSSLContextFactory
+                .getInstance( true ) );
+        chain.addLast( "sslFilter", sslFilter );
+        System.out.println( "SSL ON" );
+    }
+
     
     private static void addLogger( DefaultIoFilterChainBuilder chain ) throws Exception
     {

Modified: directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/SpringMain.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/SpringMain.java?view=diff&rev=448667&r1=448666&r2=448667
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/SpringMain.java
(original)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/SpringMain.java
Thu Sep 21 13:36:47 2006
@@ -33,7 +33,15 @@
 
     public static void main( String[] args ) throws Exception
     {
-        new ClassPathXmlApplicationContext( getApplicationContext() );
+        if( System.getProperty( "com.sun.management.jmxremote" ) != null )
+        {
+            new ClassPathXmlApplicationContext( getJmxApplicationContexts() );
+            System.out.println( "JMX enabled." );
+        }
+        else {
+            new ClassPathXmlApplicationContext( getApplicationContext() );
+            System.out.println( "JMX disabled. Please set the 'com.sun.management.jmxremote'
system property to enable JMX." );
+        }
         System.out.println( "Listening ..." );
     }
 
@@ -42,4 +50,11 @@
         return "org/apache/mina/example/chat/serverContext.xml";
     }
 
+    public static String[] getJmxApplicationContexts()
+    {
+        return new String[] {
+                "org/apache/mina/example/chat/serverContext.xml",
+                "org/apache/mina/example/chat/jmxContext.xml"
+        };
+    }
 }

Modified: directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ChatClientSupport.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ChatClientSupport.java?view=diff&rev=448667&r1=448666&r2=448667
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ChatClientSupport.java
(original)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ChatClientSupport.java
Thu Sep 21 13:36:47 2006
@@ -19,13 +19,17 @@
  */
 package org.apache.mina.example.chat.client;
 
-import java.io.IOException;
 import java.net.SocketAddress;
 
+import javax.net.ssl.SSLContext;
+
 import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.example.echoserver.ssl.BogusSSLContextFactory;
+import org.apache.mina.filter.SSLFilter;
 import org.apache.mina.transport.socket.nio.SocketConnector;
+import org.apache.mina.transport.socket.nio.SocketConnectorConfig;
 
 /**
  * A simple chat client for a given user.
@@ -49,17 +53,39 @@
         this.handler = handler;
     }
 
-    public void connect( SocketConnector connector, SocketAddress address )
-            throws IOException
+    public boolean connect( SocketConnector connector, SocketAddress address, boolean useSsl
)
     {
         if( session != null && session.isConnected() )
         {
             throw new IllegalStateException( "Already connected. Disconnect first." );
         }
         
-        ConnectFuture future1 = connector.connect( address, handler );
-        future1.join();
-        session = future1.getSession();
+        try
+        {
+            
+            SocketConnectorConfig config = new SocketConnectorConfig();
+            if( useSsl )
+            {
+                SSLContext sslContext = BogusSSLContextFactory.getInstance( false );
+                SSLFilter sslFilter = new SSLFilter( sslContext );
+                sslFilter.setUseClientMode( true );
+                config.getFilterChain().addLast( "sslFilter", sslFilter );
+            }
+     
+            ConnectFuture future1 = connector.connect( address, handler, config );
+            future1.join();
+            if( ! future1.isConnected() )
+            {
+                return false;
+            }
+            session = future1.getSession();
+            
+            return true;
+        }
+        catch ( Exception e)
+        {
+            return false;
+        }
     }
 
     public void login()

Added: directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ConnectDialog.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ConnectDialog.java?view=auto&rev=448667
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ConnectDialog.java
(added)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ConnectDialog.java
Thu Sep 21 13:36:47 2006
@@ -0,0 +1,119 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2006 The Apache Software Foundation
+ *
+ *   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.mina.example.chat.client;
+
+import java.awt.BorderLayout;
+import java.awt.Frame;
+import java.awt.HeadlessException;
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+/**
+ *
+ * @author The Apache Directory Project (mina-dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ *
+ */
+public class ConnectDialog extends JDialog
+{
+    private String serverAddress;
+    private String username;
+    private boolean useSsl;
+    private boolean cancelled = false;
+
+    public ConnectDialog( Frame owner ) throws HeadlessException
+    {
+        super(owner, "Connect", true);
+
+        serverAddress = "localhost:1234";
+        username = "user" + Math.round( Math.random() * 10 );
+        
+        final JTextField serverAddressField = new JTextField( serverAddress );
+        final JTextField usernameField = new JTextField( username );
+        final JCheckBox useSslCheckBox = new JCheckBox( "Use SSL", false );
+        
+        JPanel content = new JPanel();
+        content.setLayout( new BoxLayout( content, BoxLayout.PAGE_AXIS ) );
+        content.add( new JLabel( "Server address" ) );
+        content.add( serverAddressField );
+        content.add( new JLabel( "Username" ) );
+        content.add( usernameField );
+        content.add( useSslCheckBox );
+
+        JButton okButton = new JButton();
+        okButton.setAction( new AbstractAction( "OK" )
+        {
+            public void actionPerformed( ActionEvent e )
+            {
+                serverAddress = serverAddressField.getText();
+                username = usernameField.getText();
+                useSsl = useSslCheckBox.isSelected();
+                ConnectDialog.this.dispose();
+            }
+        } );
+        
+        JButton cancelButton = new JButton();
+        cancelButton.setAction( new AbstractAction( "Cancel" )
+        {
+            public void actionPerformed( ActionEvent e )
+            {
+                cancelled = true;
+                ConnectDialog.this.dispose();
+            }
+        } );
+        
+        JPanel buttons = new JPanel();
+        buttons.add( okButton );
+        buttons.add( cancelButton );
+        
+        getContentPane().add( content, BorderLayout.CENTER );
+        getContentPane().add( buttons, BorderLayout.SOUTH );
+    }
+
+    
+    
+    public boolean isCancelled()
+    {
+        return cancelled;
+    }
+
+    public String getServerAddress()
+    {
+        return serverAddress;
+    }
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+    public boolean isUseSsl()
+    {
+        return useSsl;
+    }
+}

Propchange: directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/ConnectDialog.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/SwingChatClient.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/SwingChatClient.java?view=diff&rev=448667&r1=448666&r2=448667
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/SwingChatClient.java
(original)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/client/SwingChatClient.java
Thu Sep 21 13:36:47 2006
@@ -146,33 +146,27 @@
         public void actionPerformed( ActionEvent e )
         {
 
-            String value = JOptionPane.showInputDialog( SwingChatClient.this,
-                    "Specify server address (default: localhost:1234)" ); // "localhost";
-            if( value == null || value.length() == 0 )
-            {
-                value = "localhost:1234";
-            }
-            SocketAddress address = parseSocketAddress( value );
-            String name = JOptionPane.showInputDialog( SwingChatClient.this,
-                            "Specify name for chat session with no spaces (default: userN)"
);
-            if( name == null || name.length() == 0 )
-            {
-                name = "user" + Math.round( Math.random() * 10 );
-            }
-            name = name.trim();
+            ConnectDialog dialog = new ConnectDialog( SwingChatClient.this );
+            dialog.pack();
+            dialog.setVisible( true );
+            
+            if( dialog.isCancelled() )
+            {
+                return;
+            }
+            
+            SocketAddress address = parseSocketAddress( dialog.getServerAddress() );
+            String name = dialog.getUsername();
+            
             handler = new SwingChatClientHandler( SwingChatClient.this );
             client = new ChatClientSupport( name, handler );
             nameField.setText( name );
-            serverField.setText( value );
-            try
-            {
-                client.connect( connector, address );
-                area.setText( "" );
-            }
-            catch( Exception ex )
+            serverField.setText( dialog.getServerAddress() );
+            
+            if( ! client.connect( connector, address, dialog.isUseSsl() ) )
             {
                 JOptionPane.showMessageDialog( SwingChatClient.this,
-                        "Could not connect to " + value + ". " );
+                        "Could not connect to " + dialog.getServerAddress() + ". " );
             }
         }
     }
@@ -224,6 +218,7 @@
 
     private void setLoggedIn()
     {
+        area.setText( "" );
         inputText.setEnabled( true );
         quitButton.setEnabled( true );
         loginButton.setEnabled( false );
@@ -275,6 +270,7 @@
 
     public void disconnected()
     {
+        append( "Connection closed.\n" );
         setLoggedOut();
     }
 

Added: directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/jmxContext.xml
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/jmxContext.xml?view=auto&rev=448667
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/jmxContext.xml
(added)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/jmxContext.xml
Thu Sep 21 13:36:47 2006
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<beans>
+
+  <!-- JMX stuff. Creates an MBeanServer. -->
+  <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
+    <property name="locateExistingServerIfPossible" value="true"/>
+  </bean>
+
+  <!-- JMX stuff. Creates an MBeanServer. -->
+  <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
+    <property name="beans">
+      <map>
+        <entry key="chatServer:name=ioHandler" value-ref="chatHandler"/>
+      </map>
+    </property>
+    <property name="assembler">
+      <bean class="org.springframework.jmx.export.assembler.MethodNameBasedMBeanInfoAssembler">
+        <property name="managedMethods" value="isChatUser,getNumberOfUsers,kick"/>
+      </bean>
+    </property>
+    <property name="server">
+      <ref local="mbeanServer"/>
+    </property>
+  </bean>
+
+</beans>

Propchange: directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/jmxContext.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/serverContext.xml
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/serverContext.xml?view=diff&rev=448667&r1=448666&r2=448667
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/serverContext.xml
(original)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/chat/serverContext.xml
Thu Sep 21 13:36:47 2006
@@ -2,75 +2,99 @@
 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 <beans>
 
-<!-- 
-        Classic Spring approach : define each bean, then do the call to bind in code
+  <!-- This makes it possible to specify java.net.SocketAddress values 
+    (e.g. :1234 below) as Strings.
+    They will be converted into java.net.InetSocketAddress objects by Spring.  -->
+  <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="acceptor" class="org.apache.mina.transport.socket.nio.SocketAcceptor"
/>
-        <bean id="address" class="java.net.InetSocketAddress">
-            <constructor-arg>
-                <value>1234</value>
-            </constructor-arg>
-        </bean>
-         <bean id="chatHandler" class="server.ChatProtocolHandler" />
---> 
+  <!-- The IoHandler implementation -->
+  <bean id="chatHandler" class="org.apache.mina.example.chat.ChatProtocolHandler" />
 
-   <!-- MINA IoAcceptorFactoryBean approach -->
-   <!-- This makes it possible to specify java.net.SocketAddress values 
-        (e.g. :1234 below) as Strings.
-        They will be converted into java.net.InetSocketAddress objects by Spring.  -->
-   <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 IoHandler implementation -->
-   <bean id="chatHandler" class="org.apache.mina.example.chat.ChatProtocolHandler" />
-     
-   <bean id="filterChainBuilder" 
-         class="org.apache.mina.integration.spring.DefaultIoFilterChainBuilderFactoryBean">
-     <property name="filters">
-       <list>
-
-         <!-- Thread pool where threads will be named IoWorker-1, IoWorker-2, etc -->
-		 <!--
-         <bean class="org.apache.mina.filter.ThreadPoolFilter">
-           <constructor-arg value="IoWorker"/>
-           <property name="maximumPoolSize" value="10"/>
-         </bean>
-         -->
-         <bean class="org.apache.mina.filter.codec.ProtocolCodecFilter" >
+  <!-- The SSL configuration -->
+  <bean id="keyStore" class="org.apache.mina.integration.spring.ssl.KeyStoreFactoryBean">
+    <property name="resource" value="classpath:org/apache/mina/example/echoserver/ssl/bogus.cert"/>
+    <property name="password" value="boguspw"/>
+  </bean>
+  
+  <bean id="bogusTrustManagerFactory" class="org.apache.mina.integration.spring.ssl.BogusTrustManagerFactory"/>
+  
+  <!-- SSLContext to be used when acting as a server (client <-> proxy) -->
+  <bean id="sslContext"  class="org.apache.mina.integration.spring.ssl.SSLContextFactoryBean">
+    <property name="protocol" value="TLS"/>
+    <property name="keyManagerFactoryAlgorithm" value="SunX509"/>
+    <property name="keyManagerFactoryKeyStore"><ref local="keyStore"/></property>
+    <property name="keyManagerFactoryKeyStorePassword" value="boguspw"/>
+    <property name="trustManagerFactory"><ref local="bogusTrustManagerFactory"/></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.SSLFilter">
+          <constructor-arg ref="sslContext"/>
+        </bean>      
+        <bean class="org.apache.mina.filter.codec.ProtocolCodecFilter">
           <constructor-arg>
-           	<bean class="org.apache.mina.filter.codec.textline.TextLineCodecFactory" />
-           </constructor-arg>
-         </bean>
-         <bean class="org.apache.mina.filter.LoggingFilter"/>
-       </list>
-     </property>
-   </bean>
-
-   <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=":1234"/>
-           <property name="handler" ref="chatHandler"/>
-           <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
+            <bean class="org.apache.mina.filter.codec.textline.TextLineCodecFactory" />
+          </constructor-arg>
+        </bean>
+        <bean class="org.apache.mina.filter.LoggingFilter" />
+      </list>
+    </property>
+  </bean>
+
+  <!-- The IoAcceptor which binds to port 1234 -->
+  <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=":1234" />
+          <property name="handler" ref="chatHandler" />
+          <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>
+
+  <!-- JMX stuff. Creates an MBeanServer. -->
+  <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
+    <property name="locateExistingServerIfPossible" value="true"/>
+  </bean>
+
+  <!-- JMX stuff. Creates an MBeanServer. -->
+  <bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
+    <property name="beans">
+      <map>
+        <entry key="chatServer:name=ioHandler">
+          <ref local="chatHandler"/>
+        </entry>
+      </map>
+    </property>
+    <property name="assembler">
+      <bean class="org.springframework.jmx.export.assembler.MethodNameBasedMBeanInfoAssembler">
+        <property name="managedMethods" value="isChatUser,getNumberOfUsers,kick"/>
+      </bean>
+    </property>
+    <property name="server">
+      <ref local="mbeanServer"/>
+    </property>
+  </bean>
+
+</beans>



Mime
View raw message