@Override public String getApplicationName() { return (this.servletContext != null ? this.servletContext.getContextPath() : ""); }
@Override public String getApplicationName() { return (this.servletContext != null ? this.servletContext.getContextPath() : ""); }
protected String getServerContextPath() { return servletContext.getContextPath(); }
private static String getContextPath_2_5(ServletContext context) { String contextPath = context.getContextPath(); if (contextPath == null || contextPath.length() == 0) { contextPath = "/"; } return contextPath; }
@Override public String getApplicationName() { return (this.servletContext != null ? this.servletContext.getContextPath() : ""); }
@Override public String getApplicationName() { return (this.servletContext != null ? this.servletContext.getContextPath() : ""); }
public String getContextPath() { return this.servletContext.getContextPath(); }
private String loadHtmlFile(String path, String serverStatus, String instance) { try (InputStream input = servletContext.getResourceAsStream(path)) { String template = IOUtils.toString(requireNonNull(input), UTF_8); return template .replaceAll(WEB_CONTEXT_PLACEHOLDER, servletContext.getContextPath()) .replaceAll(SERVER_STATUS_PLACEHOLDER, serverStatus) .replaceAll(INSTANCE_PLACEHOLDER, instance) .replaceAll(OFFICIAL_PLACEHOLDER, String.valueOf(officialDistribution.check())); } catch (Exception e) { throw new IllegalStateException("Fail to load file " + path, e); } } }
private void checkServerHealth() { long startCheckTime = System.currentTimeMillis(); for (String serverIp : serverList) { // Compatible with old codes,use status.taobao String url = "http://" + serverIp + servletContext.getContextPath() + Constants.HEALTH_CONTROLLER_PATH; // "/nacos/health"; HttpGet request = new HttpGet(url); httpclient.execute(request, new AyscCheckServerHealthCallBack(serverIp)); } long endCheckTime = System.currentTimeMillis(); long cost = endCheckTime - startCheckTime; defaultLog.debug("checkServerHealth cost: {}", cost); }
@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") @Override public void onApplicationEvent(WebServerInitializedEvent event) { Loggers.SRV_LOG.info("[SERVER-INIT] got port: {}", event.getWebServer().getPort()); Loggers.SRV_LOG.info("[SERVER-INIT] got path: {}", servletContext.getContextPath()); serverPort = event.getWebServer().getPort(); contextPath = servletContext.getContextPath(); try { RaftCore.init(); } catch (Exception e) { Loggers.RAFT.error("[NACOS-RAFT] {} {}", "failed to initialize raft sub system", e); } }
@Before public void setUp() throws Exception { when(servletContext.getContextPath()).thenReturn(TEST_CONTEXT); when(servletContext.getResourceAsStream("/index.html")).thenAnswer( (Answer<InputStream>) invocationOnMock -> toInputStream("Content of default index.html with context [%WEB_CONTEXT%], status [%SERVER_STATUS%], instance [%INSTANCE%]", UTF_8)); when(servletContext.getResourceAsStream("/integration/vsts/index.html")) .thenAnswer((Answer<InputStream>) invocationOnMock -> toInputStream("Content of vsts index.html with context [%WEB_CONTEXT%]", UTF_8)); }
@Before public void setUp() throws Exception { when(servletContext.getContextPath()).thenReturn(TEST_CONTEXT); }
@Override public void contextInitialized(final ServletContextEvent sce) { if (getEa() != null) { final String contextPath = sce.getServletContext().getContextPath(); getEa().sendEvent(new Event("jersey/test/DEPLOYED", new HashMap<String, String>() {{ put("context-path", contextPath); }})); } }
@Override public void contextDestroyed(final ServletContextEvent sce) { if (getEa() != null) { getEa().sendEvent(new Event("jersey/test/UNDEPLOYED", new HashMap<String, String>() {{ put("context-path", sce.getServletContext().getContextPath()); }})); } }
@Override public void onApplicationEvent(WebServerInitializedEvent event) { setServerPort(event.getWebServer().getPort()); setContextPath(servletContext.getContextPath()); }
@Before public void initialize() { FilterConfig filterConfig = mock(FilterConfig.class); ServletContext context = mock(ServletContext.class); when(context.getContextPath()).thenReturn("/context"); when(filterConfig.getServletContext()).thenReturn(context); underTest = new RootFilter(); underTest.init(filterConfig); }
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id is still set to its original default value // -> assign a more useful id based on available information String idParam = sc.getInitParameter(CONTEXT_ID_PARAM); if (idParam != null) { wac.setId(idParam); } else { // Generate default id... wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils.getDisplayString(sc.getContextPath())); } } wac.setServletContext(sc); String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM); if (configLocationParam != null) { wac.setConfigLocation(configLocationParam); } // The wac environment's #initPropertySources will be called in any case when the context // is refreshed; do it eagerly here to ensure servlet property sources are in place for // use in any post-processing or initialization that occurs below prior to #refresh ConfigurableEnvironment env = wac.getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(sc, null); } customizeContext(sc, wac); wac.refresh(); }
/** * <p> * Builds the JASPIC application context. * </p> * * @return a {@code String} representing the application context. */ private String buildAppContext() { final ServletRequestContext requestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); ServletRequest servletRequest = requestContext.getServletRequest(); return servletRequest.getServletContext().getVirtualServerName() + " " + servletRequest.getServletContext().getContextPath(); }
void init(JFinalConfig jfinalConfig, ServletContext servletContext) { this.servletContext = servletContext; this.contextPath = servletContext.getContextPath(); initPathKit(); Config.configJFinal(jfinalConfig); // start plugin, init log factory and init engine in this method constants = Config.getConstants(); initActionMapping(); initHandler(); initRender(); initOreillyCos(); initTokenManager(); }
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id is still set to its original default value // -> assign a more useful id based on available information if (this.contextId != null) { wac.setId(this.contextId); } else { // Generate default id... wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils.getDisplayString(getServletContext().getContextPath()) + '/' + getServletName()); } } wac.setServletContext(getServletContext()); wac.setServletConfig(getServletConfig()); wac.setNamespace(getNamespace()); wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener())); // The wac environment's #initPropertySources will be called in any case when the context // is refreshed; do it eagerly here to ensure servlet property sources are in place for // use in any post-processing or initialization that occurs below prior to #refresh ConfigurableEnvironment env = wac.getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(getServletContext(), getServletConfig()); } postProcessWebApplicationContext(wac); applyInitializers(wac); wac.refresh(); }