Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Jetty/Feature/ContextProvider"

< Jetty‎ | Feature
m
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{Jetty Feature
 
{{Jetty Feature
 
| introduction =
 
| introduction =
 +
 +
{{Jetty Redirect|http://www.eclipse.org/jetty/documentation/current/configuring-deployment.html}}
 +
 
Jetty provides capability to deploy an arbitrary context or web application with Jetty-specific configuration. The ContextProvider mechanism, which is now an extension of the core deployment infrastructure, implements this capability.
 
Jetty provides capability to deploy an arbitrary context or web application with Jetty-specific configuration. The ContextProvider mechanism, which is now an extension of the core deployment infrastructure, implements this capability.
| body =
+
 
 
You can use the [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java?root=RT_JETTY&view=markup ContextProvider] to (hot) deploy an arbitrary context or web application with Jetty-specific configuration. To statically deploy only standard web applications at startup, use the [[Jetty/Feature/WebAppDeployer|WebApp Provider]].
 
You can use the [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ContextProvider.java?root=RT_JETTY&view=markup ContextProvider] to (hot) deploy an arbitrary context or web application with Jetty-specific configuration. To statically deploy only standard web applications at startup, use the [[Jetty/Feature/WebAppDeployer|WebApp Provider]].
  
==Overview==
+
| body =
  
 
A <tt>jetty.xml</tt> typically defines a ContextProvider; within the stock jetty distribution the name of this file is<tt>jetty-contexts.xml</tt>:
 
A <tt>jetty.xml</tt> typically defines a ContextProvider; within the stock jetty distribution the name of this file is<tt>jetty-contexts.xml</tt>:
 +
 
<source lang="xml">  
 
<source lang="xml">  
 
  <Configure id="Server" class="org.eclipse.jetty.server.Server">
 
  <Configure id="Server" class="org.eclipse.jetty.server.Server">
Line 35: Line 39:
 
This example creates an instance of [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java?root=RT_JETTY&view=markup WebAppContext] and sets the ''contextPath'' to  <tt>/test</tt> and the resourceBase to  <tt>$jetty.home/webapps/test</tt>. Because the context used is a standard web application context, when started it inspects the resourceBase for a <tt>WEB-INF/web.xml</tt> for further configuration.
 
This example creates an instance of [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java?root=RT_JETTY&view=markup WebAppContext] and sets the ''contextPath'' to  <tt>/test</tt> and the resourceBase to  <tt>$jetty.home/webapps/test</tt>. Because the context used is a standard web application context, when started it inspects the resourceBase for a <tt>WEB-INF/web.xml</tt> for further configuration.
  
The ContextProvider is added to the server as a LifeCycle. This simply means that the provider starts and stops with the server. That is, when <tt>server.start()</tt> is called, then <tt>start</tt> is also be called on the provider.
+
The ContextProvider is added to the server as a LifeCycle. This simply means that the provider starts and stops with the server. That is, when <tt>server.start()</tt> is called, then <tt>start</tt> is also called on the provider.
  
 
===Property Value Substitution===
 
===Property Value Substitution===
  
The ContextProvider can automatically do property substitution on the context files that it deploys. You define a ConfigurationManager that manages the properties and pass this into the ContextProvider. There is currently one implementation of the ConfigurationManager, and that is the <tt>org.mortbay.jetty.deployer.FileConfigurationManager</tt> that reads a properties file and makes available the property values to the ContextProvider. Here's how you would configure the ContextProvider:
+
The ContextProvider can automatically do property substitution on the context files that it deploys. You define a ConfigurationManager that manages the properties and pass this into the ContextProvider. There is currently one implementation of the ConfigurationManager, and that is the <tt>org.mortbay.jetty.deployer.FileConfigurationManager</tt>, which reads a properties file and makes available the property values to the ContextProvider. Here's how you would configure the ContextProvider:
  
 
<source lang="xml">
 
<source lang="xml">
Line 77: Line 81:
 
==Contexts==
 
==Contexts==
  
Because the class of the context is defined in the Configure clause, you can deploy any type of ContextHandler with this mechanism, included base [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java?root=RT_JETTY&view=markup ContextHandler], [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java?root=RT_JETTY&view=markup ServletContextHandler], [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java?root=RT_JETTY&view=markup WebAppContext], or any class derived from them.
+
Because the class of the context is defined in the Configure clause, you can deploy any type of ContextHandler with this mechanism, including base [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java?root=RT_JETTY&view=markup ContextHandler], [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java?root=RT_JETTY&view=markup ServletContextHandler], [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java?root=RT_JETTY&view=markup WebAppContext], or any class derived from them.
  
 
==Hot Deploy==
 
==Hot Deploy==
  
If the scan interval is non-zero, the ContextProvider scans the configuration directory at that interval (in seconds) for changes to the deployment descriptors. If you add a descriptor to the directory, it deploys the new context. If you touch or update a descriptor, the provider stops, reconfigures, and redeploys it's context. If you remove a descriptor, the provider stops and removes its context from the server.
+
If the scan interval is non-zero, the ContextProvider scans the configuration directory at that interval (in seconds) for changes to the deployment descriptors. If you add a descriptor to the directory, it deploys the new context. If you touch or update a descriptor, the provider stops, reconfigures, and redeploys its context. If you remove a descriptor, the provider stops and removes its context from the server.
  
 
If the scan interval is zero, the ContextProvider scans the directory only at startup.
 
If the scan interval is zero, the ContextProvider scans the directory only at startup.
Line 89: Line 93:
 
This mechanism allows you to call most of the API available on [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java?root=RT_JETTY&view=markup ContextHandler] or its derived classes to configure the web application. Useful things to configure include:
 
This mechanism allows you to call most of the API available on [http://dev.eclipse.org/viewcvs/index.cgi/jetty/trunk/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java?root=RT_JETTY&view=markup ContextHandler] or its derived classes to configure the web application. Useful things to configure include:
  
* setAttribute
+
* <tt>setAttribute</tt>
* setClassLoader
+
* <tt>setClassLoader</tt>
* setContextPath
+
* <tt>setContextPath</tt>
* setVirtualHosts
+
* <tt>setVirtualHosts</tt>
* addServlet
+
* <tt>addServlet</tt>
* setConfigurations
+
* <tt>setConfigurations</tt>
* setExtraClassPath
+
* <tt>setExtraClassPath</tt>
* setDefaultsDescriptor
+
* <tt>setDefaultsDescriptor</tt>
* setDescriptor
+
* <tt>setDescriptor</tt>
* setOverrideDescriptor
+
* <tt>setOverrideDescriptor</tt>
* setSystemClasses
+
* <tt>setSystemClasses</tt>
* setServerClasses
+
* <tt>setServerClasses</tt>
 
| category = [[Category:Jetty Feature]]
 
| category = [[Category:Jetty Feature]]
 
}}
 
}}

Latest revision as of 15:02, 23 April 2013



Introduction

Warning2.png
Jetty 7 and Jetty 8 are now EOL (End of Life)




THIS IS NOT THE DOCUMENTATION YOU ARE LOOKING FOR!!!!!






All development and stable releases are being performed with Jetty 9 and Jetty 10.






This wiki is now officially out of date and all content has been moved to the Jetty Documentation Hub






Direct Link to updated documentation: http://www.eclipse.org/jetty/documentation/current/configuring-deployment.html


Jetty provides capability to deploy an arbitrary context or web application with Jetty-specific configuration. The ContextProvider mechanism, which is now an extension of the core deployment infrastructure, implements this capability.

You can use the ContextProvider to (hot) deploy an arbitrary context or web application with Jetty-specific configuration. To statically deploy only standard web applications at startup, use the WebApp Provider.

Feature

A jetty.xml typically defines a ContextProvider; within the stock jetty distribution the name of this file isjetty-contexts.xml:

 
 <Configure id="Server" class="org.eclipse.jetty.server.Server">
        <Ref id="DeploymentManager">
          <Call name="addAppProvider">
            <Arg>
              <New class="org.eclipse.jetty.deploy.providers.ContextProvider">
                <Set name="monitoredDir"><Property name="jetty.home" default="." />/contexts</Set>
                <Set name="scanInterval">1</Set>
              </New>
            </Arg>
          </Call>
        </Ref>
</Configure>

The ContextProvider scans the monitoredDir directory at intervals of scanInterval seconds for XML descriptors that define contexts. It then deploys any contexts to the passed contexts reference to a HandlerContainer (normally an instance of ContextHandlerCollection). The deployment descriptors are in jetty xml format, and define and configure individual contexts. A minimal example is:

 <?xml version="1.0"  encoding="ISO-8859-1"?>
 <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
 <Configure class="org.eclipse.jetty.webapp.WebAppContext">
   <Set name="contextPath">/test</Set>
   <Set name="war"><SystemProperty name="jetty.home" default<nowiki>=</nowiki>"."/>/webapps/test</Set>
 </Configure>

This example creates an instance of WebAppContext and sets the contextPath to /test and the resourceBase to $jetty.home/webapps/test. Because the context used is a standard web application context, when started it inspects the resourceBase for a WEB-INF/web.xml for further configuration.

The ContextProvider is added to the server as a LifeCycle. This simply means that the provider starts and stops with the server. That is, when server.start() is called, then start is also called on the provider.

Property Value Substitution

The ContextProvider can automatically do property substitution on the context files that it deploys. You define a ConfigurationManager that manages the properties and pass this into the ContextProvider. There is currently one implementation of the ConfigurationManager, and that is the org.mortbay.jetty.deployer.FileConfigurationManager, which reads a properties file and makes available the property values to the ContextProvider. Here's how you would configure the ContextProvider:

 <Configure id="Server" class="org.eclipse.jetty.server.Server">
        <Ref id="DeploymentManager">
          <Call name="addAppProvider">
            <Arg>
              <New class="org.eclipse.jetty.deploy.providers.ContextProvider">
                <Set name="monitoredDir"><Property name="jetty.home" default="." />/contexts</Set>
                <Set name="scanInterval">1</Set>
                <Set name="configurationManager">
                  <New class="org.mortbay.jetty.deployer.FileConfigurationManager">
                     <Set name="file"><SystemProperty name="jetty.home" default="."/>/foo.properties</Set>
                  </New>
                </Set>
              </New>
            </Arg>
          </Call>
        </Ref>
</Configure>

Here's an example of the contents of the foo.properties file:

 
 foo = /funkyapp

Here's how you would use this in a context xml file:

 <?xml version="1.0"  encoding="ISO-8859-1"?>
 <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
 <Configure class="org.mortbay.jetty.webapp.WebAppContext">
   <Set name="contextPath"><Property name="foo"/></Set>
   <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test</Set>
 </Configure>

Contexts

Because the class of the context is defined in the Configure clause, you can deploy any type of ContextHandler with this mechanism, including base ContextHandler, ServletContextHandler, WebAppContext, or any class derived from them.

Hot Deploy

If the scan interval is non-zero, the ContextProvider scans the configuration directory at that interval (in seconds) for changes to the deployment descriptors. If you add a descriptor to the directory, it deploys the new context. If you touch or update a descriptor, the provider stops, reconfigures, and redeploys its context. If you remove a descriptor, the provider stops and removes its context from the server.

If the scan interval is zero, the ContextProvider scans the directory only at startup.

Configuring Other Things

This mechanism allows you to call most of the API available on ContextHandler or its derived classes to configure the web application. Useful things to configure include:

  • setAttribute
  • setClassLoader
  • setContextPath
  • setVirtualHosts
  • addServlet
  • setConfigurations
  • setExtraClassPath
  • setDefaultsDescriptor
  • setDescriptor
  • setOverrideDescriptor
  • setSystemClasses
  • setServerClasses

Copyright © Eclipse Foundation, Inc. All Rights Reserved.