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.taobao.diamond.server.controller.ConfigController.java
public String getConfig(HttpServletRequest request, HttpServletResponse response, String dataId, String group) { response.setHeader("Content-Type", "text/html;charset=GBK"); final String address = getRemortIP(request); if (address == null) { // 400// w w w .j ava 2 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); // 304double-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:ge.taxistgela.servlet.RegistrationServlet.java
private boolean verify(HttpServletRequest request, HttpServletResponse response) throws IOException { ErrorCode errorCode = new ErrorCode(); String gRecaptchaResponse = request.getParameter("g-recaptcha-response"); if (!GoogleReCaptchaValidation.verify(gRecaptchaResponse)) { errorCode.wrongCaptcha();/*from w w w. j a v a2s . c o m*/ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().print(errorCode.toJson()); return false; } return true; }
From source file:ai.nitro.bot4j.integration.alexa.receive.webhook.impl.AlexaWebhookImpl.java
@Override public String post(final HttpServletRequest req, final HttpServletResponse res) throws IOException { String result = ""; try {/*from w w w . j a v a 2s .c o m*/ final byte[] serializedSpeechletRequest = IOUtils.toByteArray(req.getInputStream()); SpeechletRequestSignatureVerifier.checkRequestSignature(serializedSpeechletRequest, req.getHeader(Sdk.SIGNATURE_REQUEST_HEADER), req.getHeader(Sdk.SIGNATURE_CERTIFICATE_CHAIN_URL_REQUEST_HEADER)); final byte[] outputBytes = alexaReceiveHandler.handleSpeechletRequest(serializedSpeechletRequest); result = new String(outputBytes); } catch (final IOException e) { //LOG.warn(e.getMessage(), e); } catch (final SecurityException e) { final int statusCode = HttpServletResponse.SC_BAD_REQUEST; //LOG.error("Exception occurred in doPost, returning status code {}", statusCode, e); res.sendError(statusCode, e.getMessage()); } return result; }
From source file:com.controller.email.GetEmailDetailServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w. j a va2 s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String mandrillEmailId = request.getParameter("mandrill_email_id"); if (StringUtils.isEmpty(mandrillEmailId)) { Map<String, String> responseMap = new HashMap<>(); responseMap.put("error", "mandrill_email_id is required request parameter"); response.getWriter().write(new Gson().toJson(responseMap)); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } response.getWriter().write(new Gson().toJson(MandrillApiHandler.getEmailDetails(mandrillEmailId))); response.getWriter().flush(); response.setStatus(HttpServletResponse.SC_OK); return; } catch (URISyntaxException ex) { Logger.getLogger(GetEmailDetailServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.seleniumtests.it.driver.support.server.PageServlet.java
/** * Allow downloading of files in upload folder *//* w w w . java2 s . c o m*/ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { if (this.resourceFile.endsWith(".css")) { resp.addHeader("Content-Type", "text/css "); } IOUtils.copy(getClass().getResourceAsStream(this.resourceFile), resp.getOutputStream()); } catch (IOException e) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Error while handling request: " + e.getMessage()); } }
From source file:eu.webteq.web.scripts.bean.YubicoLogin.java
@Override protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) { String username = req.getParameter("u"); if (username == null || username.length() == 0) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Username not specified"); }// w w w. j a v a 2s .c o m String password = req.getParameter("pw"); if (password == null) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Password not specified"); } // Extract the OTP from the password field. String deviceid = yubikeyService.getDevice(username); if (deviceid == null || deviceid.length() == 0) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "No device id"); } int idx = password.indexOf(deviceid); if (idx == -1) { // Either the user is using the wrong key or no OTP has been included throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Failed to extract OTP"); } String otp = password.substring(idx); if (!yubikeyService.isOwner(username, YubicoClient.getPublicId(otp))) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "User does not own this device"); } YubicoResponse response = yubikeyService.verify(otp); if (response == null || response.getStatus() != YubicoResponseStatus.OK) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Invalid OTP"); } return login(username, password.substring(0, idx)); }
From source file:com.cognifide.cq.cache.plugins.statistics.action.ClearAction.java
@Override public void exectue() { String cacheName = request.getParameter(Statistics.CACHE_NAME_PARAMETER); if (StringUtils.isNotEmpty(cacheName)) { logger.info("Cache {} will be cleared", cacheName); cacheHolder.clear(cacheName);/*from ww w . ja v a 2s.c o m*/ } else { logger.error("Error while reciving request. No key prameter."); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:com.thoughtworks.go.server.newsecurity.filters.DenyIfRefererIsNotFilesFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (request.getServletPath().startsWith("/files/")) { throw new UnsupportedOperationException("Filter should not be invoked for `/files/` urls."); }// w w w.j a v a 2 s . c om if (isRequestFromArtifact(request)) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); ContentTypeAwareResponse contentTypeAwareResponse = CONTENT_TYPE_NEGOTIATION_MESSAGE_HANDLER .getResponse(request); response.setCharacterEncoding("utf-8"); response.setContentType(contentTypeAwareResponse.getContentType().toString()); response.getOutputStream().print(contentTypeAwareResponse .getFormattedMessage("Denied GoCD access for requests from artifacts.")); } else { filterChain.doFilter(request, response); } }
From source file:com.opencredo.servlet.BookDisplayCoverController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws IllegalStateException, IOException { // set the content type response.setContentType(CONTENT_TYPE); // get the ID of the book -- set "bad request" if its not a valid integer Integer id;/* w w w .j av a2s .c o m*/ try { id = ServletRequestUtils.getIntParameter(request, "book"); if (id == null) throw new IllegalStateException("must specify the book id"); } catch (Exception e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "invalid book"); return null; } // get the book from the service Book book = bookService.getBook(id); // if the book doesn't exist then set "not found" if (book == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "no such book"); return null; } // if the book doesn't have a picture, set "not found" if (book.getCoverPng() == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "book has no image"); return null; } if (logger.isDebugEnabled()) logger.debug("returning cover for book " + book.getKey() + " '" + book.getTitle() + "'" + " size: " + book.getCoverPng().length + " bytes"); // send the image response.setContentLength(book.getCoverPng().length); response.getOutputStream().write(book.getCoverPng()); response.getOutputStream().flush(); // we already handled the response return null; }
From source file:br.com.rzandonai.web.filter.AuthFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String authHeader = httpRequest.getHeader(AuthUtils.AUTH_HEADER_KEY); if (StringUtils.isBlank(authHeader) || authHeader.split(" ").length != 2) { httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, AUTH_ERROR_MSG); } else {/*from w w w.j a v a 2 s .c om*/ JWTClaimsSet claimSet = null; try { claimSet = (JWTClaimsSet) AuthUtils.decodeToken(authHeader); } catch (ParseException e) { httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, JWT_ERROR_MSG); return; } catch (JOSEException e) { httpResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, JWT_INVALID_MSG); return; } // ensure that the token is not expired if (new DateTime(claimSet.getExpirationTime()).isBefore(DateTime.now())) { httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, EXPIRE_ERROR_MSG); } else { chain.doFilter(request, response); } } }