You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by xfile80303 <le...@grokers.net> on 2009/02/18 01:57:36 UTC

[T5.1] Overriding a binding?

Hi all,

Short version:

I need to override an existing binding so I can insert my own
implementation, but I get a RuntimeException from Tapestry when I try to do
so.

How would I do this?

Long Version:

In my quest to do URL manipulation and insert "site" into the first element
of the URL, I have half the answer.  The remaining issue is that the
generated links do not contain this site parameter, and need to so the site
will not always be the default site. It would appear (from reading the
Tapestry code) that I need to override the default functionality in
org.apache.tapestry5.internal.services.LinkFactoryImpl to insert the value
into the generated Link object's path.  Again, this looks like I have to
completely copy the functionality of the LinkFactoryImpl, but that's no
biggie (thanks to open source... :) ).

The issue is, how to use my implementation instead of the default
implementation?

If, in my Module class, I try to bind to the LinkFactory interface, the
whole app fails to even deploy.
Even without my implementation in the way... I just try to replace the
existing binding with the same binding:

	public static void bind(ServiceBinder binder)
	{
		binder.bind(LinkFactory.class, LinkFactoryImpl.class);
	}

and I get a RuntimeException from Tapestry:

java.lang.RuntimeException: Service id 'LinkFactory' has already been
defined by org.apache.tapestry5.internal.services.LinkFactoryImpl(Request,
Response, RequestSecurityManager, RequestPathOptimizer, PersistentLocale,
RequestPageCache, ContextValueEncoder, URLEncoder) (at
LinkFactoryImpl.java:53) via
org.apache.tapestry5.internal.services.InternalModule.bind(ServiceBinder)
(at InternalModule.java:59) and may not be redefined by
org.apache.tapestry5.internal.services.LinkFactoryImpl(Request, Response,
RequestSecurityManager, RequestPathOptimizer, PersistentLocale,
RequestPageCache, ContextValueEncoder, URLEncoder) (at
LinkFactoryImpl.java:53) via
com.java.dse.cwp.eos.services.EosModule.bind(ServiceBinder) (at
EosModule.java:50). You should rename one of the service builder methods.


So it would seem that I would need to do this in a different way.

Thoughts?

Thanks,

Levi
-- 
View this message in context: http://n2.nabble.com/-T5.1--Overriding-a-binding--tp2344287p2344287.html
Sent from the Tapestry Users 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


Re: [T5.1] Overriding a binding?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 17 Feb 2009 22:43:46 -0300, xfile80303 <le...@grokers.net> escreveu:

> But I get a recursion exception when trying to load the web app.  This  
> type of issue seems fairly common on the mailing list, but I've not  
> found a
> solution which works here yet.

They're tricky to solve. :( Maybe the problems is with the bind method. I  
would try to use a builder method instead of the bind method to create the  
SiteLinkFactory service. Something like:

public static SiteLinkFactory buildSiteLinkFactory(...) {
	return new SiteLinkFactory(...);
}

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: [T5.1] Overriding a binding?

Posted by xfile80303 <le...@grokers.net>.
Thank you Kris!

This seems to have done the trick.


Kristian Marinkovic wrote:
> 
> you could also use the ObjectLocator service to create proxies within 
> the alias contribution to prevent the recursion 
> 
> pblic void static contributeAliasOverrides(Configuration.... , 
> ObjectLocator locator)
> {
> 
>      configuration.add(AliasContribution.create(LinkFactory.class,
> locator.proxy(LinkFactory.class, YourImplementation.class)));
> }
> 
> g,
> kris
> 

-- 
View this message in context: http://n2.nabble.com/-T5.1--Overriding-a-binding--tp2344287p2348026.html
Sent from the Tapestry Users 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


Re: [T5.1] Overriding a binding?

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
you could also use the ObjectLocator service to create proxies within 
the alias contribution to prevent the recursion 

pblic void static contributeAliasOverrides(Configuration.... , 
ObjectLocator locator)
{

     configuration.add(AliasContribution.create(LinkFactory.class,
locator.proxy(LinkFactory.class, YourImplementation.class)));
}

g,
kris




Robert Zeigler <ro...@scazdl.org> 
Gesendet von: robert zeigler <ro...@gmail.com>
18.02.2009 05:13
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
"Tapestry users" <us...@tapestry.apache.org>
Kopie

Thema
Re: [T5.1] Overriding a binding?







The problem is that the alias service is needed to dereference some of 
the objects used by your SiteLinkFactory service, but you're 
contributing SiteLinkFactory to alias, hence the recursive dependency 
problem. Try contributing to AliasOverrides, instead of Alias, which 
is really what you want.

Cheers,

Robert

On Feb 17, 2009, at 2/177:43 PM , xfile80303 wrote:

>
> Thanks for the fast reply Thiago!
>
> I have tried to set this up in my Module class:
>
>                public static void bind(ServiceBinder binder)
>                {
> binder.bind(SiteLinkFactory.class).withId("SiteLinkFactory");
>                }
>
>                public static void contributeAlias(
> Configuration<AliasContribution> configuration,
>                                                @Local SiteLinkFactory 
siteLinkFactory)
>                {
>
> configuration.add(AliasContribution.create(LinkFactory.class,
> siteLinkFactory));
>                }
>
>
> But I get a recursion exception when trying to load the web app. 
> This type
> of issue seems fairly common on the mailing list, but I've not found a
> solution which works here yet.
>
> As a baseline I've tried to create an alias for the LinkFactoryImpl 
> class
> instead of my own, but I get the same issue.
>
> This seems to imply there is some dependency in the implementation 
> of the
> LinkFactoryImpl class which has a circular reference?
>
> The LinkFactoryImpl takes these as arguments to its constructor, 
> might one
> be the issue?
>
> Request request, Response response,
> RequestSecurityManager requestSecurityManager,
> RequestPathOptimizer optimizer, PersistentLocale persistentLocale,
> RequestPageCache requestPageCache,
> ContextValueEncoder valueEncoder, URLEncoder urlEncoder
>
> Any thoughts on if I'm doing something wrong in setting up this 
> alias, or a
> way to work around this seemingly circular reference?
>
> The exception:
> java.lang.RuntimeException: Exception constructing service
> 'ServletApplicationInitializer': Unable to instantiate class
> org.apache.tapestry5.services.TapestryModule as a module: Exception
> constructing service 'Alias': Error invoking service builder method
> org.apache.tapestry5.services.TapestryModule.buildAlias(Logger, 
> String,
> AliasManager, Collection) (at TapestryModule.java:315) (for service
> 'Alias'): Error invoking service contribution method
> com.java.dse.cwp.eos.services.EosModule.contributeAlias(Configuration,
> SiteLinkFactory): Error building service proxy for service 
> 'SiteLinkFactory'
> (at com.java.dse.cwp.eos.services.util.SiteLinkFactory(Request, 
> Response,
> RequestSecurityManager, RequestPathOptimizer, PersistentLocale,
> RequestPageCache, ContextValueEncoder, URLEncoder) (at
> SiteLinkFactory.java:58) via
> com.java.dse.cwp.eos.services.EosModule.bind(ServiceBinder) (at
> EosModule.java:52)): Error invoking constructor
> com.java.dse.cwp.eos.services.util.SiteLinkFactory(Request, Response,
> RequestSecurityManager, RequestPathOptimizer, PersistentLocale,
> RequestPageCache, ContextValueEncoder, URLEncoder) (at
> SiteLinkFactory.java:58) via
> com.java.dse.cwp.eos.services.EosModule.bind(ServiceBinder) (at
> EosModule.java:52) (for service 'SiteLinkFactory'): Exception 
> constructing
> service 'Alias': Construction of service 'Alias' has failed due to
> recursion: the service depends on itself in some way. Please check
> org.apache.tapestry5.services.TapestryModule.buildAlias(Logger, 
> String,
> AliasManager, Collection) (at TapestryModule.java:315) for 
> references to
> another service that is itself dependent on service 'Alias'.
>
> Thanks,
>
> Levi
>
>
> Thiago H. de Paula Figueiredo wrote:
>>
>> Em Tue, 17 Feb 2009 21:57:36 -0300, xfile80303 <le...@grokers.net>
>> escreveu:
>>
>>> I need to override an existing binding so I can insert my own
>>> implementation, but I get a RuntimeException from Tapestry when I 
>>> try to
>>> do so. How would I do this?
>>
>> Using aliases: http://tapestry.apache.org/tapestry5/guide/alias.html.
>>
>
> -- 
> View this message in context: 
http://n2.nabble.com/-T5.1--Overriding-a-binding--tp2344287p2344459.html
> Sent from the Tapestry Users 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



Re: [T5.1] Overriding a binding?

Posted by Robert Zeigler <ro...@scazdl.org>.
The problem is that the alias service is needed to dereference some of  
the objects used by your SiteLinkFactory service, but you're  
contributing SiteLinkFactory to alias, hence the recursive dependency  
problem. Try contributing to AliasOverrides, instead of Alias, which  
is really what you want.

Cheers,

Robert

On Feb 17, 2009, at 2/177:43 PM , xfile80303 wrote:

>
> Thanks for the fast reply Thiago!
>
> I have tried to set this up in my Module class:
>
> 	public static void bind(ServiceBinder binder)
> 	{
> 		binder.bind(SiteLinkFactory.class).withId("SiteLinkFactory");
> 	}
>
> 	public static void contributeAlias(
> 			Configuration<AliasContribution> configuration,
> 			@Local SiteLinkFactory siteLinkFactory)
> 	{
>
> 		configuration.add(AliasContribution.create(LinkFactory.class,
> siteLinkFactory));
> 	}
>
>
> But I get a recursion exception when trying to load the web app.   
> This type
> of issue seems fairly common on the mailing list, but I've not found a
> solution which works here yet.
>
> As a baseline I've tried to create an alias for the LinkFactoryImpl  
> class
> instead of my own, but I get the same issue.
>
> This seems to imply there is some dependency in the implementation  
> of the
> LinkFactoryImpl class which has a circular reference?
>
> The LinkFactoryImpl takes these as arguments to its constructor,  
> might one
> be the issue?
>
> Request request, Response response,
> RequestSecurityManager requestSecurityManager,
> RequestPathOptimizer optimizer, PersistentLocale persistentLocale,
> RequestPageCache requestPageCache,
> ContextValueEncoder valueEncoder, URLEncoder urlEncoder
>
> Any thoughts on if I'm doing something wrong in setting up this  
> alias, or a
> way to work around this seemingly circular reference?
>
> The exception:
> java.lang.RuntimeException: Exception constructing service
> 'ServletApplicationInitializer': Unable to instantiate class
> org.apache.tapestry5.services.TapestryModule as a module: Exception
> constructing service 'Alias': Error invoking service builder method
> org.apache.tapestry5.services.TapestryModule.buildAlias(Logger,  
> String,
> AliasManager, Collection) (at TapestryModule.java:315) (for service
> 'Alias'): Error invoking service contribution method
> com.java.dse.cwp.eos.services.EosModule.contributeAlias(Configuration,
> SiteLinkFactory): Error building service proxy for service  
> 'SiteLinkFactory'
> (at com.java.dse.cwp.eos.services.util.SiteLinkFactory(Request,  
> Response,
> RequestSecurityManager, RequestPathOptimizer, PersistentLocale,
> RequestPageCache, ContextValueEncoder, URLEncoder) (at
> SiteLinkFactory.java:58) via
> com.java.dse.cwp.eos.services.EosModule.bind(ServiceBinder) (at
> EosModule.java:52)): Error invoking constructor
> com.java.dse.cwp.eos.services.util.SiteLinkFactory(Request, Response,
> RequestSecurityManager, RequestPathOptimizer, PersistentLocale,
> RequestPageCache, ContextValueEncoder, URLEncoder) (at
> SiteLinkFactory.java:58) via
> com.java.dse.cwp.eos.services.EosModule.bind(ServiceBinder) (at
> EosModule.java:52) (for service 'SiteLinkFactory'): Exception  
> constructing
> service 'Alias': Construction of service 'Alias' has failed due to
> recursion: the service depends on itself in some way. Please check
> org.apache.tapestry5.services.TapestryModule.buildAlias(Logger,  
> String,
> AliasManager, Collection) (at TapestryModule.java:315) for  
> references to
> another service that is itself dependent on service 'Alias'.
>
> Thanks,
>
> Levi
>
>
> Thiago H. de Paula Figueiredo wrote:
>>
>> Em Tue, 17 Feb 2009 21:57:36 -0300, xfile80303 <le...@grokers.net>
>> escreveu:
>>
>>> I need to override an existing binding so I can insert my own
>>> implementation, but I get a RuntimeException from Tapestry when I  
>>> try to
>>> do so. How would I do this?
>>
>> Using aliases: http://tapestry.apache.org/tapestry5/guide/alias.html.
>>
>
> -- 
> View this message in context: http://n2.nabble.com/-T5.1--Overriding-a-binding--tp2344287p2344459.html
> Sent from the Tapestry Users 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


Re: [T5.1] Overriding a binding?

Posted by xfile80303 <le...@grokers.net>.
Thanks for the fast reply Thiago!

I have tried to set this up in my Module class:

	public static void bind(ServiceBinder binder)
	{
		binder.bind(SiteLinkFactory.class).withId("SiteLinkFactory");
	}

	public static void contributeAlias(
			Configuration<AliasContribution> configuration,
			@Local SiteLinkFactory siteLinkFactory)
	{

		configuration.add(AliasContribution.create(LinkFactory.class,
siteLinkFactory));
	}


But I get a recursion exception when trying to load the web app.  This type
of issue seems fairly common on the mailing list, but I've not found a
solution which works here yet.

As a baseline I've tried to create an alias for the LinkFactoryImpl class
instead of my own, but I get the same issue.

This seems to imply there is some dependency in the implementation of the
LinkFactoryImpl class which has a circular reference?

The LinkFactoryImpl takes these as arguments to its constructor, might one
be the issue?

Request request, Response response,
RequestSecurityManager requestSecurityManager,
RequestPathOptimizer optimizer, PersistentLocale persistentLocale,
RequestPageCache requestPageCache,
ContextValueEncoder valueEncoder, URLEncoder urlEncoder

Any thoughts on if I'm doing something wrong in setting up this alias, or a
way to work around this seemingly circular reference?

The exception:
java.lang.RuntimeException: Exception constructing service
'ServletApplicationInitializer': Unable to instantiate class
org.apache.tapestry5.services.TapestryModule as a module: Exception
constructing service 'Alias': Error invoking service builder method
org.apache.tapestry5.services.TapestryModule.buildAlias(Logger, String,
AliasManager, Collection) (at TapestryModule.java:315) (for service
'Alias'): Error invoking service contribution method
com.java.dse.cwp.eos.services.EosModule.contributeAlias(Configuration,
SiteLinkFactory): Error building service proxy for service 'SiteLinkFactory'
(at com.java.dse.cwp.eos.services.util.SiteLinkFactory(Request, Response,
RequestSecurityManager, RequestPathOptimizer, PersistentLocale,
RequestPageCache, ContextValueEncoder, URLEncoder) (at
SiteLinkFactory.java:58) via
com.java.dse.cwp.eos.services.EosModule.bind(ServiceBinder) (at
EosModule.java:52)): Error invoking constructor
com.java.dse.cwp.eos.services.util.SiteLinkFactory(Request, Response,
RequestSecurityManager, RequestPathOptimizer, PersistentLocale,
RequestPageCache, ContextValueEncoder, URLEncoder) (at
SiteLinkFactory.java:58) via
com.java.dse.cwp.eos.services.EosModule.bind(ServiceBinder) (at
EosModule.java:52) (for service 'SiteLinkFactory'): Exception constructing
service 'Alias': Construction of service 'Alias' has failed due to
recursion: the service depends on itself in some way. Please check
org.apache.tapestry5.services.TapestryModule.buildAlias(Logger, String,
AliasManager, Collection) (at TapestryModule.java:315) for references to
another service that is itself dependent on service 'Alias'.

Thanks,

Levi


Thiago H. de Paula Figueiredo wrote:
> 
> Em Tue, 17 Feb 2009 21:57:36 -0300, xfile80303 <le...@grokers.net>
> escreveu:
> 
>> I need to override an existing binding so I can insert my own
>> implementation, but I get a RuntimeException from Tapestry when I try to  
>> do so. How would I do this?
> 
> Using aliases: http://tapestry.apache.org/tapestry5/guide/alias.html.
> 

-- 
View this message in context: http://n2.nabble.com/-T5.1--Overriding-a-binding--tp2344287p2344459.html
Sent from the Tapestry Users 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


Re: [T5.1] Overriding a binding?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 17 Feb 2009 21:57:36 -0300, xfile80303 <le...@grokers.net> escreveu:

> I need to override an existing binding so I can insert my own
> implementation, but I get a RuntimeException from Tapestry when I try to  
> do so. How would I do this?

Using aliases: http://tapestry.apache.org/tapestry5/guide/alias.html.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: [T5.1] Overriding a binding?

Posted by xfile80303 <le...@grokers.net>.
Okay, so I figured this out... here's the scoop:

I tried various incantations of contributeAlias and contributeAliasOverrides
but the issue seemed to be with the injection of my service instance.  If I
commented out all the arguments to the service's constructor then I could
get past the recursion error, but obviously that wouldn't allow my service
to do what it needed to.

Looking at the nightly docs: http://tapestry.formos.com/nightly/tapestry5/ I
noticed this line in the "new and of note" section:

"A simpler method of overriding built-in services has been added." with a
link to:

http://tapestry.formos.com/nightly/tapestry5/apidocs/org/apache/tapestry5/ioc/services/ServiceOverride

Which sounds like exactly what I want to do (Presents? ...and it's not even
my birthday.  ;) ).

So I changed from trying to contribute an Alias (or AliasOverride) to
ServiceOverride.

My first attempts followed the (seemingly) standard pattern:

	public static void bind(ServiceBinder binder)
	{
		binder.bind(SiteLinkFactory.class).withId("SiteLinkFactory");;
	}

	public static void contributeServiceOverride(
			MappedConfiguration<Class, Object> configuration,
			@InjectService("SiteLinkFactory") SiteLinkFactory siteLinkFactory)
	{
		configuration.add(LinkFactory.class, siteLinkFactory);
	}


But this got the same kind of recursion error I had been encountering
before... seemingly that the ServiceOverride service was dependent on
itself.

Thanks to a post by Kris, I changed my code to this (note, no need for a
binding):

	public static void contributeServiceOverride(
			MappedConfiguration<Class, Object> configuration,
			ObjectLocator locator)
	{
		configuration.add(LinkFactory.class, locator.proxy(LinkFactory.class,
SiteLinkFactory.class));
	}


And, we make it past the recursion issue!  <happy dance>

Thanks for your help, people.

Levi (on to the next exception... ;) )


xfile80303 wrote:
> 
> Hi all,
> 
> Short version:
> 
> I need to override an existing binding so I can insert my own
> implementation, but I get a RuntimeException from Tapestry when I try to
> do so.
> 
> How would I do this?
> 
> Long Version:
> 
> In my quest to do URL manipulation and insert "site" into the first
> element of the URL, I have half the answer.  The remaining issue is that
> the generated links do not contain this site parameter, and need to so the
> site will not always be the default site. It would appear (from reading
> the Tapestry code) that I need to override the default functionality in
> org.apache.tapestry5.internal.services.LinkFactoryImpl to insert the value
> into the generated Link object's path.  Again, this looks like I have to
> completely copy the functionality of the LinkFactoryImpl, but that's no
> biggie (thanks to open source... :) ).
> 
> The issue is, how to use my implementation instead of the default
> implementation?
> 
> If, in my Module class, I try to bind to the LinkFactory interface, the
> whole app fails to even deploy.
> Even without my implementation in the way... I just try to replace the
> existing binding with the same binding:
> 
> 	public static void bind(ServiceBinder binder)
> 	{
> 		binder.bind(LinkFactory.class, LinkFactoryImpl.class);
> 	}
> 
> and I get a RuntimeException from Tapestry:
> 
> java.lang.RuntimeException: Service id 'LinkFactory' has already been
> defined by org.apache.tapestry5.internal.services.LinkFactoryImpl(Request,
> Response, RequestSecurityManager, RequestPathOptimizer, PersistentLocale,
> RequestPageCache, ContextValueEncoder, URLEncoder) (at
> LinkFactoryImpl.java:53) via
> org.apache.tapestry5.internal.services.InternalModule.bind(ServiceBinder)
> (at InternalModule.java:59) and may not be redefined by
> org.apache.tapestry5.internal.services.LinkFactoryImpl(Request, Response,
> RequestSecurityManager, RequestPathOptimizer, PersistentLocale,
> RequestPageCache, ContextValueEncoder, URLEncoder) (at
> LinkFactoryImpl.java:53) via
> com.java.dse.cwp.eos.services.EosModule.bind(ServiceBinder) (at
> EosModule.java:50). You should rename one of the service builder methods.
> 
> 
> So it would seem that I would need to do this in a different way.
> 
> Thoughts?
> 
> Thanks,
> 
> Levi
> 

-- 
View this message in context: http://n2.nabble.com/-T5.1--Overriding-a-binding--tp2344287p2348082.html
Sent from the Tapestry Users 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