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();
}
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());
}
}
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;
}
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);
}
}
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);
}
}
Aggregations