@Override public Object invokeMethod(final Map<String, Serializable> options, final String apiInterfaceName, final String methodName, final List<String> classNameParameters, final Object[] parametersValues) throws ServerWrappedException, RemoteException { final ServerAPI apiImpl = ServerAPIFactory.getServerAPI(); try { return apiImpl.invokeMethod(options, apiInterfaceName, methodName, classNameParameters, parametersValues); } catch (final ServerWrappedException e) { // merge stack trace of the server exception throw StackTraceTransformer.mergeStackTraces(e); } }
/** * @param e * the ServerWrappedException given by the server api * @return * a safe to throw to client ServerWrappedException */ public static ServerWrappedException mergeStackTraces(final ServerWrappedException e) { try { return new StackTraceTransformer(e).merge(); } catch (final Exception e1) { System.err.println("Unable to throw the root exception: " + e1.getClass().getName() + ": " + e1.getMessage()); e1.printStackTrace(); return new ServerWrappedException(new BonitaRuntimeException( "Unable to throw the root exception because of (see log for the original stack trace)", e)); } }
@Override public Object invokeMethod(final Map<String, Serializable> options, final String apiInterfaceName, final String methodName, final List<String> classNameParameters, final Object[] parametersValues) throws ServerWrappedException { String response = null; try { response = executeHttpPost(options, apiInterfaceName, methodName, classNameParameters, parametersValues); return checkInvokeMethodReturn(response); } catch (final UndeclaredThrowableException e) { throw new ServerWrappedException(e); } catch (final Throwable e) { final StackTraceElement[] stackTrace = new Exception().getStackTrace(); StackTraceTransformer.addStackTo(e, stackTrace); throw new ServerWrappedException(e.getMessage() + " / response: " + response, e); } }
private ServerWrappedException merge() throws Exception { final Throwable cause = e.getCause(); if (field != null) { transfertStack(cause, cause); field.set(cause, null); return e; } Throwable newCause; if (cause.getMessage() != null) { newCause = cause.getClass().getConstructor(String.class).newInstance(e.getMessage()); } else { newCause = cause.getClass().newInstance(); } transfertStack(newCause, cause); return new ServerWrappedException(newCause); }
private ServerWrappedException merge() throws Exception { final Throwable cause = e.getCause(); if (field != null) { transfertStack(cause, cause); field.set(cause, null); return e; } Throwable newCause; if (cause.getMessage() != null) { newCause = cause.getClass().getConstructor(String.class).newInstance(e.getMessage()); } else { newCause = cause.getClass().newInstance(); } transfertStack(newCause, cause); return new ServerWrappedException(newCause); }
@Test public void merge_stack_keep_only_current_exception() { ServerWrappedException e = new ServerWrappedException(new IllegalStateException(new NoClassDefFoundError("org.Unknown"))); ServerWrappedException newE = StackTraceTransformer.mergeStackTraces(e); assertNull(newE.getCause().getCause()); }
/** * @param e * the ServerWrappedException given by the server api * @return * a safe to throw to client ServerWrappedException */ public static ServerWrappedException mergeStackTraces(final ServerWrappedException e) { try { return new StackTraceTransformer(e).merge(); } catch (final Exception e1) { System.err.println("Unable to throw the root exception: " + e1.getClass().getName() + ": " + e1.getMessage()); e1.printStackTrace(); return new ServerWrappedException(new BonitaRuntimeException( "Unable to throw the root exception because of (see log for the original stack trace)", e)); } }
@Override public Object invokeMethod(final Map<String, Serializable> options, final String apiInterfaceName, final String methodName, final List<String> classNameParameters, final Object[] parametersValues) throws ServerWrappedException { String response = null; try { response = executeHttpPost(options, apiInterfaceName, methodName, classNameParameters, parametersValues); return checkInvokeMethodReturn(response); } catch (final UndeclaredThrowableException e) { throw new ServerWrappedException(e); } catch (final Throwable e) { final StackTraceElement[] stackTrace = new Exception().getStackTrace(); StackTraceTransformer.addStackTo(e, stackTrace); throw new ServerWrappedException(e.getMessage() + " / response: " + response, e); } }
} catch (ServerWrappedException e) { throw StackTraceTransformer.mergeStackTraces(e);
private Object invokeMethod(final MethodCall methodCall) throws ServerWrappedException, RemoteException { final Map<String, Serializable> options = methodCall.getOptions(); final String apiInterfaceName = methodCall.getApiInterfaceName(); final String methodName = methodCall.getMethodName(); final List<String> classNameParameters = methodCall.getClassNameParameters(); final Object[] parametersValues = methodCall.getParametersValues(); try { return this.invokeMethod(options, apiInterfaceName, methodName, classNameParameters, parametersValues); } catch (final ServerWrappedException e) { throw StackTraceTransformer.mergeStackTraces(e); } }
} catch (ServerWrappedException e) { throw StackTraceTransformer.mergeStackTraces(e);
@Test public void merge_stack_reduce_stack_length() throws Exception { ProcessInstanceNotFoundException cause3 = new ProcessInstanceNotFoundException("the process"); BonitaRuntimeException cause2 = new BonitaRuntimeException("org.Unknown", cause3); IllegalStateException cause = new IllegalStateException(cause2); ServerWrappedException e = new ServerWrappedException(cause); cause.printStackTrace(); ServerWrappedException newE = StackTraceTransformer.mergeStackTraces(e); newE.getCause().printStackTrace(); noDuplicate(newE.getCause()); }
@Test public void merge_stack_work_even_with_security_restriction() { ProcessInstanceNotFoundException cause3 = new ProcessInstanceNotFoundException("the process"); BonitaRuntimeException cause2 = new BonitaRuntimeException("org.Unknown", cause3); IllegalStateException cause = new IllegalStateException(cause2); ServerWrappedException e = new ServerWrappedException(cause); Field field = StackTraceTransformer.field; StackTraceTransformer.field = null; ServerWrappedException newE = StackTraceTransformer.mergeStackTraces(e); StackTraceTransformer.field = field; assertTrue(containsMessage(newE.getCause().getStackTrace(), "org.Unknown")); assertTrue(containsMessage(newE.getCause().getStackTrace(), "the process")); }
@Test public void merge_stack_keep_stack_of_cause() { ProcessInstanceNotFoundException cause3 = new ProcessInstanceNotFoundException("the process"); BonitaRuntimeException cause2 = new BonitaRuntimeException("org.Unknown", cause3); IllegalStateException cause = new IllegalStateException(cause2); ServerWrappedException e = new ServerWrappedException(cause); ServerWrappedException newE = StackTraceTransformer.mergeStackTraces(e); assertTrue(containsStack(newE.getCause().getStackTrace(), "BonitaRuntimeException")); assertTrue(containsStack(newE.getCause().getStackTrace(), "ProcessInstanceNotFoundException")); }
@Test public void merge_stack_keep_message_of_cause() { ProcessInstanceNotFoundException cause3 = new ProcessInstanceNotFoundException("the process"); BonitaRuntimeException cause2 = new BonitaRuntimeException("org.Unknown", cause3); IllegalStateException cause = new IllegalStateException(cause2); ServerWrappedException e = new ServerWrappedException(cause); ServerWrappedException newE = StackTraceTransformer.mergeStackTraces(e); assertTrue(containsMessage(newE.getCause().getStackTrace(), "org.Unknown")); assertTrue(containsMessage(newE.getCause().getStackTrace(), "the process")); }
@Test public void merge_stack_when_no_cause() { ProcessInstanceNotFoundException cause = new ProcessInstanceNotFoundException("the process"); ServerWrappedException e = new ServerWrappedException(cause); ServerWrappedException newE = StackTraceTransformer.mergeStackTraces(e); assertEquals("the process", cause.getMessage()); assertEquals(cause, newE.getCause()); }