use of com.sun.enterprise.universal.glassfish.ASenvPropertyReader in project Payara by payara.
the class DomainDirs method getDefaultDomainsDir.
public static File getDefaultDomainsDir() throws IOException {
Map<String, String> systemProps = new ASenvPropertyReader().getProps();
String defDomains = systemProps.get(SystemPropertyConstants.DOMAINS_ROOT_PROPERTY);
if (defDomains == null)
throw new IOException(strings.get("Domain.noDomainsDir", SystemPropertyConstants.DOMAINS_ROOT_PROPERTY));
return new File(defDomains);
}
use of com.sun.enterprise.universal.glassfish.ASenvPropertyReader in project Payara by payara.
the class DomainBuilder method initialize.
/**
* Initialize template by loading template jar.
*
* @throws DomainException If exception occurs in initializing the template jar.
*/
// TODO : localization of index.html
private void initialize() throws DomainException {
String templateJarPath = (String) _domainConfig.get(DomainConfig.K_TEMPLATE_NAME);
if (templateJarPath == null || templateJarPath.isEmpty()) {
String defaultTemplateName = Version.getDefaultDomainTemplate();
if (defaultTemplateName == null || defaultTemplateName.isEmpty()) {
throw new DomainException(_strings.get("missingDefaultTemplateName"));
}
Map<String, String> envProperties = new ASenvPropertyReader().getProps();
templateJarPath = envProperties.get(SystemPropertyConstants.INSTALL_ROOT_PROPERTY) + File.separator + DEFAULT_TEMPLATE_RELATIVE_PATH + File.separator + defaultTemplateName;
}
File template = new File(templateJarPath);
if (!template.exists() || !template.getName().endsWith(".jar")) {
throw new DomainException(_strings.get("invalidTemplateJar", template.getAbsolutePath()));
}
try {
_templateJar = new JarFile(new File(templateJarPath));
JarEntry je = _templateJar.getJarEntry("config/" + DomainConstants.DOMAIN_XML_FILE);
if (je == null) {
throw new DomainException(_strings.get("missingMandatoryFile", DomainConstants.DOMAIN_XML_FILE));
}
// Loads template-info.xml
je = _templateJar.getJarEntry(TEMPLATE_INFO_XML);
if (je == null) {
throw new DomainException(_strings.get("missingMandatoryFile", TEMPLATE_INFO_XML));
}
TemplateInfoHolder templateInfoHolder = new TemplateInfoHolder(_templateJar.getInputStream(je), templateJarPath);
_extractedEntries.add(TEMPLATE_INFO_XML);
// Loads string substitution XML.
je = _templateJar.getJarEntry(STRINGSUBS_FILE);
StringSubstitutor stringSubstitutor = null;
if (je != null) {
stringSubstitutor = StringSubstitutionFactory.createStringSubstitutor(_templateJar.getInputStream(je));
List<Property> defaultStringSubsProps = stringSubstitutor.getDefaultProperties(PropertyType.PORT);
for (Property prop : defaultStringSubsProps) {
_defaultPortValues.setProperty(prop.getKey(), prop.getValue());
}
_extractedEntries.add(je.getName());
} else {
_logger.log(Level.WARNING, SLogger.MISSING_FILE, STRINGSUBS_FILE);
}
_domainTempalte = new DomainTemplate(templateInfoHolder, stringSubstitutor, templateJarPath);
// Loads default self signed certificate.
je = _templateJar.getJarEntry("config/" + DomainConstants.KEYSTORE_FILE);
if (je != null) {
_keystoreBytes = new byte[(int) je.getSize()];
InputStream in = null;
int count = 0;
try {
in = _templateJar.getInputStream(je);
count = in.read(_keystoreBytes);
if (count < _keystoreBytes.length) {
throw new DomainException(_strings.get("loadingFailure", je.getName()));
}
} finally {
if (in != null) {
in.close();
}
}
_extractedEntries.add(je.getName());
}
File parentDomainDir = FileUtils.safeGetCanonicalFile(new File(_domainConfig.getRepositoryRoot()));
createDirectory(parentDomainDir);
} catch (Exception e) {
throw new DomainException(e);
}
}
use of com.sun.enterprise.universal.glassfish.ASenvPropertyReader in project Payara by payara.
the class ServerEnvironmentImpl method postConstruct.
/**
* This is where the real initialization happens.
*/
@Override
public void postConstruct() {
// todo : dochez : this will need to be reworked...
String installRoot = startupContext.getArguments().getProperty(INSTALL_ROOT_PROP_NAME);
if (installRoot == null) {
// I am setting user.dir as installRoot.
if (System.getProperty(INSTALL_ROOT_PROP_NAME) != null) {
installRoot = System.getProperty(INSTALL_ROOT_PROP_NAME);
} else {
installRoot = System.getProperty("user.dir");
}
}
asenv = new ASenvPropertyReader(new File(installRoot));
// default
if (this.root == null) {
String envVar = System.getProperty(INSTANCE_ROOT_PROP_NAME);
if (envVar != null) {
root = new File(envVar);
} else {
String instanceRoot = startupContext.getArguments().getProperty(INSTANCE_ROOT_PROP_NAME);
if (instanceRoot == null) {
// In client container, instanceRoot is not set. It is a different question altogether as to why
// an object called ServerEnvironmentImpl is at all active in client runtime. To be consistent
// with earlier code, we use installRoot as instanceRoot.
instanceRoot = installRoot;
}
root = new File(instanceRoot);
}
}
/*
* bnevins 12/12/11
* The following chunk of code sets things like hostname to be a file under instance root
* I.e. it's crazy. It's 1 hour until SCF so I'll just fix the current problem which is a NPE
* if the value is null.
* At any rate the weird values that get set into System Properties get un-done at
* the line of code in bootstrap (see end of this comment). It's easy to trace just step out of this method
* in a debugger
* createGlassFish(gfKernel, habitat, gfProps.getProperties())
*/
asenv.getProps().put(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY, root.getAbsolutePath());
for (Map.Entry<String, String> entry : asenv.getProps().entrySet()) {
if (// don't NPE File ctor
entry.getValue() == null)
continue;
File location = new File(entry.getValue());
if (!location.isAbsolute()) {
location = new File(asenv.getProps().get(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY), entry.getValue());
}
System.setProperty(entry.getKey(), location.getAbsolutePath());
}
Properties args = startupContext.getArguments();
verbose = Boolean.parseBoolean(args.getProperty("-verbose"));
debug = Boolean.parseBoolean(args.getProperty("-debug"));
// ugly code because domainName & instanceName are final...
String s = args.getProperty("-domainname");
if (!ok(s)) {
s = root.getName();
}
domainName = s;
s = args.getProperty("-instancename");
if (!ok(s)) {
instanceName = "server";
} else {
instanceName = s;
}
// bnevins IT 10209
asenv.getProps().put(SystemPropertyConstants.SERVER_NAME, instanceName);
System.setProperty(SystemPropertyConstants.SERVER_NAME, instanceName);
// Put right the hostName that was probably broken earlier
s = asenv.getProps().get(SystemPropertyConstants.HOST_NAME_PROPERTY);
if (ok(s)) {
System.setProperty(SystemPropertyConstants.HOST_NAME_PROPERTY, s);
}
// bnevins Apr 2010 adding clustering support...
String typeString = args.getProperty("-type");
serverType = RuntimeType.getDefault();
try {
if (typeString != null)
serverType = RuntimeType.valueOf(typeString);
} catch (Exception e) {
// already handled above...
}
}
use of com.sun.enterprise.universal.glassfish.ASenvPropertyReader in project Payara by payara.
the class GFLauncher method setup.
public void setup() throws GFLauncherException, MiniXmlParserException {
ASenvPropertyReader pr;
if (isFakeLaunch()) {
pr = new ASenvPropertyReader(info.getInstallDir());
} else {
pr = new ASenvPropertyReader();
}
asenvProps = pr.getProps();
info.setup();
setupLogLevels();
MiniXmlParser parser = new MiniXmlParser(getInfo().getConfigFile(), getInfo().getInstanceName());
String domainName = parser.getDomainName();
if (GFLauncherUtils.ok(domainName)) {
info.setDomainName(domainName);
}
info.setAdminAddresses(parser.getAdminAddresses());
javaConfig = new JavaConfig(parser.getJavaConfig());
setupProfilerAndJvmOptions(parser);
setupUpgradeSecurity();
Map<String, String> realmprops = parser.getAdminRealmProperties();
if (realmprops != null) {
String classname = realmprops.get("classname");
String keyfile = realmprops.get("file");
if ("com.sun.enterprise.security.auth.realm.file.FileRealm".equals(classname) && keyfile != null) {
adminFileRealmKeyFile = keyfile;
}
}
secureAdminEnabled = parser.getSecureAdminEnabled();
renameOsgiCache();
setupMonitoring(parser);
sysPropsFromXml = parser.getSystemProperties();
asenvProps.put(INSTANCE_ROOT_PROPERTY, getInfo().getInstanceRootDir().getPath());
// Set the config java-home value as the Java home for the environment,
// unless it is empty or it is already refering to a substitution of
// the environment variable.
String jhome = javaConfig.getJavaHome();
if (GFLauncherUtils.ok(jhome) && !jhome.trim().equals("${" + JAVA_ROOT_PROPERTY + "}")) {
asenvProps.put(JAVA_ROOT_PROPERTY, jhome);
}
debugOptions = getDebug();
parseDebug();
parser.setupConfigDir(getInfo().getConfigDir(), getInfo().getInstallDir());
setLogFilename(parser);
resolveAllTokens();
fixLogFilename();
GFLauncherLogger.addLogFileHandler(logFilename, info);
setJavaExecutable();
setClasspath();
setCommandLine();
setJvmOptions();
logCommandLine();
// if no <network-config> element, we need to upgrade this domain
needsAutoUpgrade = !parser.hasNetworkConfig();
needsManualUpgrade = !parser.hasDefaultConfig();
setupCalledByClients = true;
}
Aggregations