Open source, commercial support.

Configuration

Community provided content
Register
New page Edit

Being a library, Milton tries not to impose constraints on application developers. It won't force you to use a particular logging library or configuration tool. Although Milton doesnt implement or mandate any particular configuration tool or approach, it is designed to work seemlessly with dependency injection, and this same approach allows Milton to be wired up with explicit java code.

Milton's main classes have several constructors allowing the application developer to either have less configuration and less control, or more configuration and more control.

To begin with you might just create a HttpManager like this:

HttpManager httpManager = new HttpManager(myResourceFactory);

or in spring:

<bean id="my.resource.factory" class="..." />

<bean id="http.manager" class="com.bradmcevoy.http.HttpManager">

   <constructor-arg ref="my.resource.factory"/>

</bean>

This will have the default configuration for everything, such as authentication (Basic and Digest), response handling (non gzipped) and property support (eg bean properties on resource objects are exposed via PROPFIND)

If you want to modify the authentication handling, for example to disable digest authentication, you could use an alternative constructor like this:

AuthenticationService authenticationService = AuthenticationService();

authenticationService.setDisableDigest(true);

HttpManager httpManager = new HttpManager(myResourceFactory, authenticationService );

Or as spring config:

<bean id="my.resource.factory" class="..." />

<bean id="authentication.service" class="com.bradmcevoy.http.AuthenticationService">

  <property name="disableDigest" value="true"/>

</bean>

<bean id="http.manager" class="com.bradmcevoy.http.HttpManager">

   <constructor-arg ref="my.resource.factory"/>

   <constructor-arg ref="authentication.service"/>

</bean>

MiltonServlet

While the core of milton is a pojo library and independent of servlets, there is also a milton-servlet project which contains a pre-packaged servlet.

This is useful for getting started quickly but only provides very configuration options so won't be right for everyone.

You can easily create your own servlet and this is in fact how milton is intended to be used. By creating your own servlet you have complete control of how it gets initialised and configured.

Here's what your service method should look like:

    public void service( javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse ) throws ServletException, IOException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse resp = (HttpServletResponse) servletResponse;
        try {
            Request request = new ServletRequest( req );
            Response response = new ServletResponse( resp );
            httpManager.process( request, response );
        } finally {
            servletResponse.getOutputStream().flush();
            servletResponse.flushBuffer();
        }
    }

 

blog comments powered by Disqus