@Test public void testFailureRequestOnContext() throws Exception { final Exception expected = new IllegalStateException(); runOnOtherThread(new Runnable() { @Override public void run() { try { ContextHolder.attach(context); final Requester requester = new DecoratingRequester(); final String name = randomUUID().toString(); final String ret = requester .request(new TestInvocation<>(new RequestMethod<String>() { @Override public String getName() { return name; } @Override protected String runInternal(final List<Object> parameters) throws Exception { throw expected; } })); fail("Should be throw error"); } catch (Exception actual) { assertEquals(expected, actual); } finally { ContextHolder.remove(); } } }); }
@Override public <T> T request(final Invocation<T> invocation) throws Exception { assertNotNull(invocation, "Invocation must not null"); logger.debug("Request with invocation: {}", invocation); Response<T> response; final Invocation<T> decorated = withDecorated(invocation); logger.trace("Decorated: {}", decorated); try { final T value = decorated.invoke(); logger.debug("Success: {}", value); response = Response.success(value); } catch (Exception e) { logger.debug("Failure: {}", e.toString()); response = Response.fail(e); response = handleFailover(decorated, response); } if (null != response.getError()) { final Exception error = response.getError(); error.setStackTrace(concatStackTrace(new Throwable().getStackTrace(), error.getStackTrace())); throw error; } return response.getValue(); }
DecoratingRequester implements Requester { @Override public <T> T request(final Invocation<T> invocation) throws Exception { assertNotNull(invocation, "Invocation must not null"); logger.debug("Request with invocation: {}", invocation); Response<T> response; final Invocation<T> decorated = withDecorated(invocation); logger.trace("Decorated: {}", decorated); try { final T value = decorated.invoke(); logger.debug("Success: {}", value); response = Response.success(value); } catch (Exception e) { logger.debug("Failure: {}", e.toString()); response = Response.fail(e); response = handleFailover(decorated, response); } if (null != response.getError()) { final Exception error = response.getError(); error.setStackTrace(concatStackTrace(new Throwable().getStackTrace(), error.getStackTrace())); throw error; } return response.getValue(); } }
DecoratingRequester implements Requester { @Override public <T> T request(final Invocation<T> invocation) throws Exception { assertNotNull(invocation, "Invocation must not null"); logger.debug("Request with invocation: {}", invocation); Response<T> response; final Invocation<T> decorated = withDecorated(invocation); logger.trace("Decorated: {}", decorated); try { final T value = decorated.invoke(); logger.debug("Success: {}", value); response = Response.success(value); } catch (Exception e) { logger.debug("Failure: {}", e.toString()); response = Response.fail(e); response = handleFailover(decorated, response); } if (null != response.getError()) { final Exception error = response.getError(); error.setStackTrace(concatStackTrace(new Throwable().getStackTrace(), error.getStackTrace())); throw error; } return response.getValue(); } DecoratingRequester(); }
DecoratingRequester implements Requester { @Override public <T> T request(final Invocation<T> invocation) throws Exception { assertNotNull(invocation, "Invocation must not null"); logger.debug("Request with invocation: {}", invocation); Response<T> response; final Invocation<T> decorated = withDecorated(invocation); logger.trace("Decorated: {}", decorated); try { final T value = decorated.invoke(); logger.debug("Success: {}", value); response = Response.success(value); } catch (Exception e) { logger.debug("Failure: {}", e.toString()); response = Response.fail(e); response = handleFailover(decorated, response); } if (null != response.getError()) { final Exception error = response.getError(); error.setStackTrace(concatStackTrace(new Throwable().getStackTrace(), error.getStackTrace())); throw error; } return response.getValue(); } DecoratingRequester(); @Override T request(final Invocation<T> invocation); }
DecoratingRequester implements Requester { @Override public <T> T request(final Invocation<T> invocation) throws Exception { assertNotNull(invocation, "Invocation must not null"); logger.debug("Request with invocation: {}", invocation); Response<T> response; final Invocation<T> decorated = withDecorated(invocation); logger.trace("Decorated: {}", decorated); try { final T value = decorated.invoke(); logger.debug("Success: {}", value); response = Response.success(value); } catch (Exception e) { logger.debug("Failure: {}", e.toString()); response = Response.fail(e); response = handleFailover(decorated, response); } if (null != response.getError()) { final Exception error = response.getError(); error.setStackTrace(concatStackTrace(new Throwable().getStackTrace(), error.getStackTrace())); throw error; } return response.getValue(); } DecoratingRequester(); @Override T request(final Invocation<T> invocation);  }