@Test public void handleInvalidContentPut() throws Exception { when(request.getAction()).thenReturn("PUT"); when(context.proceed()).thenThrow(new InvalidContentException("That content was invalid")); assertThat(underTest.handle(context).getStatus().getCode(), is(HttpStatus.BAD_REQUEST)); }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { try { return context.proceed(); } catch (IllegalOperationException e) { log.warn("Illegal operation: {} {}: {}", context.getRequest().getAction(), context.getRequest().getPath(), e.toString()); return HttpResponses.badRequest(e.getMessage()); } catch (InvalidContentException e) { log.warn("Invalid content: {} {}: {}", context.getRequest().getAction(), context.getRequest().getPath(), e.toString()); if (PUT.equals(context.getRequest().getAction())) { return HttpResponses.badRequest(e.getMessage()); } else { return HttpResponses.notFound(e.getMessage()); } } catch (FrozenException e) { return readOnly(context, e); } catch (Exception e) { if (e.getCause() instanceof FrozenException) { return readOnly(context, e); } String exceptionName = e.getClass().getSimpleName(); if (exceptionName.contains("OModificationOperationProhibitedException") || exceptionName.contains("OWriteOperationNotPermittedException")) { return readOnly(context, e); } else { throw e; } } }
ExceptionHandler extends ComponentSupport implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { try { return context.proceed(); } catch (IllegalOperationException e) { log.warn("Illegal operation: {} {}: {}", context.getRequest().getAction(), context.getRequest().getPath(), e.toString()); return HttpResponses.badRequest(e.getMessage()); } catch (InvalidContentException e) { log.warn("Invalid content: {} {}: {}", context.getRequest().getAction(), context.getRequest().getPath(), e.toString()); if (PUT.equals(context.getRequest().getAction())) { return HttpResponses.badRequest(e.getMessage()); } else { return HttpResponses.notFound(e.getMessage()); } } catch (FrozenException e) { return readOnly(context, e); } catch (Exception e) { if (e.getCause() instanceof FrozenException) { return readOnly(context, e); } String exceptionName = e.getClass().getSimpleName(); if (exceptionName.contains("OModificationOperationProhibitedException") || exceptionName.contains("OWriteOperationNotPermittedException")) { return readOnly(context, e); } else { throw e; } } } }
ExceptionHandler extends ComponentSupport implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { try { return context.proceed(); } catch (IllegalOperationException e) { log.warn("Illegal operation: {} {}: {}", context.getRequest().getAction(), context.getRequest().getPath(), e.toString()); return HttpResponses.badRequest(e.getMessage()); } catch (InvalidContentException e) { log.warn("Invalid content: {} {}: {}", context.getRequest().getAction(), context.getRequest().getPath(), e.toString()); if (PUT.equals(context.getRequest().getAction())) { return HttpResponses.badRequest(e.getMessage()); } else { return HttpResponses.notFound(e.getMessage()); } } catch (FrozenException e) { return readOnly(context, e); } catch (Exception e) { if (e.getCause() instanceof FrozenException) { return readOnly(context, e); } String exceptionName = e.getClass().getSimpleName(); if (exceptionName.contains("OModificationOperationProhibitedException") || exceptionName.contains("OWriteOperationNotPermittedException")) { return readOnly(context, e); } else { throw e; } } }  }
ExceptionHandler extends ComponentSupport implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { try { return context.proceed(); } catch (IllegalOperationException e) { log.warn("Illegal operation: {} {}: {}", context.getRequest().getAction(), context.getRequest().getPath(), e.toString()); return HttpResponses.badRequest(e.getMessage()); } catch (InvalidContentException e) { log.warn("Invalid content: {} {}: {}", context.getRequest().getAction(), context.getRequest().getPath(), e.toString()); if (PUT.equals(context.getRequest().getAction())) { return HttpResponses.badRequest(e.getMessage()); } else { return HttpResponses.notFound(e.getMessage()); } } catch (FrozenException e) { return readOnly(context, e); } catch (Exception e) { if (e.getCause() instanceof FrozenException) { return readOnly(context, e); } String exceptionName = e.getClass().getSimpleName(); if (exceptionName.contains("OModificationOperationProhibitedException") || exceptionName.contains("OWriteOperationNotPermittedException")) { return readOnly(context, e); } else { throw e; } } }  @Nonnull @Override Response handle(@Nonnull final Context context); }
ExceptionHandler extends ComponentSupport implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { try { return context.proceed(); } catch (IllegalOperationException e) { log.warn("Illegal operation: {} {}: {}", context.getRequest().getAction(), context.getRequest().getPath(), e.toString()); return HttpResponses.badRequest(e.getMessage()); } catch (InvalidContentException e) { log.warn("Invalid content: {} {}: {}", context.getRequest().getAction(), context.getRequest().getPath(), e.toString()); if (PUT.equals(context.getRequest().getAction())) { return HttpResponses.badRequest(e.getMessage()); } else { return HttpResponses.notFound(e.getMessage()); } } catch (FrozenException e) { return readOnly(context, e); } catch (Exception e) { if (e.getCause() instanceof FrozenException) { return readOnly(context, e); } String exceptionName = e.getClass().getSimpleName(); if (exceptionName.contains("OModificationOperationProhibitedException") || exceptionName.contains("OWriteOperationNotPermittedException")) { return readOnly(context, e); } else { throw e; } } }  @Nonnull @Override Response handle(@Nonnull final Context context);  }