List of usage examples for javax.servlet.http HttpServletResponse sendError
public void sendError(int sc) throws IOException;
From source file:com.haulmont.cuba.web.controllers.LogDownloadController.java
protected UserSession getSession(String sessionId, HttpServletResponse response) throws IOException { UUID sessionUUID;/* www . j a v a 2s . co m*/ try { sessionUUID = UUID.fromString(sessionId); } catch (Exception e) { log.error("Error parsing sessionId from URL param", e); response.sendError(HttpServletResponse.SC_BAD_REQUEST); return null; } AppContext.setSecurityContext(new SecurityContext(sessionUUID)); try { UserSession session = userSessionService.getUserSession(sessionUUID); if (session == null) response.sendError(HttpServletResponse.SC_FORBIDDEN); return session; } finally { AppContext.setSecurityContext(null); } }
From source file:com.thinkberg.webdav.DeleteHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = VFSBackend.resolveFile(request.getPathInfo()); try {/*from ww w . j ava 2s .c om*/ String fragment = new URI(request.getRequestURI()).getFragment(); if (fragment != null) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } } catch (URISyntaxException e) { throw new IOException(e.getMessage()); } try { if (!LockManager.getInstance().evaluateCondition(object, getIf(request)).result) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } } catch (LockException e) { response.sendError(SC_LOCKED); return; } catch (ParseException e) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } if (object.exists()) { int deletedObjects = object.delete(ALL_FILES_SELECTOR); LOG.debug("deleted " + deletedObjects + " objects"); if (deletedObjects > 0) { response.setStatus(HttpServletResponse.SC_OK); } else { response.sendError(HttpServletResponse.SC_FORBIDDEN); } } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } }
From source file:de.tobiasbruns.content.storage.ContentController.java
@RequestMapping(method = RequestMethod.GET, params = "projection=content") public void loadContentData(HttpServletRequest req, HttpServletResponse response) throws IOException { ContentHeader header = service.loadContentHeader(getPath(req)); if (header.getType() == ContentItemType.NODE) { response.sendError(HttpStatus.UNPROCESSABLE_ENTITY.value()); return;/* www. ja va 2 s.c o m*/ } response.setContentType(header.getContentType().orElse("application/octet-stream")); IOUtils.copy(service.loadContentData(getPath(req)), response.getOutputStream()); }
From source file:com.haulmont.cuba.portal.controllers.LogDownloadController.java
protected UserSession getSession(String sessionId, HttpServletResponse response) throws IOException { UUID sessionUUID;/*w w w . ja v a2s . c o m*/ try { sessionUUID = UUID.fromString(sessionId); } catch (Exception e) { log.error("Error parsing sessionId from URL param", e); response.sendError(HttpServletResponse.SC_BAD_REQUEST); return null; } AppContext.setSecurityContext(new SecurityContext(sessionUUID)); try { UserSession session = userSessionService.getUserSession(sessionUUID); if (session == null) response.sendError(HttpServletResponse.SC_FORBIDDEN); return session; } finally { AppContext.setSecurityContext(null); } }
From source file:net.shopxx.filter.AuthenticationFilter.java
@Override protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception { HttpServletRequest request = (HttpServletRequest) servletRequest; HttpServletResponse response = (HttpServletResponse) servletResponse; if (StringUtils.equalsIgnoreCase(request.getHeader("X-Requested-With"), "XMLHttpRequest")) { response.addHeader("loginStatus", "accessDenied"); response.sendError(HttpServletResponse.SC_FORBIDDEN); return false; }//from w ww . j a v a 2 s . c o m String loginToken = net.shopxx.util.WebUtils.getCookie(request, Admin.LOGIN_TOKEN_COOKIE_NAME); if (!StringUtils.equalsIgnoreCase(loginToken, adminService.getLoginToken())) { WebUtils.issueRedirect(request, response, "/"); return false; } return super.onAccessDenied(request, response); }
From source file:de.u808.simpleinquest.web.tasks.JobCommandController.java
@Override protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { JobIdentifier jobIdentifier = (JobIdentifier) command; log.info("Test and starting Job"); try {// w w w . j av a 2s . c om schedulerManager.startJob(jobIdentifier); } catch (SchedulerException e) { response.sendError(500); } return null; }
From source file:com.doculibre.constellio.servlets.DownloadFileServlet.java
@Override public final void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String file = request.getParameter("file"); String mimetype = request.getParameter("mimetype"); String filePathFound = getFilePathFor(file); if (filePathFound == null) { response.sendError(404); } else {//from w w w . j a va 2 s . c o m File fileFound = new File(filePathFound); response.setContentType((mimetype != null) ? mimetype : "application/octet-stream"); response.setContentLength((int) fileFound.length()); response.setHeader("Content-Disposition", "attachment; filename=\"" + fileFound.getName() + "\""); InputStream is = new BufferedInputStream(new FileInputStream(fileFound)); IOUtils.copy(is, response.getOutputStream()); } }
From source file:org.wte4j.examples.showcase.server.services.GwtOrderServiceServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String fileParameter = req.getParameter("file"); if (StringUtils.isNotEmpty(fileParameter)) { File file = new File(fileParameter); sendDocument(file, resp);//from w w w . ja v a2s . c o m file.delete(); } else resp.sendError(HttpServletResponse.SC_BAD_REQUEST); }
From source file:com.netflix.genie.web.resources.handlers.GenieResourceHttpRequestHandler.java
/** * {@inheritDoc}/* www . j a v a2 s. c o m*/ */ @Override public void handleRequest(@Nonnull final HttpServletRequest request, @Nonnull final HttpServletResponse response) throws ServletException, IOException { final Resource resource = this.getResource(request); if (resource == null || !resource.exists()) { response.sendError(HttpStatus.NOT_FOUND.value()); return; } final File file = resource.getFile(); if (file.isDirectory()) { final Object rootDirAttribute = request.getAttribute(GENIE_JOB_IS_ROOT_DIRECTORY); final boolean isRootDirectory; if (rootDirAttribute != null) { isRootDirectory = (Boolean) rootDirAttribute; } else { isRootDirectory = true; } final String accept = request.getHeader(HttpHeaders.ACCEPT); final String requestUrl; if (request.getHeader(JobConstants.GENIE_FORWARDED_FROM_HEADER) != null) { requestUrl = request.getHeader(JobConstants.GENIE_FORWARDED_FROM_HEADER); } else { requestUrl = request.getRequestURL().toString(); } try { if (accept != null && accept.contains(MediaType.TEXT_HTML_VALUE)) { response.setContentType(MediaType.TEXT_HTML_VALUE); response.getOutputStream() .write(this.directoryWriter.toHtml(file, requestUrl, !isRootDirectory).getBytes(UTF_8)); } else { response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.getOutputStream() .write(this.directoryWriter.toJson(file, requestUrl, !isRootDirectory).getBytes(UTF_8)); } } catch (final Exception e) { throw new ServletException(e); } } else { super.handleRequest(request, response); } }
From source file:com.skilrock.lms.web.loginMgmt.RolesInterceptor.java
/** * Handles a rejection by sending a 403 HTTP error * /*from www . j a va 2 s . c o m*/ * @param invocation * The invocation * @return The result code * @throws Exception */ protected String handleRejection(ActionInvocation invocation, HttpServletResponse response) throws Exception { // logger.debug("I am in Allowed roles444444444444444444444"); response.sendError(HttpServletResponse.SC_FORBIDDEN); return null; }