private String getPathInContext(final ServletContext servletContext, final String path) { return path.substring(servletContext.getContextPath().length()); } }
/** * {@inheritDoc} */ @Override public void init(final FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; serverConfig = (ServerConfig) filterConfig.getServletContext() .getAttribute(ServerConfig.class.getName()); }
/** * Returns a list of filters to be included for given path. It first checks whether the filter * is included, and then checks whether the filter is excluded for given path. * <p> * Filter included URL pattern must not be null. Filter excluded URL pattern can be null. * * @param servletContext * @param path * @return */ public List<FilterMapping> getFilterMappingsForPath(final ServletContext servletContext, final String path) { Objects.requireNonNull(servletContext); String inContextPath = getPathInContext(servletContext, path); List<FilterMapping> filterMappings = new ArrayList<>(); for (FilterMapping filterMapping : servletContext.getFilterMappings()) { if (filterMapping.getUrlPattern().matcher(inContextPath).matches()) { if (filterMapping.getUrlExcludePattern() != null) { if (!filterMapping.getUrlExcludePattern().matcher(inContextPath).matches()) { filterMappings.add(filterMapping); } } else { filterMappings.add(filterMapping); } } } return filterMappings; }
/** * Resolves servlet mapping for a given path. A null is returned when no mapping is found for given path. * * @param servletContext * @param path * @return */ //@Nullable public ServletMapping getResolvedServletMapping(final ServletContext servletContext, final String path) { Objects.requireNonNull(servletContext); for (ServletMapping servletMapping : servletContext.getServletMappings()) { String inContextPath = getPathInContext(servletContext, path); if (servletMapping.getUrlPattern().matcher(inContextPath).matches()) { return servletMapping; } } return null; }
private void serveFile(final File file, final HttpServletResponse response) throws IOException { response.setContentType(getServletContext().getMimeType(file.getName())); response.setContentLength(file.length()); response.getHeaders().setHeader(Headers.HEADER_CONTENT_DISPOSITION, "attachment; filename=" + StringUtilities.urlEncode(file.getName())); InputStream in = null; try { OutputStream out = response.getOutputStream(); in = new FileInputStream(file); IOUtilities.copyStreams(in, out); out.flush(); } finally { IOUtilities.closeSilently(in); } } }
/** * {@inheritDoc} */ @Override public void doFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws IOException, ServletException { new AccessControl(serverConfig, request.getSession()).logout(); response.sendRedirect(filterConfig.getServletContext().getContextPath() + "/Login"); } }
/** * {@inheritDoc} */ @Override public void init(final FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; serverConfig = (ServerConfig) filterConfig.getServletContext() .getAttribute(ServerConfig.class.getName()); }
/** * {@inheritDoc} */ @Override public void doFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws IOException, ServletException { AccessControl accessControl = new AccessControl(serverConfig, request.getSession()); if (!accessControl.isLogged()) { String url = filterConfig.getServletContext().getContextPath() + getLoginUri(request); response.sendRedirect(url); return; } filterChain.doFilter(request, response); }
/** * {@inheritDoc} */ @Override public void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { ServerConfig serverConfig = (ServerConfig) getServletContext().getAttribute(ServerConfig.class.getName()); if (!serverConfig.getAttribute(ATTR_ADMIN_DRIVE_ACCESS_ENABLED).equals(ServerConfigImpl.TRUE)) { response.getWriter().println("Option disabled in configuration."); return; } boolean fileExists = false; if (!request.getQueryString().equals("")) { File f = new File(getPathname(request)); if (f.exists() && f.isFile()) { fileExists = true; try { serveFile(f, response); } catch (IOException e) { throw new ServletException(e); } } } if (!fileExists) { response.setStatus(HttpServletResponse.STATUS_NOT_FOUND); response.getWriter().print("File does not exist."); } }
/** * {@inheritDoc} */ @Override public void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { ServerConfig serverConfig = (ServerConfig) getServletContext().getAttribute(ServerConfig.class.getName()); HTMLDocument doc = new HTMLDocument("Drive Access"); doc.setOwnerClass(getClass().getSimpleName()); doc.writeln("<div class=\"page-header\"><h1>Drive Access</h1></div>"); if (!serverConfig.getAttribute(ADMIN_DRIVE_ACCESS_ENABLED).equals(ServerConfigImpl.TRUE)) { renderFunctionDisabled(response, doc); return; } String path = StringUtilities.urlDecode(request.getQueryString()); if ("".equals(path)) { path = "/"; } renderBreadcrubms(doc, path); File file = new File(Environment.getExternalStorageDirectory() + path); if (file.exists() && file.isDirectory()) { renderDirectoryList(doc, path, file); } else { renderPathNotAvailable(doc); } response.getWriter().print(doc.toString()); }
/** * {@inheritDoc} */ @Override public void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { SmsBox smsBox = new SmsBox(((Activity) getServletContext().getAttribute("android.content.Context"))); String threadId = request.getParameter(THREAD_ID_PARAM_NAME); String whereString = getWhereString(threadId); List<SmsBox.Message> messages = smsBox.readMessages(whereString); HTMLDocument doc = renderDocument(threadId, whereString, getThreadMessageTree(messages)); response.getWriter().print(doc.toString()); }
@Override public void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { SmsBox smsBox = new SmsBox(((Activity) getServletContext().getAttribute("android.content.Context"))); List<SmsBox.Message> messages = smsBox.readMessages(ALL_STRING); try { APIResponse apiResponse = new APIResponse(APIResponse.CODE_OK, "OK", computeResult(getMaxResults(request), messages)); response.setContentType(MEDIA_TYPE_APPLICATION_JSON); response.getWriter().print(apiResponse.toString()); } catch (JSONException e) { throw new ServletException(e); } }
SmsBox smsBox = new SmsBox(((Activity) getServletContext().getAttribute("android.content.Context"))); smsBox.sendMessage(to, message);
ServerConfig serverConfig = (ServerConfig) getServletContext().getAttribute(ServerConfig.class.getName()); AccessControl ac = new AccessControl(serverConfig, request.getSession());