List of usage examples for javax.servlet ServletContext getContextPath
public String getContextPath();
From source file:com.afis.jx.ckfinder.connector.utils.FileUtils.java
/** * Returns Path to Tomcat ROOT folder.// www . j a va 2 s. c om * * @param sc current {@code ServletContext} object. * @param path String from which path to Tomcat ROOT folder will be calculated * @return path to Tomcat ROOT folder or empty String is path can't be found. */ private static String getTomcatRootPath(ServletContext sc, String path) { String finalPath = ""; int index = path.indexOf(sc.getContextPath() + WEB_INF_FOLDER_NAME); if (index >= 0) { path = path.substring(0, index); path = path + ROOT_FOLDER_NAME; if (isFileExist(path)) { finalPath = path; } } return finalPath; }
From source file:org.zanata.magpie.action.FrontendAssets.java
public void onInit(@Observes @Initialized(ApplicationScoped.class) ServletContext servletContext) throws Exception { manifest = getManifest();//w w w . j a v a 2 s . co m String contextPath = servletContext.getContextPath(); frontendJs = generateAbsolutePath(contextPath, manifest.getFrontendJs()); frontendCss = generateAbsolutePath(contextPath, manifest.getFrontendCss()); vendorJs = generateAbsolutePath(contextPath, manifest.getVendorJs()); LOG.info("Frontend manifest: {}", manifest); }
From source file:org.taverna.server.master.notification.atom.AtomFeed.java
@Override public void setServletContext(ServletContext servletContext) { String base = servletContext.getInitParameter(PREFERRED_URI_PARAM); if (base == null) base = servletContext.getContextPath() + "/rest"; baseURI = URI.create(base);/*w w w. ja v a 2 s.co m*/ }
From source file:com.flexive.war.listener.SessionTimeoutListener.java
@Override public void sessionDestroyed(HttpSessionEvent event) { final HttpSession session = event.getSession(); if (LOG.isDebugEnabled()) { LOG.debug("Session destroyed: " + session.getId()); }/*from ww w .jav a 2 s . c o m*/ // set parameters needed for logout final FxContext ctx = FxContext.get(); try { ctx.setSessionID(session.getId()); // retrieve context path final ServletContext servletContext = session.getServletContext(); if (servletContext != null) { ctx.setContextPath(servletContext.getContextPath()); } // get division ID from session final String divisionIdKey = FxSessionWrapper.encodeAttributeName(FxContext.SESSION_DIVISIONID); if (session.getAttribute(divisionIdKey) != null) { ctx.setDivisionId((Integer) session.getAttribute(divisionIdKey)); } if (ctx.getDivisionId() == -1 || !CacheAdmin.isEnvironmentLoaded()) { // probably during undeploy return; } ctx.setTicket(FxContext.getTicketFromEJB(session)); if (!ctx.getTicket().isGuest()) { // perform logout only when the user is logged in if (LOG.isDebugEnabled()) { LOG.debug("Performing logout for user of destroyed session (possible session timeout): " + session.getId()); } onLogout(ctx.getTicket()); ctx.logout(); } } catch (FxLogoutFailedException e) { LOG.error("Failed to logout user after session timeout: " + e.getMessage(), e); } finally { FxContext.cleanup(); } }
From source file:com.payu.ratel.config.beans.ServiceRegisterPostProcessorFactory.java
@SuppressWarnings("PMD.EmptyCatchBlock") public ServiceRegisterPostProcessor create(ConfigurableListableBeanFactory beanFactory, RegisterStrategy registerStrategy) { SelfAddressProviderChain selfAddressProvider = beanFactory.getBean(SelfAddressProviderChain.class); if (selfAddressProvider == null) { throw new IllegalStateException("No SelfAddressProvider bean in context"); }/*ww w . j ava 2 s. co m*/ final HostAndPort hostAndPort = selfAddressProvider.getHostAndPort(); ServletContext servletContext = null; try { servletContext = beanFactory.getBean(ServletContext.class); } catch (NoSuchBeanDefinitionException e) { } final String contextRoot = servletContext != null ? servletContext.getContextPath() : ""; final String address = String.format("http://%s:%s%s%s", hostAndPort.getHostText(), hostAndPort.getPort(), contextRoot, RATEL_PATH); return new ServiceRegisterPostProcessor(beanFactory, registerStrategy, address); }
From source file:com.edmunds.etm.client.impl.ClientServletContextListener.java
/** * Notification that the web application initialization process is starting. All ServletContextListeners are * notified of context initialization before any filter or servlet in the web application is initialized. * * @param servletContextEvent the servlet context event. *//*from w w w . j a v a 2 s. co m*/ @Override public void contextInitialized(ServletContextEvent servletContextEvent) { logger.debug("Starting ETM listener."); ServletContext ctx = servletContextEvent.getServletContext(); final String ipAddress = getIpAddress(); final String contextPath = ctx.getContextPath(); ClientConfigDto clientConfig = readClientConfiguration(); MavenModuleDto mavenModule = clientConfig.getMavenModule(); if (logger.isDebugEnabled()) { logger.debug(String.format("ETM application: %s", clientConfig.getMavenModule())); } // validate IP address and maven module if (StringUtils.isBlank(ipAddress)) { logger.error("Unable to register with ETM: IP address is blank"); return; } else if (mavenModule == null) { logger.error("Unable to register with ETM: Maven artifact information is missing"); return; } final ApplicationContext appCtx = SpringContextLoader.loadClassPathSpringContext(CLIENT_CONTEXT_PATH, getMavenProperties(mavenModule)); final ClientRegistrationHelper helper = (ClientRegistrationHelper) appCtx .getBean("clientRegistrationHelper"); clientManager = (ClientManager) appCtx.getBean("clientManager"); // register with the ETM controller helper.register(ctx.getServerInfo(), ipAddress, contextPath, clientConfig); }
From source file:org.apache.hadoop.hdfsproxy.LdapIpDirFilter.java
/** {@inheritDoc} */ public void init(FilterConfig filterConfig) throws ServletException { ServletContext context = filterConfig.getServletContext(); contextPath = context.getContextPath(); Configuration conf = new Configuration(false); conf.addResource("hdfsproxy-default.xml"); conf.addResource("hdfsproxy-site.xml"); // extract namenode from source conf. String nn = getNamenode(conf); InetSocketAddress nAddr = NetUtils.createSocketAddr(nn); context.setAttribute("name.node.address", nAddr); context.setAttribute("name.conf", conf); context.setAttribute(JspHelper.CURRENT_CONF, conf); // for storing hostname <--> cluster mapping to decide which source cluster // to forward context.setAttribute("org.apache.hadoop.hdfsproxy.conf", conf); if (lctx == null) { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(InitialLdapContext.INITIAL_CONTEXT_FACTORY, conf.get("hdfsproxy.ldap.initial.context.factory", "com.sun.jndi.ldap.LdapCtxFactory")); env.put(InitialLdapContext.PROVIDER_URL, conf.get("hdfsproxy.ldap.provider.url")); try {/* w w w. j a v a2 s . c o m*/ lctx = new InitialLdapContext(env, null); } catch (NamingException ne) { throw new ServletException("NamingException in initializing ldap" + ne.toString()); } baseName = conf.get("hdfsproxy.ldap.role.base"); hdfsIpSchemaStr = conf.get("hdfsproxy.ldap.ip.schema.string", "uniqueMember"); hdfsIpSchemaStrPrefix = conf.get("hdfsproxy.ldap.ip.schema.string.prefix", "cn="); hdfsUidSchemaStr = conf.get("hdfsproxy.ldap.uid.schema.string", "uid"); hdfsPathSchemaStr = conf.get("hdfsproxy.ldap.hdfs.path.schema.string", "documentLocation"); } LOG.info(contextPath + ":: LdapIpDirFilter initialization successful"); }
From source file:com.sishuok.es.maintain.icon.web.controller.IconController.java
/** * ? ? ??/*w w w. j a v a2 s.co m*/ * * @param request * @return */ @RequestMapping(value = "/genCssFile") @ResponseBody public String genIconCssFile(HttpServletRequest request) { this.permissionList.assertHasEditPermission(); String uploadFileTemplate = ".%1$s{background:url(%2$s/%3$s);width:%4$spx;height:%5$spx;display:inline-block;vertical-align: middle;%6$s}"; String cssSpriteTemplate = ".%1$s{background:url(%2$s/%3$s) no-repeat -%4$spx -%5$spx;width:%6$spx;height:%7$spx;display:inline-block;vertical-align: middle;%8$s}"; ServletContext sc = request.getServletContext(); String ctx = sc.getContextPath(); List<String> cssList = Lists.newArrayList(); Searchable searchable = Searchable.newSearchable().addSearchParam("type_in", new IconType[] { IconType.upload_file, IconType.css_sprite }); List<Icon> iconList = baseService.findAllWithNoPageNoSort(searchable); for (Icon icon : iconList) { if (icon.getType() == IconType.upload_file) { cssList.add(String.format(uploadFileTemplate, icon.getIdentity(), ctx, icon.getImgSrc(), icon.getWidth(), icon.getHeight(), icon.getStyle())); continue; } if (icon.getType() == IconType.css_sprite) { cssList.add(String.format(cssSpriteTemplate, icon.getIdentity(), ctx, icon.getSpriteSrc(), icon.getLeft(), icon.getTop(), icon.getWidth(), icon.getHeight(), icon.getStyle())); continue; } } try { ServletContextResource resource = new ServletContextResource(sc, iconClassFile); FileUtils.writeLines(resource.getFile(), cssList); } catch (Exception e) { LogUtils.logError("gen icon error", e); return "?" + e.getMessage(); } return "??"; }
From source file:com.daphne.es.maintain.icon.web.controller.IconController.java
/** * ? ? ??/* ww w. j a v a 2 s .c o m*/ * * @param request * @return */ @RequestMapping(value = "/genCssFile") @ResponseBody public String genIconCssFile(HttpServletRequest request) { this.permissionList.assertHasEditPermission(); String uploadFileTemplate = ".%1$s{background:url(%2$s/%3$s);width:%4$spx;height:%5$spx;display:inline-block;vertical-align: middle;%6$s}"; String cssSpriteTemplate = ".%1$s{background:url(%2$s/%3$s) no-repeat -%4$spx -%5$spx;width:%6$spx;height:%7$spx;display:inline-block;vertical-align: middle;%8$s}"; ServletContext sc = request.getServletContext(); String ctx = sc.getContextPath(); List<String> cssList = Lists.newArrayList(); Searchable searchable = Searchable.newSearchable().addSearchParam("type_in", new IconType[] { IconType.upload_file, IconType.css_sprite }); List<Icon> iconList = baseService.findAllWithNoPageNoSort(searchable); for (Icon icon : iconList) { if (icon.getType() == IconType.upload_file) { cssList.add(String.format(uploadFileTemplate, icon.getIdentity(), ctx, icon.getImgSrc(), icon.getWidth(), icon.getHeight(), icon.getStyle())); continue; } if (icon.getType() == IconType.css_sprite) { cssList.add(String.format(cssSpriteTemplate, icon.getIdentity(), ctx, icon.getSpriteSrc(), icon.getLeft(), icon.getTop(), icon.getWidth(), icon.getHeight(), icon.getStyle())); continue; } } try { ServletContextResource resource = new ServletContextResource(sc, iconClassFile); FileUtils.writeLines(resource.getFile(), cssList); } catch (Exception e) { LogUtils.logError("gen icon error", e); return "?" + e.getMessage(); } return "??"; }
From source file:com.luna.maintain.icon.web.controller.IconController.java
/** * ? ? ??/* www .jav a2 s. c o m*/ * * @param request * @return */ @RequestMapping(value = "/genCssFile") @ResponseBody public String genIconCssFile(HttpServletRequest request) { this.permissionList.assertHasEditPermission(); String uploadFileTemplate = ".%1$s{background:url(%2$s/%3$s);width:%4$spx;height:%5$spx;display:inline-block;vertical-align: middle;%6$s}"; String cssSpriteTemplate = ".%1$s{background:url(%2$s/%3$s) no-repeat -%4$spx -%5$spx;width:%6$spx;height:%7$spx;display:inline-block;vertical-align: middle;%8$s}"; ServletContext sc = request.getServletContext(); String ctx = sc.getContextPath(); List<String> cssList = Lists.newArrayList(); Searchable searchable = Searchable.newSearchable().addSearchParam("type_in", new IconType[] { IconType.upload_file, IconType.css_sprite }); List<Icon> iconList = baseService.findAllWithNoPageNoSort(searchable); for (Icon icon : iconList) { if (icon.getType() == IconType.upload_file) { cssList.add(String.format(uploadFileTemplate, icon.getIdentity(), ctx, icon.getImgSrc(), icon.getWidth(), icon.getHeight(), icon.getStyle())); continue; } if (icon.getType() == IconType.css_sprite) { cssList.add(String.format(cssSpriteTemplate, icon.getIdentity(), ctx, icon.getSpriteSrc(), icon.getLeft(), icon.getTop(), icon.getWidth(), icon.getHeight(), icon.getStyle())); continue; } } try { ServletContextResource resource = new ServletContextResource(sc, iconClassFile); FileUtils.writeLines(resource.getFile(), cssList); } catch (Exception e) { log.error("gen icon error", e); return "?" + e.getMessage(); } return "??"; }