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:gsn.http.AddressingReqHandler.java

public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setStatus(HttpServletResponse.SC_OK);
    String vsName = request.getParameter("name");
    VSensorConfig sensorConfig = Mappings.getVSensorConfig(vsName);
    logger.info(new StringBuilder().append("Structure request for *").append(vsName).append("* received.")
            .toString());// ww  w .j ava  2s. c  o m
    StringBuilder sb = new StringBuilder("<virtual-sensor name=\"").append(vsName).append("\" last-modified=\"")
            .append(new File(sensorConfig.getFileName()).lastModified()).append("\">\n");
    for (KeyValue df : sensorConfig.getAddressing())
        sb.append("<predicate key=\"").append(StringEscapeUtils.escapeXml(df.getKey().toString())).append("\">")
                .append(StringEscapeUtils.escapeXml(df.getValue().toString())).append("</predicate>\n");
    sb.append("</virtual-sensor>");
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
    response.setHeader("Pragma", "no-cache");
    response.getWriter().write(sb.toString());
}

From source file:org.smigo.comment.CommentController.java

@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/rest/comment", produces = "application/json", method = RequestMethod.POST)
@ResponseBody//from   ww  w  . j  a v a2  s  .  c om
public Object addMessage(@Valid @RequestBody Comment comment, BindingResult result,
        @AuthenticationPrincipal AuthenticatedUser user, HttpServletResponse response) {
    if (result.hasErrors()) {
        response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
        return result.getAllErrors();
    }
    return commentHandler.addComment(comment, user.getId());
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController.java

protected void doError(HttpServletResponse response, String errorMsg, int httpstatus) {
    response.setStatus(httpstatus);
    try {//from  ww w.  ja  va 2s. c  o m
        response.getWriter().write(errorMsg);
    } catch (IOException e) {
        log.debug("IO exception during output", e);
    }
}

From source file:org.smigo.comment.CommentController.java

@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/rest/comment", produces = "application/json", method = RequestMethod.PUT)
@ResponseBody// www . ja v  a2s  .c  om
public Object updateComment(@Valid @RequestBody Comment comment, BindingResult result,
        @AuthenticationPrincipal AuthenticatedUser user, HttpServletResponse response) {
    if (result.hasErrors()) {
        response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
        return result.getAllErrors();
    }
    commentHandler.updateComment(comment, user);
    return Collections.emptyList();
}

From source file:vn.edu.vnuk.tasks_jpa.controller.TasksController.java

@RequestMapping(value = "deleteTask", method = RequestMethod.POST)
public void delete(Long id, HttpServletResponse response) throws SQLException {
    dao.delete(id);//ww  w.  j a va  2 s .  c om
    response.setStatus(200);
}

From source file:arena.web.view.ErrorView.java

@SuppressWarnings("unchecked")
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    if (this.message != null) {
        response.setStatus(this.errorCode);
        response.getWriter()//from  w w  w.  j ava 2 s  .co m
                .append(ServletUtils.replaceWildcards(this.message, this.allowRequestArgs, model, request));
        response.flushBuffer();
    } else {
        response.sendError(this.errorCode);
    }
}

From source file:com.appleframework.monitor.action.UserAction.java

@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(ModelMap map, HttpServletResponse response) {
    response.setStatus(HttpStatus.UNAUTHORIZED.value());
    return "app/login";
}

From source file:vn.edu.vnuk.tasks_jpa.controller.TasksController.java

@RequestMapping(value = "completeTask", method = RequestMethod.POST)
public void complete(Long id, HttpServletResponse response) throws SQLException {
    dao.complete(id);//from   w w  w.  j av a  2 s  .co  m
    response.setStatus(200);
}

From source file:com.dangdang.ddframe.job.security.WwwAuthFilter.java

private void needAuthenticate(final HttpServletResponse response) {
    response.setStatus(401);
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
    response.setHeader("WWW-authenticate", AUTH_PREFIX + "Realm=\"Elastic Job Console Auth\"");
}

From source file:RedirectNewLocation.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    PrintWriter out = response.getWriter();

    response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
    response.setHeader("Location", "http://www.java2s.com");

    response.setContentType("text/html");
    return;//from   w w w .  ja  v  a 2 s  . c om
}