Example usage for javax.servlet.http HttpServletResponse setStatus

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

Introduction

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

Prototype

public void setStatus(int sc);

Source Link

Document

Sets the status code for this response.

Usage

From source file:org.nekorp.workflow.backend.controller.imp.ReporteClienteControllerImp.java

/**{@inheritDoc}*/
@Override//w w w.ja v a 2  s.  c  om
@RequestMapping(value = "/{idServicio}", method = RequestMethod.GET)
@ResponseBody
public ReporteCliente getDatosReporte(@PathVariable Long idCliente, @PathVariable Long idServicio,
        HttpServletResponse response) {
    Servicio servicio = servicioDao.consultar(idServicio);
    if (servicio == null) {
        response.setStatus(HttpStatus.NOT_FOUND.value());
        return null;
    }
    if (servicio.getIdCliente().longValue() != idCliente.longValue()) {
        response.setStatus(HttpStatus.NOT_FOUND.value());
        return null;
    }
    response.setHeader("Content-Type", "application/json;charset=UTF-8");
    return dataFactory.getData(servicio);
}

From source file:com.sg.rest.security.components.WebTokenAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx)
        throws IOException, ServletException {

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

    AuthenficationFailed dto;//from w  ww .  ja  v  a2s .  co  m
    if (authEx instanceof WebSecurityAccountNotFoundException) {
        dto = new AuthenficationFailed(
                AuthentificationFailureStatus.TOKEN_AUTHENTICATION_ACCOUNT_DO_NOT_EXISTS);
        //dto.setErrorCode(ErrorCodes.TOKEN_AUTHENTICATION_ACCOUNT_DO_NOT_EXISTS);
    } else if (authEx instanceof WebSecurityBadTokenException) {
        dto = new AuthenficationFailed(AuthentificationFailureStatus.TOKEN_AUTHENTICATION_BAD_TOKEN);
        //dto.setErrorCode(ErrorCodes.TOKEN_AUTHENTICATION_BAD_TOKEN);
    } else if (authEx instanceof WebSecurityTokenExpiredException) {
        dto = new AuthenficationFailed(AuthentificationFailureStatus.TOKEN_AUTHENTICATION_TOKEN_EXPIRED);
        //dto.setErrorCode(ErrorCodes.TOKEN_AUTHENTICATION_TOKEN_EXPIRED);
    } else if (authEx instanceof InsufficientAuthenticationException) {
        dto = new AuthenficationFailed(AuthentificationFailureStatus.TOKEN_AUTHENTICATION_NO_TOKEN);
        //dto.setErrorCode(ErrorCodes.TOKEN_AUTHENTICATION_NO_TOKEN);
    } else {
        dto = new AuthenficationFailed(AuthentificationFailureStatus.UNKNOWN);
    }

    LOGGER.error("Authentication failed " + dto.getEventRef().getId() + ": ", authEx);

    response.setContentType(CustomMediaTypes.APPLICATION_JSON_UTF8.getMediatype().toString());
    jacksonObjectMapper.writeValue(response.getWriter(), dto);
}

From source file:net.skhome.roborace.web.controller.UserController.java

@RequestMapping(method = RequestMethod.PUT)
public void updateUserAccount(@RequestBody @Valid final UserAccount account,
        final HttpServletResponse response) {

    try {//from w ww  .  j  a v  a  2 s.  c o  m
        service.updateUserAccount(account);
        response.setStatus(HttpServletResponse.SC_OK);
    } catch (DataAccessException ex) {
        throw new ResourceNotFoundException(account.getId());
    }

}

From source file:cf.spring.servicebroker.CatalogHandler.java

@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!"get".equalsIgnoreCase(request.getMethod())) {
        response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        return;/* w ww  .  j  a  va  2 s .  com*/
    }
    if (!authenticator.authenticate(request, response)) {
        return;
    }
    ApiVersionValidator.validateApiVersion(request);
    response.setContentType(Constants.JSON_CONTENT_TYPE);

    mapper.writeValue(response.getOutputStream(), catalog.get());
}

From source file:com.sentinel.rest.handlers.HttpLogoutSuccessHandler.java

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    LOG.trace("Method: onLogoutSuccess called.");

    response.setStatus(HttpServletResponse.SC_OK);
    response.getWriter().flush();/* w ww . j a  v  a  2 s .c o m*/

    LOG.trace("Method: onLogoutSuccess finished.");
}

From source file:net.skhome.roborace.web.controller.UserController.java

@RequestMapping(method = RequestMethod.POST)
@ResponseBody/* w  w  w. j  av a  2  s. co  m*/
public Map<String, String> createUserAccount(@RequestBody @Valid final UserAccount account,
        final HttpServletResponse response) {

    try {
        service.createUserAccount(account);
        response.setStatus(HttpServletResponse.SC_CREATED);
        return Collections.singletonMap("id", account.getId());
    } catch (DataAccessException ex) {
        throw new ResourceAlreadyExistsException(account.getUsername());
    }

}

From source file:com.iggroup.oss.sample.web.controller.BaseController.java

/**
 * SampleException handler. Set the HTTP status and return a SampleErrorList
 * object//from  w w  w  . j  av a2s.c  o  m
 * 
 * @param se the sample exception being handled
 * @param req HTTP request
 * @param res HTTP response
 * @return a JAXB friendly SampleErrorList
 * @throws IOException IO exception
 */
@ExceptionHandler(SampleException.class)
@ResponseBody
public SampleErrorList exceptionHandler(SampleException se, HttpServletRequest req, HttpServletResponse res)
        throws IOException {

    LOGGER.debug("Handling:", se);
    res.setStatus(se.getHttpStatus());

    return new SampleErrorList(se.getErrors());

}

From source file:br.gov.frameworkdemoiselle.util.BasicAuthFilter.java

private void setUnauthorizedStatus(HttpServletResponse response, Exception cause) throws IOException {
    response.setStatus(SC_UNAUTHORIZED);
    response.setContentType("text/html");

    response.getWriter().write(cause.getMessage());
    response.getWriter().flush();/*  ww w  . java 2  s .  co m*/
    response.getWriter().close();
}

From source file:eu.stratosphere.nephele.jobmanager.web.SetupInfoServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    resp.setStatus(HttpServletResponse.SC_OK);
    resp.setContentType("application/json");

    if ("globalConfiguration".equals(req.getParameter("get"))) {
        writeGlobalConfiguration(resp);// w w  w  .j av  a2s  . co  m
    } else if ("taskmanagers".equals(req.getParameter("get"))) {
        writeTaskmanagers(resp);
    }

}

From source file:edu.mayo.cts2.framework.plugin.service.lexevs.bulk.AbstractBulkDownloadController.java

protected void writeException(HttpServletResponse response, String message, int errorCode) {
    response.setContentType("text/plain; charset=utf-8");
    response.setStatus(errorCode);

    try {//from   ww  w  . ja  va  2s  . c om
        IOUtils.write(message, response.getOutputStream());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}