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.smigo.comment.CommentController.java

@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/rest/comment/{id}", produces = "application/json", method = RequestMethod.DELETE)
@ResponseBody//from   w ww.  j a  v a2s  .  c  o m
public void removeMessage(@PathVariable int id, @AuthenticationPrincipal AuthenticatedUser user,
        HttpServletResponse response) {
    HttpStatus httpStatus = commentHandler.removeComment(id, user);
    response.setStatus(httpStatus.value());
}

From source file:org.openmrs.module.metadatasharing.web.controller.ExceptionResolver.java

/**
 * @see org.springframework.web.servlet.HandlerExceptionResolver#resolveException(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Exception)
 *//* ww w  . ja v a 2  s . c  o m*/
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception exception) {
    if (exception instanceof PackageNotFoundException) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return new ModelAndView("/module/metadatasharing/packageNotFound");
    }
    return null;
}

From source file:net.gplatform.sudoor.server.security.model.ResponseCodeHandler.java

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    response.setStatus(responseCode);
}

From source file:net.mindengine.blogix.web.BlogixServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) {
    String uri = req.getRequestURI();
    try {//from   www.j  a  v  a 2  s  .c  o  m
        res.setStatus(200);
        String contentType = findContentTypeFor(uri);
        if (contentType != null) {
            res.setContentType(contentType);
        }
        blogix.processUri(uri, res.getOutputStream());
    } catch (Throwable e) {
        res.setStatus(400);
        printResponseText(res, ExceptionUtils.getMessage(e) + "\n" + ExceptionUtils.getStackTrace(e));
    }
}

From source file:org.smigo.user.authentication.RestAuthenticationFailureHandler.java

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    response.setStatus(HttpStatus.FORBIDDEN.value());
    List<ObjectError> errors = new ArrayList<ObjectError>();
    if (exception instanceof BadCredentialsException) {
        errors.add(new ObjectError("bad-credentials", "msg.badcredentials"));
    } else {//from   ww  w .  ja  v a2 s. co m
        errors.add(new ObjectError("username", "msg.unknownerror"));
    }
    String responseBody = objectMapper.writeValueAsString(errors);
    response.getWriter().append(responseBody);

    final String username = Arrays.toString(request.getParameterMap().get("username"));
    final String note = "Authentication Failure:" + username + System.lineSeparator() + exception;
    log.info(note);
    mailHandler.sendAdminNotification("authentication failure", note);
}

From source file:de.knightsoftnet.validators.server.security.HttpLogoutSuccessHandler.java

@Override
public void onLogoutSuccess(final HttpServletRequest prequest, final HttpServletResponse presponse,
        final Authentication pauthentication) throws IOException {
    LOGGER.info("User logged out!");
    presponse.setStatus(HttpServletResponse.SC_OK);
    this.csrfCookieHandler.setCookie(prequest, presponse);
}

From source file:eu.europeana.core.util.web.ExceptionResolver.java

private ModelAndView ajaxFailure(HttpServletRequest request, HttpServletResponse response, Exception e) {
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    ModelAndView page = ThemeFilter.createThemedModelAndViewPage("xml/ajax");
    page.addObject("success", false);
    page.addObject("exception", getStackTrace(e));
    clickStreamLogger.logUserAction(request, ClickStreamLogger.UserAction.AJAX_ERROR);
    log.warn("Problem handling AJAX request", e);
    return page;//from   w ww . j a  va 2s .  c o m
}

From source file:net.gplatform.sudoor.server.security.model.ResponseCodeHandler.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.setStatus(responseCode);
}

From source file:net.sf.j2ep.responsehandlers.TraceResponseHandler.java

/**
 * Will either respond with data from the underlying server
 * or the proxy's own data./*w ww.  j a  v a2s  . c o  m*/
 * @see net.sf.j2ep.model.ResponseHandler#process(javax.servlet.http.HttpServletResponse)
 */
public void process(HttpServletResponse response) throws IOException {

    if (proxyTargeted) {
        response.setStatus(HttpServletResponse.SC_OK);
        response.setHeader("content-type", "message/http");
        response.setHeader("Connection", "close");

        String path = method.getPath();
        String protocol = method.getParams().getVersion().toString();
        PrintWriter writer = response.getWriter();
        writer.println("TRACE " + path + " " + protocol);
        Header[] headers = method.getRequestHeaders();
        for (int i = 0; i < headers.length; i++) {
            writer.print(headers[i]);
        }
        writer.flush();
        writer.close();

    } else {
        setHeaders(response);
        response.setStatus(getStatusCode());
        sendStreamToClient(response);
    }
}

From source file:org.smigo.species.varieties.VarietyController.java

@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/rest/variety", method = RequestMethod.POST)
public Object addVariety(@Valid @RequestBody Variety variety, BindingResult result,
        HttpServletResponse response, @AuthenticationPrincipal AuthenticatedUser user) {
    if (result.hasErrors()) {
        response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
        return result.getAllErrors();
    }/*from www  . j a  v  a2 s .  c  o m*/
    variety.setUserId(user.getId());
    final int id = varietyDao.addVariety(variety);
    response.setStatus(HttpServletResponse.SC_CREATED);
    return id;
}