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:pdfjsannotator.controller.AnnotationController.java

@RequestMapping(value = "/api/annotations/{id}", method = RequestMethod.DELETE)
public void delete(@PathVariable String id, HttpServletResponse response) {
    LOGGER.info("Requested deletion of annotation with id " + id);
    response.setStatus(204);
    annotationRepository.delete(id);/*from w ww. j a  v  a2 s.c  o  m*/
}

From source file:name.martingeisse.servlet_httpclient.sidekicks.fakecdn.FakeCdnFilter.java

/**
 * //from   ww  w  .ja v  a 2 s.  c  o  m
 */
private void doCdn(ServletRequest request, ServletResponse response, String key)
        throws IOException, ServletException {
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    FakeCdnRecord record = cdn.request(key);
    httpResponse.setStatus(record.getStatusCode());
    httpResponse.setContentType(record.getContentType());
    httpResponse.setHeader("Cache-Control", "" + (365 * 24 * 3600));
    httpResponse.setHeader("Date", dateTimeHeaderFormatter.print(new DateTime()));
    httpResponse.setHeader("Expires", dateTimeHeaderFormatter.print(new DateTime().plusDays(365)));
    httpResponse.setHeader("Last-Modified", dateTimeHeaderFormatter.print(new DateTime(2000, 1, 1, 0, 0)));
    IOUtils.copy(new ByteArrayInputStream(record.getData()), httpResponse.getOutputStream());
    httpResponse.getOutputStream().flush();
    httpResponse.getOutputStream().close();
}

From source file:it.tidalwave.northernwind.frontend.util.InitializationDiagnosticsDispatcherServletDecorator.java

/*******************************************************************************************************************
 *
 *
 ******************************************************************************************************************/
private void sendProcessingError(final @Nonnull Throwable t, final @Nonnull HttpServletResponse response)
        throws IOException {
    response.setStatus(500);
    response.setContentType("text/html");
    final PrintWriter pw = new PrintWriter(new PrintStream(response.getOutputStream(), true, "UTF-8"));
    pw.print("<html>\n<head>\n<title>Configuration Error</title>\n</head>\n<body>\n");
    pw.print("<h1>Configuration Error</h1>\n<pre>\n");
    pw.print(t.toString());/* w w  w. j a  v a2s.  c  o m*/
    //        t.printStackTrace(pw);
    pw.print("</pre>\n");
    pw.print("<h2>Boot log</h2>\n<pre>\n");
    pw.print(BootLogger.getLogContent());
    pw.print("</pre></body>\n</html>");
    pw.close();
    response.getOutputStream().close();
}

From source file:org.ng200.openolympus.controller.auth.OpenOlympusAuthenticationFailureHandler.java

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    response.setContentType("application/json");
    response.setStatus(HttpStatus.OK.value());
    AuthenticationResponder.writeLoginStatusJson(response.getWriter(), "failed", null);
}

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

@RequestMapping("completeTask")
public void complete(int id, HttpServletResponse response) throws SQLException {
    TaskDao dao = new TaskDao();
    dao.complete(id);/*from   w  w  w.j a  v a  2  s. c  om*/
    response.setStatus(200);
}

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

@RequestMapping(value = { "/{username}" }, method = RequestMethod.DELETE)
public void activate(@PathVariable final String username, final HttpServletRequest request,
        final HttpServletResponse response) {
    if (null == userService.deleteDbUser(username)) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }//www  . j  a va  2  s  . co  m
}

From source file:org.smigo.config.RestExceptionResolver.java

private ModelAndView getModelAndView(HttpServletResponse response, HttpStatus httpStatus, Object[] model) {
    if (response.getStatus() == 200) {
        response.setStatus(httpStatus.value());
    }/* w  ww  .j a v a2 s .  c o  m*/
    ModelAndView jsonView = new ModelAndView(view);
    jsonView.addObject(model);
    return jsonView;
}

From source file:de.devbliss.apitester.dummyserver.DummyRequestHandler.java

private void handleException(Exception e, HttpServletResponse response) throws IOException {
    response.setContentType(CONTENT_TYPE_ERROR);
    response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    response.getWriter().write("exception type: " + e.getClass());
    response.getWriter().write(e.getMessage());
}

From source file:com.sjtu.icare.modules.sys.utils.security.FormAuthenticationFilter.java

private void onLoginFail(ServletResponse response, String errorString) throws IOException {
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    //       JSONObject errorJsonObject = new JSONObject();
    //       errorJsonObject.put("errno", HttpServletResponse.SC_UNAUTHORIZED+"");
    //       errorJsonObject.put("error", errorString);
    BasicReturnedJson result = new BasicReturnedJson();
    result.setError(errorString);// ww  w. ja va  2s .  co  m
    result.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    httpResponse.getWriter().write(result.toString());
}

From source file:com.tamnd.app.config.security.AuthFailure.java

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    if (exception instanceof BadCredentialsException) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    } else if (exception instanceof UsernameNotFoundException) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    } else {//ww w . j a  va2 s . c om
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    }
}