1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.mina.examples.reverser;
20
21 import org.apache.mina.protocol.ProtocolHandler;
22 import org.apache.mina.protocol.ProtocolHandlerAdapter;
23 import org.apache.mina.protocol.ProtocolSession;
24
25 /***
26 * {@link ProtocolHandler} implementation of reverser server protocol.
27 *
28 * @author The Apache Directory Project (dev@directory.apache.org)
29 * @version $Rev: 332218 $, $Date: 2005-11-10 12:52:42 +0900 $,
30 */
31 public class ReverseProtocolHandler extends ProtocolHandlerAdapter
32 {
33 public void exceptionCaught( ProtocolSession session, Throwable cause )
34 {
35
36 session.close();
37 }
38
39 public void messageReceived( ProtocolSession session, Object message )
40 {
41
42 String str = message.toString();
43 StringBuffer buf = new StringBuffer( str.length() );
44 for( int i = str.length() - 1; i >= 0; i-- )
45 {
46 buf.append( str.charAt( i ) );
47 }
48
49
50 session.write( buf.toString() );
51 }
52 }