Bingo - worked like a charm. IMO this should be core functionality in
Tapestry; it is part of the Servlet spec after all. My web.xml contains:

------------------------------------------------------
        <context-param>
                <param-name>tapestry.app-package</param-name>
                <param-value>com.myapp.web.tapestry</param-value>
        </context-param>

        <filter>
                <filter-name>tapestryFilter</filter-name>
        
<filter-class>org.apache.tapestry.spring.TapestrySpringFilter</filter-class>
        </filter>

        <filter-mapping>
                <filter-name>tapestryFilter</filter-name>
                <url-pattern>/*</url-pattern>
        </filter-mapping>
       ...
------------------------------------------------------

My filter class looks like:

------------------------------------------------------
package com.myapp.web.tapestry.services;

import java.io.IOException;

import org.apache.tapestry.ioc.OrderedConfiguration;
import org.apache.tapestry.ioc.annotations.InjectService;
import org.apache.tapestry.services.Request;
import org.apache.tapestry.services.RequestFilter;
import org.apache.tapestry.services.RequestHandler;
import org.apache.tapestry.services.Response;
import org.slf4j.Logger;

/**
 * This module is automatically included as part of the Tapestry IoC
Registry, it's a good place to
 * configure and extend Tapestry, or to place your own service definitions.
 */
public class TapestryFilterModule {

        public RequestFilter buildServletExtensionFilter(final Logger log) {
                return new RequestFilter() {
                        public boolean service(Request request, Response 
response, RequestHandler
handler)
                                        throws IOException {
                                String path = request.getPath();
                                if (path.endsWith(".spr")) return false;

                                return handler.service(request, response);
                        }
                };
        }

        /**
         * This is a contribution to the RequestHandler service configuration. 
This
is how we extend
         * Tapestry using the ServletExtensionFilter.
         */
        public void contributeRequestHandler(OrderedConfiguration<RequestFilter>
configuration,
                        @InjectService("ServletExtensionFilter")
                        RequestFilter filter) {
                configuration.add("ServletExtension", filter, 
"before:StaticFiles");
        }
}
------------------------------------------------------

Note the class I made has to be in the ${tapestry.app-package}/services
package, and be called exactly "${tapestry filter name in web.xml, changed
to uppercase first letter}Module.java". The first method needs to be called
build[TextOfYourChoice](), and then @InjectService("[TextOfYourChoice]").
Pretty crazy reflection going on.

I hardcoded the file extension for testing but that's hardly a good design.
A solid implementation should build a collection of valid extensions passed
in as properties, then loop over them and return false if any match. I don't
have access to the ServletContext via the Request parameter so I'll have to
figure out another way to do it.

Thanks Jonathan!
-- 
View this message in context: 
http://www.nabble.com/T5-user-servlet-mapped-to-extension-*.spr-gets-rejected-as-invalid-component-tf4687080.html#a13418606
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to