Example usage for org.springframework.http HttpStatus REQUEST_ENTITY_TOO_LARGE

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

Introduction

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

Prototype

HttpStatus REQUEST_ENTITY_TOO_LARGE

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

Click Source Link

Document

413 Request Entity Too Large .

Usage

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

@ExceptionHandler(TooManyResultException.class)
@ResponseBody//from   w  ww  .  j ava  2 s . c o m
@ResponseStatus(HttpStatus.REQUEST_ENTITY_TOO_LARGE)
public ErrorMessage handleTooManyResultException(TooManyResultException e, HttpServletRequest req) {
    return new ErrorMessage("TOO_MANY_RESULTS");
}

From source file:de.thm.arsnova.controller.SecurityExceptionControllerAdvice.java

@ResponseStatus(HttpStatus.REQUEST_ENTITY_TOO_LARGE)
@ExceptionHandler(RequestEntityTooLargeException.class)
public void handleRequestEntityTooLargeException(final Exception e, final HttpServletRequest request) {
}

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

@ResponseStatus(value = HttpStatus.REQUEST_ENTITY_TOO_LARGE)
@ExceptionHandler(InsufficientResources.class)
public void handleException(InsufficientResources exception, HttpServletRequest request,
        HttpServletResponse response) {/*from  w w w.jav  a 2s.  co 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);
        }/*from  www .  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;
}

From source file:com.oneops.antenna.ws.AntennaWsController.java

/**
 * Get all cache entries. If cache has more than 100 items, it will respond with
 * <b>413 Request Entity Too Large</b> http status code.
 *
 * @return cache entries map.// w w  w .  ja  va  2  s . co m
 */
@RequestMapping(value = "/cache/entries", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<Map<String, Object>> getCacheEntries() {
    // Do a cache maintenance first before getting the size
    cache.instance().cleanUp();
    long size = cache.instance().size();
    Map<String, Object> stat = new LinkedHashMap<String, Object>(3);
    if (size > 100) {
        stat.put("status", "Too many cache entries (size=" + size + ")");
        return new ResponseEntity<Map<String, Object>>(stat, HttpStatus.REQUEST_ENTITY_TOO_LARGE);
    }
    stat.put("status", "ok");
    stat.put("size", size);

    Map<SinkKey, List<BasicSubscriber>> map = cache.instance().asMap();
    Map<String, Object> entries = new HashMap<String, Object>(map.size());
    for (SinkKey key : map.keySet()) {
        entries.put(key.getOrg(), map.get(key).toString());
    }
    stat.put("entries", entries);
    return new ResponseEntity<Map<String, Object>>(stat, HttpStatus.OK);
}