Search in sources :

Example 11 with ConfigParser

use of org.jvnet.hk2.config.ConfigParser 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 12 with ConfigParser

use of org.jvnet.hk2.config.ConfigParser 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 13 with ConfigParser

use of org.jvnet.hk2.config.ConfigParser 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 14 with ConfigParser

use of org.jvnet.hk2.config.ConfigParser 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)

Example 15 with ConfigParser

use of org.jvnet.hk2.config.ConfigParser in project Payara by payara.

the class DomainXml method run.

@Override
public void run(ConfigParser parser) throws ConfigPopulatorException {
    LogRecord lr = new LogRecord(Level.FINE, startupClass + this.getClass().getName());
    lr.setLoggerName(getClass().getName());
    EarlyLogHandler.earlyMessages.add(lr);
    ClassLoader parentClassLoader = (registry == null) ? getClass().getClassLoader() : registry.getParentClassLoader();
    if (parentClassLoader == null)
        parentClassLoader = getClass().getClassLoader();
    ServiceLocatorUtilities.addOneConstant(habitat, parentClassLoader, null, ClassLoader.class);
    try {
        parseDomainXml(parser, getDomainXml(env), env.getInstanceName());
    } catch (IOException e) {
        throw new ConfigPopulatorException(localStrings.getLocalString("ConfigParsingFailed", "Failed to parse domain.xml"), e);
    }
    // run the upgrades...
    if ("upgrade".equals(context.getPlatformMainServiceName())) {
        upgrade();
    }
    // run the cleanup.
    for (ServiceHandle<?> cc : habitat.getAllServiceHandles(ConfigurationCleanup.class)) {
        try {
            // run the upgrade
            cc.getService();
            lr = new LogRecord(Level.FINE, successfulCleanupWith + cc.getClass());
            lr.setLoggerName(getClass().getName());
            EarlyLogHandler.earlyMessages.add(lr);
        } catch (Exception e) {
            lr = new LogRecord(Level.FINE, e.toString() + e);
            lr.setLoggerName(getClass().getName());
            EarlyLogHandler.earlyMessages.add(lr);
            lr = new LogRecord(Level.SEVERE, cc.getClass() + cleaningDomainXmlFailed + e);
            lr.setLoggerName(getClass().getName());
            EarlyLogHandler.earlyMessages.add(lr);
        }
    }
    decorate();
}
Also used : LogRecord(java.util.logging.LogRecord) ConfigPopulatorException(org.jvnet.hk2.config.ConfigPopulatorException) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ConfigPopulatorException(org.jvnet.hk2.config.ConfigPopulatorException)

Aggregations

ConfigParser (org.jvnet.hk2.config.ConfigParser)12 DomDocument (org.jvnet.hk2.config.DomDocument)12 URL (java.net.URL)8 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)6 IOException (java.io.IOException)5 PropertyVetoException (java.beans.PropertyVetoException)3 ArrayList (java.util.ArrayList)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)3 Domain (com.sun.enterprise.config.serverbeans.Domain)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 LogRecord (java.util.logging.LogRecord)2 GlassFishConfigBean (org.glassfish.config.support.GlassFishConfigBean)2 MultiMap (org.jvnet.hk2.component.MultiMap)2 ConfigModel (org.jvnet.hk2.config.ConfigModel)2