Guys, it was solved by adding this to the IoHandlerAdapter
implementation.================================================IoFilter CODEC_FILTER = new ProtocolCodecFilter(new ObjectSerializationCodecFactory());
public void sessionCreated(IoSession session) throws Exception {
session.getFilterChain().addLast( "codec", CODEC_FILTER );
================================================
I looked at Reverser example
I just want to say, thank you for such great framework.
[]s
Claudio
Em 29-06-2006 11:23, Claudio Miranda escreveu:
Hi folks,I am trying to develop a small POC using MINA, using IoHandler, and I am getting this exception:java.lang.IllegalStateException: Write requests must be transformed to class org.apache.mina.common.ByteBuffer: [Claudio Miranda | QE 28, cj. L, casa 3 | 30 | 9876.54 | [Tying code sucks | 23 | teste array 1, teste array 2, teste array 3, ]] at org.apache.mina.common.support.AbstractIoFilterChain$1.filterWrite(AbstractIoFilterChain.java:128)See the attached code: ProtocolEchoHandler is the server part and there is the Client class. The exception is throw when the Client class is invoked. The MyVO is a POJO class (not serializable).I see at Tennis example, the session.write(new TennisBall(10)); and the TennisBall is not serializable, but I thing this doesn't matter.http://svn.apache.org/viewvc/directory/trunks/mina/examples/src/main/java/org/apache/mina/examples/tennis/Main.java?revision=400068&view=markupSo, how can I use IoHandler and use session to write POJO classes ? Thanks in advance ------------------------------------------------------------------------ package claudius; import java.net.InetSocketAddress; import org.apache.mina.common.ConnectFuture; import org.apache.mina.common.IoConnectorConfig; import org.apache.mina.common.IoSession; import org.apache.mina.transport.socket.nio.SocketConnector; public class Client {public static void main(String[] args) throws Exception {SocketConnector connector = new SocketConnector();// Set connect timeout.( ( IoConnectorConfig ) connector.getDefaultConfig()).setConnectTimeout( 30 );// Start communication.InetSocketAddress address = new InetSocketAddress("localhost",9999); ConnectFuture connectClient = connector.connect(address, new ProtocolEchoHandler()); connectClient.join(); IoSession session = connectClient.getSession();MyVO vo = new MyVO(); vo.setName("Claudio Miranda");vo.setAddress("Wes Side, 274"); vo.setAge(30); vo.setSalary(9876.54); NotSoComplexObject complex = new NotSoComplexObject(); complex.setS1("Playing is better than typing code"); complex.setI2(new Integer(23)); complex.setArr3(new String[]{"teste array 1", "teste array 2", "teste array 3"}); vo.setObject(complex); session.write(vo);// Wait until the match ends.session.getCloseFuture().join();}} ------------------------------------------------------------------------ package claudius; import java.net.InetSocketAddress; import org.apache.mina.common.ByteBuffer; import org.apache.mina.common.DefaultIoFilterChainBuilder; import org.apache.mina.common.IdleStatus; import org.apache.mina.common.IoAcceptor; import org.apache.mina.common.IoAcceptorConfig; import org.apache.mina.common.IoHandlerAdapter; import org.apache.mina.common.IoSession; import org.apache.mina.common.TransportType; import org.apache.mina.filter.LoggingFilter; import org.apache.mina.transport.socket.nio.SocketAcceptor; import org.apache.mina.transport.socket.nio.SocketAcceptorConfig; import org.apache.mina.transport.socket.nio.SocketSessionConfig; public class ProtocolEchoHandler extends IoHandlerAdapter {public void messageSent(IoSession session, Object message) throws Exception {System.out.println("messageSent"); System.out.println("messageSent ! message type: " + message.getClass().getName()); }public void messageReceived(IoSession session, Object message) throws Exception {System.out.println("message type: " + message.getClass().getName()); if (message instanceof ByteBuffer) { ByteBuffer buf = (ByteBuffer) message; String cmd = buf.toString(); System.out.println("cmd = " + cmd); ByteBuffer wb = ByteBuffer.allocate(buf.remaining()); wb.put(buf); wb.flip(); session.write(wb); } else { System.out.println("message type: " + message.getClass().getName()); }} public void sessionCreated(IoSession session) throws Exception {if( session.getTransportType() == TransportType.SOCKET ) { ( ( SocketSessionConfig ) session.getConfig() ).setReceiveBufferSize( 2048 ); } session.setIdleTime( IdleStatus.BOTH_IDLE, 10 ); }public void sessionIdle( IoSession session, IdleStatus status ) {System.out.println("*** IDLE #" +session.getIdleCount( IdleStatus.BOTH_IDLE ) + " ***" ); }public void exceptionCaught( IoSession session, Throwable cause ) {cause.printStackTrace(); session.close(); }public static void main(String[] args) throws Exception {int PORT = 9999; IoAcceptor acceptor = new SocketAcceptor(); IoAcceptorConfig config = new SocketAcceptorConfig(); ((SocketAcceptorConfig) config).setReuseAddress(true);DefaultIoFilterChainBuilder chain = config.getFilterChain();chain.addLast( "logger", new LoggingFilter() ); System.out.println( "Logging ON" );// Bindacceptor.bind(new InetSocketAddress(PORT), new ProtocolEchoHandler(), config); System.out.println( "Listening on port " + PORT ); }}
-- Claudio Miranda ___________________________________________________________________ http://www.claudius.com.br/blog claudio|em|claudius.com.br http://www.summa-tech.com Summa Technologies do Brasil http://www.soujava.org.br
smime.p7s
Description: S/MIME Cryptographic Signature
