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.eureka.v1_0.account.information.api.AccountInformationController.java
@ResponseBody @RequestMapping(method = RequestMethod.POST, consumes = MediaType.TEXT_XML_VALUE, produces = MediaType.TEXT_XML_VALUE, value = "/resetpassword") public ResetPasswordResponse resetPassword(@RequestBody ResetPasswordRequest resetPasswordRequest, HttpServletRequest request, HttpServletResponse response) { if (resetPasswordRequest != null) { try {/* ww w . j a va 2 s .co m*/ witLoggerService.debug(JaxbHandler.toXml(resetPasswordRequest)); ResetPasswordResponse resetPasswordResponse = this.accountInformationApiService .resetPassword(resetPasswordRequest); if (resetPasswordResponse != null) { witLoggerService.debug(JaxbHandler.toXml(resetPasswordResponse)); response.setStatus(HttpServletResponse.SC_OK); return resetPasswordResponse; } else { response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED); } } catch (Exception ex) { witLoggerService.warn(ex); ex.printStackTrace(); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return null; }
From source file:org.clothocad.phagebook.controllers.ColleagueController.java
@RequestMapping(value = "/approveColleagueRequest", method = RequestMethod.POST) public void approveColleagueRequest(@RequestParam Map<String, String> params, HttpServletResponse response) throws ServletException, IOException { Object pColleagueId = params.get("colleagueId"); String colleagueId = pColleagueId != null ? (String) pColleagueId : ""; Object pUserId = params.get("userId"); String userId = pUserId != null ? (String) pUserId : ""; boolean isValid = false; //used only to make sure the person exists in Clotho if (!colleagueId.equals("") && !userId.equals("")) { isValid = true;/*w w w . j av a 2s.c o m*/ } if (isValid) { //ESTABLISH CONNECTION ClothoConnection conn = new ClothoConnection(Args.clothoLocation); Clotho clothoObject = new Clotho(conn); String username = this.backendPhagebookUser; String password = this.backendPhagebookPassword; Map loginMap = new HashMap(); loginMap.put("username", username); loginMap.put("credentials", password); clothoObject.login(loginMap); // Person user = ClothoAdapter.getPerson(userId, clothoObject); List<String> colleagueRequests = user.getColleagueRequests(); if (colleagueRequests.contains(colleagueId)) { colleagueRequests.remove(colleagueId); user.setColleagueRequests(colleagueRequests); } Person colleague = ClothoAdapter.getPerson(colleagueId, clothoObject); List<String> colleaguesUser = user.getColleagues(); List<String> colleaguesColleague = colleague.getColleagues(); if (!colleaguesUser.contains(colleague.getId())) { if (!colleaguesColleague.contains(user.getId())) { colleaguesUser.add(colleague.getId()); colleaguesColleague.add(user.getId()); colleague.setColleagues(colleaguesColleague); user.setColleagues(colleaguesUser); } } clothoObject.logout(); ClothoAdapter.setPerson(user, clothoObject); ClothoAdapter.setPerson(colleague, clothoObject); response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_OK); JSONObject responseJSON = new JSONObject(); responseJSON.put("message", "Colleague Request Accepted!"); PrintWriter out = response.getWriter(); out.print(responseJSON); out.flush(); conn.closeConnection(); } else { response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); JSONObject responseJSON = new JSONObject(); responseJSON.put("message", "missing parameters for ajax"); PrintWriter out = response.getWriter(); out.print(responseJSON); out.flush(); } }
From source file:com.ebay.pulsar.collector.servlet.IngestServlet.java
private void batchAdd(HttpServletRequest request, String pathInfo, HttpServletResponse response) throws Exception { String eventType = pathInfo.substring(pathInfo.lastIndexOf('/') + 1); UTF8InputStreamReaderWrapper reader; if (request.getCharacterEncoding() != null) { reader = new UTF8InputStreamReaderWrapper(request.getInputStream(), request.getCharacterEncoding()); } else {/* w ww .j a va 2s. c om*/ reader = new UTF8InputStreamReaderWrapper(request.getInputStream()); } List<Map<String, Object>> eventList = mapper.readValue(reader, TYPE_LIST_OF_MAP); List<ValidationResult> failedEvents = null; for (Map<String, Object> values : eventList) { if (validator != null) { ValidationResult result = validator.validate(values, eventType); if (result == null || result.isSuccess()) { JetstreamEvent event = createEvent(values, eventType); inboundChannel.onMessage(event); } else { if (failedEvents == null) { failedEvents = new ArrayList<ValidationResult>(); } failedEvents.add(result); } } else { JetstreamEvent event = createEvent(values, eventType); inboundChannel.onMessage(event); } } if (failedEvents == null) { response.setStatus(HttpServletResponse.SC_OK); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); PrintWriter printWriter = response.getWriter(); printWriter.write("["); for (int i = 0, t = failedEvents.size() - 1; i < t; i++) { printWriter.write(validateReusltWriter.writeValueAsString(failedEvents.get(i))); printWriter.write(","); } printWriter.write(validateReusltWriter.writeValueAsString(failedEvents.get(failedEvents.size() - 1))); printWriter.write("]"); } }
From source file:com.jaspersoft.jasperserver.rest.services.RESTRole.java
@Override protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { WSRole role = restUtils.populateServiceObject(req.getPathInfo(), req.getParameterMap(), WSRole.class); WSRoleSearchCriteria criteria = restUtils.populateServiceObject(req.getPathInfo(), req.getParameterMap(), WSRoleSearchCriteria.class); WSRole[] roles = null;//from ww w.j a v a 2s .c o m try { roles = userAndRoleManagementService.findRoles(criteria); if (roles != null && roles.length != 0) { userAndRoleManagementService.deleteRole(role); if (log.isDebugEnabled()) { log.debug(role + " role were deleted"); } } else { throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, "role: " + role + " was not found"); } } catch (AxisFault axisFault) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, axisFault.getLocalizedMessage()); } restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, ""); }
From source file:memedb.httpd.MemeDBHandler.java
protected void sendError(HttpServletResponse response, String errMsg) throws IOException { sendError(response, errMsg, errMsg, null, HttpServletResponse.SC_BAD_REQUEST, log); }
From source file:org.energyos.espi.datacustodian.web.api.IntervalBlockRESTController.java
@RequestMapping(value = Routes.ROOT_INTERVAL_BLOCK_MEMBER, method = RequestMethod.PUT, consumes = "application/atom+xml", produces = "application/atom+xml") @ResponseBody//w w w . j av a2 s . c o m public void update(HttpServletResponse response, @PathVariable Long intervalBlockId, @RequestParam Map<String, String> params, InputStream stream) throws IOException, FeedException { IntervalBlock intervalBlock = intervalBlockService.findById(intervalBlockId); if (intervalBlock != null) { try { intervalBlock.merge(intervalBlockService.importResource(stream)); intervalBlockService.persist(intervalBlock); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } } }
From source file:com.streamsets.pipeline.stage.origin.sdcipctokafka.IpcToKafkaServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String requestor = req.getRemoteAddr() + ":" + req.getRemotePort(); if (shuttingDown) { LOG.debug("Shutting down, discarding incoming request from '{}'", requestor); resp.setStatus(HttpServletResponse.SC_GONE); } else {// ww w. j av a2s . c o m String appId = req.getHeader(Constants.X_SDC_APPLICATION_ID_HEADER); String compression = req.getHeader(Constants.X_SDC_COMPRESSION_HEADER); String contentType = req.getContentType(); String json1Fragmentable = req.getHeader(Constants.X_SDC_JSON1_FRAGMENTABLE_HEADER); if (!Constants.APPLICATION_BINARY.equals(contentType)) { invalidRequestMeter.mark(); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, Utils.format( "Wrong content-type '{}', expected '{}'", contentType, Constants.APPLICATION_BINARY)); } else if (!"true".equals(json1Fragmentable)) { invalidRequestMeter.mark(); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, Utils.format( "RPC client is not using a fragmentable JSON1 encoding, client;s SDC must be upgraded")); } else if (!configs.appId.equals(appId)) { invalidRequestMeter.mark(); LOG.warn("IPC from '{}' invalid appId '{}', rejected", requestor, appId); resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Invalid 'appId'"); } else { long start = System.currentTimeMillis(); LOG.debug("Request accepted from '{}'", requestor); try (InputStream in = req.getInputStream()) { InputStream is = in; boolean processRequest = true; if (compression != null) { switch (compression) { case Constants.SNAPPY_COMPRESSION: is = new SnappyFramedInputStream(is, true); break; default: invalidRequestMeter.mark(); LOG.warn("Invalid compression '{}' in request from '{}', returning error", compression, requestor); resp.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported compression: " + compression); processRequest = false; } } if (processRequest) { LOG.debug("Processing request from '{}'", requestor); List<byte[]> messages = SdcStreamFragmenter.fragment(is, maxMessageSize, maxRpcRequestSize); LOG.debug("Request from '{}' broken into '{}' messages", requestor, messages.size()); long kStart = System.currentTimeMillis(); SdcKafkaProducer producer = getKafkaProducer(); long kafkaTime = System.currentTimeMillis() - kStart; try { for (byte[] message : messages) { // we are using round robing partition strategy, partition key is ignored kStart = System.currentTimeMillis(); producer.enqueueMessage(configs.topic, message, ""); kafkaTime += System.currentTimeMillis() - kStart; } kStart = System.currentTimeMillis(); producer.write(); kafkaTime += System.currentTimeMillis() - kStart; resp.setStatus(HttpServletResponse.SC_OK); requestMeter.mark(); } catch (StageException ex) { LOG.warn("Kakfa producer error: {}", ex.toString(), ex); errorQueue.offer(ex); errorRequestMeter.mark(); LOG.warn("Error while reading payload from '{}': {}", requestor, ex.toString(), ex); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.toString()); } finally { kStart = System.currentTimeMillis(); releaseKafkaProducer(producer); kafkaTime += System.currentTimeMillis() - kStart; } kafkaTimer.update(kafkaTime, TimeUnit.MILLISECONDS); kafkaMessagesMeter.mark(messages.size()); } } catch (Exception ex) { errorRequestMeter.mark(); LOG.warn("Error while reading payload from '{}': {}", requestor, ex.toString(), ex); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.toString()); } finally { requestTimer.update(System.currentTimeMillis() - start, TimeUnit.MILLISECONDS); } } } }
From source file:uk.co.grahamcox.yui.YuiController.java
/** * Perform the combo request for a set of modules * @param group the group to request/*from w ww . jav a2 s . c o m*/ * @param webRequest the means to get the module list * @param response the response to write to * @throws IOException if an error occurs */ @RequestMapping("/combo/{group}") public void getComboModules(@PathVariable("group") String group, WebRequest webRequest, HttpServletResponse response) throws IOException { Iterator<String> names = webRequest.getParameterNames(); boolean missing = false; while (names.hasNext()) { String next = names.next(); Matcher matcher = COMBO_MODULE_PATTERN.matcher(next); if (matcher.matches()) { String moduleName = matcher.group(1); Filter filter = Filter.RAW; if (matcher.group(3) != null) { switch (matcher.group(3)) { case "debug": filter = Filter.DEBUG; break; case "min": filter = Filter.MINIFY; break; } } getModule(group, moduleName, filter, response); } else { matcher = COMBO_LANGUAGE_PATTERN.matcher(next); if (matcher.matches()) { String moduleName = matcher.group(1); String language = matcher.group(3); Filter filter = Filter.RAW; if (matcher.group(5) != null) { switch (matcher.group(5)) { case "debug": filter = Filter.DEBUG; break; case "min": filter = Filter.MINIFY; break; } } getModuleLanguage(group, moduleName, language, filter, response); } else { missing = true; } } } if (missing) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No valid modules were requested"); } }
From source file:com.enonic.cms.web.webdav.DavResourceImpl.java
@Override public void addMember(final DavResource member, InputContext in) throws DavException { if (!exists()) { throw new DavException(DavServletResponse.SC_CONFLICT); }/*from w ww . ja v a 2s . com*/ if (!isCollection()) { throw new DavException(HttpServletResponse.SC_BAD_REQUEST); } final String memberName = Text.getName(member.getLocator().getRepositoryPath()); final File localFile = new File(this.file, memberName); if (in.hasStream()) { createFile(localFile, in); } else { createCollection(localFile, in); } }
From source file:org.bjason.oauth2.TokenResource.java
private Response buildBadAuthCodeResponse(String description) throws OAuthSystemException { OAuthResponse response = OAuthASResponse.errorResponse(HttpServletResponse.SC_BAD_REQUEST) .setError(OAuthError.TokenResponse.INVALID_GRANT).setErrorDescription(description) .buildJSONMessage();/* w ww . java 2 s.c om*/ return Response.status(response.getResponseStatus()).entity(response.getBody()).build(); }