{
if(this.server == null)
{
log.debug("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.debug("Could not marshall invocation payload object " + payload, e);
throw new IOException(e.getMessage());
}
}
}
int simulatedTimeout = getSimulatedTimeout(configuration, metadata);
if (simulatedTimeout <= 0)
{
return server.transport(payload);
}
else
{
if (log.isTraceEnabled()) log.trace("using simulated timeout: " + simulatedTimeout);
class Holder {public Object value;}
final Holder resultHolder = new Holder();
final Object finalPayload = payload;
Runnable r = new Runnable()
{
public void run()
{
try
{
resultHolder.value = server.transport(finalPayload);
if (log.isTraceEnabled()) log.trace("result: " + resultHolder.value);
}
catch (Exception e)
{
resultHolder.value = e;
if (log.isTraceEnabled()) log.trace("exception: " + e);
}
}
};
// BasicThreadPool timeout mechanism depends on the interrupted status of
// the running thread.
Thread.interrupted();
ThreadPool pool = getTimeoutThreadPool();
WaitingTaskWrapper wrapper = new WaitingTaskWrapper(r, simulatedTimeout);
if (log.isTraceEnabled()) log.trace("starting task in thread pool");
pool.runTaskWrapper(wrapper);
if (log.isTraceEnabled()) log.trace("task finished in thread pool");
Object result = resultHolder.value;
if (result == null)
{
if (log.isTraceEnabled()) log.trace("invocation timed out");
Exception cause = new SocketTimeoutException("timed out");
throw new CannotConnectException("Can not connect http client invoker.", cause);
}
else if (result instanceof IOException)
{
throw (IOException) result;
}
else if (result instanceof RuntimeException)
{
throw (RuntimeException) result;
}
else
{
if (log.isTraceEnabled()) log.trace("returning result: " + result);
return result;
}
}
// 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.debug("Error making invocation in RMI client invoker.", e);
throw new CannotConnectException("Error making invocation in RMI client invoker.", e);
}
}