List of usage examples for javax.servlet.http HttpServletResponse SC_BAD_REQUEST
int SC_BAD_REQUEST
To view the source code for javax.servlet.http HttpServletResponse SC_BAD_REQUEST.
Click Source Link
From source file:com.cloudera.oryx.kmeans.serving.web.AssignServlet.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;//ww w .j a 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; } RealVector vec = generation.toVector(DelimitedDataUtils.decode(line)); if (vec == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count"); return; } int assignment = DistanceToNearestServlet.findClosest(generation, vec).getClosestCenterId(); response.getWriter().write(Integer.toString(assignment)); }
From source file:com.baidu.stqa.signet.web.common.exception.ExceptionResolver.java
@Override protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { Object errors = null;//from www .j a va 2 s.c om if (ex instanceof MethodArgumentNotValidException) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); errors = getDecorateErrors(ex); } else { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); errors = ex.getMessage(); LOGGER.error(ex); } ObjectMapper mapper = new ObjectMapper(); String errorJson = "Error occur when covert object to json!"; try { errorJson = mapper.writeValueAsString(errors); } catch (Exception e) { e.printStackTrace(); } ServletOutputStream outputStream = null; try { outputStream = response.getOutputStream(); outputStream.write(errorJson.getBytes()); } catch (IOException e) { e.printStackTrace(); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; }
From source file:com.carolinarollergirls.scoreboard.jetty.LoadXmlScoreBoard.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { super.doPost(request, response); try {/*from ww w . j av a 2 s . co m*/ if (!ServletFileUpload.isMultipartContent(request)) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } ServletFileUpload sfU = new ServletFileUpload(); FileItemIterator items = sfU.getItemIterator(request); while (items.hasNext()) { FileItemStream item = items.next(); if (!item.isFormField()) { InputStream stream = item.openStream(); Document doc = editor.toDocument(stream); stream.close(); handleDocument(request, response, doc); return; } } response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No XML uploaded"); } catch (FileUploadException fuE) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, fuE.getMessage()); } catch (JDOMException jE) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, jE.getMessage()); } }
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 ww w . j a 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:cz.incad.kramerius.client.CacheServlet.java
private void proccesRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String action = req.getParameter("action"); resp.setContentType("text/plain;charset=utf-8"); if ("save".equals(action)) { saveToFile(req, resp);/* ww w . j a v a2s .co m*/ } else if ("get".equals(action)) { loadFromFile(req, resp); } else { resp.sendError(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:cn.leancloud.diamond.server.controller.ConfigController.java
public String getConfig(HttpServletRequest request, HttpServletResponse response, String dataId, String group) { response.setHeader("Content-Type", "text/html;charset=UTF-8"); final String address = getRemortIP(request); if (address == null) { // ?400//from w ww. ja v a2 s . c o m response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return "400"; } if (GlobalCounter.getCounter().decrementAndGet() >= 0) { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); return "503"; } String md5 = this.configService.getContentMD5(dataId, group); if (md5 == null) { return "404"; } response.setHeader(Constants.CONTENT_MD5, md5); // 304???double-check?? if (diskService.isModified(dataId, group)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return "304"; } String path = configService.getConfigInfoPath(dataId, group); // ? if (diskService.isModified(dataId, group)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return "304"; } // ? response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setHeader("Cache-Control", "no-cache,no-store"); return "forward:" + path; }
From source file:com.pureinfo.tgirls.servlet.OtherCompanyInitServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JsonBase result = new JsonBase(); response.setContentType("text/json; charset=utf-8"); String userId = request.getParameter("uid"); if (StringUtils.isEmpty(userId)) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return;// w ww.j a v a 2s . c o m } try { IUserMgr umgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class); User currentUser = umgr.getUserByTaobaoId(userId); if (currentUser == null) { response.sendRedirect(request.getContextPath() + "/tgirls/need-login.html"); return; } logger.info("other company init with user[" + currentUser.getTaobaoID() + "]"); IPhotoMgr mgr = (IPhotoMgr) ArkContentHelper.getContentMgrOf(Photo.class); List<Photo> uploadlist = mgr.getUserUploadPublicPics(currentUser.getTaobaoID()); if (uploadlist != null) { List<JSONObject> pjsonlist = new ArrayList<JSONObject>(); Photo object = null; for (Iterator iterator = uploadlist.iterator(); iterator.hasNext();) { object = (Photo) iterator.next(); pjsonlist.add(new JSONObject(object)); } logger.debug("uploads:" + pjsonlist.size()); result.put("uploads", pjsonlist); uploadlist.clear(); } List<Photo> buylist = mgr.getUserBuyPublicPics(currentUser.getTaobaoID()); if (buylist != null) { List<JSONObject> pjsonlist = new ArrayList<JSONObject>(); Photo object = null; for (Iterator iterator = buylist.iterator(); iterator.hasNext();) { object = (Photo) iterator.next(); pjsonlist.add(new JSONObject(object)); } logger.debug("buys:" + pjsonlist.size()); result.put("buys", pjsonlist); buylist.clear(); } // List<JSONObject> infolist = GetInformationsServlet.getInformations(currentUser.getTaobaoID()); // if (infolist != null) { // result.put("informations", infolist); // } result.put("uinfo", new JSONObject(currentUser)); } catch (JSONException e) { logger.error("json error", e); } catch (PureException e) { logger.error("ark error", e); } // logger.debug("result:" + result.toString()); response.getWriter().write(result.toString()); return; }
From source file:com.commsen.apropos.web.servlet.DownloadPropertiesServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String name = req.getParameter("name"); if (StringUtils.isBlank(name)) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing package name!"); return;/* ww w . j a va 2 s. c om*/ } PropertyPackage propertyPackage = PropertiesManager.getPropertyPackage(name.trim()); StringEscapeUtils.escapeHtml(name); if (propertyPackage == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Property package called " + StringEscapeUtils.escapeHtml(name) + " was not found!"); return; } String type = req.getParameter("type"); if (StringUtils.isBlank(type)) { type = "properties"; } if (type.toLowerCase().equals("properties")) { resp.setContentType("text/plain; charset=ASCI"); propertyPackage.asProperties().store(resp.getOutputStream(), "Property file obtained from " + req.getLocalName()); } else if (type.toLowerCase().equals("xml")) { resp.setContentType("text/xml; charset=UTF-8"); propertyPackage.asProperties().storeToXML(resp.getOutputStream(), "Property file obtained from " + req.getRequestURI()); } else { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unsupported type: " + StringEscapeUtils.escapeHtml(type) + " !"); return; } }
From source file:com.collective.celos.servlet.JSONWorkflowServlet.java
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException { String id = req.getParameter(CelosClient.ID_PARAM); try {/*from ww w .j ava 2 s . com*/ if (id == null) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, CelosClient.ID_PARAM + " parameter missing."); return; } Scheduler scheduler = getOrCreateCachedScheduler(); Workflow wf = scheduler.getWorkflowConfiguration().findWorkflow(new WorkflowID(id)); if (wf == null) { res.sendError(HttpServletResponse.SC_NOT_FOUND, "Workflow not found: " + id); } else { ScheduledTime time = getRequestTime(req); try (StateDatabaseConnection connection = getStateDatabase().openConnection()) { List<SlotState> slotStates = scheduler.getSlotStates(wf, scheduler.getWorkflowStartTime(wf, time), time, connection); ObjectNode object = createJSONObject(slotStates); writer.writeValue(res.getOutputStream(), object); } } } catch (Exception e) { throw new ServletException(e); } }
From source file:com.oneops.cms.ws.rest.MdRestController.java
@ExceptionHandler(MDException.class) public void handleDJExceptions(MDException e, HttpServletResponse response) throws IOException { sendError(response, HttpServletResponse.SC_BAD_REQUEST, e); }