org.apache.sling.api.SlingHttpServletResponse Java Examples
The following examples show how to use
org.apache.sling.api.SlingHttpServletResponse.
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: RelationTypesDataSourceServlet.java From aem-core-cif-components with Apache License 2.0 | 7 votes |
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { ResourceBundle resourceBundle = request.getResourceBundle(null); List<Resource> values = new ArrayList<>(); for (RelationType relationType : RelationType.values()) { ValueMap vm = new ValueMapDecorator(new HashMap<String, Object>()); vm.put("value", relationType); vm.put("text", toText(resourceBundle, relationType.getText())); values.add(new ValueMapResource(request.getResourceResolver(), new ResourceMetadata(), JcrConstants.NT_UNSTRUCTURED, vm)); } DataSource ds = new SimpleDataSource(values.iterator()); request.setAttribute(DataSource.class.getName(), ds); }
Example #2
Source File: ScriptResultServlet.java From APM with Apache License 2.0 | 6 votes |
@Override protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws IOException { String fileName = request.getParameter("filename"); String content = request.getParameter("content"); if (fileName == null || fileName.length() == 0) { LOGGER.error("Parameter fileName is required"); return; } response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8")); InputStream input = IOUtils.toInputStream(content); IOUtils.copy(input, response.getOutputStream()); }
Example #3
Source File: ScriptRemoveServlet.java From APM with Apache License 2.0 | 6 votes |
private void removeSingleFile(ResourceResolver resolver, SlingHttpServletResponse response, String fileName) throws IOException { if (StringUtils.isEmpty(fileName)) { ServletUtils.writeMessage(response, "error", "File name to be removed cannot be empty"); } else { final Script script = scriptFinder.find(fileName, resolver); if (script == null) { ServletUtils .writeMessage(response, "error", String.format("Script not found: '%s'", fileName)); } else { final String scriptPath = script.getPath(); try { scriptStorage.remove(script, resolver); ServletUtils.writeMessage(response, "success", String.format("Script removed successfully: %s", scriptPath)); } catch (RepositoryException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); ServletUtils.writeJson(response, String.format("Cannot remove script: '%s'." + " Repository error: %s", scriptPath, e.getMessage())); } } } }
Example #4
Source File: TransformationFilter.java From sling-whiteboard with Apache License 2.0 | 6 votes |
/** * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, * javax.servlet.ServletResponse, javax.servlet.FilterChain) */ @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof SlingHttpServletRequest)) { throw new ServletException("Request is not a Apache Sling HTTP request."); } final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response; List<TransformationStep> steps = manager.getSteps(slingRequest); if (!steps.isEmpty()) { TransformationContext context = new TransformationContextImpl(slingRequest, slingResponse, steps); steps.forEach(transformer -> transformer.before(context)); response = new TransformationResponse(context); chain.doFilter(request, response); steps.forEach(transformer -> transformer.after(context)); response.flushBuffer(); } else { chain.doFilter(request, response); } }
Example #5
Source File: DefaultHtmlServlet.java From sling-whiteboard with Apache License 2.0 | 6 votes |
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { final Resource r = request.getResource(); final String resourceType = r.getResourceType(); final ResourceSchema m = registry.getSchema(resourceType); if(m == null) { response.sendError( HttpServletResponse.SC_BAD_REQUEST, "ResourceSchema not found for resource type " + resourceType + " at " + request.getResource().getPath()); return; } response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); renderingLogic.render(r, m, new HtmlResourceRenderer(registry, request, response.getWriter())); response.getWriter().flush(); }
Example #6
Source File: ExportServlet.java From sling-org-apache-sling-models-impl with Apache License 2.0 | 6 votes |
private void addScriptBindings(SlingScriptHelper scriptHelper, SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { SimpleBindings bindings = new SimpleBindings(); bindings.put(SLING, scriptHelper); bindings.put(RESOURCE, request.getResource()); bindings.put(SlingModelsScriptEngineFactory.RESOLVER, request.getResource().getResourceResolver()); bindings.put(REQUEST, request); bindings.put(RESPONSE, response); try { bindings.put(READER, request.getReader()); } catch (Exception e) { bindings.put(READER, new BufferedReader(new StringReader(""))); } bindings.put(OUT, response.getWriter()); bindings.put(LOG, logger); scriptEngineFactory.invokeBindingsValuesProviders(bindingsValuesProvidersByContext, bindings); SlingBindings slingBindings = new SlingBindings(); slingBindings.putAll(bindings); request.setAttribute(SlingBindings.class.getName(), slingBindings); }
Example #7
Source File: SolrQueryHandler.java From aem-solr-search with Apache License 2.0 | 6 votes |
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); JSONArray solrDocs = new JSONArray(); SolrClient solr = getQueryingSolrClient(); try { LOG.debug("Query using Solr Client {} and the solr core {}", solr, core); QueryResponse result = solr.query(core, new SolrQuery("*:*")); SolrDocumentList list=result.getResults(); response.getWriter().write(list.toString()); } catch (SolrServerException e) { e.printStackTrace(); } }
Example #8
Source File: GraphqlProductViewHandler.java From commerce-cif-connector with Apache License 2.0 | 6 votes |
protected String generateHtmlOutput(Collection<Hit> hits, SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { // if resource type is not set return String representation of search result if (request.getParameter("itemResourceType") == null) { return hits.toString(); } StringResponseWrapper hitResponse = new StringResponseWrapper(response); RequestDispatcherOptions requestDispatcherOptions = new RequestDispatcherOptions(null); // Force a resource type, to render the resource in a specific way requestDispatcherOptions.setForceResourceType(request.getParameter("itemResourceType")); for (Hit hit : hits) { Resource resource = (Resource) hit.get("resource"); if (resource != null) { request.setAttribute(Resource.class.getCanonicalName(), resource); RequestDispatcher dispatcher = request.getRequestDispatcher(resource, requestDispatcherOptions); dispatcher.include(request, hitResponse); request.removeAttribute(Resource.class.getCanonicalName()); } } return hitResponse.getString(); }
Example #9
Source File: ThreeServlet11.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 5 votes |
@Override protected final void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { LOG.info("Servlet GET Method requested"); // Write a standard text/html response response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.getWriter().write("<html><body>Text to write to response</body></html>"); }
Example #10
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 #11
Source File: HistoryListServlet.java From APM with Apache License 2.0 | 5 votes |
@Override protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws IOException { String filter = request.getParameter("filter"); List<HistoryEntry> executions = history.findAllHistoryEntries(request.getResourceResolver()); if (StringUtils.isNotBlank(filter)) { CollectionUtils.filter(executions, new ExecutionHistoryFilter(filter)); } ServletUtils.writeJson(response, executions); }
Example #12
Source File: CatalogIdentifierDatasource.java From commerce-cif-connector with Apache License 2.0 | 5 votes |
@Override protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws ServletException, IOException { DataSource ds; if (catalogIdentifierService == null) { ds = EmptyDataSource.instance(); } else { ds = buildValuesList(request.getResourceResolver()); } request.setAttribute(DataSource.class.getName(), ds); }
Example #13
Source File: CommentServlet.java From publick-sling-blog with Apache License 2.0 | 5 votes |
/** * Return all comments on a GET request in order of newest to oldest. */ @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { final PrintWriter writer = response.getWriter(); response.setCharacterEncoding(CharEncoding.UTF_8); response.setContentType("application/json"); List<Resource> comments = commentService.getComments(request); try { JSONArray jsonArray = new JSONArray(); for (Resource comment : comments) { final JSONObject json = new JSONObject(); final ValueMap properties = comment.getValueMap(); final Resource post = commentService.getParentPost(comment); json.put(PublickConstants.COMMENT_PROPERTY_COMMENT, properties.get(PublickConstants.COMMENT_PROPERTY_COMMENT, String.class)); json.put(JSON_ID, properties.get(JcrConstants.JCR_UUID, String.class)); json.put(JSON_EDITED, properties.get(PublickConstants.COMMENT_PROPERTY_EDITED, false)); json.put(JSON_REPLIES, commentService.numberOfReplies(comment)); json.put(JSON_SPAM, properties.get(PublickConstants.COMMENT_PROPERTY_SPAM, false)); json.put(JSON_POST, new JSONObject() .put(JSON_POST_TEXT, post.getValueMap().get(PublickConstants.COMMENT_PROPERTY_TITLE, String.class)) .put(JSON_POST_LINK, linkRewriter.rewriteLink(post.getPath(), request.getServerName()))); jsonArray.put(json); } response.setStatus(SlingHttpServletResponse.SC_OK); writer.write(jsonArray.toString()); } catch (JSONException e) { LOGGER.error("Could not write JSON", e); response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
Example #14
Source File: ScriptRemoveServlet.java From APM with Apache License 2.0 | 5 votes |
private void removeAllFiles(ResourceResolver resolver, SlingHttpServletResponse response, String all) throws IOException { if (!Boolean.parseBoolean(all)) { ServletUtils.writeMessage(response, "error", "Remove all scripts is not confirmed"); } else { final List<String> paths = new LinkedList<>(); final List<Script> scripts = scriptFinder.findAll(resolver); try { for (Script script : scripts) { final String path = script.getPath(); scriptStorage.remove(script, resolver); paths.add(path); } final Map<String, Object> context = new HashMap<>(); context.put("paths", paths); ServletUtils.writeMessage(response, "success", String.format("Scripts removed successfully, total: %d", scripts.size()), context); } catch (RepositoryException e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); ServletUtils.writeJson(response, "Cannot save remove all scripts. Repository error: " + e.getMessage()); } } }
Example #15
Source File: ThreeServlet10.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 5 votes |
@Override protected final void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { LOG.info("Servlet GET Method requested"); // Write a standard text/html response response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.getWriter().write("<html><body>Text to write to response</body></html>"); }
Example #16
Source File: ThreeServlet17.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 5 votes |
@Override protected final void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { LOG.info("Servlet GET Method requested"); // Write a standard text/html response response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.getWriter().write("<html><body>Text to write to response</body></html>"); }
Example #17
Source File: SystemFilter.java From publick-sling-blog with Apache License 2.0 | 5 votes |
/** * Prevent unauthorables from accessing Sling's user admin. * * @param request The Sling HTTP Servlet Request. * @param response The Sling HTTP Servlet Response. * @param chain The Filter Chain to continue processin the response. */ @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { // Since this is a Sling Filter, the request and response objects are guaranteed // to be of types SlingHttpServletRequest and SlingHttpServletResponse. final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request; final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse)response; final String path = slingRequest.getPathInfo().toLowerCase(); final String method = slingRequest.getMethod(); response.setCharacterEncoding(CharEncoding.UTF_8); if ("POST".equals(method) && path.startsWith("/system")) { if (userService != null) { final boolean allow = userService.isAuthorable(slingRequest.getResourceResolver().adaptTo(Session.class)); if (allow) { chain.doFilter(request, response); } else { slingResponse.sendError(SlingHttpServletResponse.SC_FORBIDDEN); } } else { slingResponse.sendError(SlingHttpServletResponse.SC_FORBIDDEN); } } else { chain.doFilter(request, response); } }
Example #18
Source File: ThreeServlet15.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 5 votes |
@Override protected final void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { LOG.info("Servlet GET Method requested"); // Write a standard text/html response response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.getWriter().write("<html><body>Text to write to response</body></html>"); }
Example #19
Source File: ThreeServlet4.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 5 votes |
@Override protected final void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { LOG.info("Servlet GET Method requested"); // Write a standard text/html response response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.getWriter().write("<html><body>Text to write to response</body></html>"); }
Example #20
Source File: ChildrenDataSourceServletTest.java From commerce-cif-connector with Apache License 2.0 | 5 votes |
@Before public void before() { servlet = new ChildrenDataSourceServlet(); request = mock(SlingHttpServletRequest.class); response = mock(SlingHttpServletResponse.class); SlingBindings slingBindings = mock(SlingBindings.class); SlingScriptHelper slingScriptHelper = mock(SlingScriptHelper.class); Resource resource = mock(Resource.class); Resource dataSourceResource = mock(Resource.class); dataSourceProperties = new ModifiableMappedValueMapDecorator(new HashMap<>()); ResourceResolver resourceResolver = mock(ResourceResolver.class); CommerceBasePathsService commerceBasePathsService = mock(CommerceBasePathsService.class); ExpressionResolver expressionResolver = mock(ExpressionResolver.class); Resource parentResource = mockFolderResource("path"); children = new ArrayList<>(); when(resourceResolver.getResource(TEST_PATH)).thenReturn(parentResource); when(slingBindings.getSling()).thenReturn(slingScriptHelper); when(request.getResource()).thenReturn(resource); when(resource.getChild(Config.DATASOURCE)).thenReturn(dataSourceResource); when(dataSourceResource.getValueMap()).thenReturn(dataSourceProperties); when(request.getResourceResolver()).thenReturn(resourceResolver); when(slingScriptHelper.getService(ExpressionResolver.class)).thenReturn(expressionResolver); when(slingScriptHelper.getService(CommerceBasePathsService.class)).thenReturn(commerceBasePathsService); when(expressionResolver.resolve(anyString(), (Locale) anyObject(), (Class<? extends Object>) anyObject(), (SlingHttpServletRequest) anyObject())).thenAnswer((Answer<Object>) invocation -> invocation.getArguments()[0]); Map<String, Object> requestAttributes = new HashMap<>(); requestAttributes.put(SlingBindings.class.getName(), slingBindings); doAnswer(invocation -> requestAttributes.put((String) invocation.getArguments()[0], invocation.getArguments()[1])).when(request) .setAttribute(anyString(), anyObject()); when(request.getAttribute(anyString())).thenAnswer(invocationOnMock -> requestAttributes.get(invocationOnMock.getArguments()[0])); when(parentResource.listChildren()).thenAnswer(invocationOnMock -> children.iterator()); }
Example #21
Source File: RedirectFilter.java From sling-whiteboard with Apache License 2.0 | 5 votes |
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if(request instanceof SlingHttpServletRequest) { final SlingHttpServletRequest sr = (SlingHttpServletRequest)request; if(sr.getMethod().equals(ResourceSchemasConstants.POST_METHOD) && sr.getParameter(ResourceSchemasConstants.SRS_FORM_MARKER_PARAMETER) != null) { response = new ResponseWrapper((SlingHttpServletResponse)response); } } chain.doFilter(request, response); }
Example #22
Source File: ThreeServlet2.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 5 votes |
@Override protected final void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { LOG.info("Servlet GET Method requested"); // Write a standard text/html response response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.getWriter().write("<html><body>Text to write to response</body></html>"); }
Example #23
Source File: SearchDataSourceServlet.java From commerce-cif-connector with Apache License 2.0 | 5 votes |
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException { final String PARAMETER_OFFSET = "_commerce_offset"; final String PARAMETER_LIMIT = "_commerce_limit"; final String PARAMETER_COMMERCE_TYPE = "_commerce_commerce_type"; final Config cfg = new Config(request.getResource().getChild(Config.DATASOURCE)); final SlingScriptHelper sling = ((SlingBindings) request.getAttribute(SlingBindings.class.getName())).getSling(); final ExpressionHelper ex = new ExpressionHelper(sling.getService(ExpressionResolver.class), request); final String itemRT = cfg.get("itemResourceType", String.class); final long offset = ex.get(cfg.get("offset", "0"), long.class); final long limit = ex.get(cfg.get("limit", "20"), long.class); final String commerceType = ex.get(cfg.get("commerceType", "product"), String.class); Map<String, Object> queryParameters = new HashMap<>(request.getParameterMap()); queryParameters.put(PARAMETER_OFFSET, String.valueOf(offset)); queryParameters.put(PARAMETER_LIMIT, String.valueOf(limit)); queryParameters.put(PARAMETER_COMMERCE_TYPE, commerceType); final String rootPath = request.getParameter("root"); String rootCategoryId = new CatalogSearchSupport(request.getResourceResolver()).findCategoryId(rootPath); if (rootCategoryId != null) { queryParameters.put(CATEGORY_ID_PARAMETER, rootCategoryId); queryParameters.put(CATEGORY_PATH_PARAMETER, rootPath); } String queryString = new ObjectMapper().writeValueAsString(queryParameters); try { Iterator<Resource> virtualResults = request.getResourceResolver().findResources(queryString, VIRTUAL_PRODUCT_QUERY_LANGUAGE); final DataSource ds = new SimpleDataSource(new TransformIterator<>(virtualResults, r -> new ResourceWrapper(r) { public String getResourceType() { return itemRT; } })); request.setAttribute(DataSource.class.getName(), ds); } catch (Exception x) { response.sendError(500, x.getMessage()); LOGGER.error("Error finding resources", x); } }
Example #24
Source File: MimeTypeServlet.java From sling-samples with Apache License 2.0 | 5 votes |
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("text/plain"); response.setCharacterEncoding("UTF-8"); final String mimeType = detector.getMimeType(request.getResource()); response.getWriter().write(PREFIX); response.getWriter().write(String.valueOf(mimeType)); }
Example #25
Source File: SolrUpdateHandler.java From aem-solr-search with Apache License 2.0 | 5 votes |
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); Resource page = request.getResource(); GeometrixxMediaContentType contentType = page.adaptTo(GeometrixxMediaPage.class); response.getWriter().write(contentType.getJson().toJSONString()); }
Example #26
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 #27
Source File: RatingPostServlet.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 rating = request.getParameter(RatingsUtil.PROPERTY_RATING); final String userId = request.getRemoteUser(); logger.debug("New rating from {} : {}", userId, rating); // save rating ResourceResolver resolver = null; try { resolver = factory.getServiceResourceResolver(null); final Resource reqResource = resolver.getResource(request.getResource().getPath()); ratingsService.setRating(reqResource, userId, Double.valueOf(rating)); } catch ( final LoginException le ) { throw new ServletException("Unable to login", le); } finally { if ( resolver != null ) { resolver.close(); } } response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); response.setStatus(200); final PrintWriter pw = response.getWriter(); pw.print("{ "); pw.print(" \"rating\" : "); pw.print(String.valueOf(ratingsService.getRating(request.getResource()))); pw.print("}"); }
Example #28
Source File: StatsTestServlet.java From sling-samples with Apache License 2.0 | 5 votes |
@Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { final RequestParameter param = request.getRequestParameter(IMPORT_FILE_ATTRIB_NAME); if(param == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing required parameter " + IMPORT_FILE_ATTRIB_NAME); return; } InputStream is = null; final PrintWriter pw = response.getWriter(); response.setContentType("text/plain"); response.setCharacterEncoding("UTF-8"); try { is = param.getInputStream(); pw.println("Creating stats from supplied mbox file..."); int counter=0; final Iterator<Message> it = parser.parse(is); while(it.hasNext()) { final Message m = it.next(); final String [] to = MailStatsProcessorImpl.toArray(m.getTo()); final String [] cc = MailStatsProcessorImpl.toArray(m.getCc()); for(String from : MailStatsProcessorImpl.toArray(m.getFrom())) { processor.computeStats(m.getDate(), from.toString(), to, cc); } counter++; } pw.println(counter + " messages parsed"); } finally { processor.flush(); pw.flush(); if(is != null) { is.close(); } } }
Example #29
Source File: ThreeServlet14.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 5 votes |
@Override protected final void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { LOG.info("Servlet GET Method requested"); // Write a standard text/html response response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.getWriter().write("<html><body>Text to write to response</body></html>"); }
Example #30
Source File: IsProductListPageServlet.java From commerce-cif-connector with Apache License 2.0 | 5 votes |
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) { final Config cfg = new Config(request.getResource()); final SlingScriptHelper sling = ((SlingBindings) request.getAttribute(SlingBindings.class.getName())).getSling(); final ExpressionHelper ex = new ExpressionHelper(sling.getService(ExpressionResolver.class), request); final String path = ex.getString(cfg.get("path", String.class)); boolean decision = isProductListPage(path, request.getResourceResolver()); request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(decision)); if (decision) { prepareCatalogPathProperty(path, request); } }