}
return portNumber;
}
private Remote createRmiService(final Interface serviceInterface) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(UnicastRemoteObject.class);
enhancer.setCallback(new MethodInterceptor() {
public Object intercept(Object arg0, Method method, Object[] args, MethodProxy arg3) throws Throwable {
try {
return invokeTarget(JavaInterfaceUtil.findOperation(method, serviceInterface.getOperations()), args);
} catch (InvocationTargetException e) {
final Throwable cause = e.getCause();
for (Class<?> declaredType : method.getExceptionTypes()) {
if (declaredType.isInstance(cause)) {
throw e;
}
}
if (cause.getCause() != null) {
// TUSCANY-2545: don't inlcude nested cause object
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
public Object run() throws Exception {
Field field = Throwable.class.getDeclaredField("cause");
field.setAccessible(true);
field.set(cause, null);
field.setAccessible(false);
return null;
}
});
}
throw cause;
}
}
});
Class<?> targetJavaInterface = getTargetJavaClass(serviceInterface);
targetJavaInterface = RemoteInterfaceGenerator.generate(targetJavaInterface);
enhancer.setClassLoader(targetJavaInterface.getClassLoader());
enhancer.setInterfaces(new Class[] {targetJavaInterface});
return (Remote)enhancer.create();
}