directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r448084 - in /directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec: Server.java ServerHandler.java
Date Wed, 20 Sep 2006 06:13:57 GMT
Author: trustin
Date: Tue Sep 19 23:13:57 2006
New Revision: 448084

URL: http://svn.apache.org/viewvc?view=rev&rev=448084
Log:
* Replaced all printlns with LoggingFilter

Modified:
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec/Server.java
    directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec/ServerHandler.java

Modified: directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec/Server.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec/Server.java?view=diff&rev=448084&r1=448083&r2=448084
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec/Server.java
(original)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec/Server.java
Tue Sep 19 23:13:57 2006
@@ -22,6 +22,8 @@
 import java.net.InetSocketAddress;
 
 import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
 import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
 
@@ -53,11 +55,18 @@
 
         try
         {
-            // Create ServiceRegistry.
+            // Create an acceptor
             IoAcceptor acceptor = new SocketAcceptor();
-            ( ( SocketAcceptorConfig ) acceptor.getDefaultConfig() )
-                    .setReuseAddress( true );
-            acceptor.bind( new InetSocketAddress( port ), new ServerHandler() );
+            
+            // Create a service configuration
+            SocketAcceptorConfig cfg = new SocketAcceptorConfig();
+            cfg.setReuseAddress( true );
+            cfg.getFilterChain().addLast(
+                    "protocolFilter",
+                    new ProtocolCodecFilter( new HttpServerProtocolCodecFactory() ) );
+            cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
+
+            acceptor.bind( new InetSocketAddress( port ), new ServerHandler(), cfg );
 
             System.out.println( "Server now listening on port " + port );
         }

Modified: directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec/ServerHandler.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec/ServerHandler.java?view=diff&rev=448084&r1=448083&r2=448084
==============================================================================
--- directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec/ServerHandler.java
(original)
+++ directory/trunks/mina/example/src/main/java/org/apache/mina/example/httpserver/codec/ServerHandler.java
Tue Sep 19 23:13:57 2006
@@ -21,9 +21,9 @@
 
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
 import org.apache.mina.common.IoSession;
-import org.apache.mina.filter.codec.ProtocolCodecFactory;
-import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.util.SessionLog;
 
 /**
  * An {@link IoHandler} for HTTP.
@@ -31,48 +31,18 @@
  * @author The Apache Directory Project (mina-dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
-public class ServerHandler implements IoHandler
+public class ServerHandler extends IoHandlerAdapter
 {
-    public ServerHandler()
-    {
-    }
-
-    public void sessionCreated( IoSession session ) throws Exception
-    {
-        ProtocolCodecFactory codec = new HttpServerProtocolCodecFactory();
-
-        session.getFilterChain().addFirst( "protocolFilter",
-                new ProtocolCodecFilter( codec ) );
-        //    session.getFilterChain().addLast("logger", new LoggingFilter());
-    }
-
     public void sessionOpened( IoSession session )
     {
-        System.out.println( "SERVER SESSIOn OPENED - "
-                + session.getRemoteAddress() );
         // set idle time to 60 seconds
         session.setIdleTime( IdleStatus.BOTH_IDLE, 60 );
     }
 
-    public void sessionClosed( IoSession session )
-    {
-        System.out.println( "SERVER SESSIOn CLOSED" );
-    }
-
     public void messageReceived( IoSession session, Object message )
     {
-        HttpResponseMessage response = null;
-
-        HttpRequestMessage msg = ( HttpRequestMessage ) message;
-
-        System.out
-                .println( "***************************  REQUEST  ***************************"
);
-        System.out.println( msg );
-        System.out
-                .println( "*****************************************************************"
);
-
         // Check that we can service the request context
-        response = new HttpResponseMessage();
+        HttpResponseMessage response = new HttpResponseMessage();
         response.setContentType( "text/plain" );
         response.setResponseCode( HttpResponseMessage.HTTP_STATUS_SUCCESS );
         response.appendBody( "CONNECTED" );
@@ -97,23 +67,14 @@
             session.write( response ).join();
     }
 
-    public void messageSent( IoSession session, Object message )
-    {
-        System.out.println( "  MESSAGE SENT - WRITTEN BYTES="
-                + session.getWrittenBytes() );
-    }
-
     public void sessionIdle( IoSession session, IdleStatus status )
     {
-        System.out.println( "Disconnecting the idle." );
-        // disconnect an idle client
+        SessionLog.info( session, "Disconnecting the idle." );
         session.close();
     }
 
     public void exceptionCaught( IoSession session, Throwable cause )
     {
-        cause.printStackTrace();
-        // close the connection on exceptional situation
         session.close();
     }
 }



Mime
View raw message