Example usage for org.springframework.http HttpStatus BAD_REQUEST

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

Introduction

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

Prototype

HttpStatus BAD_REQUEST

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

Click Source Link

Document

400 Bad Request .

Usage

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

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(BadRequestException.class)
public void handleBadRequestException(final Exception e, final HttpServletRequest request) {
}

From source file:org.cloudfoundry.identity.uaa.codestore.CodeStoreEndpointsTests.java

@Test
public void testGenerateCodeWithNullData() throws Exception {
    Timestamp expiresAt = new Timestamp(System.currentTimeMillis() + 60000);
    ExpiringCode expiringCode = new ExpiringCode(null, expiresAt, null);

    try {//from w ww  .  j a  v  a  2s . c  o m
        codeStoreEndpoints.generateCode(expiringCode);

        fail("code is null, should throw CodeStoreException.");
    } catch (CodeStoreException e) {
        assertEquals(e.getStatus(), HttpStatus.BAD_REQUEST);
    }
}

From source file:com.envision.envservice.rest.LeaveWordResource.java

@POST
@Consumes(MediaType.APPLICATION_JSON)//from ww  w. ja v  a 2  s.c  om
@Produces(MediaType.APPLICATION_JSON)
public Response addNew(@Context HttpServletRequest request, LeaveWordBo leaveWord) throws Exception {
    HttpStatus status = HttpStatus.CREATED;
    String response = StringUtils.EMPTY;

    if (!checkParam(leaveWord)) {
        status = HttpStatus.BAD_REQUEST;
        response = FailResult.toJson(Code.PARAM_ERROR, "?");
    } else if (!checkContentLength(leaveWord)) {
        status = HttpStatus.BAD_REQUEST;
        response = FailResult.toJson(Code.CONTENT_TOO_LONG, "");
    } else {
        DBLogger logger = operationLog(request, leaveWord.getUserIdTarget());

        String leaveWordId = leaveWordService.addLeaveWord(leaveWord);

        loggerService.setSuccess(logger.getId(), true, leaveWordId);
    }

    return Response.status(status.value()).entity(response).build();
}

From source file:org.ow2.proactive.procci.rest.ComputeRest.java

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<EntitiesRendering> listAllComputes() {
    logger.debug("Get all Compute instances");
    try {/*from w w  w  . j a  v  a 2 s .  co  m*/

        List<EntityRendering> entityRenderings = instanceService.getInstancesRendering(mixinService);
        return new ResponseEntity<>(new EntitiesRendering.Builder().addEntities(entityRenderings).build(),
                HttpStatus.OK);
    } catch (ClientException e) {
        logger.error(this.getClass().getName(), e);
        return new ResponseEntity(e.getJsonError(), HttpStatus.BAD_REQUEST);
    } catch (ServerException e) {
        logger.error(this.getClass().getName(), e);
        return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:io.kamax.mxisd.controller.DefaultExceptionHandler.java

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MissingServletRequestParameterException.class)
public String handle(HttpServletRequest req, MissingServletRequestParameterException e) {
    return handle(req, "M_INCOMPLETE_REQUEST", e.getMessage());
}

From source file:org.fineract.module.stellar.TestCreateBridge.java

@Test
public void createBridgeWithNullMifosTenantId() {
    final String mifosAddress = testRig.getMifosAddress();

    final AccountBridgeConfiguration newAccount = new AccountBridgeConfiguration(null, "x", mifosAddress);
    final Response creationResponse = given().header(StellarBridgeTestHelpers.CONTENT_TYPE_HEADER)
            .body(newAccount).post("/modules/stellarbridge");

    creationResponse.then().assertThat().statusCode(HttpStatus.BAD_REQUEST.value());
}

From source file:org.openbaton.marketplace.api.exceptions.GlobalExceptionHandler.java

@ExceptionHandler({ PackageIntegrityException.class })
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
protected @ResponseBody ResponseEntity<Object> handleInvalidRequest(Exception e, WebRequest request) {
    if (log.isDebugEnabled()) {
        log.error("Exception was thrown -> Return message: " + e.getMessage(), e);
    } else {/*from   ww w .j  a  v  a2 s . c o  m*/
        log.error("Exception was thrown -> Return message: " + e.getMessage());
    }
    ExceptionResource exc = new ExceptionResource("Bad Request", e.getMessage());
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    Map body = new HashMap<>();
    body.put("error", "Upload Error");
    body.put("exception", e.getClass().toString());
    body.put("message", e.getMessage());
    body.put("path", request.getContextPath());
    body.put("status", HttpStatus.BAD_REQUEST.value());
    body.put("timestamp", new Date().getTime());
    ResponseEntity responseEntity = new ResponseEntity(body, headers, HttpStatus.BAD_REQUEST);
    return responseEntity;
}

From source file:org.mitre.uma.web.PermissionRegistrationEndpoint.java

@RequestMapping(method = RequestMethod.POST, consumes = MimeTypeUtils.APPLICATION_JSON_VALUE, produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
public String getPermissionTicket(@RequestBody String jsonString, Model m, Authentication auth) {

    ensureOAuthScope(auth, SystemScopeService.UMA_PROTECTION_SCOPE);

    try {/*from   w ww  .  j  a v  a 2 s  .  c o  m*/

        // parse the permission request

        JsonElement el = parser.parse(jsonString);
        if (el.isJsonObject()) {
            JsonObject o = el.getAsJsonObject();

            Long rsid = getAsLong(o, "resource_set_id");
            Set<String> scopes = getAsStringSet(o, "scopes");

            if (rsid == null || scopes == null || scopes.isEmpty()) {
                // missing information
                m.addAttribute("code", HttpStatus.BAD_REQUEST);
                m.addAttribute("errorMessage",
                        "Missing required component of permission registration request.");
                return JsonErrorView.VIEWNAME;
            }

            // trim any restricted scopes
            Set<SystemScope> scopesRequested = scopeService.fromStrings(scopes);
            scopesRequested = scopeService.removeRestrictedAndReservedScopes(scopesRequested);
            scopes = scopeService.toStrings(scopesRequested);

            ResourceSet resourceSet = resourceSetService.getById(rsid);

            // requested resource set doesn't exist
            if (resourceSet == null) {
                m.addAttribute("code", HttpStatus.NOT_FOUND);
                m.addAttribute("errorMessage", "Requested resource set not found: " + rsid);
                return JsonErrorView.VIEWNAME;
            }

            // authorized user of the token doesn't match owner of the resource set
            if (!resourceSet.getOwner().equals(auth.getName())) {
                m.addAttribute("code", HttpStatus.FORBIDDEN);
                m.addAttribute("errorMessage",
                        "Party requesting permission is not owner of resource set, expected "
                                + resourceSet.getOwner() + " got " + auth.getName());
                return JsonErrorView.VIEWNAME;
            }

            // create the permission
            PermissionTicket permission = permissionService.createTicket(resourceSet, scopes);

            if (permission != null) {
                // we've created the permission, return the ticket
                JsonObject out = new JsonObject();
                out.addProperty("ticket", permission.getTicket());
                m.addAttribute("entity", out);

                m.addAttribute("code", HttpStatus.CREATED);

                return JsonEntityView.VIEWNAME;
            } else {
                // there was a failure creating the permission object

                m.addAttribute("code", HttpStatus.INTERNAL_SERVER_ERROR);
                m.addAttribute("errorMessage", "Unable to save permission and generate ticket.");

                return JsonErrorView.VIEWNAME;
            }

        } else {
            // malformed request
            m.addAttribute("code", HttpStatus.BAD_REQUEST);
            m.addAttribute("errorMessage", "Malformed JSON request.");
            return JsonErrorView.VIEWNAME;
        }
    } catch (JsonParseException e) {
        // malformed request
        m.addAttribute("code", HttpStatus.BAD_REQUEST);
        m.addAttribute("errorMessage", "Malformed JSON request.");
        return JsonErrorView.VIEWNAME;
    }

}

From source file:it.reply.orchestrator.exception.GlobalControllerExceptionHandler.java

/**
 * Invalid TOSCA exception handler.//w  w w .ja v  a 2s.com
 * 
 * @param ex
 *          the exception
 * @return a {@code ResponseEntity} instance
 */
@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public Error handleException(ToscaException ex) {

    return new Error().withCode(HttpStatus.BAD_REQUEST.value())
            .withTitle(HttpStatus.BAD_REQUEST.getReasonPhrase()).withMessage(ex.getMessage());
}

From source file:org.jasig.portlet.survey.mvc.SurveyRestController.java

/**
 * Create a survey//www.j a  v  a2  s.  c o  m
 * 
 * @param survey
 * @return
 */
@PreAuthorize("hasRole('ADMIN')")
@ApiMethod(description = "Create a survey", responsestatuscode = "201")
@RequestMapping(method = RequestMethod.POST, value = "/")
public @ApiResponseObject ResponseEntity<SurveyDTO> addSurvey(@ApiBodyObject @RequestBody SurveyDTO survey,
        Principal principal) {
    survey.setLastUpdateUser(principal.getName());
    SurveyDTO newSurvey = null;
    HttpStatus status = HttpStatus.CREATED;

    try {
        newSurvey = dataService.createSurvey(survey);
    } catch (Exception e) {
        status = HttpStatus.BAD_REQUEST;
        log.error("Error creating survey: " + survey.toString(), e);
    }

    return new ResponseEntity<>(newSurvey, status);
}