Search in sources :

Example 1 with TomcatWebAppBuilder

use of org.apache.tomee.catalina.TomcatWebAppBuilder in project tomee by apache.

the class TomcatWebappDeployer method deploy.

@Override
public AppInfo deploy(final String host, final String context, final File file) {
    final TomcatWebAppBuilder tomcatWebAppBuilder = (TomcatWebAppBuilder) SystemInstance.get().getComponent(WebAppBuilder.class);
    final Collection<String> alreadyDeployed = tomcatWebAppBuilder.availableApps();
    final AppInfo appInfo = fakeInfo(file, host, context);
    appInfo.properties.setProperty("tomcat.unpackWar", "false");
    try {
        // classloader == null -> standalone war
        tomcatWebAppBuilder.deployWebApps(appInfo, null);
    } catch (final Exception e) {
        // tomcat lost the real exception (only in lifecycle exception string) so try to find it back
        final DeploymentExceptionManager dem = SystemInstance.get().getComponent(DeploymentExceptionManager.class);
        if (dem != null && dem.hasDeploymentFailed()) {
            Throwable lastException = dem.getLastException();
            // TODO: fix it, since we dont use this appInfo clean is ignored. Not a big deal while dem stores few exceptions only.
            dem.clearLastException(appInfo);
            if (TomEERuntimeException.class.isInstance(lastException)) {
                lastException = TomEERuntimeException.class.cast(lastException).getCause();
            }
            throw new OpenEJBRuntimeException(Exception.class.cast(lastException));
        }
        throw new OpenEJBRuntimeException(e);
    }
    TomcatWebAppBuilder.ContextInfo info = contextInfo(file);
    if (info == null) {
        // try another time doing a diff with apps before deployment and apps after
        final Collection<String> deployedNow = tomcatWebAppBuilder.availableApps();
        final Iterator<String> it = deployedNow.iterator();
        while (it.hasNext()) {
            if (alreadyDeployed.contains(it.next())) {
                it.remove();
            }
        }
        if (deployedNow.size() == 1) {
            info = contextInfo(new File(deployedNow.iterator().next()));
        }
    }
    if (info == null || info.appInfo == null) {
        LOGGER.error("Can't find of appInfo for " + (file != null ? file.getAbsolutePath() : null) + ", availables: " + tomcatWebAppBuilder.availableApps());
    }
    if (info == null) {
        // error
        return null;
    }
    return info.appInfo;
}
Also used : TomcatWebAppBuilder(org.apache.tomee.catalina.TomcatWebAppBuilder) TomcatWebAppBuilder(org.apache.tomee.catalina.TomcatWebAppBuilder) WebAppBuilder(org.apache.openejb.assembler.classic.WebAppBuilder) TomEERuntimeException(org.apache.tomee.catalina.TomEERuntimeException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) TomEERuntimeException(org.apache.tomee.catalina.TomEERuntimeException) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) File(java.io.File) DeploymentExceptionManager(org.apache.openejb.assembler.classic.DeploymentExceptionManager)

Example 2 with TomcatWebAppBuilder

use of org.apache.tomee.catalina.TomcatWebAppBuilder in project tomee by apache.

the class TomcatWsRegistry method createNewContext.

private static Context createNewContext(final ClassLoader classLoader, String authMethod, String transportGuarantee, final String realmName, final String name) {
    String path = name;
    if (path == null) {
        path = "/";
    }
    if (!path.startsWith("/")) {
        path = "/" + path;
    }
    final StandardContext context = new IgnoredStandardContext();
    context.setPath(path);
    context.setDocBase("");
    context.setParentClassLoader(classLoader);
    context.setDelegate(true);
    context.setName(name);
    ((TomcatWebAppBuilder) SystemInstance.get().getComponent(WebAppBuilder.class)).initJ2EEInfo(context);
    // Configure security
    if (authMethod != null) {
        authMethod = authMethod.toUpperCase();
    }
    if (transportGuarantee != null) {
        transportGuarantee = transportGuarantee.toUpperCase();
    }
    if (authMethod == null || "NONE".equals(authMethod)) {
    //NOPMD
    // ignore none for now as the  NonLoginAuthenticator seems to be completely hosed
    } else if ("BASIC".equals(authMethod) || "DIGEST".equals(authMethod) || "CLIENT-CERT".equals(authMethod)) {
        //Setup a login configuration
        final LoginConfig loginConfig = new LoginConfig();
        loginConfig.setAuthMethod(authMethod);
        loginConfig.setRealmName(realmName);
        context.setLoginConfig(loginConfig);
        //Setup a default Security Constraint
        final String securityRole = SystemInstance.get().getProperty(TOMEE_JAXWS_SECURITY_ROLE_PREFIX + name, "default");
        for (final String role : securityRole.split(",")) {
            final SecurityCollection collection = new SecurityCollection();
            collection.addMethod("GET");
            collection.addMethod("POST");
            collection.addPattern("/*");
            collection.setName(role);
            final SecurityConstraint sc = new SecurityConstraint();
            sc.addAuthRole("*");
            sc.addCollection(collection);
            sc.setAuthConstraint(true);
            sc.setUserConstraint(transportGuarantee);
            context.addConstraint(sc);
            context.addSecurityRole(role);
        }
        //Set the proper authenticator
        if ("BASIC".equals(authMethod)) {
            context.addValve(new BasicAuthenticator());
        } else if ("DIGEST".equals(authMethod)) {
            context.addValve(new DigestAuthenticator());
        } else if ("CLIENT-CERT".equals(authMethod)) {
            context.addValve(new SSLAuthenticator());
        } else if ("NONE".equals(authMethod)) {
            context.addValve(new NonLoginAuthenticator());
        }
        context.getPipeline().addValve(new OpenEJBValve());
    } else {
        throw new IllegalArgumentException("Invalid authMethod: " + authMethod);
    }
    return context;
}
Also used : TomcatWebAppBuilder(org.apache.tomee.catalina.TomcatWebAppBuilder) NonLoginAuthenticator(org.apache.catalina.authenticator.NonLoginAuthenticator) TomcatWebAppBuilder(org.apache.tomee.catalina.TomcatWebAppBuilder) WebAppBuilder(org.apache.openejb.assembler.classic.WebAppBuilder) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) IgnoredStandardContext(org.apache.tomee.catalina.IgnoredStandardContext) SSLAuthenticator(org.apache.catalina.authenticator.SSLAuthenticator) BasicAuthenticator(org.apache.catalina.authenticator.BasicAuthenticator) OpenEJBValve(org.apache.tomee.catalina.OpenEJBValve) DigestAuthenticator(org.apache.catalina.authenticator.DigestAuthenticator) IgnoredStandardContext(org.apache.tomee.catalina.IgnoredStandardContext) StandardContext(org.apache.catalina.core.StandardContext) LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection)

Example 3 with TomcatWebAppBuilder

use of org.apache.tomee.catalina.TomcatWebAppBuilder in project tomee by apache.

the class Deployer method deploy.

public static void deploy(final ServletContext ctx) {
    final TomcatWebAppBuilder builder = SystemInstance.get().getComponent(TomcatWebAppBuilder.class);
    builder.configureStart(null, StandardContext.class.cast(Reflections.get(Reflections.get(ctx, "context"), "context")));
}
Also used : TomcatWebAppBuilder(org.apache.tomee.catalina.TomcatWebAppBuilder) StandardContext(org.apache.catalina.core.StandardContext)

Aggregations

TomcatWebAppBuilder (org.apache.tomee.catalina.TomcatWebAppBuilder)3 StandardContext (org.apache.catalina.core.StandardContext)2 WebAppBuilder (org.apache.openejb.assembler.classic.WebAppBuilder)2 File (java.io.File)1 BasicAuthenticator (org.apache.catalina.authenticator.BasicAuthenticator)1 DigestAuthenticator (org.apache.catalina.authenticator.DigestAuthenticator)1 NonLoginAuthenticator (org.apache.catalina.authenticator.NonLoginAuthenticator)1 SSLAuthenticator (org.apache.catalina.authenticator.SSLAuthenticator)1 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)1 AppInfo (org.apache.openejb.assembler.classic.AppInfo)1 DeploymentExceptionManager (org.apache.openejb.assembler.classic.DeploymentExceptionManager)1 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)1 LoginConfig (org.apache.tomcat.util.descriptor.web.LoginConfig)1 SecurityCollection (org.apache.tomcat.util.descriptor.web.SecurityCollection)1 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)1 IgnoredStandardContext (org.apache.tomee.catalina.IgnoredStandardContext)1 OpenEJBValve (org.apache.tomee.catalina.OpenEJBValve)1 TomEERuntimeException (org.apache.tomee.catalina.TomEERuntimeException)1