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, String msg) throws IOException;

Source Link

Document

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

Usage

From source file:org.n52.iceland.service.Service.java

protected void onHttpException(HttpServletRequest request, HttpServletResponse response,
        HTTPException exception) throws IOException {
    this.serviceEventBus.submit(new ExceptionEvent(exception));
    response.sendError(exception.getStatus().getCode(), exception.getMessage());
}

From source file:com.collective.celos.servlet.RegisterServlet.java

protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException {
    try {/*from   w  w w.j a  v  a  2 s  . c om*/
        BucketID bucket = getRequestBucketID(req);
        RegisterKey key = getRequestKey(req);
        try (StateDatabaseConnection connection = getStateDatabase().openConnection()) {
            JsonNode value = connection.getRegister(bucket, key);
            if (value == null) {
                res.sendError(HttpServletResponse.SC_NOT_FOUND, "Register not found");
            } else {
                writer.writeValue(res.getOutputStream(), value);
            }
        }
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:com.sesnu.orion.web.controller.PaymentController.java

@RequestMapping(value = "/api/user/pay", method = RequestMethod.POST)
public @ResponseBody List<PayView> addItem(HttpServletResponse response, @RequestBody Payment pay)
        throws Exception {

    List<ShippingView> ships = shipDao.listByOrderId(pay.getOrderRef());
    if (ships.size() == 0 && !pay.getName().equals("DU License")) {
        response.sendError(400, Util.parseError("Item not yet marked as shipped"));
        return null;
    }/*  w ww.  j  av a 2 s.c  o m*/
    OrderView order = orderDAO.get(pay.getOrderRef());

    pay.setEstimate(calcEstimate(order, pay).getValue());
    pay.setUpdatedOn(Util.parseDate(new Date(), "/"));
    pay.setStatus("Initiated");
    pay.setId(null);
    payDao.saveOrUpdate(pay);

    List<PayView> pays = payDao.listAll();
    if (pays.size() > 0) {
        return pays;
    }
    response.sendError(404);
    return null;

}

From source file:org.ngrinder.security.SvnHttpBasicEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response, // LB
        AuthenticationException authException) throws IOException, ServletException {
    // Get the first part of url path and use it as a realm.
    String pathInfo = request.getPathInfo();
    String[] split = StringUtils.split(pathInfo, '/');
    response.addHeader("WWW-Authenticate",
            "Basic realm=\"" + StringUtils.defaultIfBlank(split[0], "admin") + "\"");
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage());
}