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.zimbra.cs.servlet.ZimbraServlet.java
public static void proxyServletRequest(HttpServletRequest req, HttpServletResponse resp, String accountId) throws IOException, ServiceException { Provisioning prov = Provisioning.getInstance(); Account acct = prov.get(AccountBy.id, accountId); if (acct == null) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "no such user"); return;//from w w w.j a v a 2 s . c o m } proxyServletRequest(req, resp, prov.getServer(acct), null); }
From source file:com.zimbra.cs.servlet.util.AuthUtil.java
/** * If returns null, then resp.sendError has been called. *//*from ww w . jav a2s .com*/ public static Account basicAuthRequest(HttpServletRequest req, HttpServletResponse resp, boolean sendChallenge, boolean isDav) throws IOException, ServiceException { try { return basicAuthRequest(req, !sendChallenge, isDav); } catch (UserServletException e) { if (e.getHttpStatusCode() == HttpServletResponse.SC_UNAUTHORIZED) { if (sendChallenge) { resp.addHeader(WWW_AUTHENTICATE_HEADER, getRealmHeader(req, null)); resp.sendError(e.getHttpStatusCode(), e.getMessage()); } } else { resp.sendError(e.getHttpStatusCode(), e.getMessage()); } return null; } }
From source file:com.fluidops.iwb.server.HybridSearchServlet.java
/** * Send the specified error message to the client (if the connection is * still open).// ww w .ja v a2 s.c o m * * @param resp * @param errorCode * @param message */ protected static void error(HttpServletResponse resp, int errorCode, String message) { try { log.info("Error (" + errorCode + "): " + message); if (!resp.isCommitted()) resp.sendError(errorCode, message); } catch (IllegalStateException e) { // should never occur log.warn("Error message could not be send. Stream is committed: " + message); } catch (IOException e) { log.error("Error message could not be sent", e); } }
From source file:com.adito.vfs.webdav.DAVServlet.java
protected static AuthenticationScheme configureAuthenticationScheme(HttpServletRequest request, HttpServletResponse response) throws IOException { AuthenticationScheme seq = AuthenticationModuleManager.getInstance() .getSchemeForAuthenticationModuleInUse(WebDAVAuthenticationModule.MODULE_NAME); if (seq == null || !seq.getEnabled()) { log.error(//from w ww .j a v a2 s. c o m "User cannot authenticate via WebDAV using only HTTP BASIC authentication as the current policy does not allow this."); response.sendError(DAVStatus.SC_FORBIDDEN, "You cannot authenticate via WebDAV using only HTTP BASIC authentication as the current policy does not allow this."); return seq; } seq.addModule(WebDAVAuthenticationModule.MODULE_NAME); try { seq.init(request.getSession()); } catch (Exception e) { IOException ioe = new IOException("Failed to authentication scheme."); ioe.initCause(e); throw ioe; } seq.nextAuthenticationModule(); request.getSession().setAttribute(Constants.AUTH_SENT, Boolean.TRUE); request.getSession().setAttribute(Constants.AUTH_SESSION, seq); return seq; }
From source file:com.example.notes.RestNotesControllerAdvice.java
@ExceptionHandler(ResourceDoesNotExistException.class) public void handleResourceDoesNotExistException(ResourceDoesNotExistException ex, HttpServletRequest request, HttpServletResponse response) throws IOException { response.sendError(HttpStatus.NOT_FOUND.value(), "The resource '" + request.getRequestURI() + "' does not exist"); }
From source file:eu.trentorise.game.api.rest.ExceptionHandler.java
@org.springframework.web.bind.annotation.ExceptionHandler(IllegalArgumentException.class) public void handleIllegalArgument(HttpServletResponse res, Exception e) throws IOException { res.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); }
From source file:eu.trentorise.game.api.rest.ExceptionHandler.java
@org.springframework.web.bind.annotation.ExceptionHandler(ResourceNotFoundException.class) public void handleResourceNotFound(HttpServletResponse res, Exception e) throws IOException { res.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage()); }
From source file:org.sharetask.web.authentication.Http401UnauthenticatedEntryPoint.java
/** * Always returns a 401 error code to the client. *///www . ja v a 2s .c o m @Override public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException arg2) throws IOException, ServletException { log.debug("Pre-authenticated entry point called. Rejecting access"); final HttpServletResponse httpResponse = response; httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthenticated request"); }
From source file:com.xpn.xwiki.user.impl.xwiki.MyBasicAuthenticator.java
public static void showLogin(HttpServletRequest request, HttpServletResponse response, String realmName) throws IOException { // save this request SecurityFilter.saveRequestInformation(request); // determine the number of login attempts int loginAttempts; if (request.getSession().getAttribute(LOGIN_ATTEMPTS) != null) { loginAttempts = ((Integer) request.getSession().getAttribute(LOGIN_ATTEMPTS)).intValue(); loginAttempts += 1;/*from ww w .j av a2s . c o m*/ } else { loginAttempts = 1; } request.getSession().setAttribute(LOGIN_ATTEMPTS, new Integer(loginAttempts)); if (loginAttempts <= MAX_ATTEMPTS) { response.setHeader("WWW-Authenticate", "BASIC realm=\"" + realmName + "\""); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); } else { request.getSession().removeAttribute(LOGIN_ATTEMPTS); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, LOGIN_FAILED_MESSAGE); } }
From source file:com.example.notes.RestNotesControllerAdvice.java
@ExceptionHandler(IllegalArgumentException.class) public void handleIllegalArgumentException(IllegalArgumentException ex, HttpServletResponse response) throws IOException { response.sendError(HttpStatus.BAD_REQUEST.value(), ex.getMessage()); }