List of usage examples for javax.servlet.http HttpServletResponse sendError
public void sendError(int sc, String msg) throws IOException;
Sends an error response to the client using the specified status and clears the buffer.
From source file:com.streamsets.pipeline.lib.sdcipc.SdcIpcRequestFragmenter.java
@Override public boolean validate(HttpServletRequest req, HttpServletResponse res) throws IOException { boolean valid; if (!APPLICATION_BINARY.equalsIgnoreCase(req.getContentType())) { res.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Unsupported content type: " + req.getContentType()); valid = false;//from w ww . j a v a2 s . c o m } else if (!"true".equalsIgnoreCase(req.getHeader(X_SDC_JSON1_FRAGMENTABLE_HEADER))) { res.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Missing '" + X_SDC_JSON1_FRAGMENTABLE_HEADER + "' header"); valid = false; } else { valid = true; } return valid; }
From source file:org.craftercms.search.controller.SearchRestController.java
@ExceptionHandler(Exception.class) public void handleException(Exception e, HttpServletRequest request, HttpServletResponse response) throws IOException { logger.error("RESTful request " + request.getRequestURI() + " failed", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ExceptionUtils.getRootCauseMessage(e)); }
From source file:com.cloudera.oryx.kmeans.serving.web.AddServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { KMeansGenerationManager generationManager = getGenerationManager(); Generation generation = generationManager.getCurrentGeneration(); if (generation == null) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "API method unavailable until model has been built and loaded"); return;//from w ww. jav a 2s . c o m } for (CharSequence line : CharStreams.readLines(request.getReader())) { generationManager.append(line); RealVector vec = generation.toVector(DelimitedDataUtils.decode(line)); if (vec == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count"); return; } // TODO update the centers, along the lines of Meyerson et al. } }
From source file:org.apereo.openlrs.OpenLRSAuthenticationFilter.java
private void unauthorized(HttpServletResponse response, String message, String type) throws IOException { response.setHeader("WWW-Authenticate", type + " realm=\"OpenLRS\""); response.sendError(401, message);/* w w w. ja v a 2s. co m*/ }
From source file:de.steilerdev.myVerein.server.security.rest.RestAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { logger.warn("[{}] Unauthorized access to authentication entry point", SecurityHelper.getClientIpAddr(request)); if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); }/*from ww w . java2 s .c o m*/ }
From source file:org.tec.webapp.web.controller.TestResponseController.java
/** * send 401 response code/*from www. j a v a 2 s . co m*/ * * @param response the http response * * @return empty model */ @RequestMapping(method = RequestMethod.GET) public ModelAndView unauth(HttpServletResponse response) { JSONModelAndView jmv = new JSONModelAndView(); try { if (mLogger.isDebugEnabled()) { mLogger.debug("sending error " + HttpServletResponse.SC_UNAUTHORIZED); } response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication required"); } catch (Throwable e) { jmv.setError(new WebError("failed to set response", e)); } return jmv; }
From source file:org.dataconservancy.dcs.access.server.FileUploadServlet.java
@SuppressWarnings("unchecked") protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (!ServletFileUpload.isMultipartContent(req)) { resp.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Error: Request type not supported."); return;//from w w w .j a v a 2 s. co m } FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); try { List<FileItem> items = upload.parseRequest(req); String depositurl = null; for (FileItem item : items) { if (item.getFieldName() != null && item.getFieldName().equals("depositurl")) { depositurl = item.getString(); } } if (depositurl == null) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing required paremeter: depositurl"); return; } for (FileItem item : items) { String name = item.getName(); if (item.isFormField() || name == null || name.isEmpty()) { continue; } uploadfile(depositurl, name, item.getInputStream(), resp); } } catch (IOException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error: " + e.getMessage()); return; } catch (FileUploadException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error: " + e.getMessage()); return; } }
From source file:com.hp.autonomy.frontend.configuration.authentication.XhrAccessDeniedHandler.java
@Override public void handle(final HttpServletRequest request, final HttpServletResponse response, final AccessDeniedException e) throws IOException, ServletException { // if AJAX, add 403 to the response, otherwise redirect to the given page if ("XMLHttpRequest".equalsIgnoreCase(request.getHeader("X-Requested-With"))) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "Blocked by " + this.getClass().getName()); } else {/* w w w . j a va 2 s . c om*/ response.sendRedirect(request.getContextPath() + '/' + loginPage); } }
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 av a2 s . c o m 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); } } }
From source file:jeeves.config.springutil.JeevesAccessDeniedHandler.java
@Override public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { if (!response.isCommitted()) { if (matcher != null && matcher.matches(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage()); }//w w w .j av a 2s. c o m if (_errorPage != null) { request.setAttribute(WebAttributes.ACCESS_DENIED_403, accessDeniedException); response.setStatus(HttpServletResponse.SC_FORBIDDEN); final String referer = _escaper.escape(request.getRequestURI()); RequestDispatcher dispatcher = request.getRequestDispatcher(_errorPage + "?referer=" + referer); dispatcher.forward(request, response); } else { response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage()); } } }