Search in sources :

Example 21 with DomDocument

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;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) GlassFishDocument(org.glassfish.config.support.GlassFishDocument) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 22 with DomDocument

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);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ConfigParser(org.jvnet.hk2.config.ConfigParser) XMLInputFactory(javax.xml.stream.XMLInputFactory) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 23 with DomDocument

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);
    }
}
Also used : ConfigParser(org.jvnet.hk2.config.ConfigParser) URL(java.net.URL) PropertyVetoException(java.beans.PropertyVetoException) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 24 with DomDocument

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);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Dom(org.jvnet.hk2.config.Dom) ConfigParser(org.jvnet.hk2.config.ConfigParser) ServerDirs(com.sun.enterprise.util.io.ServerDirs) Domain(com.sun.enterprise.config.serverbeans.Domain) File(java.io.File) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) URL(java.net.URL) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 25 with DomDocument

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;
}
Also used : Dom(org.jvnet.hk2.config.Dom) ArrayList(java.util.ArrayList) ConfigParser(org.jvnet.hk2.config.ConfigParser) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) URL(java.net.URL) IOException(java.io.IOException) DomDocument(org.jvnet.hk2.config.DomDocument) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) PrivilegedAction(java.security.PrivilegedAction) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) Domain(com.sun.enterprise.config.serverbeans.Domain) File(java.io.File)

Aggregations

DomDocument (org.jvnet.hk2.config.DomDocument)25 ConfigModel (org.jvnet.hk2.config.ConfigModel)12 ConfigParser (org.jvnet.hk2.config.ConfigParser)12 URL (java.net.URL)8 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)7 IOException (java.io.IOException)6 ThreadFactory (java.util.concurrent.ThreadFactory)6 GlassFishDocument (org.glassfish.config.support.GlassFishDocument)6 Domain (com.sun.enterprise.config.serverbeans.Domain)5 Dom (org.jvnet.hk2.config.Dom)5 PropertyVetoException (java.beans.PropertyVetoException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)3 GET (javax.ws.rs.GET)3 Produces (javax.ws.rs.Produces)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 ResourcesGenerator (org.glassfish.admin.rest.generator.ResourcesGenerator)3 GlassFishConfigBean (org.glassfish.config.support.GlassFishConfigBean)3 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)3 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)3