List of usage examples for javax.servlet.http HttpServletResponse sendError
public void sendError(int sc) throws IOException;
From source file:org.netxilia.server.security.ExcludeAjaxExceptionTranslationFilter.java
private void handleException(HttpServletRequest request, HttpServletResponse response, FilterChain chain, RuntimeException exception) throws IOException { if (request.getHeader(AJAX_HEADER) == null) { throw new RuntimeException(exception); }//from w ww . java 2 s .co m if (exception instanceof AuthenticationException) { logger.debug("Returning AJAX CALL"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } else if (exception instanceof AccessDeniedException) { if (authenticationTrustResolver.isAnonymous(SecurityContextHolder.getContext().getAuthentication())) { logger.debug("Returning AJAX CALL"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } } throw new RuntimeException(exception); }
From source file:com.google.gerrit.httpd.auth.openid.OAuthSessionOverOpenID.java
boolean login(HttpServletRequest request, HttpServletResponse response, OAuthServiceProvider oauth) throws IOException { log.debug("Login " + this); if (isOAuthFinal(request)) { if (!checkState(request)) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return false; }// w w w. ja va 2 s . c om log.debug("Login-Retrieve-User " + this); token = oauth.getAccessToken(new OAuthVerifier(request.getParameter("code"))); user = oauth.getUserInfo(token); if (isLoggedIn()) { log.debug("Login-SUCCESS " + this); authenticateAndRedirect(request, response); return true; } response.sendError(SC_UNAUTHORIZED); return false; } log.debug("Login-PHASE1 " + this); redirectToken = LoginUrlToken.getToken(request); response.sendRedirect(oauth.getAuthorizationUrl() + "&state=" + state); return false; }
From source file:com.googlesource.gerrit.plugins.github.notification.WebhookServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (Strings.emptyToNull(config.webhookUser) == null) { logger.error("No webhookUser defined: cannot process GitHub events"); resp.sendError(SC_INTERNAL_SERVER_ERROR); return;// ww w. jav a2 s .c o m } WebhookEventHandler<?> handler = getWebhookHandler(req.getHeader("X-Github-Event")); if (handler == null) { resp.sendError(SC_NOT_FOUND); return; } try (BufferedReader reader = req.getReader()) { String body = Joiner.on("\n").join(CharStreams.readLines(reader)); if (!validateSignature(req.getHeader("X-Hub-Signature"), body, req.getCharacterEncoding())) { logger.error("Signature mismatch to the payload"); resp.sendError(SC_FORBIDDEN); return; } session.get().setUserAccountId(Account.Id.fromRef(config.webhookUser)); GitHubLogin login = loginProvider.get(config.webhookUser); if (login == null || !login.isLoggedIn()) { logger.error("Cannot login to github as {}. {}.webhookUser is not correctly configured?", config.webhookUser, GitHubConfig.CONF_SECTION); resp.setStatus(SC_INTERNAL_SERVER_ERROR); return; } requestScopedLoginProvider.get(req).login(login.getToken()); if (callHander(handler, body)) { resp.setStatus(SC_NO_CONTENT); } else { resp.sendError(SC_INTERNAL_SERVER_ERROR); } } }
From source file:eu.trentorise.smartcampus.communicatorservice.controller.NotificationController.java
@RequestMapping(method = RequestMethod.GET, value = "/user/notification/{id}") public @ResponseBody Notification getNotificationByUser(HttpServletRequest request, HttpServletResponse response, HttpSession session, @PathVariable("id") String id) throws DataException, IOException, NotFoundException, SmartCampusException { String userId = getUserId();//from w w w . ja v a2 s . c om if (userId == null) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return null; } return notificationManager.getByIdAndUser(id, userId); }
From source file:com.haulmont.cuba.core.controllers.FileUploadController.java
@RequestMapping(value = "/upload", method = RequestMethod.POST) public void upload(HttpServletRequest request, HttpServletResponse response) throws IOException { UserSession userSession = getSession(request, response); if (userSession == null) return;//from w w w . jav a 2 s. c o m AppContext.setSecurityContext(new SecurityContext(userSession)); try { InputStream is = request.getInputStream(); if (is == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } FileDescriptor fd = getFileDescriptor(request, response); if (fd == null) return; try { fileStorage.saveStream(fd, is); } catch (FileStorageException e) { log.error("Unable to upload file", e); response.sendError(e.getType().getHttpStatus()); } finally { IOUtils.closeQuietly(is); } } finally { AppContext.setSecurityContext(null); } }