Search in sources :

Example 16 with GlassFishException

use of org.glassfish.embeddable.GlassFishException in project Payara by payara.

the class PayaraMicroImpl method packageUberJar.

private void packageUberJar() {
    UberJarCreator creator = new UberJarCreator(uberJar);
    if (rootDir != null) {
        creator.setDomainDir(rootDir);
    }
    if (postBootFileName != null) {
        creator.setPostBootCommands(new File(postBootFileName));
    }
    if (preBootFileName != null) {
        creator.setPreBootCommands(new File(preBootFileName));
    }
    if (postDeployFileName != null) {
        creator.setPostDeployCommands(new File(postDeployFileName));
    }
    if (logPropertiesFile) {
        creator.setLoggingPropertiesFile(new File(userLogPropertiesFile));
    }
    if (deployments != null) {
        for (File deployment : deployments) {
            creator.addDeployment(deployment);
        }
    }
    if (libraries != null) {
        for (File lib : libraries) {
            creator.addLibraryJar(lib);
        }
    }
    if (deploymentRoot != null) {
        creator.setDeploymentDir(deploymentRoot);
    }
    if (copyDirectory != null) {
        creator.setDirectoryToCopy(copyDirectory);
    }
    if (GAVs != null) {
        try {
            // Convert the provided GAV Strings into target URLs
            getGAVURLs();
            for (Map.Entry<String, URL> deploymentMapEntry : deploymentURLsMap.entrySet()) {
                URL deployment = deploymentMapEntry.getValue();
                String name = deploymentMapEntry.getKey();
                creator.addDeployment(name, deployment);
            }
        } catch (GlassFishException ex) {
            LOGGER.log(Level.SEVERE, "Unable to process maven deployment units", ex);
        }
    }
    // write the system properties file
    Properties props = new Properties();
    if (hzMulticastGroup != null) {
        props.setProperty("payaramicro.mcAddress", hzMulticastGroup);
    }
    if (hzPort != Integer.MIN_VALUE) {
        props.setProperty("payaramicro.mcPort", Integer.toString(hzPort));
    }
    if (instanceName != null) {
        props.setProperty("payaramicro.name", instanceName);
    }
    if (instanceGroup != null) {
        props.setProperty("payaramicro.instanceGroup", instanceGroup);
    }
    if (hzStartPort != Integer.MIN_VALUE) {
        props.setProperty("payaramicro.startPort", Integer.toString(hzStartPort));
    }
    if (rootDir != null) {
        props.setProperty("payaramicro.rootDir", rootDir.getAbsolutePath());
    }
    if (alternateDomainXML != null) {
        props.setProperty("payaramicro.domainConfig", "MICRO-INF/domain/domain.xml");
    }
    if (minHttpThreads != Integer.MIN_VALUE) {
        props.setProperty("payaramicro.minHttpThreads", Integer.toString(minHttpThreads));
    }
    if (maxHttpThreads != Integer.MIN_VALUE) {
        props.setProperty("payaramicro.maxHttpThreads", Integer.toString(maxHttpThreads));
    }
    if (alternateHZConfigFile != null) {
        props.setProperty("payaramicro.hzConfigFile", "MICRO-INF/domain/hzconfig.xml");
    }
    if (hzClusterName != null) {
        props.setProperty("payaramicro.clusterName", hzClusterName);
    }
    if (hzClusterPassword != null) {
        props.setProperty("payaramicro.clusterPassword", hzClusterPassword);
    }
    if (clustermode != null) {
        props.setProperty("payaramicro.clusterMode", clustermode);
    }
    if (interfaces != null) {
        props.setProperty("payaramicro.interfaces", interfaces);
    }
    if (secretsDir != null) {
        props.setProperty("payaramicro.secretsDir", secretsDir);
    }
    if (sslCert != null) {
        props.setProperty("payaramicro.sslCert", sslCert);
    }
    props.setProperty("payaramicro.autoBindHttp", Boolean.toString(autoBindHttp));
    props.setProperty("payaramicro.autoBindSsl", Boolean.toString(autoBindSsl));
    props.setProperty("payaramicro.autoBindRange", Integer.toString(autoBindRange));
    props.setProperty("payaramicro.lite", Boolean.toString(liteMember));
    props.setProperty("payaramicro.enableHealthCheck", Boolean.toString(enableHealthCheck));
    props.setProperty("payaramicro.logo", Boolean.toString(generateLogo));
    props.setProperty("payaramicro.logToFile", Boolean.toString(logToFile));
    props.setProperty("payaramicro.enableAccessLog", Boolean.toString(enableAccessLog));
    props.setProperty("payaramicro.enableAccessLogFormat", Boolean.toString(enableAccessLogFormat));
    props.setProperty("payaramicro.logPropertiesFile", Boolean.toString(logPropertiesFile));
    props.setProperty("payaramicro.noCluster", Boolean.toString(noCluster));
    props.setProperty("payaramicro.hostAware", Boolean.toString(hostAware));
    props.setProperty("payaramicro.disablePhoneHome", Boolean.toString(disablePhoneHome));
    props.setProperty("payaramicro.showServletMappings", Boolean.toString(showServletMappings));
    if (userLogFile != null) {
        props.setProperty("payaramicro.userLogFile", userLogFile);
    }
    if (httpPort != Integer.MIN_VALUE) {
        props.setProperty("payaramicro.port", Integer.toString(httpPort));
    }
    if (sslPort != Integer.MIN_VALUE) {
        props.setProperty("payaramicro.sslPort", Integer.toString(sslPort));
    }
    if (enableRequestTracing) {
        props.setProperty("payaramicro.enableRequestTracing", Boolean.toString(enableRequestTracing));
    }
    if (!requestTracingThresholdUnit.equals("SECONDS")) {
        props.setProperty("payaramicro.requestTracingThresholdUnit", requestTracingThresholdUnit);
    }
    if (requestTracingThresholdValue != 30) {
        props.setProperty("payaramicro.requestTracingThresholdValue", Long.toString(requestTracingThresholdValue));
    }
    if (enableRequestTracingAdaptiveSampling) {
        props.setProperty("payaramicro.enableRequestTracingAdaptiveSampling", Boolean.toString(enableRequestTracingAdaptiveSampling));
    }
    if (requestTracingAdaptiveSamplingTargetCount != 12) {
        props.setProperty("payaramicro.requestTracingAdaptiveSamplingTargetCount", Integer.toString(requestTracingAdaptiveSamplingTargetCount));
    }
    if (requestTracingAdaptiveSamplingTimeValue != 1) {
        props.setProperty("payaramicro.requestTracingAdaptiveSamplingTimeValue", Integer.toString(requestTracingAdaptiveSamplingTimeValue));
    }
    if (!requestTracingAdaptiveSamplingTimeUnit.equals("MINUTES")) {
        props.setProperty("payaramicro.requestTracingAdaptiveSamplingTimeUnit", requestTracingAdaptiveSamplingTimeUnit);
    }
    // write all user defined system properties
    if (userSystemProperties != null) {
        Enumeration<String> names = (Enumeration<String>) userSystemProperties.propertyNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement();
            props.setProperty(name, userSystemProperties.getProperty(name));
        }
    }
    creator.addBootProperties(props);
    // add the alternate domain.xml file if present
    if (alternateDomainXML != null && alternateDomainXML.isFile() && alternateDomainXML.canRead()) {
        creator.setDomainXML(alternateDomainXML);
    }
    // add the alternate hazelcast config to the uberJar
    if (alternateHZConfigFile != null) {
        creator.setAlternateHZConfigFile(alternateHZConfigFile);
    }
    creator.buildUberJar();
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) Enumeration(java.util.Enumeration) BootstrapProperties(org.glassfish.embeddable.BootstrapProperties) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Properties(java.util.Properties) JarFile(java.util.jar.JarFile) File(java.io.File) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) URL(java.net.URL)

Example 17 with GlassFishException

use of org.glassfish.embeddable.GlassFishException in project Payara by payara.

the class EmbeddedTest method setup.

@BeforeClass
public static void setup() throws GlassFishException {
    glassfish = GlassFishRuntime.bootstrap().newGlassFish();
    glassfish.start();
    WebContainer webcontainer = glassfish.getService(WebContainer.class);
    Collection<WebListener> listeners = webcontainer.getWebListeners();
    System.out.println("Network listener size before creation " + listeners.size());
    for (WebListener listener : listeners) {
        System.out.println("Network listener " + listener.getPort());
    }
    try {
        HttpListener listener = new HttpListener();
        listener.setPort(8080);
        listener.setId("embedded-listener-1");
        webcontainer.addWebListener(listener);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    listeners = webcontainer.getWebListeners();
    System.out.println("Network listener size after creation " + listeners.size());
    Assert.assertTrue(listeners.size() == 1);
    for (WebListener listener : listeners) {
        System.out.println("Network listener " + listener.getPort());
    }
}
Also used : WebListener(org.glassfish.embeddable.web.WebListener) WebContainer(org.glassfish.embeddable.web.WebContainer) HttpListener(org.glassfish.embeddable.web.HttpListener) GlassFishException(org.glassfish.embeddable.GlassFishException) NamingException(javax.naming.NamingException) BeforeClass(org.junit.BeforeClass)

Example 18 with GlassFishException

use of org.glassfish.embeddable.GlassFishException in project Payara by payara.

the class GlassFishSecurityProvider method authenticate.

@Override
public Object authenticate(String username, String password) {
    gf = getGlassFish();
    AuthenticationService authService = null;
    try {
        authService = getAuthService();
    } catch (GlassFishException gfe) {
        gfe.printStackTrace();
        return null;
    }
    Subject fs = null;
    try {
        fs = authService.login(username, password.toCharArray(), fs);
    } catch (LoginException e) {
        e.printStackTrace();
        return null;
    }
    return fs;
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) LoginException(javax.security.auth.login.LoginException) AuthenticationService(org.glassfish.security.services.api.authentication.AuthenticationService) Subject(javax.security.auth.Subject)

Example 19 with GlassFishException

use of org.glassfish.embeddable.GlassFishException in project Payara by payara.

the class VerifierMain method main.

public static void main(String[] args) throws GlassFishException, IOException {
    VerifierFrameworkContext verifierFrameworkContext = new Initializer(args).getVerificationContext();
    // Since in gui mode, we don't get a chance to clean up, we need to install a shutdown hook
    addShutdownHook();
    gfr = GlassFishRuntime.bootstrap();
    GlassFishProperties gfp = new GlassFishProperties();
    gfp.setProperty(StartupContext.TIME_ZERO_NAME, (new Long(System.currentTimeMillis())).toString());
    final String VERIFIER_MODULE = "org.glassfish.verifier";
    gfp.setProperty(StartupContext.STARTUP_MODULE_NAME, VERIFIER_MODULE);
    // gfp.setConfigFileURI("file:/tmp/domain.xml");
    GlassFish gf = gfr.newGlassFish(gfp);
    gf.start();
    int failedCount = -1;
    Verifier verifier = gf.getService(Verifier.class);
    if (verifierFrameworkContext.isUsingGui()) {
        MainFrame mf = new MainFrame(verifierFrameworkContext.getJarFileName(), true, verifier);
        mf.setSize(800, 600);
        mf.setVisible(true);
    } else {
        LocalStringManagerImpl smh = StringManagerHelper.getLocalStringsManager();
        try {
            verifier.init(verifierFrameworkContext);
            verifier.verify();
        } catch (Exception e) {
            LogRecord logRecord = new LogRecord(Level.SEVERE, smh.getLocalString(verifier.getClass().getName() + // NOI18N
            ".verifyFailed", // NOI18N
            "Could not verify successfully."));
            logRecord.setThrown(e);
            verifierFrameworkContext.getResultManager().log(logRecord);
        }
        verifier.generateReports();
        failedCount = verifierFrameworkContext.getResultManager().getFailedCount() + verifierFrameworkContext.getResultManager().getErrorCount();
        System.exit(failedCount);
    }
}
Also used : LocalStringManagerImpl(com.sun.enterprise.util.LocalStringManagerImpl) LogRecord(java.util.logging.LogRecord) GlassFish(org.glassfish.embeddable.GlassFish) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) MainFrame(com.sun.enterprise.tools.verifier.gui.MainFrame) GlassFishException(org.glassfish.embeddable.GlassFishException) IOException(java.io.IOException)

Example 20 with GlassFishException

use of org.glassfish.embeddable.GlassFishException in project Payara by payara.

the class VirtualServer method removeContext.

/**
 * Stops the given <tt>context</tt> and removes it from this
 * <tt>VirtualServer</tt>.
 * @throws org.glassfish.embeddable.GlassFishException
 */
@Override
public void removeContext(Context context) throws GlassFishException {
    ActionReport report = services.getService(ActionReport.class, "plain");
    Deployment deployment = services.getService(Deployment.class);
    String name;
    if (context instanceof ContextFacade) {
        name = ((ContextFacade) context).getAppName();
    } else {
        name = context.getPath();
    }
    ApplicationInfo appInfo = deployment.get(name);
    if (appInfo == null) {
        report.setMessage("Cannot find deployed application of name " + name);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        throw new GlassFishException("Cannot find deployed application of name " + name);
    }
    ReadableArchive source = appInfo.getSource();
    if (source == null) {
        report.setMessage("Cannot get source archive for undeployment");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        throw new GlassFishException("Cannot get source archive for undeployment");
    }
    UndeployCommandParameters params = new UndeployCommandParameters(name);
    params.origin = UndeployCommandParameters.Origin.undeploy;
    params.target = "server";
    ExtendedDeploymentContext deploymentContext = null;
    try {
        deploymentContext = deployment.getBuilder(_logger, params, report).source(source).build();
        deployment.undeploy(name, deploymentContext);
        deployment.unregisterAppFromDomainXML(name, "server");
    } catch (IOException e) {
        _logger.log(Level.SEVERE, LogFacade.REMOVE_CONTEXT_ERROR, e);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        throw new GlassFishException("Cannot create context for undeployment ", e);
    } catch (TransactionFailure e) {
        throw new GlassFishException(e);
    } finally {
        if (deploymentContext != null) {
            deploymentContext.clean();
        }
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, LogFacade.REMOVED_CONTEXT, name);
    }
}
Also used : GlassFishException(org.glassfish.embeddable.GlassFishException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) Deployment(org.glassfish.internal.deployment.Deployment) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext)

Aggregations

GlassFishException (org.glassfish.embeddable.GlassFishException)25 File (java.io.File)7 IOException (java.io.IOException)5 URL (java.net.URL)5 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)5 Properties (java.util.Properties)4 NamingException (javax.naming.NamingException)4 ActionReport (org.glassfish.api.ActionReport)3 BootstrapProperties (org.glassfish.embeddable.BootstrapProperties)3 BundleException (org.osgi.framework.BundleException)3 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)2 ModuleStartup (com.sun.enterprise.module.bootstrap.ModuleStartup)2 StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)2 BindException (java.net.BindException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 CommandException (org.glassfish.api.admin.CommandException)2