@Test public void testBypassHttpErrorExceptionPropagatesCodeWithMessageWithHeader() throws Exception { final int httpStatus = HttpStatus.FORBIDDEN; final String errorMessage = "Error Message"; final String headerName = "Header Name"; final String headerValue = "Header Value"; ListMultimap<String, String> headers = ArrayListMultimap.create(); headers.put(headerName, headerValue); BypassHttpErrorException bypassException = new BypassHttpErrorException(httpStatus, errorMessage, headers); when(request.getAction()).thenReturn(HttpMethods.GET); doThrow(bypassException).when(proxyFacet).get(context); Response response = underTest.handle(context); assertStatusCode(response, httpStatus); assertStatusMessage(response, errorMessage); assertThat(response.getHeaders().get(headerName), is(headerValue)); }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { final Response response = buildMethodNotAllowedResponse(context); if (response != null) { return response; } try { Payload payload = proxyFacet(context).get(context); if (payload != null) { return buildPayloadResponse(context, payload); } return buildNotFoundResponse(context); } catch (BypassHttpErrorException e) { return buildHttpErrorResponce(e); } catch (ProxyServiceException e) { return HttpResponses.serviceUnavailable(); } catch (CooperationException e) { return HttpResponses.serviceUnavailable(e.getMessage()); } catch (IOException | UncheckedIOException e) { return HttpResponses.badGateway(); } }
ProxyHandler extends ComponentSupport implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { final Response response = buildMethodNotAllowedResponse(context); if (response != null) { return response; } try { Payload payload = proxyFacet(context).get(context); if (payload != null) { return buildPayloadResponse(context, payload); } return buildNotFoundResponse(context); } catch (BypassHttpErrorException e) { return buildHttpErrorResponce(e); } catch (ProxyServiceException e) { return HttpResponses.serviceUnavailable(); } catch (CooperationException e) { return HttpResponses.serviceUnavailable(e.getMessage()); } catch (IOException | UncheckedIOException e) { return HttpResponses.badGateway(); } } }
ProxyHandler extends ComponentSupport implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { final Response response = buildMethodNotAllowedResponse(context); if (response != null) { return response; } try { Payload payload = proxyFacet(context).get(context); if (payload != null) { return buildPayloadResponse(context, payload); } return buildNotFoundResponse(context); } catch (BypassHttpErrorException e) { return buildHttpErrorResponce(e); } catch (ProxyServiceException e) { return HttpResponses.serviceUnavailable(); } catch (CooperationException e) { return HttpResponses.serviceUnavailable(e.getMessage()); } catch (IOException | UncheckedIOException e) { return HttpResponses.badGateway(); } }  }
ProxyHandler extends ComponentSupport implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { final Response response = buildMethodNotAllowedResponse(context); if (response != null) { return response; } try { Payload payload = proxyFacet(context).get(context); if (payload != null) { return buildPayloadResponse(context, payload); } return buildNotFoundResponse(context); } catch (BypassHttpErrorException e) { return buildHttpErrorResponce(e); } catch (ProxyServiceException e) { return HttpResponses.serviceUnavailable(); } catch (CooperationException e) { return HttpResponses.serviceUnavailable(e.getMessage()); } catch (IOException | UncheckedIOException e) { return HttpResponses.badGateway(); } }  @Nonnull @Override Response handle(@Nonnull final Context context); }
ProxyHandler extends ComponentSupport implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { final Response response = buildMethodNotAllowedResponse(context); if (response != null) { return response; } try { Payload payload = proxyFacet(context).get(context); if (payload != null) { return buildPayloadResponse(context, payload); } return buildNotFoundResponse(context); } catch (BypassHttpErrorException e) { return buildHttpErrorResponce(e); } catch (ProxyServiceException e) { return HttpResponses.serviceUnavailable(); } catch (CooperationException e) { return HttpResponses.serviceUnavailable(e.getMessage()); } catch (IOException | UncheckedIOException e) { return HttpResponses.badGateway(); } }  @Nonnull @Override Response handle(@Nonnull final Context context);  }