VS: BaseURLSource with access to current request

2013-09-23 Thread Ville Virtanen
Hi,

this is unfortunate and I have a fix for it, but a hackish one. The injected
Request is a proxy, so you can do this:

create empty container service, and inject it to the baseurlresource (just
like the request earlier.) Add setter to your container service for the
request, and contribute startupservice with a code piece that injects the
request and your container service, and then just putthe request to your
container service's setter, and then it will be there when the first request
comes in. This works because the injected request is actually a proxy, and
not an actual request. Haven't tried that though, so no guarantees. Note
that the container service must NOT declare the request in the constructor.

Docs to add startup code: http://tapestry.apache.org/registry-startup.html 

Ville
Ps. If anyone has better fix for this, please share as I'm interested too.

-Alkuperäinen viesti-
Lähettäjä: Andy Pahne [mailto:li...@bodenkurier.de] 
Lähetetty: 22. syyskuuta 2013 21:43
Vastaanottaja: Tapestry users
Aihe: Re: BaseURLSource with access to current request


No, that does not work. When I try to inject the Request object as a method
parameter, the application won't start. An Exception is thrown on startup:
2013-09-22 20:40:30,689 ERROR ServiceOverride:64 - Construction of service
ServiceOverride failed: Error invoking service contribution method
de.bodenkurier.web.site.services.AppModule.contributeServiceOverride(MappedC
onfiguration, Request): Exception constructing service 'ServiceOverride':
Construction of service 'ServiceOverride' has failed due to recursion: the
service depends on itself in some way. Please check
org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl(Map) (at
ServiceOverrideImpl.java:31) via
org.apache.tapestry5.ioc.services.TapestryIOCModule.bind(ServiceBinder) (at
TapestryIOCModule.java:49) for references to another service that is itself
dependent on service 'ServiceOverride'.
…
...


Am 22.09.2013 um 20:05 schrieb Ville Virtanen
ville.virta...@orientimport.fi:

 
public static void contributeServiceOverride(final 
 MappedConfigurationClass,Object configuration, final Request request) {
BaseURLSource source = new  BaseURLSource()
{
 ...

configuration.add(BaseURLSource.class, source);
}
 
 Ville


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



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



VS: BaseURLSource with access to current request

2013-09-23 Thread Ville Virtanen
Thanks!

Multiple simple an efficient options, just what Tapestry is all about ;)

Ville

-Alkuperäinen viesti-
Lähettäjä: Lance Java [mailto:lance.j...@googlemail.com] 
Lähetetty: 23. syyskuuta 2013 12:21
Vastaanottaja: Tapestry users
Aihe: Re: BaseURLSource with access to current request

Your ClassCastException is caused by using configuration.add(…, …) instead
of configuration.addInstance(…, …)

If you find that contribution to ServiceOverride fails causes circular
dependency you can decorate instead of override:

static BaseURLSource decorateBaseURLSource(BaseUrlSource default, @Autobuild
MyBaseURLSource override) {
   return override;
}

Another option is to @Inject RequestGlobals instead of Request and call
getRequest(). This might eliminate the circular dependency too.


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



VS: BaseURLSource with access to current request

2013-09-22 Thread Ville Virtanen
If that is not enough, you can also inject the request and us it in the
contributed BaseUrlSource to sniff the host.

public static void contributeServiceOverride(final
MappedConfigurationClass,Object configuration, final Request request) {
BaseURLSource source = new  BaseURLSource()
{

  public String getBaseURL(boolean secure)
{

   String protocol = secure ? https : http;
   int  port = secure ? 8443 : 8080;
  request... instead the line below.
   return String.format(%s://localhost:%d , protocol,
port);

}
};
configuration.add(BaseURLSource.class, source);
}

Ville

-Alkuperäinen viesti-
Lähettäjä: Nicolas Bouillon [mailto:nico...@bouil.org] 
Lähetetty: 22. syyskuuta 2013 19:49
Vastaanottaja: Tapestry users
Aihe: Re: BaseURLSource with access to current request

Hi,

You can try starting you application server with this JVM options :

-Dtapestry.hostport-secure=443 -Dtapestry.hostport=80

Nicolas.


2013/9/22 Andy Pahne li...@bodenkurier.de:
 Hi there,

 I have a T5 app, that
  - is party protected with SSL (fronted with Apache)
  - also has some unprotected content not using SSL
  - is used to run more than one domain   ( www.example.com,
www.example.co.uk )
  - can be completely browsed using https scheme, even the unprotected
pages

 I have this mostly working, but there is one problem when https browsing
the site's pages which are not @Secure annotated: the links constructed have
the form
http://www.example.com:443/page1

 I tried to resolve this problem by contributing a service override for
BaseURLSource, as described in http://tapestry.apache.org/https.html

 However, the given implementation does not fit my needs, because I need
access to the current Request, because I need to extract the hostname from
it. I just cannot use a constant for the hostname, like in the example in
the docs:

 public static void
contributeServiceOverride(MappedConfigurationClass,Object configuration) {
 BaseURLSource source = new  BaseURLSource()
 {

   public String getBaseURL(boolean secure)
 {

String protocol = secure ? https : http;
int  port = secure ? 8443 : 8080;

return String.format(%s://localhost:%d , protocol,
port);

 }
 };
 configuration.add(BaseURLSource.class, source);
 }



 So here is my question: how do I construct an implementation of
BaseURLSource that has access to the current Request?

 I guess that's possible, but I am not familiar with Tapestry-IOC and
googling for approaches only, I only found solutions that are somewhat
static and do not depend on the current request.

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


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



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