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:nl.surfnet.coin.api.oauth.Http401UnauthorizedEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.addHeader("WWW-Authenticate", "Bearer realm=\"api.surfconext\""); httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized"); }
From source file:com.graphhopper.http.GHBaseServlet.java
public void writeError(HttpServletResponse res, int code, String str) { try {/* www .ja va 2 s. co m*/ res.sendError(code, str); } catch (IOException ex) { logger.error("Cannot write error " + code + " message:" + str, ex); } }
From source file:net.solarnetwork.central.dras.web.ControllerSupport.java
/** * DataIntegrityViolationException handler. * //from w w w . j a v a2s.c om * <p>Logs a WARN log and returns HTTP 404 (Forbidden).</p> * * @param e the security exception * @param res the servlet response */ @ExceptionHandler(DataIntegrityViolationException.class) public void handleSecurityException(DataIntegrityViolationException e, HttpServletResponse res) { log.error("DataIntegrityViolationException", e); try { res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Invalid input."); } catch (IOException ioe) { log.debug("IOException sending DataIntegrityViolationException response: {}", ioe.getMessage()); } }
From source file:cn.org.once.cstack.config.UserAjaxAuthenticationFailureHandler.java
@Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { logger.warn("Authentication failed"); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Bad credentials"); }
From source file:fr.treeptik.cloudunit.config.UserAjaxAuthenticationFailureHandler.java
@Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { logger.warn("Authentication failed"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authentication failed"); }
From source file:gov.nih.nci.cabig.ctms.lookandfeel.AssetServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (req.getPathInfo().contains("..")) { resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Illegal path"); return;//from ww w . j a v a2 s . c om } String resource = resourcePath(req.getPathInfo()); String mimeType = contentType(req.getPathInfo()); if (mimeType != null) { resp.setContentType(mimeType); } // TODO: this is primitive. Should add content-length at least InputStream resStream = getClass().getResourceAsStream(resource); if (resStream == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); } else { IOUtils.copy(resStream, resp.getOutputStream()); } }
From source file:com.sentinel.rest.handlers.HttpAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { LOG.trace("Method: commence called."); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()); LOG.trace("Method: commence finished."); }
From source file:io.spring.initializr.web.project.AbstractInitializrController.java
@ExceptionHandler public void invalidProjectRequest(HttpServletResponse response, InvalidProjectRequestException ex) throws IOException { response.sendError(HttpStatus.BAD_REQUEST.value(), ex.getMessage()); }
From source file:com.cloudera.oryx.kmeans.serving.web.AssignServlet.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;/* w w w . jav a 2 s . com*/ } String line = pathInfo.subSequence(1, pathInfo.length()).toString(); Generation generation = getGenerationManager().getCurrentGeneration(); if (generation == null) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "API method unavailable until model has been built and loaded"); return; } RealVector vec = generation.toVector(DelimitedDataUtils.decode(line)); if (vec == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count"); return; } int assignment = DistanceToNearestServlet.findClosest(generation, vec).getClosestCenterId(); response.getWriter().write(Integer.toString(assignment)); }
From source file:com.github.marceloverdijk.spring.security.jwt.web.JwtAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { HttpStatus unauthorized = HttpStatus.UNAUTHORIZED; response.sendError(unauthorized.value(), unauthorized.getReasonPhrase()); }