InvokerLocator locator = (InvokerLocator)invocation.getMetaData(REMOTING, INVOKER_LOCATOR);
if (locator == null)
{
throw new RuntimeException("No InvokerLocator supplied. Can't invoke remotely!");
}
String subsystem = (String)invocation.getMetaData(REMOTING, SUBSYSTEM);
if (subsystem == null) subsystem = "AOP";
Client client = new Client(locator, subsystem);
try
{
client.connect();
org.jboss.aop.joinpoint.InvocationResponse response = (org.jboss.aop.joinpoint.InvocationResponse)client.invoke(invocation, null);
invocation.setResponseContextInfo(response.getContextInfo());
return response.getResponse();
}
catch (Exception e)
{
StackTraceElement[] serverStackTrace;
if (e.getCause() != null)
serverStackTrace = e.getCause().getStackTrace();
else
serverStackTrace = e.getStackTrace();
Exception clientException = new Exception();
StackTraceElement[] clientStackTrace = clientException.getStackTrace();
StackTraceElement[] completeStackTrace = new StackTraceElement[serverStackTrace.length + clientStackTrace.length];
System.arraycopy(serverStackTrace, 0, completeStackTrace, 0, serverStackTrace.length);
System.arraycopy(clientStackTrace, 0, completeStackTrace, serverStackTrace.length, clientStackTrace.length);
if (e.getCause() != null)
e.getCause().setStackTrace(completeStackTrace);
else
e.setStackTrace(completeStackTrace);
throw e;
}
finally
{
client.disconnect();
}