Example usage for javax.servlet.http HttpServletResponse sendError

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

Introduction

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

Prototype

public void sendError(int sc) throws IOException;

Source Link

Document

Sends an error response to the client using the specified status code and clears the buffer.

Usage

From source file:com.googlecode.commonspringaspects.servlets.PerformanceHttpRequestHandler.java

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

    if (!enabled) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;//from  w  ww. j ava  2 s .  co  m
    }

    if (request.getMethod().equals("POST")) {

        MonitorFactory.reset();
        response.sendRedirect(request.getRequestURI());

    } else {

        response.setContentType("text/html");
        PrintWriter writer = response.getWriter();
        writer.print("<html>");
        writer.print("<body><form action='' method='post'> <input type='submit' value='Reset JAMon'> </form>");
        writer.print(MonitorFactory.getRootMonitor().getReport(3, "desc"));
        writer.print("</body></html>");

    }
}

From source file:com.carolinarollergirls.scoreboard.jetty.StreamServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    super.doPost(request, response);

    response.sendError(HttpServletResponse.SC_NOT_FOUND);
}

From source file:com.nec.harvest.servlet.interceptor.async.TimeoutCallableProcessingInterceptor.java

@Override
public <T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception {
    final HttpServletResponse servletResponse = request.getNativeResponse(HttpServletResponse.class);
    if (!servletResponse.isCommitted()) {
        servletResponse.sendError(HttpStatus.SERVICE_UNAVAILABLE.value());
    }/*from  w  w  w  .  j  a  va2s. c o m*/

    return CallableProcessingInterceptor.RESPONSE_HANDLED;
}

From source file:com.pubkit.web.controller.BaseController.java

@ExceptionHandler(IllegalArgumentException.class)
void handleBadRequests(HttpServletResponse response) throws IOException {
    response.sendError(HttpStatus.BAD_REQUEST.value());
}

From source file:com.pubkit.web.controller.BaseController.java

@ExceptionHandler(RoquitoServerException.class)
void handleServerError(HttpServletResponse response) throws IOException {
    response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value());
}

From source file:com.pubkit.web.controller.BaseController.java

@ExceptionHandler(RoquitoAuthException.class)
void handleAuthError(HttpServletResponse response) throws IOException {
    response.sendError(HttpStatus.NETWORK_AUTHENTICATION_REQUIRED.value());
}

From source file:ejportal.webapp.interceptor.UserRoleAuthorizationInterceptor.java

/**
 * Handle a request that is not authorized according to this interceptor.
 * Default implementation sends HTTP status code 403 ("forbidden").
 * /*  w  w  w  .j  a va  2 s  . com*/
 * <p>
 * This method can be overridden to write a custom message, forward or
 * redirect to some error page or login page, or throw a ServletException.
 * 
 * @param request
 *            current HTTP request
 * @param response
 *            current HTTP response
 * @throws ServletException
 *             the servlet exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
protected void handleNotAuthorized(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    response.sendError(HttpServletResponse.SC_FORBIDDEN);
}

From source file:de.otto.mongodb.profiler.web.AbstractController.java

@ExceptionHandler(RuntimeException.class)
public void onRuntimeException(RuntimeException e, HttpServletResponse response) throws IOException {

    logger.error(e, "Unhandled exception caught.");

    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}

From source file:org.wallride.web.controller.admin.user.UserSelect2Controller.java

@RequestMapping(value = "/{language}/users/select/{id}", method = RequestMethod.GET)
public @ResponseBody DomainObjectSelect2Model select(@PathVariable String language, @PathVariable Long id,
        HttpServletResponse response) throws IOException {
    User user = userService.getUserById(id);
    if (user == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }//from  www.  j a  v a  2s  .c  o  m

    DomainObjectSelect2Model model = new DomainObjectSelect2Model(user.getId(), user.toString());
    return model;
}

From source file:com.carolinarollergirls.scoreboard.jetty.LoadXmlScoreBoard.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    super.doGet(request, response);
    response.sendError(HttpServletResponse.SC_NOT_FOUND);
}