Java Code Examples for org.apache.catalina.core.StandardContext#getServletContext()

The following examples show how to use org.apache.catalina.core.StandardContext#getServletContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationProcessor.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
public AnnotationProcessor(final StandardContext context) {
    servletContext = context.getServletContext();
    classLoader = servletContext.getClassLoader();
    try {
        pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
        consumesClass = (Class<Consumes>) classLoader.loadClass(Consumes.class.getName());
        producesClass = (Class<Produces>) classLoader.loadClass(Produces.class.getName());
        apiClazz= (Class<SwaggerDefinition>)classLoader.loadClass((SwaggerDefinition.class.getName()));
        infoClass = (Class<io.swagger.annotations.Info>)classLoader
                .loadClass((io.swagger.annotations.Info.class.getName()));
        tagClass = (Class<io.swagger.annotations.Tag>)classLoader
                .loadClass((io.swagger.annotations.Tag.class.getName()));
        extensionClass = (Class<io.swagger.annotations.Extension>)classLoader
                .loadClass((io.swagger.annotations.Extension.class.getName()));
        extensionPropertyClass = (Class<io.swagger.annotations.ExtensionProperty>)classLoader
                .loadClass(io.swagger.annotations.ExtensionProperty.class.getName());
        scopeClass = (Class<org.wso2.carbon.apimgt.annotations.api.Scope>) classLoader
                .loadClass(org.wso2.carbon.apimgt.annotations.api.Scope.class.getName());
        scopesClass = (Class<org.wso2.carbon.apimgt.annotations.api.Scopes>) classLoader
                .loadClass(org.wso2.carbon.apimgt.annotations.api.Scopes.class.getName());
        apiOperation = (Class<io.swagger.annotations.ApiOperation>)classLoader
                .loadClass((io.swagger.annotations.ApiOperation.class.getName()));
    } catch (ClassNotFoundException e) {
        log.error("An error has occurred while loading classes ", e);
    }
}
 
Example 2
Source File: AnnotationProcessor.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
public AnnotationProcessor(final StandardContext context) {
    servletContext = context.getServletContext();
    classLoader = servletContext.getClassLoader();
    try {
        pathClazz = (Class<Path>) classLoader.loadClass(Path.class.getName());
        consumesClass = (Class<Consumes>) classLoader.loadClass(Consumes.class.getName());
        producesClass = (Class<Produces>) classLoader.loadClass(Produces.class.getName());
        apiClazz= (Class<SwaggerDefinition>)classLoader.loadClass((SwaggerDefinition.class.getName()));
        apiOperation = (Class<io.swagger.annotations.ApiOperation>)classLoader
                .loadClass((io.swagger.annotations.ApiOperation.class.getName()));
        authorizationClass = (Class<io.swagger.annotations.Authorization>)classLoader
                .loadClass((io.swagger.annotations.Authorization.class.getName()));
        authorizationScopeClass = (Class<io.swagger.annotations.AuthorizationScope>)classLoader
                .loadClass((io.swagger.annotations.AuthorizationScope.class.getName()));
        extensionClass = (Class<io.swagger.annotations.Extension>)classLoader
                .loadClass((io.swagger.annotations.Extension.class.getName()));
        extensionPropertyClass = (Class<io.swagger.annotations.ExtensionProperty>)classLoader
                .loadClass(io.swagger.annotations.ExtensionProperty.class.getName());
        scopeClass = (Class<org.wso2.carbon.apimgt.annotations.api.Scope>) classLoader
                .loadClass(org.wso2.carbon.apimgt.annotations.api.Scope.class.getName());
        scopesClass = (Class<org.wso2.carbon.apimgt.annotations.api.Scopes>) classLoader
                .loadClass(org.wso2.carbon.apimgt.annotations.api.Scopes.class.getName());

    } catch (ClassNotFoundException e) {
        log.error("An error has occurred while loading classes ", e);
    }
}
 
Example 3
Source File: TomcatWebAppBuilder.java    From tomee with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void beforeStart(final StandardContext standardContext) {
    if (standardContext.getResources() != null && LazyStopStandardRoot.class.isInstance(standardContext.getResources())) {
        // reset after reload
        Reflections.set(standardContext, "resources",  LazyStopStandardRoot.class.cast(standardContext.getResources()).getDelegate());
    }

    final ServletContext sc = standardContext.getServletContext();
    if (sc != null && !SystemInstance.get().getOptions().get(OPENEJB_JSESSION_ID_SUPPORT, true)) {
        final Set<SessionTrackingMode> defaultTrackingModes = sc.getEffectiveSessionTrackingModes();
        if (defaultTrackingModes.contains(SessionTrackingMode.URL)) {
            final Set<SessionTrackingMode> newModes = new HashSet<>();
            newModes.remove(SessionTrackingMode.URL);
            sc.setSessionTrackingModes(newModes);
        }
    }
    initContextLoader(standardContext);

    // used to add custom filters first - our arquillian integration uses it for instance
    // needs to be done now (= before start event) because of addFilterMapBefore() usage
    final String filters = SystemInstance.get().getProperty("org.apache.openejb.servlet.filters");
    if (filters != null) {
        final String[] names = filters.split(",");
        for (final String name : names) {
            final String[] clazzMapping = name.split("=");

            final FilterDef filterDef = new FilterDef();
            filterDef.setFilterClass(clazzMapping[0]);
            filterDef.setFilterName(clazzMapping[0]);
            standardContext.addFilterDef(filterDef);

            final FilterMap filterMap = new FilterMap();
            filterMap.setFilterName(clazzMapping[0]);
            filterMap.addURLPattern(clazzMapping[1]);
            standardContext.addFilterMapBefore(filterMap);
        }
    }

    // mainly to get back compatibility with tomcat <= 8.0
    final String cookieProcessor = SystemInstance.get().getProperty("tomee.tomcat.cookieProcessor");
    if (cookieProcessor != null) {
        // not that important for now if we use the container loader, we mainly want to be able to access
        // the legacy one
        final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            final Class<?> cookieProcessorClass = contextClassLoader.loadClass(cookieProcessor.trim());
            standardContext.setCookieProcessor(CookieProcessor.class.cast(cookieProcessorClass.newInstance()));
        } catch (final Exception e) {
            throw new IllegalArgumentException("Cannot set CookieProcessor: " + cookieProcessor);
        }
    }
}