Clever serialization broken by CORBA RMI

B

Brian J. Sayatovic

I thought I was all too clever when I tried to do lazy reading of data
from an InputStream until such time that I wanted to serialize the
data over IBM's CORBA based RMI.

The basic setup is that clients will POST data to a servlet of mine
which will then build a Request object to pass in a remote call to a
stateless session bean. My initial simple design was to read the POST
data into memory as a byte[] member of the Request object and then let
it follow the normal serialization workflow.

However, as some of the payloads were large, I wanted a way to
optimize it. It turns out, I had no use of the byte[] within the
servlet layer. So, I thought I'd make my Request object in the
servlet layer hold the InputStream of POST data from the servlet and
not read from it until the RMI layer starts to serialize it. My
Externalizable request contained these methods:

public class Request implements Externalizable {
private InputStream inputStream = ...;

public void writeExternal(ObjectOutput pOut)
throws IOException
{
byte[] buffer = new byte[this.bufferSize];
int read;
while((read = this.inputStream.read(buffer)) >= 0) {
pOut.write(buffer, 0, read);
}
}

public void readExternal(ObjectInput pIn)
throws IOException
{
this.readValueFromStream(pIn);
}
}

I've not elaborated on the "readValueFromStream" method to save space
in this message, but it basically reads it into a byte[].

The goal of all this was that the data would never be read entirely
into memory in the servlet layer. The servlet-side would read no more
than "bufferSize" bytes into memory and chunk it out to the
ObjectOutput. The sessionbean-side would read this data from
ObjectInput into a byte[]. Thus, the servlet-side never had to fully
realize the POST data -- only the server side did.

However, on the sessionbean-side side, the data was null. I was able
to determine that the problem is occurign in this CORBA method:

Object[] copies = Util.copyObjects(new Object[]{arg0},_orb());

The debugger shows that "arg0" is non-null, but copies[0] is null
after the above call.

I suspect this is some sort of optimization that CORBA does when it
determines that the remote call is really local -- it just does an
in-memory copy of the Object instead of truly reading and writing
bytes.

Any ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top