use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class EventsTest method getDocument.
@Override
public DomDocument getDocument(ServiceLocator habitat) {
DomDocument doc = habitat.getService(GlassFishDocument.class);
if (doc == null) {
return new GlassFishDocument(habitat, Executors.newCachedThreadPool(new ThreadFactory() {
public Thread newThread(Runnable r) {
Thread t = Executors.defaultThreadFactory().newThread(r);
t.setDaemon(true);
return t;
}
}));
}
return doc;
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class Utils method getServiceLocator.
public static ServiceLocator getServiceLocator(final InputStream inputStream, String name) {
try {
final ServiceLocator habitat = getNewServiceLocator(name);
final ConfigParser parser = new ConfigParser(habitat);
XMLInputFactory xif = XMLInputFactory.class.getClassLoader() == null ? XMLInputFactory.newFactory() : XMLInputFactory.newFactory(XMLInputFactory.class.getName(), XMLInputFactory.class.getClassLoader());
final DomDocument document = parser.parse(xif.createXMLStreamReader(inputStream));
ServiceLocatorUtilities.addOneConstant(habitat, document);
return habitat;
} catch (Exception e) {
e.printStackTrace();
throw new GrizzlyConfigException(e.getMessage(), e);
}
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class ConfigDisposalTest method parseDomainXml.
public void parseDomainXml() {
ConfigParser parser = new ConfigParser(habitat);
URL url = ConfigDisposalTest.class.getResource("/domain.xml");
System.out.println("URL : " + url);
try {
DomDocument doc = parser.parse(url, new SimpleDocument(habitat));
System.out.println("[parseDomainXml] ==> Successfully parsed");
assert (doc != null);
} catch (Exception ex) {
ex.printStackTrace();
assert (false);
}
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class SecureAdminClientManager method prepareDomain.
private Domain prepareDomain(final String serverName, final String nodeDir, final String node, final File nodeDirRoot) {
/*
* At least one of serverName, nodeDir, or node must be non-null.
* Otherwise we'll have no way of figuring out which domain.xml to
* look in to see if we should use client authentication. This will
* often be the case, for instance, if create-local-instance is
* run directly (not from another command). In such cases, if
* secure admin is enabled the user should provide --user and
* --passwordfile on the command line to authenticate to the DAS.
*/
if (serverName == null && nodeDir == null && node == null) {
return null;
}
final ServerDirsSelector selector;
try {
final String nodeDirToUse = (nodeDir != null ? nodeDir : nodeDirRoot.getAbsolutePath());
selector = ServerDirsSelector.getInstance(null, serverName, nodeDirToUse, node);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
/*
* If the caller did not pass any of the values we can use to locate
* the domain.xml, then we cannot run in client-cert mode.
*/
final ServerDirs dirs = selector.dirs();
if (dirs == null) {
return null;
}
final File domainXMLFile = dirs.getDomainXml();
if (!domainXMLFile.exists()) {
return null;
}
try {
ServiceLocator habitat = Globals.getStaticHabitat();
ConfigParser parser = new ConfigParser(habitat);
URL domainURL = domainXMLFile.toURI().toURL();
DomDocument doc = parser.parse(domainURL);
Dom domDomain = doc.getRoot();
Domain d = domDomain.createProxy(Domain.class);
return d;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.jvnet.hk2.config.DomDocument in project Payara by payara.
the class VerifyDomainXmlCommand method executeCommand.
/**
*/
@Override
protected int executeCommand() throws CommandException, CommandValidationException {
File domainXMLFile = getDomainXml();
logger.log(Level.FINER, "Domain XML file = {0}", domainXMLFile);
try {
// get the list of JAR files from the modules directory
ArrayList<URL> urls = new ArrayList<URL>();
File idir = new File(System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
File mdir = new File(idir, "modules");
for (File f : mdir.listFiles()) {
if (f.toString().endsWith(".jar")) {
urls.add(f.toURI().toURL());
}
}
final URL[] urlsA = urls.toArray(new URL[urls.size()]);
ClassLoader cl = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {
@Override
public Object run() {
return new URLClassLoader(urlsA, Globals.class.getClassLoader());
}
});
ModulesRegistry registry = new StaticModulesRegistry(cl);
ServiceLocator serviceLocator = registry.createServiceLocator("default");
ConfigParser parser = new ConfigParser(serviceLocator);
URL domainURL = domainXMLFile.toURI().toURL();
DomDocument doc = parser.parse(domainURL);
Dom domDomain = doc.getRoot();
Domain domain = domDomain.createProxy(Domain.class);
DomainXmlVerifier validator = new DomainXmlVerifier(domain);
if (validator.invokeConfigValidator())
return 1;
} catch (Exception e) {
throw new CommandException(e);
}
return 0;
}
Aggregations