Search in sources :

Example 16 with Digester

use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.

the class SetParentClassLoaderRule method createStartDigester.

/**
     * Create and configure the Digester we will be using for startup.
     * @return the main digester to parse server.xml
     */
protected Digester createStartDigester() {
    long t1 = System.currentTimeMillis();
    // Initialize the digester
    Digester digester = new Digester();
    digester.setValidating(false);
    digester.setRulesValidation(true);
    HashMap<Class<?>, List<String>> fakeAttributes = new HashMap<>();
    ArrayList<String> attrs = new ArrayList<>();
    attrs.add("className");
    fakeAttributes.put(Object.class, attrs);
    digester.setFakeAttributes(fakeAttributes);
    digester.setUseContextClassLoader(true);
    // Configure the actions we will be using
    digester.addObjectCreate("Server", "org.apache.catalina.core.StandardServer", "className");
    digester.addSetProperties("Server");
    digester.addSetNext("Server", "setServer", "org.apache.catalina.Server");
    digester.addObjectCreate("Server/GlobalNamingResources", "org.apache.catalina.deploy.NamingResourcesImpl");
    digester.addSetProperties("Server/GlobalNamingResources");
    digester.addSetNext("Server/GlobalNamingResources", "setGlobalNamingResources", "org.apache.catalina.deploy.NamingResourcesImpl");
    digester.addObjectCreate("Server/Listener", // MUST be specified in the element
    null, "className");
    digester.addSetProperties("Server/Listener");
    digester.addSetNext("Server/Listener", "addLifecycleListener", "org.apache.catalina.LifecycleListener");
    digester.addObjectCreate("Server/Service", "org.apache.catalina.core.StandardService", "className");
    digester.addSetProperties("Server/Service");
    digester.addSetNext("Server/Service", "addService", "org.apache.catalina.Service");
    digester.addObjectCreate("Server/Service/Listener", // MUST be specified in the element
    null, "className");
    digester.addSetProperties("Server/Service/Listener");
    digester.addSetNext("Server/Service/Listener", "addLifecycleListener", "org.apache.catalina.LifecycleListener");
    //Executor
    digester.addObjectCreate("Server/Service/Executor", "org.apache.catalina.core.StandardThreadExecutor", "className");
    digester.addSetProperties("Server/Service/Executor");
    digester.addSetNext("Server/Service/Executor", "addExecutor", "org.apache.catalina.Executor");
    digester.addRule("Server/Service/Connector", new ConnectorCreateRule());
    digester.addRule("Server/Service/Connector", new SetAllPropertiesRule(new String[] { "executor", "sslImplementationName", "protocol" }));
    digester.addSetNext("Server/Service/Connector", "addConnector", "org.apache.catalina.connector.Connector");
    digester.addObjectCreate("Server/Service/Connector/SSLHostConfig", "org.apache.tomcat.util.net.SSLHostConfig");
    digester.addSetProperties("Server/Service/Connector/SSLHostConfig");
    digester.addSetNext("Server/Service/Connector/SSLHostConfig", "addSslHostConfig", "org.apache.tomcat.util.net.SSLHostConfig");
    digester.addRule("Server/Service/Connector/SSLHostConfig/Certificate", new CertificateCreateRule());
    digester.addRule("Server/Service/Connector/SSLHostConfig/Certificate", new SetAllPropertiesRule(new String[] { "type" }));
    digester.addSetNext("Server/Service/Connector/SSLHostConfig/Certificate", "addCertificate", "org.apache.tomcat.util.net.SSLHostConfigCertificate");
    digester.addObjectCreate("Server/Service/Connector/Listener", // MUST be specified in the element
    null, "className");
    digester.addSetProperties("Server/Service/Connector/Listener");
    digester.addSetNext("Server/Service/Connector/Listener", "addLifecycleListener", "org.apache.catalina.LifecycleListener");
    digester.addObjectCreate("Server/Service/Connector/UpgradeProtocol", // MUST be specified in the element
    null, "className");
    digester.addSetProperties("Server/Service/Connector/UpgradeProtocol");
    digester.addSetNext("Server/Service/Connector/UpgradeProtocol", "addUpgradeProtocol", "org.apache.coyote.UpgradeProtocol");
    // Add RuleSets for nested elements
    digester.addRuleSet(new NamingRuleSet("Server/GlobalNamingResources/"));
    digester.addRuleSet(new EngineRuleSet("Server/Service/"));
    digester.addRuleSet(new HostRuleSet("Server/Service/Engine/"));
    digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/"));
    addClusterRuleSet(digester, "Server/Service/Engine/Host/Cluster/");
    digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/Context/"));
    // When the 'engine' is found, set the parentClassLoader.
    digester.addRule("Server/Service/Engine", new SetParentClassLoaderRule(parentClassLoader));
    addClusterRuleSet(digester, "Server/Service/Engine/Cluster/");
    long t2 = System.currentTimeMillis();
    if (log.isDebugEnabled()) {
        log.debug("Digester for server.xml created " + (t2 - t1));
    }
    return (digester);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Digester(org.apache.tomcat.util.digester.Digester) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with Digester

use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.

the class ContextConfig method createContextDigester.

/**
     * Create (if necessary) and return a Digester configured to process the
     * context configuration descriptor for an application.
     * @return the digester for context.xml files
     */
protected Digester createContextDigester() {
    Digester digester = new Digester();
    digester.setValidating(false);
    digester.setRulesValidation(true);
    HashMap<Class<?>, List<String>> fakeAttributes = new HashMap<>();
    ArrayList<String> attrs = new ArrayList<>();
    attrs.add("className");
    fakeAttributes.put(Object.class, attrs);
    digester.setFakeAttributes(fakeAttributes);
    RuleSet contextRuleSet = new ContextRuleSet("", false);
    digester.addRuleSet(contextRuleSet);
    RuleSet namingRuleSet = new NamingRuleSet("Context/");
    digester.addRuleSet(namingRuleSet);
    return digester;
}
Also used : RuleSet(org.apache.tomcat.util.digester.RuleSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Digester(org.apache.tomcat.util.digester.Digester) ArrayList(java.util.ArrayList) JavaClass(org.apache.tomcat.util.bcel.classfile.JavaClass) List(java.util.List) ArrayList(java.util.ArrayList)

Example 18 with Digester

use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.

the class HostConfig method createDigester.

// ------------------------------------------------------ Protected Methods
/**
     * Create the digester which will be used to parse context config files.
     * @param contextClassName The class which will be used to create the
     *  context instance
     * @return the digester
     */
protected static Digester createDigester(String contextClassName) {
    Digester digester = new Digester();
    digester.setValidating(false);
    // Add object creation rule
    digester.addObjectCreate("Context", contextClassName, "className");
    // Set the properties on that object (it doesn't matter if extra
    // properties are set)
    digester.addSetProperties("Context");
    return (digester);
}
Also used : Digester(org.apache.tomcat.util.digester.Digester)

Example 19 with Digester

use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.

the class ContextConfig method init.

/**
     * Process a "init" event for this Context.
     */
protected void init() {
    // Called from StandardContext.init()
    Digester contextDigester = createContextDigester();
    contextDigester.getParser();
    if (log.isDebugEnabled()) {
        log.debug(sm.getString("contextConfig.init"));
    }
    context.setConfigured(false);
    ok = true;
    contextConfig(contextDigester);
}
Also used : Digester(org.apache.tomcat.util.digester.Digester)

Example 20 with Digester

use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.

the class SetParentClassLoaderRule method createStopDigester.

/**
     * Create and configure the Digester we will be using for shutdown.
     * @return the digester to process the stop operation
     */
protected Digester createStopDigester() {
    // Initialize the digester
    Digester digester = new Digester();
    digester.setUseContextClassLoader(true);
    // Configure the rules we need for shutting down
    digester.addObjectCreate("Server", "org.apache.catalina.core.StandardServer", "className");
    digester.addSetProperties("Server");
    digester.addSetNext("Server", "setServer", "org.apache.catalina.Server");
    return (digester);
}
Also used : Digester(org.apache.tomcat.util.digester.Digester)

Aggregations

Digester (org.apache.tomcat.util.digester.Digester)28 File (java.io.File)14 XmlErrorHandler (org.apache.tomcat.util.descriptor.XmlErrorHandler)11 IOException (java.io.IOException)8 WebRuleSet (org.apache.tomcat.util.descriptor.web.WebRuleSet)8 WebXml (org.apache.tomcat.util.descriptor.web.WebXml)8 Test (org.junit.Test)8 InputStream (java.io.InputStream)6 FileInputStream (java.io.FileInputStream)5 InputSource (org.xml.sax.InputSource)5 LifecycleException (org.apache.catalina.LifecycleException)4 SAXParseException (org.xml.sax.SAXParseException)3 ConnectException (java.net.ConnectException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 BufferedInputStream (java.io.BufferedInputStream)1 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1 Socket (java.net.Socket)1