Example usage for javax.servlet ServletContext getMajorVersion

List of usage examples for javax.servlet ServletContext getMajorVersion

Introduction

In this page you can find the example usage for javax.servlet ServletContext getMajorVersion.

Prototype

public int getMajorVersion();

Source Link

Document

Returns the major version of the Servlet API that this servlet container supports.

Usage

From source file:com.dcs.controller.filter.SecurityServlet.java

public static String getContextPath(ServletContext context) {
    if (context.getMajorVersion() == 2 && context.getMinorVersion() < 5) {
        return null;
    }/*from ww  w  .jav a  2  s . c  o  m*/

    try {
        return getContextPath_2_5(context);
    } catch (NoSuchMethodError error) {
        return null;
    }
}

From source file:com.denksoft.springstarter.util.TilesViewExtended.java

protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    MutableTilesContainer container = (MutableTilesContainer) TilesAccess.getContainer(getServletContext());

    log.info("There is no definition registered. Registering a new definition " + getBeanName());
    Definition definition = new Definition();

    Attribute attr = new Attribute();
    attr.setName("body");
    attr.setValue("/WEB-INF/jsp/" + getBeanName() + ".jsp");

    definition.addAttribute(attr);// w w  w  .  j a  v a 2s  .com
    definition.setExtends("rootLayout");
    definition.setName(getBeanName());

    container.register(definition, request, response);

    exposeModelAsRequestAttributes(model, request);
    JstlUtils.exposeLocalizationContext(request, this.jstlAwareMessageSource);
    //container.render(getUrl(), request, response);

    if (!response.isCommitted()) {
        // Tiles is going to use a forward, but some web containers (e.g. OC4J 10.1.3)
        // do not properly expose the Servlet 2.4 forward request attributes... However,
        // must not do this on Servlet 2.5 or above, mainly for GlassFish compatibility.
        ServletContext sc = getServletContext();
        if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
            WebUtils.exposeForwardRequestAttributes(request);
        }
    }

    container.render(getUrl(), new Object[] { request, response });
}

From source file:org.wp.spring.php.view.PHPView.java

protected void checkServletAPIVersion(ServletContext servletContext) {
    int major = servletContext.getMajorVersion();
    int minor = servletContext.getMinorVersion();

    if ((major < 2) || ((major == 2) && (minor < 4))) {
        throw new QuercusRuntimeException("Quercus requires Servlet API 2.4+.");
    }/* ww  w.  jav a 2s .co  m*/
}

From source file:net.vksn.ecm.spring.tiles3.TilesView.java

@Override
protected void initServletContext(ServletContext servletContext) {
    super.initServletContext(servletContext);
    if (servletContext.getMajorVersion() == 2 && servletContext.getMinorVersion() < 5) {
        this.exposeForwardAttributes = true;
    }/* w w  w  .j  ava 2  s .  c o  m*/
}

From source file:com.icesoft.faces.webapp.http.servlet.ServletEnvironmentRequest.java

private void initializeServlet2point4Properties(HttpServletRequest servletRequest) {
    ServletContext context = servletRequest.getSession().getServletContext();
    if (context.getMajorVersion() > 1 && context.getMinorVersion() > 3) {
        remotePort = servletRequest.getRemotePort();
        localName = servletRequest.getLocalName();
        localAddr = servletRequest.getLocalAddr();
        localPort = servletRequest.getLocalPort();
    }//from  ww  w.j  a v  a 2  s .  co m
}

From source file:net.centro.rtb.monitoringcenter.MonitoringCenterServlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);

    boolean disableAuthorization = Boolean.TRUE.toString()
            .equalsIgnoreCase(servletConfig.getInitParameter(DISABLE_AUTHORIZATION_INIT_PARAM));
    if (!disableAuthorization) {
        String credentials = null;

        String username = servletConfig.getInitParameter(USERNAME_INIT_PARAM);
        String password = servletConfig.getInitParameter(PASSWORD_INIT_PARAM);
        if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
            credentials = username.trim() + ":" + password.trim();
        } else {/*from  ww w  .j  a va  2 s . c  om*/
            credentials = DEFAULT_CREDENTIALS;
        }

        this.encodedCredentials = BaseEncoding.base64().encode(credentials.getBytes());
    }

    this.objectMapper = new ObjectMapper()
            .registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MICROSECONDS, false))
            .registerModule(new HealthCheckModule()).setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .setTimeZone(TimeZone.getDefault()).setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"));

    this.graphiteMetricFormatter = new GraphiteMetricFormatter(TimeUnit.SECONDS, TimeUnit.MICROSECONDS);

    try {
        this.threadDumpGenerator = new ThreadDump(ManagementFactory.getThreadMXBean());
    } catch (NoClassDefFoundError ignore) {
    }

    ServletContext servletContext = servletConfig.getServletContext();
    String servletSpecVersion = servletContext.getMajorVersion() + "." + servletContext.getMinorVersion();
    this.serverInfo = ServerInfo.create(servletContext.getServerInfo(), servletSpecVersion);
}

From source file:org.smigo.config.WebAppInitializer.java

@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
    super.beforeSpringSecurityFilterChain(servletContext);
    log.info("Starting servlet context");
    log.info("contextName: " + servletContext.getServletContextName());
    log.info("contextPath:" + servletContext.getContextPath());
    log.info("effectiveMajorVersion:" + servletContext.getEffectiveMajorVersion());
    log.info("effectiveMinorVersion:" + servletContext.getEffectiveMinorVersion());
    log.info("majorVersion:" + servletContext.getMajorVersion());
    log.info("minorVersion:" + servletContext.getMinorVersion());
    log.info("serverInfo:" + servletContext.getServerInfo());
    //               ", virtualServerName:" + servletContext.getVirtualServerName() +
    log.info("toString:" + servletContext.toString());

    for (Enumeration<String> e = servletContext.getAttributeNames(); e.hasMoreElements();) {
        log.info("Attribute:" + e.nextElement());
    }//from   w  w  w . j a v a  2 s  . c o m
    for (Map.Entry<String, String> env : System.getenv().entrySet()) {
        log.info("System env:" + env.toString());
    }
    for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
        log.info("System prop:" + prop.toString());
    }

    final String profile = System.getProperty("smigoProfile", EnvironmentProfile.PRODUCTION);
    log.info("Starting with profile " + profile);

    WebApplicationContext context = new AnnotationConfigWebApplicationContext() {
        {
            register(WebConfiguration.class);
            setDisplayName("SomeRandomName");
            getEnvironment().setActiveProfiles(profile);
        }
    };

    FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("CharacterEncodingFilter",
            new CharacterEncodingFilter());
    characterEncodingFilter.setInitParameter("encoding", "UTF-8");
    characterEncodingFilter.setInitParameter("forceEncoding", "true");
    characterEncodingFilter.addMappingForUrlPatterns(null, false, "/*");

    servletContext.addListener(new RequestContextListener());
    servletContext.addListener(new ContextLoaderListener(context));

    //http://stackoverflow.com/questions/4811877/share-session-data-between-2-subdomains
    //        servletContext.getSessionCookieConfig().setDomain(getDomain());

    DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
    dispatcherServlet.setThrowExceptionIfNoHandlerFound(false);
    servletContext.addServlet("dispatcher", dispatcherServlet).addMapping("/");
}

From source file:com.parakhcomputer.web.servlet.view.tiles2.DynamicTilesViewProcessor.java

/**
 * Renders output using Tiles.//from  w  w w .jav  a2  s .  c om
 */
protected void renderMergedOutputModel(String beanName, String url, ServletContext servletContext,
        HttpServletRequest request, HttpServletResponse response, TilesContainer container) throws Exception {
    JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext));

    if (!response.isCommitted()) {
        // Tiles is going to use a forward, but some web containers (e.g.
        // OC4J 10.1.3)
        // do not properly expose the Servlet 2.4 forward request
        // attributes... However,
        // must not do this on Servlet 2.5 or above, mainly for GlassFish
        // compatibility.
        if (servletContext.getMajorVersion() == 2 && servletContext.getMinorVersion() < 5) {
            WebUtils.exposeForwardRequestAttributes(request);
        }
    }

    String definitionName = startDynamicDefinition(beanName, url, request, response, container);

    container.render(definitionName, request, response);

    endDynamicDefinition(definitionName, beanName, request, response, container);
}

From source file:com.dhcc.framework.web.context.DhccContextLoader.java

protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac,
        ServletContext sc) {
    Log logger = LogFactory.getLog(DhccContextLoader.class);
    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);/*  w ww .j  av a 2  s .  c  o m*/
        } else {
            // Generate default id...
            if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
                // Servlet <= 2.4: resort to name specified in web.xml, if any.
                wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX
                        + ObjectUtils.getDisplayString(sc.getServletContextName()));
            } else {
                wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX
                        + ObjectUtils.getDisplayString(sc.getContextPath()));
            }
        }
    }

    wac.setServletContext(sc);
    String initParameter = sc.getInitParameter(CONFIG_LOCATION_PARAM);
    if (isMicrokernelStart(sc)) {
        initParameter = "classpath:codeTemplate/applicationSetupContext.xml";
        logger.error("because cant't  connect to db or setup flg is 0 so init application as  Microkernel ");
    } else {
        logger.info("initParameter==" + initParameter);
    }
    if (initParameter != null) {
        wac.setConfigLocation(initParameter);
    }
    customizeContext(sc, wac);
    wac.refresh();
}

From source file:com.atlassian.jira.startup.JiraSystemInfo.java

/**
 * This only gets the most basic environment information to avoid bring up the JIRA world before the raw database
 * checks are done.//from  ww  w  .j  a v a  2s  . c  o  m
 * <p/>
 * It MUST BE CAREFUL not to access an JIRA code that will bring up the world
 *
 * @param context - a ServletContext that the app is running in.  This may be nulll
 */
public void obtainBasicInfo(final ServletContext context) {
    final SystemInfoUtils systemInfoUtils = new SystemInfoUtilsImpl();
    final ReleaseInfo releaseInfo = ReleaseInfo.getReleaseInfo(ReleaseInfo.class);

    logMsg.outputHeader("Environment");

    logMsg.outputProperty("JIRA Build", buildUtilsInfo.getBuildInformation());
    logMsg.outputProperty("Build Date", String.valueOf(buildUtilsInfo.getCurrentBuildDate()));
    logMsg.outputProperty("JIRA Installation Type", releaseInfo.getInfo());

    if (context != null) {
        logMsg.outputProperty("Application Server", context.getServerInfo() + " - Servlet API "
                + context.getMajorVersion() + "." + context.getMinorVersion());
    }
    logMsg.outputProperty("Java Version", jiraSystemProperties.getProperty("java.version", STRANGELY_UNKNOWN)
            + " - " + jiraSystemProperties.getProperty("java.vendor", STRANGELY_UNKNOWN));
    logMsg.outputProperty("Current Working Directory",
            jiraSystemProperties.getProperty("user.dir", STRANGELY_UNKNOWN));

    final Runtime rt = Runtime.getRuntime();
    final long maxMemory = rt.maxMemory() / MEGABYTE;
    final long totalMemory = rt.totalMemory() / MEGABYTE;
    final long freeMemory = rt.freeMemory() / MEGABYTE;
    final long usedMemory = totalMemory - freeMemory;

    logMsg.outputProperty("Maximum Allowable Memory", maxMemory + "MB");
    logMsg.outputProperty("Total Memory", totalMemory + "MB");
    logMsg.outputProperty("Free Memory", freeMemory + "MB");
    logMsg.outputProperty("Used Memory", usedMemory + "MB");

    for (final MemoryInformation memory : systemInfoUtils.getMemoryPoolInformation()) {
        logMsg.outputProperty("Memory Pool: " + memory.getName(), memory.toString());
    }
    logMsg.outputProperty("JVM Input Arguments", systemInfoUtils.getJvmInputArguments());

    // do we have any patches
    Set<AppliedPatchInfo> appliedPatches = AppliedPatches.getAppliedPatches();
    if (appliedPatches.size() > 0) {
        logMsg.outputHeader("Applied Patches");
        for (AppliedPatchInfo appliedPatch : appliedPatches) {
            logMsg.outputProperty(appliedPatch.getIssueKey(), appliedPatch.getDescription());
        }
    }
    logMsg.outputProperty("Java Compatibility Information", "JIRA version = " + buildUtilsInfo.getVersion()
            + ", Java Version = " + jiraSystemProperties.getProperty("java.version", STRANGELY_UNKNOWN));
}