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.netflix.spinnaker.fiat.controllers.AuthorizeController.java
@ApiOperation(value = "Used mostly for testing. Not really any real value to the rest of " + "the system. Disabled by default.") @RequestMapping(method = RequestMethod.GET) public Set<UserPermission.View> getAll(HttpServletResponse response) throws IOException { if (!configProps.isGetAllEnabled()) { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "/authorize is disabled"); return null; }// w ww.j a va2 s.c om log.debug("UserPermissions requested for all users"); return permissionsRepository.getAllById().values().stream().map(UserPermission::getView) .collect(Collectors.toSet()); }
From source file:com.cloudera.oryx.als.serving.web.EstimateForAnonymousServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return;/*ww w . ja v a2 s .co m*/ } Iterator<String> pathComponents = SLASH.split(pathInfo).iterator(); String toItemID; Pair<String[], float[]> itemIDsAndValue; try { toItemID = pathComponents.next(); itemIDsAndValue = RecommendToAnonymousServlet.parseItemValuePairs(pathComponents); } catch (NoSuchElementException nsee) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString()); return; } if (itemIDsAndValue.getFirst().length == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items"); return; } String[] itemIDs = itemIDsAndValue.getFirst(); unescapeSlashHack(itemIDs); float[] values = itemIDsAndValue.getSecond(); OryxRecommender recommender = getRecommender(); try { float estimate = recommender.estimateForAnonymous(toItemID, itemIDs, values); Writer out = response.getWriter(); out.write(Float.toString(estimate)); out.write('\n'); } catch (NotReadyException nre) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (NoSuchItemException nsie) { response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString()); } }
From source file:org.owasp.dependencytrack.controller.token.TokenHandlerInterceptor.java
/** * Intercepts an incoming requests, determines if method was POST and enforces token policy. * @param request The HttpServletRequest to intercept * @param response The HttpServletResponse * @param handler not-used but required for interface definition * @return a Boolean indicating if the request should be further processed. * @throws Exception Required by interface *///from w w w . j a v a2s . com @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if ("POST".equalsIgnoreCase(request.getMethod())) { if (!TokenManager.isTokenValid(request)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "Incorrect token value"); return false; } } return true; }
From source file:com.commsen.apropos.web.servlet.DownloadPropertiesServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String name = req.getParameter("name"); if (StringUtils.isBlank(name)) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing package name!"); return;/*from ww w . j a v a2s . c om*/ } PropertyPackage propertyPackage = PropertiesManager.getPropertyPackage(name.trim()); StringEscapeUtils.escapeHtml(name); if (propertyPackage == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Property package called " + StringEscapeUtils.escapeHtml(name) + " was not found!"); return; } String type = req.getParameter("type"); if (StringUtils.isBlank(type)) { type = "properties"; } if (type.toLowerCase().equals("properties")) { resp.setContentType("text/plain; charset=ASCI"); propertyPackage.asProperties().store(resp.getOutputStream(), "Property file obtained from " + req.getLocalName()); } else if (type.toLowerCase().equals("xml")) { resp.setContentType("text/xml; charset=UTF-8"); propertyPackage.asProperties().storeToXML(resp.getOutputStream(), "Property file obtained from " + req.getRequestURI()); } else { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unsupported type: " + StringEscapeUtils.escapeHtml(type) + " !"); return; } }
From source file:org.example.security.RestAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { Logger.getLogger("org.example.security.RestAuthenticationEntryPoint") .info("Inside RestAuthenticationEntryPoint..."); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); }
From source file:cc.kune.core.server.searcheable.SearchEngineServletFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException, DefaultException { if (filterConfig == null) { return;/* w w w. j a v a 2s . c o m*/ } if (request instanceof HttpServletRequest) { final HttpServletRequest httpReq = (HttpServletRequest) request; final StringBuffer url = httpReq.getRequestURL(); final String queryString = httpReq.getQueryString(); if ((queryString != null) && (queryString.contains(SiteParameters.ESCAPED_FRAGMENT_PARAMETER))) { if (!enabled) { final HttpServletResponse httpRes = (HttpServletResponse) response; httpRes.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Search Engine service disabled temporally"); return; } // rewrite the URL back to the original #! version // remember to unescape any %XX characters final String urlWithEscapedFragment = request .getParameter(SiteParameters.ESCAPED_FRAGMENT_PARAMETER); final String newUrl = url.append("?").append(queryString).toString() .replaceFirst(SiteParameters.ESCAPED_FRAGMENT_PARAMETER, SiteParameters.NO_UA_CHECK) .replaceFirst("/ws", "") + "#" + urlWithEscapedFragment; LOG.info("New url with hash: " + newUrl); final String page = "In development"; // return the snapshot response.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8"); response.getOutputStream().write(page.getBytes()); } else { try { // not an _escaped_fragment_ URL, so move up the chain of // servlet (filters) chain.doFilter(request, response); } catch (final ServletException e) { LOG.error("Servlet exception caught: " + e); } } } }
From source file:com.cnd.greencube.web.base.filter.AccessDeniedFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) servletResponse; response.addHeader(new String(Base64.decodeBase64("UG93ZXJlZEJ5"), "utf-8"), new String(Base64.decodeBase64("VG9wIFRlYW0="), "utf-8")); response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE); }
From source file:net.shopxx.filter.AccessDeniedFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) servletResponse; response.addHeader(new String(Base64.decodeBase64("UG93ZXJlZEJ5"), "utf-8"), new String(Base64.decodeBase64("Y2hlbmd6aGFuZy5jbw=="), "utf-8")); response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE); }
From source file:net.myrrix.web.servlets.EstimateForAnonymousServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return;/*from w ww. j ava 2s.c o m*/ } Iterator<String> pathComponents = SLASH.split(pathInfo).iterator(); long toItemID; Pair<long[], float[]> itemIDsAndValue; try { toItemID = Long.parseLong(pathComponents.next()); itemIDsAndValue = RecommendToAnonymousServlet.parseItemValuePairs(pathComponents); } catch (NoSuchElementException nsee) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString()); return; } catch (NumberFormatException nfe) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString()); return; } if (itemIDsAndValue.getFirst().length == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items"); return; } long[] itemIDs = itemIDsAndValue.getFirst(); float[] values = itemIDsAndValue.getSecond(); MyrrixRecommender recommender = getRecommender(); try { float estimate = recommender.estimateForAnonymous(toItemID, itemIDs, values); Writer out = response.getWriter(); out.write(Float.toString(estimate)); out.write('\n'); } catch (NotReadyException nre) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (NoSuchItemException nsie) { response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString()); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); } }
From source file:common.web.servlets.StaticFilesServlet.java
/** * Handles the HTTP <code>POST</code> method. * @param request servlet request/* w w w . j a va 2s . 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 { response.sendError(HttpServletResponse.SC_FORBIDDEN, "Forbidden"); }