You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by neo anderson <ja...@yahoo.co.uk> on 2009/09/03 22:25:55 UTC

Re: T5: ServletRequestFilter and dependency injection

I follow this setting to add my own request filter. However, I notice that if
I, for instance, add 

	public MyHttpServletRequestFilter(final FilterConfig filterConfig) {
		this.filterConfig = filterConfig;
	}

in the constructor, when accessing to the url e.g.
http://localhost:8080/myproject. It will throw 

No service implements the interface javax.servlet.FilterConfig. (I search
wiki and mailing list, but do find solution related)

Is there any way I can access the FilterConfig from
HttpServletRequestFilter.service()? or what is the correct way if I want to
obtain FilterConfig?

Thanks.

The rootcause is as below:

java.lang.RuntimeException: No service implements the interface
javax.servlet.FilterConfig.

org.apache.tapestry5.ioc.internal.RegistryImpl.getService(RegistryImpl.java:560)

org.apache.tapestry5.ioc.internal.ObjectLocatorImpl.getService(ObjectLocatorImpl.java:44)

org.apache.tapestry5.ioc.internal.services.MasterObjectProviderImpl$1.invoke(MasterObjectProviderImpl.java:56)

org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)

org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)

org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)

org.apache.tapestry5.ioc.internal.services.MasterObjectProviderImpl.provide(MasterObjectProviderImpl.java:41)

$MasterObjectProvider_1238176ce8a.provide($MasterObjectProvider_1238176ce8a.java)

org.apache.tapestry5.ioc.internal.RegistryImpl.getObject(RegistryImpl.java:696)

org.apache.tapestry5.ioc.internal.ObjectLocatorImpl.getObject(ObjectLocatorImpl.java:49)

org.apache.tapestry5.ioc.internal.util.InternalUtils.calculateInjection(InternalUtils.java:209)

org.apache.tapestry5.ioc.internal.util.InternalUtils.access$000(InternalUtils.java:43)

org.apache.tapestry5.ioc.internal.util.InternalUtils$2.invoke(InternalUtils.java:256)

org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)

org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)

org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)

org.apache.tapestry5.ioc.internal.util.InternalUtils.calculateParameters(InternalUtils.java:260)

org.apache.tapestry5.ioc.internal.util.InternalUtils.calculateParametersForConstructor(InternalUtils.java:227)

org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.createObject(ConstructorServiceCreator.java:56)

org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)

org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)

org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)

org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)

org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)

org.apache.tapestry5.ioc.internal.SingletonServiceLifecycle.createService(SingletonServiceLifecycle.java:29)

org.apache.tapestry5.ioc.internal.LifecycleWrappedServiceCreator.createObject(LifecycleWrappedServiceCreator.java:46)

org.apache.tapestry5.ioc.internal.AdvisorStackBuilder.createObject(AdvisorStackBuilder.java:60)

org.apache.tapestry5.ioc.internal.InterceptorStackBuilder.createObject(InterceptorStackBuilder.java:52)

org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:60)

org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)

org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)

org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)

org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)

org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)

org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:68)

org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:57)

$HttpServletRequestFilter_1238176ceaf.delegate($HttpServletRequestFilter_1238176ceaf.java)

$HttpServletRequestFilter_1238176ceaf.service($HttpServletRequestFilter_1238176ceaf.java)

$HttpServletRequestHandler_1238176ceb4.service($HttpServletRequestHandler_1238176ceb4.java)

org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:726)

$HttpServletRequestHandler_1238176ceb4.service($HttpServletRequestHandler_1238176ceb4.java)

$HttpServletRequestHandler_1238176ceae.service($HttpServletRequestHandler_1238176ceae.java)
	org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:127)







Robert Zeigler wrote:
> 
> You can use the constructor.
> For example, if you had a servlet request filter called  
> "MyHttpServletRequestFilter", you would have something like:
> 
> MyHttpServletRequestFilter.java :
> 
> MyHttpServletRequestFilter implements ServletRequestFilter {
> 	private final Logger _logger;
> 	public MyHttpServletRequestFilter(final Logger logger) {
> 		_logger = logger;
> 	}
>          ...
> }
> 
> 
> And then your application module's "bind" method would look something  
> like:
> 
> public static void bind(ServiceBinder binder) {
>          ...
> 	 
> binder 
> .bind 
> (HttpServletRequestFilter 
> .class,MyHttpServletRequestFilter.class).withId("myservletfilter");
>          ...
> }
> 
> 
> And then your contribution would look like:
> 
> public static void contributeHttpServletRequestHandler(
> 	OrderedConfiguration<HttpServletRequestHandler> configuration,
> 	@InjectService("myservletfilter")
> 	HttpServletRequestFilter myfilter)
> {
> 	configuration.add("myfilter",myfilter);
> }
> 
> Cheers,
> 
> Robert
> 
> On Feb 7, 2008, at 2/77:59 PM , Angelo Chen wrote:
> 
>>
>> Hi,
>>
>> How to inject dependency into a a filter? can't use constructor as  
>> it is
>> registered as:
>>
>>   public static void contributeHttpServletRequestHandler(
>>            OrderedConfiguration<HttpServletRequestFilter>  
>> configuration)
>>    {
>>        configuration.add("URLRewriteRequestFilter", new
>> URLRewriteRequestFilter());
>>    }
>>
>> my purpose is to inject a logger into it, any ideas? Thanks,
>>
>> A.C.
>> -- 
>> View this message in context:
>> http://www.nabble.com/T5%3A-ServletRequestFilter-and-dependency-injection-tp15347956p15347956.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-ServletRequestFilter-and-dependency-injection-tp15347956p25283493.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org