List of usage examples for io.netty.handler.codec.http HttpResponseStatus PRECONDITION_FAILED
HttpResponseStatus PRECONDITION_FAILED
To view the source code for io.netty.handler.codec.http HttpResponseStatus PRECONDITION_FAILED.
Click Source Link
From source file:com.mastfrog.acteur.CheckIfUnmodifiedSinceHeader.java
@Inject CheckIfUnmodifiedSinceHeader(HttpEvent event, Page page) { DateTime dt = event.getHeader(Headers.IF_UNMODIFIED_SINCE); if (dt != null) { DateTime pageLastModified = page.getResponseHeaders().getLastModified(); if (pageLastModified != null) { boolean modSince = pageLastModified.getMillis() > dt.getMillis(); if (modSince) { setState(new RespondWith(HttpResponseStatus.PRECONDITION_FAILED)); return; }// ww w. j a v a2 s . co m } } setState(new ConsumedState()); }
From source file:org.glowroot.local.ui.HttpServerHandlerTest.java
License:Apache License
@Test public void shouldCreateJsonServiceExceptionResponse() { // given//from www .j a v a 2 s. c om Exception e = new JsonServiceException(HttpResponseStatus.PRECONDITION_FAILED, new IllegalStateException("An ignored message")); // when FullHttpResponse httpResponse = HttpServerHandler.newHttpResponseFromException(e); // then String content = httpResponse.content().toString(Charsets.ISO_8859_1); assertThat(content).isEqualTo("{\"message\":\"\"}"); assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.PRECONDITION_FAILED); }
From source file:org.glowroot.local.ui.HttpServerHandlerTest.java
License:Apache License
@Test public void shouldCreateJsonServiceExceptionResponseWithMessage() { // given/*from ww w. j ava2 s. c o m*/ Exception e = new JsonServiceException(HttpResponseStatus.PRECONDITION_FAILED, "A message"); // when FullHttpResponse httpResponse = HttpServerHandler.newHttpResponseFromException(e); // then String content = httpResponse.content().toString(Charsets.ISO_8859_1); assertThat(content).isEqualTo("{\"message\":\"A message\"}"); assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.PRECONDITION_FAILED); }
From source file:org.glowroot.local.ui.HttpServerHandlerTest.java
License:Apache License
@Test public void shouldCreateJsonServiceExceptionResponseFromInvocationTargetException() { // given// www . j a v a2s. c o m Exception e = new InvocationTargetException(new JsonServiceException(HttpResponseStatus.PRECONDITION_FAILED, new IllegalStateException("An ignored message"))); // when FullHttpResponse httpResponse = HttpServerHandler.newHttpResponseFromException(e); // then String content = httpResponse.content().toString(Charsets.ISO_8859_1); assertThat(content).isEqualTo("{\"message\":\"\"}"); assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.PRECONDITION_FAILED); }
From source file:org.glowroot.local.ui.HttpServerHandlerTest.java
License:Apache License
@Test public void shouldCreateJsonServiceExceptionResponseWithMessageFromInvocationTargetException() { // given/* w w w.j a va 2 s.c om*/ Exception e = new InvocationTargetException( new JsonServiceException(HttpResponseStatus.PRECONDITION_FAILED, "A message")); // when FullHttpResponse httpResponse = HttpServerHandler.newHttpResponseFromException(e); // then String content = httpResponse.content().toString(Charsets.ISO_8859_1); assertThat(content).isEqualTo("{\"message\":\"A message\"}"); assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.PRECONDITION_FAILED); }
From source file:org.glowroot.ui.CommonHandlerTest.java
License:Apache License
@Test public void shouldCreateJsonServiceExceptionResponse() throws Exception { // given/*from w w w . java2 s . com*/ Exception e = new JsonServiceException(HttpResponseStatus.PRECONDITION_FAILED, new IllegalStateException("An ignored message")); // when CommonResponse httpResponse = HTTP_SERVER_HANDLER.newHttpResponseFromException(mock(CommonRequest.class), mock(Authentication.class), e); // then String content = ((ByteBuf) httpResponse.getContent()).toString(Charsets.ISO_8859_1); assertThat(content).isEqualTo("{\"message\":\"\"}"); assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.PRECONDITION_FAILED); }
From source file:org.glowroot.ui.CommonHandlerTest.java
License:Apache License
@Test public void shouldCreateJsonServiceExceptionResponseWithMessage() throws Exception { // given/*from ww w.j av a2 s . co m*/ Exception e = new JsonServiceException(HttpResponseStatus.PRECONDITION_FAILED, "A message"); // when CommonResponse httpResponse = HTTP_SERVER_HANDLER.newHttpResponseFromException(mock(CommonRequest.class), mock(Authentication.class), e); // then String content = ((ByteBuf) httpResponse.getContent()).toString(Charsets.ISO_8859_1); assertThat(content).isEqualTo("{\"message\":\"A message\"}"); assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.PRECONDITION_FAILED); }
From source file:org.glowroot.ui.CommonHandlerTest.java
License:Apache License
@Test public void shouldCreateJsonServiceExceptionResponseFromInvocationTargetException() throws Exception { // given/*from w ww.j a va 2 s . c o m*/ Exception e = new InvocationTargetException(new JsonServiceException(HttpResponseStatus.PRECONDITION_FAILED, new IllegalStateException("An ignored message"))); // when CommonResponse httpResponse = HTTP_SERVER_HANDLER.newHttpResponseFromException(mock(CommonRequest.class), mock(Authentication.class), e); // then String content = ((ByteBuf) httpResponse.getContent()).toString(Charsets.ISO_8859_1); assertThat(content).isEqualTo("{\"message\":\"\"}"); assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.PRECONDITION_FAILED); }
From source file:org.glowroot.ui.CommonHandlerTest.java
License:Apache License
@Test public void shouldCreateJsonServiceExceptionResponseWithMessageFromInvocationTargetException() throws Exception { // given/*from ww w . j a v a 2 s . c o m*/ Exception e = new InvocationTargetException( new JsonServiceException(HttpResponseStatus.PRECONDITION_FAILED, "A message")); // when CommonResponse httpResponse = HTTP_SERVER_HANDLER.newHttpResponseFromException(mock(CommonRequest.class), mock(Authentication.class), e); // then String content = ((ByteBuf) httpResponse.getContent()).toString(Charsets.ISO_8859_1); assertThat(content).isEqualTo("{\"message\":\"A message\"}"); assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.PRECONDITION_FAILED); }
From source file:org.glowroot.ui.HttpServerHandlerTest.java
License:Apache License
@Test public void shouldCreateJsonServiceExceptionResponse() { // given//from w w w .j ava2 s .c o m Exception e = new JsonServiceException(HttpResponseStatus.PRECONDITION_FAILED, new IllegalStateException("An ignored message")); // when FullHttpResponse httpResponse = HttpServerHandler.newHttpResponseFromException(e); // then String content = httpResponse.content().toString(Charsets.ISO_8859_1); assertThat(content).isEqualTo("{\"message\":\"\"}"); assertThat(httpResponse.status()).isEqualTo(HttpResponseStatus.PRECONDITION_FAILED); }