Example usage for javax.servlet.http HttpServletResponse SC_BAD_REQUEST

List of usage examples for javax.servlet.http HttpServletResponse SC_BAD_REQUEST

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_BAD_REQUEST.

Prototype

int SC_BAD_REQUEST

To view the source code for javax.servlet.http HttpServletResponse SC_BAD_REQUEST.

Click Source Link

Document

Status code (400) indicating the request sent by the client was syntactically incorrect.

Usage

From source file:org.energyos.espi.thirdparty.web.BatchRESTController.java

@RequestMapping(value = Routes.BATCH_DOWNLOAD_MY_DATA_COLLECTION, method = RequestMethod.GET, produces = "application/atom+xml")
@ResponseBody//from   w w w .j  a  va  2s.com
public void download_collection(HttpServletResponse response, @PathVariable Long retailCustomerId,
        @RequestParam Map<String, String> params) throws IOException, FeedException {

    response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE);
    response.addHeader("Content-Disposition", "attachment; filename=GreenButtonDownload.xml");
    try {
        // TODO -- need authorization hook
        exportService.exportUsagePointsFull(0L, retailCustomerId, response.getOutputStream(),
                new ExportFilter(params));

    } catch (Exception e) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    }

}

From source file:com.haulmont.cuba.core.controllers.FileUploadController.java

private UserSession getSession(HttpServletRequest request, HttpServletResponse response) throws IOException {
    UUID sessionId;//ww  w  .  j  ava2 s  .  c  om
    try {
        sessionId = UUID.fromString(request.getParameter("s"));
    } catch (Exception e) {
        log.error("Error parsing sessionId from URL param", e);
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return null;
    }
    UserSession session = userSessions.getAndRefresh(sessionId);
    if (session == null)
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
    return session;
}

From source file:com.vmware.identity.samlservice.impl.LogoutStateValidator.java

@Override
public com.vmware.identity.samlservice.SamlValidator.ValidationResult validate(LogoutState t) {
    log.debug("Validating request {}", t);

    ValidationResult vr = null;//w w w  . ja v  a 2s  .  c  om

    try {
        Validate.notNull(t);

        HttpServletRequest httpRequest = t.getRequest();
        Validate.notNull(httpRequest);

        IdmAccessor accessor = t.getIdmAccessor();
        Validate.notNull(accessor);
        Validate.notNull(accessor.getTenant());

        SessionManager sm = t.getSessionManager();
        Validate.notNull(sm);

        LogoutRequest request = t.getLogoutRequest();
        LogoutResponse response = t.getLogoutResponse();
        Validate.isTrue(request != null || response != null);
        if (request != null) {
            vr = validateLogoutRequest(vr, accessor, request);
        } else {
            vr = validateLogoutResponse(vr, accessor, response, sm);
        }

    } catch (Exception e) {
        vr = new ValidationResult(HttpServletResponse.SC_BAD_REQUEST, "BadRequest", null);
        log.debug("Caught exception while Validating {} returning 400", e.toString());
    }
    return vr;
}

From source file:org.energyos.espi.datacustodian.web.customer.CustomerDownloadMyDataController.java

@RequestMapping(value = Routes.RETAIL_CUSTOMER_DOWNLOAD_MY_DATA_COLLECTION, method = RequestMethod.GET)
public void downloadMyDataCollection(HttpServletResponse response, @PathVariable Long retailCustomerId,
        @RequestParam Map<String, String> params) throws IOException, FeedException {

    response.setContentType(MediaType.TEXT_HTML_VALUE);
    response.addHeader("Content-Disposition", "attachment; filename=GreenButtonDownload.xml");
    try {//w  w  w  .j  ava2 s .com
        // TODO -- need authorization hook
        exportService.exportUsagePointsFull(0L, retailCustomerId, response.getOutputStream(),
                new ExportFilter(params));

    } catch (Exception e) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:cz.muni.fi.pa165.deliverysystemweb.CourierActionBean.java

public Resolution view() {
    String id = getContext().getRequest().getParameter("id");

    Long l_id;/*from w  w  w.  ja va  2  s.c o  m*/
    try {
        l_id = Long.valueOf(id);
    } catch (NumberFormatException ex) {
        return new ErrorResolution(HttpServletResponse.SC_BAD_REQUEST);
    }

    try {
        courierDTO = courierService.findCourier(l_id);
    } catch (DataAccessException ex) {
        return new ErrorResolution(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }

    if (courierDTO == null) {
        return new ErrorResolution(HttpServletResponse.SC_NOT_FOUND);
    }
    return new ForwardResolution("/courier/view.jsp");
}

From source file:io.lavagna.web.security.login.PersonaLoginTest.java

@Test
public void notPostRequest() throws IOException {
    Assert.assertTrue(personaLogin.doAction(req, resp));
    verify(resp).setStatus(HttpServletResponse.SC_BAD_REQUEST);
}

From source file:com.oneops.transistor.ws.rest.CatalogRestController.java

@ExceptionHandler(CIValidationException.class)
public void handleCIValidationExceptions(CIValidationException e, HttpServletResponse response)
        throws IOException {
    logger.error(e);/* w w  w.  j ava2s  . c o  m*/
    sendError(response, HttpServletResponse.SC_BAD_REQUEST, e);
}

From source file:com.vmware.identity.MetadataController.java

/**
 * Handle GET request for the metadata//from   w w  w .  j a v a2 s . c  om
 */
@RequestMapping(value = "/SAML2/Metadata/{tenant:.*}", method = RequestMethod.GET)
public void metadata(Locale locale, @PathVariable(value = "tenant") String tenant, Model model,
        HttpServletResponse response) throws IOException {
    logger.info("Welcome to Metadata handler! " + "The client locale is " + locale.toString() + ", tenant is "
            + tenant);

    //TODO - check for correlation id in the headers PR1561606
    String correlationId = UUID.randomUUID().toString();
    DefaultIdmAccessorFactory factory = new DefaultIdmAccessorFactory(correlationId);
    try {
        IdmAccessor accessor = factory.getIdmAccessor();
        accessor.setTenant(tenant);
        String metadata = accessor.exportConfigurationAsString();
        Validate.notNull(metadata);
        response.setHeader("Content-Disposition", "attachment; filename=" + SAML_METADATA_FILENAME);
        Shared.sendResponse(response, Shared.METADATA_CONTENT_TYPE, metadata);
    } catch (Exception e) {
        logger.error("Caught exception", e);
        ValidationResult vr = new ValidationResult(HttpServletResponse.SC_BAD_REQUEST, "BadRequest", null);
        String message = vr.getMessage(messageSource, locale);
        response.sendError(vr.getResponseCode(), message);
        logger.info("Responded with ERROR " + vr.getResponseCode() + ", message " + message);
    }

    model.addAttribute("tenant", tenant);
}

From source file:org.axonframework.samples.trader.webui.rest.RestController.java

@RequestMapping(value = "/command", method = RequestMethod.POST)
public @ResponseBody String mappedCommand(String command, HttpServletResponse response) throws IOException {
    try {//ww w  .  j ava2 s  . co m
        Object actualCommand = xStream.fromXML(command);
        commandBus.dispatch(new GenericCommandMessage<Object>(actualCommand));
    } catch (StructuralCommandValidationFailedException e) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "This is an invalid request.");
    } catch (Exception e) {
        logger.error("Problem whils deserializing an xml: {}", command, e);
        return "ERROR - " + e.getMessage();
    }

    return "OK";
}

From source file:com.fpmislata.banco.presentation.controladores.CuentaBancariaController.java

@RequestMapping(value = "/cuentabancaria", method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
public void insert(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        @RequestBody String jsonEntrada) throws IOException {
    try {/* w  w  w .j  ava2 s  .com*/
        CuentaBancaria cuentaBancaria = (CuentaBancaria) jsonTransformer.fromJsonToObject(jsonEntrada,
                CuentaBancaria.class);
        cuentaBancariaService.insert(cuentaBancaria);
        String jsonSalida = jsonTransformer.ObjectToJson(cuentaBancaria);

        httpServletResponse.setStatus(HttpServletResponse.SC_OK);
        httpServletResponse.setContentType("application/json; charset=UTF-8");
        httpServletResponse.getWriter().println(jsonSalida);

    } catch (BusinessException ex) {
        List<BusinessMessage> bussinessMessage = ex.getBusinessMessages();
        String jsonSalida = jsonTransformer.ObjectToJson(bussinessMessage);
        httpServletResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        httpServletResponse.setContentType("application/json; charset=UTF-8");
        httpServletResponse.getWriter().println(jsonSalida);
    } catch (Exception ex) {
        throw new RuntimeException(ex);

    }
}