Servlet Integration

Starting with 2.4, Milton requires Servlet 3.0 API

To integrate milton with your Servlet 3.0 application, first add the jars as discussed in previous pages

If you're using a supported framework like Spring or Restlet see following pages

But if you're using plain old servlets, add the MiltonFilter to your web.xml as follows

<filter>
        <filter-name>MiltonFilter</filter-name>
        <filter-class>io.milton.servlet.MiltonFilter</filter-class>
        
        <!-- This param shows how to exclude certain paths from the MiltonFilter -->
        <!-- These paths will "fall through" the filter and be handled as normal servlet resources -->
        <init-param>
            <param-name>milton.exclude.paths</param-name>
            <param-value>/myExcludedPaths,/moreExcludedPaths</param-value>
        </init-param>
        <init-param>
            <param-name>resource.factory.class</param-name>
            
<param-value>io.milton.http.annotated.AnnotationResourceFactory</param-value>
        </init-param>
        
        <!-- List packages where milton should find, and instantiate, controllers -->
        <init-param>
            <param-name>controllerPackagesToScan</param-name>
            <param-value>com.mycompany</param-value>
        </init-param>
        
        
        <!-- If using DefaultMiltonConfigurator, or a subclass, you can set any bean property of the HttpManagerBuilder here -->
        <init-param>
            <param-name>enableExpectContinue</param-name>
            <param-value>false</param-value>
        </init-param>        
    </filter>

    <filter-mapping>
        <filter-name>MiltonFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

Configuration

By default the DefaultMiltonConfigurator is used to perform configuration

If you don't provide any configuration information the defaults defined in HttpManagerBuilder will be used, which noteably will use the FileSystemResourceFactory to provide webdav access to the current user's home directory

You can change any bean property on HttpManageBuilder by providing init params with the corresponding bean property name. For example:

        <!-- If using DefaultMiltonConfigurator, or a subclass, you can set any bean property of the HttpManagerBuilder here -->
        <init-param>
            <param-name>enableExpectContinue</param-name>
            <param-value>false</param-value>
        </init-param>  

The DefaultMiltonConfigurator also allows you to set certain specific objects in configuration, such as the authentication handlers. See javadoc for that class for more details

To perform more complex configuration tasks you can provide your own MiltonConfigurator like this:

        <!-- By default the DefaultMiltonConfigurator will be used to configure milton, but you provide your own configurator here -->
        <init-param>
            <param-name>milton.configurator</param-name>
            <param-value>com.mycompany.MyMiltonConfigurator</param-value>
        </init-param>

You should probably subclass DefaultMiltonConfigurator to get the benefit of bean property initialisation etc. For example:

public class MyMiltonConfigurator extends DefaultMiltonConfigurator {

    @Override
    protected void build() {       
        builder.setSecurityManager(...);       // set your own security manager and other properties
        super.build();
        ...
     }

Next Article:

Spring Integration