You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by vam <va...@nv.hanty.usi.ru> on 2006/12/11 07:01:37 UTC

ObjectSerialization problem

Hi!

MINA 1.0 provides an own object serialization streams. But I have a problem
with it...
or may be It's my unawareness.

Try MINA 1.0.0 and MINA 1.0.1;
JDK 1.5.0_09
Windows 2003 Server

Source:


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import junit.framework.TestCase;

import
org.apache.mina.filter.codec.serialization.ObjectSerializationInputStream;
import
org.apache.mina.filter.codec.serialization.ObjectSerializationOutputStream;

public class ObjectSerializationStreamsTest extends TestCase {

	public ObjectSerializationStreamsTest(String arg0) {
		super(arg0);
	}

	public static void main(String[] args) {
	
junit.textui.TestRunner.run(ObjectSerializationStreamsTest.class);
	}

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/*
	 * Standart Object streams works - OK...
	 */
	public void testObjectStandartStreams() throws Exception {
		ObjectInputStream osis;
		ObjectOutputStream osos;
		//Integer msgA = new Integer(12345);
		String msgA = "Test";
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		osos = new ObjectOutputStream(baos);
		osos.writeObject(msgA);
		osos.flush();
		byte xbA[] = baos.toByteArray();
		osis = new ObjectInputStream(new ByteArrayInputStream(xbA));
		osos.writeObject(msgA);
		Object msg = osis.readObject();
		assertEquals(msgA, msg);
		osos.close();
		osis.close();
	}
	
	/*
	 * MINA Object streams works - FAILED!..
	 */
	public void testObjectSerializationStreams() throws Exception {
		ObjectSerializationInputStream osis;
		ObjectSerializationOutputStream osos;
		//Integer msgA = new Integer(12345);
		String msgA = new String("Test");
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		osos = new ObjectSerializationOutputStream(baos);
		osos.writeObject(msgA);
		osos.flush();
		byte xbA[] = baos.toByteArray();
		osis = new ObjectSerializationInputStream(new
ByteArrayInputStream(xbA));
		osos.writeObject(msgA);
		Object msg = osis.readObject();
		assertEquals(msgA, msg);
		osos.close();
		osis.close();
	}
	
}


Output:


..E
Time: 0,109
There was 1 error:
1)
testObjectSerializationStreams(ru.territory.telex.mina.test.ObjectSerializat
ionStreamsTest)java.nio.BufferUnderflowException
	at org.apache.mina.common.ByteBuffer.getObject(ByteBuffer.java:1613)
	at
org.apache.mina.filter.codec.serialization.ObjectSerializationInputStream.re
adObject(ObjectSerializationInputStream.java:125)
	at
ru.territory.telex.mina.test.ObjectSerializationStreamsTest.testObjectSerial
izationStreams(ObjectSerializationStreamsTest.java:61)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
	at
ru.territory.telex.mina.test.ObjectSerializationStreamsTest.main(ObjectSeria
lizationStreamsTest.java:20)

FAILURES!!!
Tests run: 2,  Failures: 0,  Errors: 1


Sorry, my poor English.

Andrew Vokhmin.