Java Code Examples for org.apache.sling.api.SlingHttpServletResponse#sendRedirect()
The following examples show how to use
org.apache.sling.api.SlingHttpServletResponse#sendRedirect() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportMboxServlet.java From sling-samples with Apache License 2.0 | 5 votes |
@Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { RequestParameter param = request.getRequestParameter(IMPORT_FILE_ATTRIB_NAME); if (param != null) { logger.info("Processing attachment: " + param.toString()); InputStream mboxIS = param.getInputStream(); store.saveAll(parser.parse(mboxIS)); response.sendRedirect(MailArchiveServerConstants.ARCHIVE_PATH + ".html"); } else { logger.info("No attachment to process."); } }
Example 2
Source File: CommentPostServlet.java From sling-samples with Apache License 2.0 | 5 votes |
@Override protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { final String title = request.getParameter(CommentsUtil.PROPERTY_TITLE); final String text = request.getParameter(CommentsUtil.PROPERTY_TEXT); final String userId = request.getRemoteUser(); logger.debug("New comment from {} : {} - {}", new Object[] {userId, title, text}); // TODO - check values // save comment ResourceResolver resolver = null; try { resolver = factory.getServiceResourceResolver(null); final Resource reqResource = resolver.getResource(request.getResource().getPath()); final Comment c = new Comment(); c.setTitle(title); c.setText(text); c.setCreatedBy(userId); this.commentsService.addComment(reqResource, c); // send redirect at the end final String path = request.getResource().getPath(); response.sendRedirect(resolver.map(request.getContextPath() + path + ".html")); } catch ( final LoginException le ) { throw new ServletException("Unable to login", le); } finally { if ( resolver != null ) { resolver.close(); } } }
Example 3
Source File: SummaryRedirectServlet.java From APM with Apache License 2.0 | 5 votes |
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { String mode = StringUtils.defaultString(request.getRequestPathInfo().getSelectorString()); String scriptPath = request.getRequestPathInfo().getSuffix(); ScriptHistory scriptHistory = Optional.ofNullable(scriptFinder.find(scriptPath, request.getResourceResolver())) .map(script -> history.findScriptHistory(request.getResourceResolver(), script)) .orElse(ScriptHistoryImpl.empty(scriptPath)); String lastSummaryPath = getLastSummaryPath(scriptHistory, mode); if (!lastSummaryPath.isEmpty()) { response.sendRedirect("/apm/summary.html" + lastSummaryPath); } else { response.sendRedirect("/apm/history.html"); } }
Example 4
Source File: ScriptDownloadServlet.java From APM with Apache License 2.0 | 4 votes |
@Override protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { String fileName = request.getParameter("filename"); String filePath = request.getParameter("filepath"); String mode = request.getParameter("mode"); try { final ResourceResolver resourceResolver = request.getResourceResolver(); final Session session = resourceResolver.adaptTo(Session.class); if (!("view").equals(mode)) { response.setContentType("application/octet-stream"); // Your content type response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8")); } String path = StringUtils.replace(filePath, "_jcr_content", "jcr:content"); Node jcrContent = session.getNode(path + "/jcr:content"); InputStream input = jcrContent.getProperty("jcr:data").getBinary().getStream(); session.save(); int read; byte[] bytes = new byte[BYTES_DOWNLOAD]; OutputStream os = response.getOutputStream(); while ((read = input.read(bytes)) != -1) { os.write(bytes, 0, read); } input.close(); os.flush(); os.close(); } catch (RepositoryException e) { LOGGER.error(e.getMessage(), e); response.sendRedirect("/etc/cqsm.html"); // response.sendError(500); } }