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:org.tec.webapp.web.view.JSONView.java
/** * {@inheritDoc}//w w w. j a v a2s .c om */ @Override() protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { try { JSONSerializable json = (JSONSerializable) model.get(JSONModelAndView.ERROR_KEY); if (json != null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failed to process response"); } else { json = (JSONSerializable) model.get(JSONModelAndView.JSON_KEY); if (json != null) { if (mLogger.isDebugEnabled()) { mLogger.debug("JSON Response\n" + json.toJSON()); } response.setContentType(MimeTypeUtils.APPLICATION_JSON_VALUE); PrintWriter pw = response.getWriter(); pw.write(json.toJSON()); pw.flush(); } else // null json for controllers that usurp the response or didn't intend to { mLogger.warn("null json object"); } } } catch (Exception e) { mLogger.error("error", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "failed to process response"); } }
From source file:cn.org.once.cstack.config.Http401EntryPoint.java
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException arg) throws IOException, ServletException { // Maybe change the log level... log.warn("Access Denied [ " + request.getRequestURL().toString() + "] : " + arg.getMessage()); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Access unauthorized"); }
From source file:com.cloudera.oryx.als.serving.web.RecommendToAnonymousServlet.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 . j a v a2 s .co m } Iterator<String> pathComponents = SLASH.split(pathInfo).iterator(); Pair<String[], float[]> itemIDsAndValue; try { itemIDsAndValue = 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(); float[] values = itemIDsAndValue.getSecond(); OryxRecommender recommender = getRecommender(); RescorerProvider rescorerProvider = getRescorerProvider(); try { Rescorer rescorer = rescorerProvider == null ? null : rescorerProvider.getRecommendToAnonymousRescorer(itemIDs, recommender, getRescorerParams(request)); output(response, recommender.recommendToAnonymous(itemIDs, values, getHowMany(request), rescorer)); } catch (NotReadyException nre) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (NoSuchItemException nsie) { response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString()); } catch (IllegalArgumentException iae) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString()); } }
From source file:com.sonicle.webtop.core.app.AbstractServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/* w ww . ja v a 2s . com*/ processRequest(request, response); } catch (Throwable t) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, t.getMessage()); } finally { LoggerUtils.clearDC(); } }
From source file:com.sonicle.webtop.core.app.AbstractServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from w w w . jav a 2s . co m*/ processRequest(request, response); } catch (Throwable t) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, t.getMessage()); } finally { LoggerUtils.clearDC(); } }
From source file:org.kurento.repository.RepositoryController.java
@RequestMapping(method = RequestMethod.DELETE, value = "/{itemId}") public void removeRepositoryItem(@PathVariable("itemId") String itemId, HttpServletResponse response) { try {/*from w ww .j a v a 2s. com*/ repoService.removeRepositoryItem(itemId); } catch (ItemNotFoundException e) { try { response.sendError(HttpStatus.NOT_FOUND.value(), e.getMessage()); } catch (IOException ioe) { ioe.printStackTrace(); throw new KurentoException(ioe); } } }
From source file:com.netflix.genie.web.controllers.GenieExceptionMapper.java
/** * Handle Genie Exceptions./*from www . j av a2s. c om*/ * * @param response The HTTP response * @param e The exception to handle * @throws IOException on error in sending error */ @ExceptionHandler(GenieException.class) public void handleGenieException(final HttpServletResponse response, final GenieException e) throws IOException { this.countException(e); log.error(e.getLocalizedMessage(), e); response.sendError(e.getErrorCode(), e.getLocalizedMessage()); }
From source file:org.kurento.repository.RepositoryController.java
@RequestMapping(method = RequestMethod.GET, value = "/{itemId}") public RepositoryItemPlayer getReadEndpoint(@PathVariable("itemId") String itemId, HttpServletResponse response) { try {/* www. j a v a 2 s.co m*/ return repoService.getReadEndpoint(itemId); } catch (ItemNotFoundException e) { try { response.sendError(HttpStatus.NOT_FOUND.value(), e.getMessage()); } catch (IOException ioe) { ioe.printStackTrace(); throw new KurentoException(ioe); } return null; } }
From source file:com.dp2345.filter.AccessDeniedFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { HttpServletResponse response = (HttpServletResponse) servletResponse; // PoweredBy dp2345.com response.addHeader(new String(base64.decode("UG93ZXJlZEJ5"), "utf-8"), new String(base64.decode("ZHAyMzQ1LmNvbQ=="), "utf-8")); response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE); }
From source file:GoTo.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { // Determine the site where they want to go String site = req.getPathInfo(); String query = req.getQueryString(); // Handle a bad request if (site == null) { res.sendError(res.SC_BAD_REQUEST, "Extra path info required"); }//from w w w .j a v a 2 s.c o m // Cut off the leading "/" and append the query string // We're assuming the path info URL is always absolute String url = site.substring(1) + (query == null ? "" : "?" + query); // Log the requested URL and redirect log(url); // or write to a special file res.sendRedirect(url); }