Example usage for javax.servlet.http HttpServletResponse SC_BAD_REQUEST

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

Introduction

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

Prototype

int SC_BAD_REQUEST

To view the source code for javax.servlet.http HttpServletResponse SC_BAD_REQUEST.

Click Source Link

Document

Status code (400) indicating the request sent by the client was syntactically incorrect.

Usage

From source file:com.intbit.util.ServletUtil.java

public static void printIllegalArgumentError(HttpServletResponse response, String errorMsg) throws IOException {
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    Map<String, Object> error = new HashMap<>();
    error.put("error", errorMsg);
    response.getWriter().write(AppConstants.GSON.toJson(error));
    response.getWriter().flush();//  w  w  w  .  j  ava 2 s.  c o m
}

From source file:com.intbit.util.ServletUtil.java

public static void printIllegalArgumentError(HttpServletResponse response, List<String> errorMsgs)
        throws IOException {
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    Map<String, Object> error = new HashMap<>();
    error.put("error", errorMsgs);
    response.getWriter().write(AppConstants.GSON.toJson(error));
    response.getWriter().flush();//from   ww  w .  ja  v a 2 s. co m
}

From source file:com.janrain.backplane2.server.InvalidRequestException.java

public InvalidRequestException(String message) {
    this(message, HttpServletResponse.SC_BAD_REQUEST, null);
}

From source file:eu.trentorise.game.api.rest.ExceptionHandler.java

@org.springframework.web.bind.annotation.ExceptionHandler(IllegalArgumentException.class)
public void handleIllegalArgument(HttpServletResponse res, Exception e) throws IOException {
    res.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
}

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 {//from w  w  w  . j  ava  2 s  .c o  m
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    }
}

From source file:com.pureinfo.tgirls.servlet.GetScriptServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String scriptType = request.getParameter("scriptType");
    if (StringUtils.isEmpty(scriptType)) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;/*w  w w . j ava 2 s.  c o  m*/
    }

    String location = null;
    String userId = null;
    String photoId = null;
    ScriptType st = null;//

    try {
        st = ScriptType.getScriptType(Integer.parseInt(scriptType));
    } catch (Exception e) {
    }

    switch (st) {
    case UserInfo:
        userId = request.getParameter("utid");
        location = ScriptManager.mapUserInfoScriptLocation(userId);
        break;
    case UserUpload:
        userId = request.getParameter("utid");
        location = ScriptManager.mapUserUploadScriptLocation(userId);
        break;
    case UserBuy:
        userId = request.getParameter("utid");
        location = ScriptManager.mapUserBuyScriptLocation(userId);
        break;
    case Pic:
        photoId = request.getParameter("picId");
        location = ScriptManager.mapPhotoScriptLocation(photoId);
        break;

    default:
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }

    if (StringUtils.isEmpty(location)) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }

    location += "?version=" + Math.random();
    logger.debug("return script:" + location);

    response.setHeader("Location", location);
    response.setHeader("Content-Encoding", "gzip");
    response.setStatus(HttpServletResponse.SC_SEE_OTHER);
    response.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
    response.setHeader("Pragma", "no-cache"); //HTTP 1.0
    response.setDateHeader("Expires", -1);
    response.setDateHeader("max-age", 0);

    return;

}

From source file:com.janrain.backplane2.server.InvalidRequestException.java

public InvalidRequestException(String message, @Nullable String errorDescription) {
    this(message, HttpServletResponse.SC_BAD_REQUEST, errorDescription);
}

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 {/*  w  ww  . j ava  2 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:fr.epsi.controllers.rest.ProductController.java

@RequestMapping(value = "/product/{reference}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody Product order(@PathVariable("reference") String reference, HttpServletResponse resp) {

    try {//from   w  w  w  . j  a  v  a 2 s  . c  om
        Products productModel = Products.getInstance();

        // On recupere le produit par reference
        Product product = productModel.findByRef(reference);

        if (product != null) {
            return product;
        } else {
            resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        }
        return null;
    } catch (Exception e) {
        resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return null;
    }
}

From source file:gov.nih.nci.cabig.ctms.lookandfeel.AssetServletTest.java

public void testPostNotAllowed() throws Exception {
    request.setMethod("POST");
    servlet.service(request, response);/*from w w w  .ja v  a2  s .c  o m*/
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
}