开发者

Tomcat server.xml parser

开发者 https://www.devze.com 2023-04-01 12:30 出处:网络
I need to modify from code, Tomcat\'s server.xml. Ok it is just an XML file and there are plenty of ways to parse it but I was wondering if there is already an API specifically for server.xml (e.g. fr

I need to modify from code, Tomcat's server.xml.

Ok it is just an XML file and there are plenty of ways to parse it but I was wondering if there is already an API specifically for server.xml (e.g. from Apache) and will not have to write any code to parse it.

So is there?

Note:The program to parse the server.xml will do it "offl开发者_如何学运维ine" i.e. it is not part of a Valve or some other component that has access to the container


Generate xsd by xml (using IDEA or something) -> generate jaxb representation by xsd (using jaxb) will not take long time


You coudl use the same parsing routines Tomcat uses for loading server.xml, i.e. Commons Digester. This way you can reuse a regular Tomcat catalina.jar and avoid generated code than can get outdated.

From the startup sequence documentation:

        b3) createStartDigester() 
            Configures a digester for the main server.xml elements like
            org.apache.catalina.core.StandardServer (can change of course :)
            org.apache.catalina.deploy.NamingResources
                Stores naming resources in the J2EE JNDI tree
            org.apache.catalina.LifecycleListener
                implements events for start/stop of major components
            org.apache.catalina.core.StandardService
                The single entry for a set of connectors,
                so that a container can listen to multiple connectors
                ie, single entry
            org.apache.coyote.tomcat5.CoyoteConnector
                Connectors to listen for incoming requests only
            It also adds the following rulesets to the digester
                NamingRuleSet
                EngineRuleSet
                HostRuleSet
                ContextRuleSet
        b4) Load the server.xml and parse it using the digester
            Parsing the server.xml using the digester is an automatic
            XML-object mapping tool, that will create the objects defined in server.xml
            Startup of the actual container has not started yet.


Is it even a good practice to do it , programmatically ?

0

精彩评论

暂无评论...
验证码 换一张
取 消