{
if(this.server == null)
{
log.error("Server stub has not been set in RMI invoker client. See previous errors for details.");
//throw new IOException("Server stub hasn't been set!");
throw new CannotConnectException("Server stub has not been set.");
}
try
{
Object payload = invocation;
if(marshaller != null && !(marshaller instanceof RMIMarshaller))
{
if(marshaller instanceof MarshallerDecorator)
{
payload = ((MarshallerDecorator) marshaller).addDecoration(payload);
}
else
{
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
if (marshaller instanceof VersionedMarshaller)
((VersionedMarshaller) marshaller).write(payload, byteOut, Version.getDefaultVersion());
else
marshaller.write(payload, byteOut);
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
ObjectInputStream ois = new ObjectInputStream(byteIn);
try
{
byteOut.close();
payload = ois.readObject();
ois.close();
}
catch(ClassNotFoundException e)
{
log.error("Could not marshall invocation payload object " + payload, e);
throw new IOException(e.getMessage());
}
}
}
Object response = server.transport(payload);
/* Jira Issue: JBREM-167
if(unmarshaller != null && !(unmarshaller instanceof RMIUnMarshaller))
{
PipedOutputStream pos = new PipedOutputStream();
PipedInputStream pis = new PipedInputStream();
pos.connect(pis);
ObjectOutputStream oos = new ObjectOutputStream(pos);
oos.writeObject(response);
oos.flush();
oos.reset();
oos.writeObject(Boolean.TRUE);
oos.flush();
oos.reset();
try
{
oos.close();
response = unmarshaller.read(pis, metadata);
pis.close();
}
catch(ClassNotFoundException e)
{
log.error("Could not unmarshall invocation response" + response, e);
throw new IOException(e.getMessage());
}
}
*/
return response;
}
catch(RemoteException e)
{
log.error(e);
throw new CannotConnectException("Error making invocation in RMI client invoker.", e);
}
}