List of usage examples for javax.servlet ServletContext getServerInfo
public String getServerInfo();
From source file:org.debux.webmotion.server.tools.HttpUtils.java
/** * @return true if webmotion in Tomcat container. *//*from w w w . j a v a2 s . c o m*/ public static boolean isTomcatContainer(ServletContext context) { String serverInfo = context.getServerInfo(); return StringUtils.containsIgnoreCase(serverInfo, "tomcat"); }
From source file:org.debux.webmotion.server.tools.HttpUtils.java
/** * @return true if webmotion in Glassfish container. *//* www. j av a 2s . com*/ public static boolean isGlassfishContainer(ServletContext context) { String serverInfo = context.getServerInfo(); return StringUtils.containsIgnoreCase(serverInfo, "glassfish"); }
From source file:org.debux.webmotion.server.tools.HttpUtils.java
/** * @return true if webmotion in Jetty container. *//*from www . ja va 2 s .c o m*/ public static boolean isJettyContainer(ServletContext context) { String serverInfo = context.getServerInfo(); return StringUtils.containsIgnoreCase(serverInfo, "jetty"); }
From source file:flex.messaging.services.http.proxy.RequestFilter.java
/** * Before calling the endpoint, set up the cookies found in the request. * @param context the context//from ww w . j av a 2 s .com */ public static void copyCookiesToEndpoint(ProxyContext context) { HttpServletRequest clientRequest = FlexContext.getHttpRequest(); context.clearRequestCookies(); if (clientRequest != null) { javax.servlet.http.Cookie[] cookies = clientRequest.getCookies(); HttpState initState = context.getHttpClient().getState(); if (cookies != null) { // Gather up the cookies keyed on the length of the path. // This is done so that if we have two cookies with the same name, // we pass the cookie with the longest path first to the endpoint TreeMap cookieMap = new TreeMap(); for (javax.servlet.http.Cookie cookie : cookies) { CookieInfo origCookie = new CookieInfo(cookie.getName(), cookie.getDomain(), cookie.getName(), cookie.getValue(), cookie.getPath(), cookie.getMaxAge(), null, cookie.getSecure()); CookieInfo newCookie = RequestUtil.createCookie(origCookie, context, context.getTarget().getUrl().getHost(), context.getTarget().getUrl().getPath()); if (newCookie != null) { Integer pathInt = Integer.valueOf(0 - newCookie.path.length()); ArrayList list = (ArrayList) cookieMap.get(pathInt); if (list == null) { list = new ArrayList(); cookieMap.put(pathInt, list); } list.add(newCookie); } } // loop through (in order) the cookies we've gathered for (Object mapValue : cookieMap.values()) { ArrayList list = (ArrayList) mapValue; for (Object aList : list) { CookieInfo cookieInfo = (CookieInfo) aList; if (Log.isInfo()) { String str = "-- Cookie in request: " + cookieInfo; Log.getLogger(HTTPProxyService.LOG_CATEGORY).debug(str); } Cookie cookie = new Cookie(cookieInfo.domain, cookieInfo.name, cookieInfo.value, cookieInfo.path, cookieInfo.maxAge, cookieInfo.secure); // If this is a session cookie and we're dealing with local domain, make sure the session // cookie has the latest session id. This check is needed when the session was invalidated // and then recreated in this request; we shouldn't be sending the old session id to the endpoint. if (context.isLocalDomain() && STRING_JSESSIONID.equalsIgnoreCase(cookieInfo.clientName)) { FlexSession flexSession = FlexContext.getFlexSession(); if (flexSession != null && flexSession.isValid()) { String sessionId = flexSession.getId(); String cookieValue = cookie.getValue(); if (!cookieValue.contains(sessionId)) { int colonIndex = cookieValue.indexOf(':'); if (colonIndex != -1) { // Websphere changes jsession id to the following format: // 4 digit cacheId + jsessionId + ":" + cloneId. ServletContext servletContext = FlexContext.getServletContext(); String serverInfo = servletContext != null ? servletContext.getServerInfo() : null; boolean isWebSphere = serverInfo != null && serverInfo.contains("WebSphere"); if (isWebSphere) { String cacheId = cookieValue.substring(0, 4); String cloneId = cookieValue.substring(colonIndex); String wsSessionId = cacheId + sessionId + cloneId; cookie.setValue(wsSessionId); } else { cookie.setValue(sessionId); } } else { cookie.setValue(sessionId); } } } } // finally add the cookie to the current request initState.addCookie(cookie); context.addRequestCookie(cookie); } } } } }
From source file:com.olegchir.fadeok.init.AppInitializer.java
public void onStartup(ServletContext servletContext) throws ServletException { System.out.println("Initializing Application for " + servletContext.getServerInfo()); //Create webapp context AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext(); applicationContext.setConfigLocation(CONFIG_LOCATION); servletContext.addListener(new ContextLoaderListener(applicationContext)); // servletContext.addListener(new CompleteAutoloadTilesListener()); // Add the servlet mapping manually and make it initialize automatically DispatcherServlet dispatcherServlet = new DispatcherServlet(applicationContext); ServletRegistration.Dynamic servlet = servletContext.addServlet("mvc-dispatcher", dispatcherServlet); servlet.addMapping("/"); servlet.setAsyncSupported(true);/* www. j a v a 2s . co m*/ servlet.setLoadOnStartup(1); }
From source file:org.phenotips.pingback.internal.client.data.ServletContainerPingDataProviderTest.java
@Test public void provideData() throws Exception { ServletEnvironment servletEnvironment = mock(ServletEnvironment.class); ReflectionUtils.setFieldValue(this.mocker.getComponentUnderTest(), "environment", servletEnvironment); ServletContext servletContext = mock(ServletContext.class); when(servletEnvironment.getServletContext()).thenReturn(servletContext); when(servletContext.getServerInfo()).thenReturn("Apache Tomcat/7.0.4 (optional text)"); JSONAssert.assertEquals(/*from w w w. ja v a2 s.c om*/ "{\"servletContainerVersion\":\"7.0.4\",\"servletContainerName\":\"Apache Tomcat\"}", new JSONObject(this.mocker.getComponentUnderTest().provideData()), false); }
From source file:nl.nn.adapterframework.webcontrol.ConfigurationServlet.java
private void setDefaultApplicationServerType(IbisContext ibisContext) { ServletContext context = getServletContext(); String serverInfo = context.getServerInfo(); String defaultApplicationServerType = null; if (StringUtils.containsIgnoreCase(serverInfo, "WebSphere Liberty")) { defaultApplicationServerType = "WLP"; } else if (StringUtils.containsIgnoreCase(serverInfo, "WebSphere")) { defaultApplicationServerType = "WAS"; } else if (StringUtils.containsIgnoreCase(serverInfo, "Tomcat")) { defaultApplicationServerType = "TOMCAT"; } else if (StringUtils.containsIgnoreCase(serverInfo, "JBoss")) { defaultApplicationServerType = "JBOSS"; } else if (StringUtils.containsIgnoreCase(serverInfo, "jetty")) { String javaHome = AppConstants.getInstance().getString("java.home", ""); if (StringUtils.containsIgnoreCase(javaHome, "tibco")) { defaultApplicationServerType = "TIBCOAMX"; } else {//from w ww. j a va 2s. co m defaultApplicationServerType = "JETTYMVN"; } } else { ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance(); configWarnings.add(log, "Unknown server info [" + serverInfo + "] default application server type could not be determined, TOMCAT will be used as default value"); defaultApplicationServerType = "TOMCAT"; } ibisContext.setDefaultApplicationServerType(defaultApplicationServerType); }
From source file:burrito.Configurator.java
private boolean isDevMode(ServletContext context) { String serverInfo = context.getServerInfo(); /*/*from w ww. j av a 2 s. c o m*/ * ServerInfo will look something like "Google App Engine Development/x.x.x" when running in * the development server. In production mode it will look like "Google App Engine/x.x.x" */ return serverInfo.contains("Development"); }
From source file:org.opendatakit.aggregate.odktables.impl.api.wink.GaeAwareContentEncodingResponseFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { if (servletRequest instanceof HttpServletRequest) { HttpServletRequest req = (HttpServletRequest) servletRequest; ServletContext sc = req.getSession().getServletContext(); CallingContext cc = ContextFactory.getCallingContext(sc, req); String server = sc.getServerInfo(); /*/*from ww w. j a va2s . c o m*/ * AppEngine leaves the GZIP header even though it unzips the content * before delivering it to the app. */ boolean isGaeDevelopmentEnvironment = server.contains("Development"); boolean isGaeEnvironment = false; try { UserService us = cc.getUserService(); if (us != null) { Realm realm = us.getCurrentRealm(); if (realm != null) { Boolean outcome = realm.getIsGaeEnvironment(); if (outcome != null) { isGaeEnvironment = outcome; } } } } catch (Exception e) { // ignore... } if (isGaeEnvironment && !isGaeDevelopmentEnvironment) { // don't try to process anything -- GAE does but does not remove headers logger.info("Gae environment -- ignoring Accept-Encoding header"); chain.doFilter(servletRequest, servletResponse); } else { // perhaps wrap response with GZIP logger.info("not Gae environment -- processing Accept-Encoding header"); super.doFilter(servletRequest, servletResponse, chain); } } }
From source file:org.opendatakit.aggregate.odktables.impl.api.wink.GaeAwareContentEncodingRequestFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { if (servletRequest instanceof HttpServletRequest) { HttpServletRequest req = (HttpServletRequest) servletRequest; ServletContext sc = req.getSession().getServletContext(); CallingContext cc = ContextFactory.getCallingContext(sc, req); String server = sc.getServerInfo(); /*//www.j a v a 2s .c o m * AppEngine leaves the GZIP header even though it unzips the content * before delivering it to the app. */ boolean isGaeDevelopmentEnvironment = server.contains("Development"); boolean isGaeEnvironment = false; try { UserService us = cc.getUserService(); if (us != null) { Realm realm = us.getCurrentRealm(); if (realm != null) { Boolean outcome = realm.getIsGaeEnvironment(); if (outcome != null) { isGaeEnvironment = outcome; } } } } catch (Exception e) { // ignore... } if (isGaeEnvironment && !isGaeDevelopmentEnvironment) { // don't try to process anything -- GAE does but does not remove headers logger.info("Gae environment -- ignoring Content-Encoding header"); chain.doFilter(servletRequest, servletResponse); } else { // perhaps wrap response with GZIP logger.info("not Gae environment -- processing Content-Encoding header"); super.doFilter(servletRequest, servletResponse, chain); } } }