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:eu.roschi.obdkinesis.webserver.GetCountsServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { MultiMap<String> params = new MultiMap<>(); UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8"); // We need both parameters to properly query for counts if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;// www . j a va2 s . co m } // Parse query string as a single integer - the number of seconds since "now" to query for new counts String resource = params.getString(PARAMETER_RESOURCE); int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS)); Calendar c = Calendar.getInstance(); c.add(Calendar.SECOND, -1 * rangeInSeconds); Date startTime = c.getTime(); //if (LOG.isDebugEnabled()) { LOG.debug(String.format("Querying for counts of resource %s since %s", resource, DATE_FORMATTER.get().format(startTime))); //} DynamoDBQueryExpression<HttpReferrerPairsCount> query = new DynamoDBQueryExpression<>(); HttpReferrerPairsCount hashKey = new HttpReferrerPairsCount(); hashKey.setResource(resource); query.setHashKeyValues(hashKey); Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT) .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime))); query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates)); List<HttpReferrerPairsCount> counts = mapper.query(HttpReferrerPairsCount.class, query); // Return the counts as JSON resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_OK); JSON.writeValue(resp.getWriter(), counts); }
From source file:com.rmn.qa.servlet.BmpServlet.java
/** * Stops and cleans up the proxy./* ww w. j av a 2s . c o m*/ * * Content should contain the uuid in a json content * * expects a parameter passed in query string of "uuid" * * @return Responds with a 202 Accepted if the proxy is removed or does not exist. * @return Responds with a 400 Bad Request if the uuid is not specified or there is no reason to create the proxy * (see above). */ @Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uuid = request.getParameter("uuid"); if (StringUtils.isBlank(uuid)) { log.error("uuid not present"); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "uuid must be specified in json"); return; } log.info("Stopping proxy with uuid " + uuid); BmpProxyRegistry.getInstance().stopProxy(uuid); response.setStatus(HttpServletResponse.SC_ACCEPTED); }
From source file:eu.stratosphere.nephele.jobmanager.web.LogfileInfoServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {/*w w w.j av a2s. co m*/ if ("stdout".equals(req.getParameter("get"))) { // Find current stdtout file for (File f : logDir.listFiles()) { // contains "jobmanager" ".log" and no number in the end ->needs improvement if (f.getName().equals("jobmanager-stdout.log") || (f.getName().indexOf("jobmanager") != -1 && f.getName().indexOf(".out") != -1 && !Character.isDigit(f.getName().charAt(f.getName().length() - 1)))) { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("text/plain "); writeFile(resp.getOutputStream(), f); break; } } } else { // Find current logfile for (File f : logDir.listFiles()) { // contains "jobmanager" ".log" and no number in the end ->needs improvement if (f.getName().equals("jobmanager-stderr.log") || (f.getName().indexOf("jobmanager") != -1 && f.getName().indexOf(".log") != -1 && !Character.isDigit(f.getName().charAt(f.getName().length() - 1)))) { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("text/plain "); writeFile(resp.getOutputStream(), f); break; } } } } catch (Throwable t) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); resp.getWriter().print(t.getMessage()); if (LOG.isWarnEnabled()) { LOG.warn(StringUtils.stringifyException(t)); } } }
From source file:com.alertlogic.aws.kinesis.test1.webserver.GetCountsServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { MultiMap<String> params = new MultiMap<>(); UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8"); // We need both parameters to properly query for counts if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;/*from w w w. ja v a2 s. c o m*/ } // Parse query string as a single integer - the number of seconds since "now" to query for new counts String resource = params.getString(PARAMETER_RESOURCE); int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS)); Calendar c = Calendar.getInstance(); c.add(Calendar.SECOND, -1 * rangeInSeconds); Date startTime = c.getTime(); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Querying for counts of resource %s since %s", resource, DATE_FORMATTER.get().format(startTime))); } DynamoDBQueryExpression<HttpReferrerPairsCount> query = new DynamoDBQueryExpression<>(); HttpReferrerPairsCount hashKey = new HttpReferrerPairsCount(); hashKey.setResource(resource); query.setHashKeyValues(hashKey); Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT) .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime))); query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates)); List<HttpReferrerPairsCount> counts = mapper.query(HttpReferrerPairsCount.class, query); // Return the counts as JSON resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_OK); JSON.writeValue(resp.getWriter(), counts); }
From source file:org.energyos.espi.datacustodian.web.api.ApplicationInformationRESTController.java
@RequestMapping(value = Routes.ROOT_APPLICATION_INFORMATION_MEMBER, method = RequestMethod.GET, produces = "application/atom+xml") @ResponseBody/*from w ww .j av a2 s . c o m*/ public void show(HttpServletResponse response, @PathVariable Long applicationInformationId, @RequestParam Map<String, String> params) throws IOException, FeedException { response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); try { exportService.exportApplicationInformation(applicationInformationId, response.getOutputStream(), new ExportFilter(params)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:es.tid.cep.esperanza.Rules.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/*from w w w . j a va 2 s. c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); response.setContentType("application/json;charset=UTF-8"); try { String ruleName = request.getPathInfo(); ruleName = ruleName == null ? "" : ruleName.substring(1); logger.debug("rule asked for " + ruleName); EPAdministrator epa = epService.getEPAdministrator(); if (ruleName.length() != 0) { EPStatement st = epa.getStatement(ruleName); if (st == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); out.printf("{\"error\":\"%s not found\"}\n", ruleName); } else { out.println(Utils.Statement2JSONObject(st)); } } else { String[] sttmntNames = epa.getStatementNames(); JSONArray ja = new JSONArray(); for (String name : sttmntNames) { logger.debug("getting rule " + name); EPStatement st = epa.getStatement(name); ja.put(Utils.Statement2JSONObject(st)); } out.println(ja.toString()); } } catch (EPException epe) { logger.error("getting statement", epe); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.printf("{\"error\":%s}\n", JSONObject.valueToString(epe.getMessage())); } finally { out.close(); } }
From source file:com.kinesis.datavis.servlet.GetBidRqCountsServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { MultiMap<String> params = new MultiMap<>(); UrlEncoded.decodeTo(req.getQueryString(), params, "UTF-8"); // We need both parameters to properly query for counts if (!params.containsKey(PARAMETER_RESOURCE) || !params.containsKey(PARAMETER_RANGE_IN_SECONDS)) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return;//from ww w. ja v a 2 s . com } // Parse query string as a single integer - the number of seconds since "now" to query for new counts String resource = params.getString(PARAMETER_RESOURCE); int rangeInSeconds = Integer.parseInt(params.getString(PARAMETER_RANGE_IN_SECONDS)); Calendar c = Calendar.getInstance(); c.add(Calendar.SECOND, -1 * rangeInSeconds); Date startTime = c.getTime(); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Querying for counts of resource %s since %s", resource, DATE_FORMATTER.get().format(startTime))); } DynamoDBQueryExpression<BidRequestCount> query = new DynamoDBQueryExpression<>(); BidRequestCount hashKey = new BidRequestCount(); hashKey.setHashKey(Ticker.getInstance().hashKey()); query.setHashKeyValues(hashKey); Condition recentUpdates = new Condition().withComparisonOperator(ComparisonOperator.GT) .withAttributeValueList(new AttributeValue().withS(DATE_FORMATTER.get().format(startTime))); // Condition attrFilter = // new Condition(). // withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(resource)); query.setRangeKeyConditions(Collections.singletonMap("timestamp", recentUpdates)); // query.setQueryFilter(Collections.singletonMap("wh", attrFilter)); List<BidRequestCount> counts = mapper.query(BidRequestCount.class, query); // System.out.println(counts.size()); // Return the counts as JSON resp.setContentType("application/json"); resp.setStatus(HttpServletResponse.SC_OK); JSON.writeValue(resp.getWriter(), counts); }
From source file:com.telefonica.iot.perseo.EventsServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// w w w . ja va 2 s.c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Utils.putCorrelatorAndTrans(request); logger.debug("events doPost"); response.setCharacterEncoding("UTF-8"); response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); try { StringBuilder sb = new StringBuilder(); String eventText = Utils.getBodyAsString(request); logger.info("incoming event:" + eventText); org.json.JSONObject jo = new JSONObject(eventText); logger.debug("event as JSONObject: " + jo); Map<String, Object> eventMap = Utils.JSONObject2Map(jo); logger.debug("event as map: " + eventMap); epService.getEPRuntime().sendEvent(eventMap, Constants.IOT_EVENT); logger.debug("event was sent: " + eventMap); } catch (JSONException je) { logger.error("error: " + je); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); out.printf("{\"error\":\"%s\"}\n", je.getMessage()); } finally { out.close(); } }
From source file:io.lavagna.web.security.login.PersonaLoginTest.java
@Test public void missingAssertionElement() throws IOException { when(req.getMethod()).thenReturn("POST"); when(req.getParameterMap()).thenReturn(parameterMap); Assert.assertTrue(personaLogin.doAction(req, resp)); verify(resp).setStatus(HttpServletResponse.SC_BAD_REQUEST); }
From source file:de.thm.arsnova.controller.UserController.java
@RequestMapping(value = { "/{username}/activate" }, method = { RequestMethod.POST, RequestMethod.GET }) public void activate(@PathVariable final String username, @RequestParam final String key, final HttpServletRequest request, final HttpServletResponse response) { DbUser dbUser = userService.getDbUser(username); if (null != dbUser && key.equals(dbUser.getActivationKey())) { dbUser.setActivationKey(null);/*from w w w.jav a2s. c om*/ userService.updateDbUser(dbUser); return; } response.setStatus(HttpServletResponse.SC_BAD_REQUEST); }