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.trentorise.smartcampus.unidataservice.controller.rest.StudentInfoController.java
@RequestMapping(method = RequestMethod.GET, value = "/getstudentdata") public @ResponseBody StudentInfoData getStudentInfo(HttpServletRequest request, HttpServletResponse response) throws InvocationException { try {//w w w. j a v a2 s . c o m User user = getCurrentUser(); String userId = getUserId(user); if (userId == null) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); return null; } String token = getToken(request); String idAda = getIdAda(token); StudentInfoData sd = getStudentInfo(idAda); if (sd != null) { return sd; } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } return null; } catch (Exception e) { e.printStackTrace(); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } return null; }
From source file:com.facebook.tsdb.tsdash.server.TsdbServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.sendError(HttpServletResponse.SC_BAD_REQUEST); }
From source file:org.energyos.espi.datacustodian.web.api.ReadingTypeRESTController.java
@RequestMapping(value = Routes.ROOT_READING_TYPE_COLLECTION, method = RequestMethod.POST, consumes = "application/atom+xml", produces = "application/atom+xml") @ResponseBody/*from w ww . j a va2 s .c om*/ public void create(HttpServletResponse response, @RequestParam Map<String, String> params, InputStream stream) throws IOException { response.setContentType(MediaType.APPLICATION_ATOM_XML_VALUE); try { ReadingType readingType = this.readingTypeService.importResource(stream); exportService.exportReadingType(readingType.getId(), response.getOutputStream(), new ExportFilter(params)); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.commons.student.ViewStudentApplicationDA.java
public ActionForward downloadDocument(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws IOException { final IndividualCandidacyDocumentFile document = getDomainObject(request, "documentOID"); if (document != null && isAuthorized(document)) { response.setContentType(document.getContentType()); response.addHeader("Content-Disposition", "attachment; filename=\"" + document.getFilename() + "\""); response.setContentLength(document.getSize().intValue()); final DataOutputStream dos = new DataOutputStream(response.getOutputStream()); dos.write(document.getContent()); dos.close();/* www. j av a 2 s .c om*/ } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST)); response.getWriter().close(); } return null; }
From source file:com.mengka.diamond.server.controller.ConfigController.java
/** * /*from www .j av a2 s .c o m*/ * ?dataIdgroupId * @param request * @param response * @param probeModify * @return */ @RequestMapping(method = RequestMethod.POST) public String getProbeModifyResult(HttpServletRequest request, HttpServletResponse response, @RequestParam(Constants.PROBE_MODIFY_REQUEST) String probeModify) { response.setHeader("Content-Type", "text/html;charset=utf-8"); final String address = getRemortIP(request); if (address == null) { // ?400 response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return "400"; } if (GlobalCounter.getCounter().decrementAndGet() >= 0) { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); return "503"; } final List<ConfigKey> configKeyList = getConfigKeyList(probeModify); StringBuilder resultBuilder = new StringBuilder(); for (ConfigKey key : configKeyList) { String md5 = this.configService.getContentMD5(key.getDataId(), key.getGroup()); if (!StringUtils.equals(md5, key.getMd5())) { resultBuilder.append(key.getDataId()).append(Constants.WORD_SEPARATOR).append(key.getGroup()) .append(Constants.LINE_SEPARATOR); } } String returnHeader = resultBuilder.toString(); try { returnHeader = URLEncoder.encode(resultBuilder.toString(), "UTF-8"); } catch (Exception e) { // ignore } request.setAttribute("content", returnHeader); // ? response.setHeader("Pragma", "no-cache"); response.setDateHeader("Expires", 0); response.setHeader("Cache-Control", "no-cache,no-store"); return "200"; }
From source file:io.lavagna.web.security.login.PersonaLoginTest.java
@Test public void verifierStatusNotOkay() throws IOException { prepareSuccessfulPreconditions();//from ww w . ja va 2 s .co m VerifierResponse verifier = new VerifierResponse(); when(restTemplate.postForObject(any(String.class), any(), eq(VerifierResponse.class))).thenReturn(verifier); Assert.assertTrue(personaLogin.doAction(req, resp)); verify(resp).setStatus(HttpServletResponse.SC_BAD_REQUEST); }
From source file:org.openinfinity.web.controller.ProductController.java
@Log @ExceptionHandler({ SystemException.class, ApplicationException.class, BusinessViolationException.class }) public void exceptionOccurred(AbstractCoreException abstractCoreException, HttpServletResponse response, Locale locale) {/*from w ww . ja va2s. c o m*/ ProductModel productModel = new ProductModel(); if (abstractCoreException.isErrorLevelExceptionMessagesIncluded()) { Collection<String> localizedErrorMessages = getLocalizedExceptionMessages( abstractCoreException.getErrorLevelExceptionIds(), locale); productModel.addErrorStatuses("errorLevelExceptions", localizedErrorMessages); } if (abstractCoreException.isWarningLevelExceptionMessagesIncluded()) { Collection<String> localizedErrorMessages = getLocalizedExceptionMessages( abstractCoreException.getWarningLevelExceptionIds(), locale); productModel.addErrorStatuses("warningLevelExceptions", localizedErrorMessages); } if (abstractCoreException.isInformativeLevelExceptionMessagesIncluded()) { Collection<String> localizedErrorMessages = getLocalizedExceptionMessages( abstractCoreException.getInformativeLevelExceptionIds(), locale); productModel.addErrorStatuses("informativeLevelExceptions", localizedErrorMessages); } response.setStatus(HttpServletResponse.SC_BAD_REQUEST); SerializerUtil.jsonSerialize(ServletUtil.getWriter(response), productModel.getErrorStatuses()); }
From source file:com.thinkberg.moxo.dav.PropFindHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { SAXReader saxReader = new SAXReader(); try {//from www .j a v a 2s. c o m Document propDoc = saxReader.read(request.getInputStream()); // log(propDoc); Element propFindEl = propDoc.getRootElement(); Element propEl = (Element) propFindEl.elementIterator().next(); String propElName = propEl.getName(); List<String> requestedProperties = new ArrayList<String>(); boolean ignoreValues = false; if (TAG_PROP.equals(propElName)) { for (Object id : propEl.elements()) { requestedProperties.add(((Element) id).getName()); } } else if (TAG_ALLPROP.equals(propElName)) { requestedProperties = DavResource.ALL_PROPERTIES; } else if (TAG_PROPNAMES.equals(propElName)) { requestedProperties = DavResource.ALL_PROPERTIES; ignoreValues = true; } FileObject object = getResourceManager().getFileObject(request.getPathInfo()); if (object.exists()) { // respond as XML encoded multi status response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.setStatus(SC_MULTI_STATUS); Document multiStatusResponse = getMultiStatusRespons(object, requestedProperties, getBaseUrl(request), getDepth(request), ignoreValues); //log(multiStatusResponse); // write the actual response XMLWriter writer = new XMLWriter(response.getWriter(), OutputFormat.createCompactFormat()); writer.write(multiStatusResponse); writer.flush(); writer.close(); } else { log("!! " + object.getName().getPath() + " NOT FOUND"); response.sendError(HttpServletResponse.SC_NOT_FOUND); } } catch (DocumentException e) { log("!! inavlid request: " + e.getMessage()); response.sendError(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:com.adobe.acs.commons.analysis.jcrchecksum.impl.servlets.ChecksumGeneratorServlet.java
private void handleRequest(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, RepositoryException { response.setContentType("text/plain"); response.setCharacterEncoding("UTF-8"); String optionsName = request.getParameter(ServletConstants.OPTIONS_NAME); ChecksumGeneratorOptions options = ChecksumGeneratorOptionsFactory.getOptions(request, optionsName); if (log.isDebugEnabled()) { log.debug(options.toString());//from ww w. j a v a 2s . com } Set<String> paths = RequestChecksumGeneratorOptions.getPaths(request); if (CollectionUtils.isEmpty(paths)) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().print("ERROR: At least one path must be specified"); } final Session session = request.getResourceResolver().adaptTo(Session.class); for (final String path : paths) { log.debug("Generating checksum for path [ {} ]", path); Map<String, String> checksums = checksumGenerator.generateChecksums(session, path, options); log.debug("Collected [ {} ] checksum entries under [ {} ]", checksums.size(), path); for (final Map.Entry<String, String> entry : checksums.entrySet()) { log.trace("Checksum [ {} ~> {} ]", entry.getKey(), entry.getValue()); response.getWriter().println(entry.getKey() + "\t" + entry.getValue()); } } }
From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestControllerTest.java
@Test public void validationException_shouldReturnBadRequestResponse() throws Exception { Errors ex = new BindException(new Person(), ""); ex.reject("error.message"); SimpleObject responseSimpleObject = controller.validationExceptionHandler(new ValidationException(ex), request, response);//from www. j a v a2 s . c o m assertThat(response.getStatus(), is(HttpServletResponse.SC_BAD_REQUEST)); SimpleObject errors = (SimpleObject) responseSimpleObject.get("error"); Assert.assertEquals("webservices.rest.error.invalid.submission", errors.get("code")); }