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.openmrs.module.openhmis.cashier.web.controller.ReceiptController.java

private boolean validateBill(Integer billId, Bill bill, HttpServletResponse response) throws IOException {
    if (bill == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND,
                "Could not find bill with bill Id '" + billId + "'");

        return false;
    }/*from w w  w.ja v a  2 s . c om*/

    if (bill.isReceiptPrinted() && !Context.hasPrivilege(PrivilegeConstants.REPRINT_RECEIPT)) {
        if (StringUtils.isEmpty(bill.getReceiptNumber())) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN,
                    "You do not have permission to reprint receipt '" + bill.getReceiptNumber() + "'");
        } else {
            response.sendError(HttpServletResponse.SC_FORBIDDEN,
                    "You do not have permission to reprint bill '" + billId + "'");
        }

        return false;
    }

    return true;
}

From source file:org.awesomeagile.webapp.security.AwesomeAgileAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.addHeader("WWW-Authenticate", "AwesomeAgile");
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage());
}

From source file:org.openmrs.module.clinicalsummary.web.controller.response.MedicationAcceptedController.java

@RequestMapping(method = RequestMethod.POST, value = "/module/clinicalsummary/response/acceptMedication")
public void processAccept(final @RequestParam(required = true, value = "id") Integer responseId,
        final @RequestParam(required = true, value = "comment") String comment,
        final HttpServletResponse response) throws IOException {

    if (Context.isAuthenticated()) {
        if (StringUtils.isBlank(comment))
            response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                    Context.getMessageSourceService().getMessage("clinicalsummary.response.required"));
        else {//from w ww .j a  v a2  s .c om
            UtilService service = Context.getService(UtilService.class);
            MedicationResponse medicationResponse = service.getResponse(MedicationResponse.class, responseId);
            medicationResponse.setReviewer(Context.getAuthenticatedUser().getPerson());
            medicationResponse.setDateReviewed(new Date());
            medicationResponse.setReviewComment(comment);
            medicationResponse.setActionType(ActionType.ACTION_ACCEPT);
            service.saveResponse(medicationResponse);
        }
    }
}

From source file:org.magnum.dataup.VideoService.java

private String sendError(HttpServletResponse response, int sc, String msg) {
    try {//from ww w. ja  va  2 s. c o  m
        response.sendError(sc, msg);
    } catch (Exception e) {
        // ignore
    }
    return msg;
}

From source file:com.cloudera.oryx.kmeans.serving.web.DistanceToNearestServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    CharSequence pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
        return;//from w w  w  .ja v a 2  s. c  o m
    }
    String line = pathInfo.subSequence(1, pathInfo.length()).toString();

    Generation generation = getGenerationManager().getCurrentGeneration();
    if (generation == null) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
                "API method unavailable until model has been built and loaded");
        return;
    }

    String[] tokens = DelimitedDataUtils.decode(line);
    RealVector vector = generation.toVector(tokens);
    if (vector == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count");
        return;
    }
    double distance = findClosest(generation, vector).getSquaredDistance();
    response.getWriter().write(Double.toString(distance));
}

From source file:info.losd.galen.api.GalenApiController.java

@ExceptionHandler(IllegalArgumentException.class)
void illegalArgumentException(HttpServletResponse response) throws IOException {
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    response.sendError(HttpStatus.BAD_REQUEST.value(), "The method specified is invalid");
}

From source file:org.trustedanalytics.platformoperations.rest.PlatformExceptionHandler.java

@ExceptionHandler(AccessDeniedException.class)
public void accessForbidden(HttpServletResponse response) throws IOException {

    long errorId = generateErrorId();
    LOGGER.warn(ErrorFormatter.formatErrorMessage("Access forbidden.", errorId));
    response.sendError(FORBIDDEN.value(),
            ErrorFormatter.formatErrorMessage("You do not have permission to perform this action!", errorId));
}

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

protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException {
    String id = req.getParameter(CelosClient.ID_PARAM);
    try {/* ww w  . j a  v  a2 s . c om*/
        if (id == null) {
            res.sendError(HttpServletResponse.SC_BAD_REQUEST, CelosClient.ID_PARAM + " parameter missing.");
            return;
        }
        SlotID slotID = new SlotID(new WorkflowID(id), getRequestTime(req));
        try (StateDatabaseConnection connection = getStateDatabase().openConnection()) {
            SlotState slotState = connection.getSlotState(slotID);
            if (slotState == null) {
                res.sendError(HttpServletResponse.SC_NOT_FOUND, "Slot not found: " + id);
            } else {
                ObjectNode object = slotState.toJSONNode();
                writer.writeValue(res.getOutputStream(), object);
            }
        }
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:com.linuxbox.enkive.web.EnkiveServlet.java

/**
 * Helper function to make error responding easier.
 * //w  ww . j  a va2s.c  om
 * @param responseCode
 * @param errorMsg
 * @param resp
 * @throws ServletException
 * @throws IOException
 */
public void respondError(int responseStatus, String errorMsg, HttpServletResponse resp) throws IOException {
    if (errorMsg != null && !errorMsg.isEmpty())
        resp.sendError(responseStatus, errorMsg);
    else
        resp.sendError(responseStatus);
}

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

protected void sendErrorResponse(HttpServletResponse httpServletResponse, int code, String message) {
    try {//from w w  w  . ja va  2s .c  o  m
        httpServletResponse.sendError(code, message);
    } catch (IOException e) {
        LOG.error("Error sending error response", e);
    }
}