Search in sources :

Example 1 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.

the class InplantedTest method testWeb.

@Test
public void testWeb() throws Exception {
    System.out.println("test web");
    File f = new File(System.getProperty("basedir"));
    f = new File(f, "target");
    f = new File(f, "test-classes");
    ScatteredArchive.Builder builder = new ScatteredArchive.Builder("hello", f);
    builder.addClassPath(f.toURI().toURL());
    builder.resources(f);
    ScatteredArchive war = builder.buildWar();
    System.out.println("War content");
    Enumeration<String> contents = war.entries();
    while (contents.hasMoreElements()) {
        System.out.println(contents.nextElement());
    }
    try {
        System.out.println("Port created " + server.createPort(14587));
        server.addContainer(ContainerBuilder.Type.web);
        server.start();
        DeployCommandParameters dp = new DeployCommandParameters(f);
        String appName = server.getDeployer().deploy(war, dp);
        System.out.println("Application deployed under name = " + appName);
        if (appName != null) {
            server.getDeployer().undeploy(appName, null);
        }
    } catch (IOException e) {
        // To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
    } catch (LifecycleException e) {
        // To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) Test(org.junit.Test)

Example 2 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.

the class InplantedTest method testWeb.

@Test
public void testWeb() throws Exception {
    System.out.println("test web");
    File f = new File(System.getProperty("basedir"));
    f = new File(f, "target");
    f = new File(f, "test-classes");
    ScatteredArchive.Builder builder = new ScatteredArchive.Builder("hello", f);
    builder.addClassPath(f.toURI().toURL());
    builder.resources(f);
    ScatteredArchive war = builder.buildWar();
    System.out.println("War content");
    Enumeration<String> contents = war.entries();
    while (contents.hasMoreElements()) {
        System.out.println(contents.nextElement());
    }
    Port http = server.createPort(8080);
    ContainerBuilder b = server.createConfig(ContainerBuilder.Type.web);
    server.addContainer(b);
    EmbeddedWebContainer embedded = (EmbeddedWebContainer) b.create(server);
    embedded.bind(http, "http");
    DeployCommandParameters dp = new DeployCommandParameters(f);
    String appName = server.getDeployer().deploy(war, dp);
    WebClient webClient = new WebClient();
    Page page = webClient.getPage("http://localhost:8080/test-classes/hello");
    System.out.println("Got response " + page.getWebResponse().getContentAsString());
    Assert.assertTrue("Servlet returned wrong content", page.getWebResponse().getContentAsString().startsWith("Hello World"));
    server.getDeployer().undeploy(appName, null);
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) EmbeddedWebContainer(org.glassfish.api.embedded.web.EmbeddedWebContainer) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Page(com.gargoylesoftware.htmlunit.Page) File(java.io.File) WebClient(com.gargoylesoftware.htmlunit.WebClient) Test(org.junit.Test)

Example 3 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.

the class ResourceValidator method loadOnCurrentInstance.

/**
 * Copy from ApplicationLifeCycle.java
 */
private boolean loadOnCurrentInstance() {
    final DeployCommandParameters commandParams = dc.getCommandParameters(DeployCommandParameters.class);
    final Properties appProps = dc.getAppProps();
    if (commandParams.enabled) {
        // if the current instance match with the target
        if (domain.isCurrentInstanceMatchingTarget(commandParams.target, commandParams.name(), server.getName(), dc.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class))) {
            return true;
        }
        if (server.isDas()) {
            String objectType = appProps.getProperty(ServerTags.OBJECT_TYPE);
            if (objectType != null) {
                // if it's a system application needs to be loaded on DAS
                if (objectType.equals(DeploymentProperties.SYSTEM_ADMIN) || objectType.equals(DeploymentProperties.SYSTEM_ALL)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties)

Example 4 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.

the class ResourceValidator method event.

@Override
public void event(Event event) {
    if (event.is(Deployment.AFTER_APPLICATION_CLASSLOADER_CREATION)) {
        dc = (DeploymentContext) event.hook();
        Application application = dc.getModuleMetaData(Application.class);
        DeployCommandParameters commandParams = dc.getCommandParameters(DeployCommandParameters.class);
        target = commandParams.target;
        if (System.getProperty("deployment.resource.validation", "true").equals("false")) {
            deplLogger.log(Level.INFO, SKIP_RESOURCE_VALIDATION);
            return;
        }
        if (application == null) {
            return;
        }
        AppResources appResources = new AppResources();
        // Puts all resouces found in the application via annotation or xml into appResources
        parseResources(application, appResources);
        // Ensure we have a valid component invocation before triggering lookups
        String componentId = null;
        for (BundleDescriptor bundleDescriptor : application.getBundleDescriptors()) {
            if (bundleDescriptor instanceof JndiNameEnvironment) {
                componentId = DOLUtils.getComponentEnvId((JndiNameEnvironment) bundleDescriptor);
                if (componentId != null) {
                    break;
                }
            }
        }
        contextUtil.setInstanceComponentId(componentId);
        try (Context ctx = contextUtil.pushContext()) {
            validateResources(application, appResources);
        }
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) Context(org.glassfish.internal.api.JavaEEContextUtil.Context) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) InitialContext(javax.naming.InitialContext) Application(com.sun.enterprise.deployment.Application)

Example 5 with DeployCommandParameters

use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.

the class HotDeployService method getApplicationState.

public Optional<ApplicationState> getApplicationState(DeploymentContext context) {
    DeployCommandParameters commandParams = context.getCommandParameters(DeployCommandParameters.class);
    boolean hotDeploy = commandParams != null ? commandParams.hotDeploy : false;
    return getApplicationState(hotDeploy, context.getSourceDir());
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters)

Aggregations

DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)69 IOException (java.io.IOException)25 File (java.io.File)24 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)24 ActionReport (org.glassfish.api.ActionReport)23 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)16 Application (com.sun.enterprise.deployment.Application)14 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)13 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)13 Logger (java.util.logging.Logger)12 Properties (java.util.Properties)10 DeploymentContextImpl (org.glassfish.deployment.common.DeploymentContextImpl)10 DeploymentException (org.glassfish.deployment.common.DeploymentException)10 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)10 ArchiveHandler (org.glassfish.api.deployment.archive.ArchiveHandler)9 VersioningSyntaxException (org.glassfish.deployment.versioning.VersioningSyntaxException)9 Deployment (org.glassfish.internal.deployment.Deployment)9 PropertyVetoException (java.beans.PropertyVetoException)8 URI (java.net.URI)8 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)8