Example usage for org.springframework.http HttpStatus REQUEST_TIMEOUT

List of usage examples for org.springframework.http HttpStatus REQUEST_TIMEOUT

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus REQUEST_TIMEOUT.

Prototype

HttpStatus REQUEST_TIMEOUT

To view the source code for org.springframework.http HttpStatus REQUEST_TIMEOUT.

Click Source Link

Document

408 Request Timeout .

Usage

From source file:com.sentinel.web.controllers.LoginController.java

@RequestMapping(method = RequestMethod.GET, value = "/all/invalid_session")
public @ResponseBody ResponseEntity<String> handleInvalidSession(HttpServletRequest request,
        HttpServletResponse response) {/*from  www . jav a2  s .c  om*/
    return new ResponseEntity<>("Logged in from a different device", HttpStatus.REQUEST_TIMEOUT);
}

From source file:fr.olympicinsa.riocognized.exception.MyExceptionHandler.java

@ExceptionHandler(InterruptedException.class)
@ResponseBody/*from  ww  w . j a va  2s  . c om*/
@ResponseStatus(HttpStatus.REQUEST_TIMEOUT)
public ErrorMessage handleInterruptedException(HttpRequestMethodNotSupportedException e,
        HttpServletRequest req) {
    return new ErrorMessage("METHOD_NOT_ALLOWED");
}

From source file:org.dataone.proto.trove.mn.rest.base.AbstractWebController.java

@ResponseStatus(value = HttpStatus.REQUEST_TIMEOUT)
@ExceptionHandler(AuthenticationTimeout.class)
public void handleException(AuthenticationTimeout exception, HttpServletRequest request,
        HttpServletResponse response) {/*from   w  w  w .j  a  v  a 2 s  .c o  m*/
    handleBaseException((BaseException) exception, request, response);
}

From source file:org.spring.data.gemfire.rest.GemFireRestInterfaceTest.java

@SuppressWarnings("deprecation")
private RestTemplate setErrorHandler(final RestTemplate restTemplate) {
    restTemplate.setErrorHandler(new ResponseErrorHandler() {
        private final Set<HttpStatus> errorStatuses = new HashSet<>();

        /* non-static */ {
            errorStatuses.add(HttpStatus.BAD_REQUEST);
            errorStatuses.add(HttpStatus.UNAUTHORIZED);
            errorStatuses.add(HttpStatus.FORBIDDEN);
            errorStatuses.add(HttpStatus.NOT_FOUND);
            errorStatuses.add(HttpStatus.METHOD_NOT_ALLOWED);
            errorStatuses.add(HttpStatus.NOT_ACCEPTABLE);
            errorStatuses.add(HttpStatus.REQUEST_TIMEOUT);
            errorStatuses.add(HttpStatus.CONFLICT);
            errorStatuses.add(HttpStatus.REQUEST_ENTITY_TOO_LARGE);
            errorStatuses.add(HttpStatus.REQUEST_URI_TOO_LONG);
            errorStatuses.add(HttpStatus.UNSUPPORTED_MEDIA_TYPE);
            errorStatuses.add(HttpStatus.TOO_MANY_REQUESTS);
            errorStatuses.add(HttpStatus.INTERNAL_SERVER_ERROR);
            errorStatuses.add(HttpStatus.NOT_IMPLEMENTED);
            errorStatuses.add(HttpStatus.BAD_GATEWAY);
            errorStatuses.add(HttpStatus.SERVICE_UNAVAILABLE);
        }/* w  w  w. ja v  a  2 s . c o m*/

        @Override
        public boolean hasError(final ClientHttpResponse response) throws IOException {
            return errorStatuses.contains(response.getStatusCode());
        }

        @Override
        public void handleError(final ClientHttpResponse response) throws IOException {
            System.err.printf("%1$d - %2$s%n", response.getRawStatusCode(), response.getStatusText());
            System.err.println(readBody(response));
        }

        private String readBody(final ClientHttpResponse response) throws IOException {
            BufferedReader responseBodyReader = null;

            try {
                responseBodyReader = new BufferedReader(new InputStreamReader(response.getBody()));

                StringBuilder buffer = new StringBuilder();
                String line;

                while ((line = responseBodyReader.readLine()) != null) {
                    buffer.append(line).append(System.getProperty("line.separator"));
                }

                return buffer.toString().trim();
            } finally {
                FileSystemUtils.close(responseBodyReader);
            }
        }
    });

    return restTemplate;
}