You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andy Pahne <li...@bodenkurier.de> on 2013/09/22 18:14:19 UTC

BaseURLSource with access to current request

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(MappedConfiguration<Class,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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: BaseURLSource with access to current request

Posted by Andy Pahne <li...@bodenkurier.de>.
I tried another approach, which unfortunately did not work as well.

I copied the source of Tapestry's BaseURLSourceImpl. Then renamed it to CustomBaseURLSourceImpl. For the purpose of the test I did not even modify the source, only gave the class a new name.

Then I tried to contribute it as a service override like that:


    public static void contributeServiceOverride(MappedConfiguration<Class,Object> configuration){
        configuration.add(BaseURLSource.class, BodenkurierBaseURLSource.class);
    }


The application started without exception, but on each request I end up with the exception below.

What am I doing wrong with my attempt to configure my CustomBaseURLSource?

Andy



java.lang.RuntimeException: Exception constructing service 'AssetPathConstructor': Cannot cast java.lang.Class to org.apache.tapestry5.services.BaseURLSource
	at org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:75)
	at org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:54)
	at $AssetPathConstructor_13264d9b38100810.delegate(Unknown Source)
	at $AssetPathConstructor_13264d9b38100810.constructAssetPath(Unknown Source)
	at org.apache.tapestry5.internal.services.ClasspathAssetAliasManagerImpl.toClientURL(ClasspathAssetAliasManagerImpl.java:103)
	at $ClasspathAssetAliasManager_13264d9b38100809.toClientURL(Unknown Source)
	at org.apache.tapestry5.internal.services.ClasspathAssetFactory.buildDefaultPath(ClasspathAssetFactory.java:79)
	at org.apache.tapestry5.internal.services.ClasspathAssetFactory.clientURL(ClasspathAssetFactory.java:59)
	at org.apache.tapestry5.internal.services.ClasspathAssetFactory.access$000(ClasspathAssetFactory.java:33)
	at org.apache.tapestry5.internal.services.ClasspathAssetFactory$2.toClientURL(ClasspathAssetFactory.java:129)
	at org.apache.tapestry5.services.TapestryModule$28.renderMarkup(TapestryModule.java:1943)
	at $MarkupRenderer_13264d9b38100890.renderMarkup(Unknown Source)
	at org.apache.tapestry5.services.TapestryModule$27.renderMarkup(TapestryModule.java:1931)
	at $MarkupRenderer_13264d9b38100890.renderMarkup(Unknown Source)
	at org.got5.tapestry5.jquery.services.js.JSModule$1.renderMarkup(JSModule.java:40)
	at $MarkupRenderer_13264d9b38100890.renderMarkup(Unknown Source)
	at org.apache.tapestry5.services.TapestryModule$26.renderMarkup(TapestryModule.java:1913)
	at $MarkupRenderer_13264d9b38100890.renderMarkup(Unknown Source)
	at org.apache.tapestry5.services.TapestryModule$25.renderMarkup(TapestryModule.java:1894)
	at $MarkupRenderer_13264d9b38100890.renderMarkup(Unknown Source)
	at $MarkupRenderer_13264d9b3810088a.renderMarkup(Unknown Source)
	at org.apache.tapestry5.internal.services.PageMarkupRendererImpl.renderPageMarkup(PageMarkupRendererImpl.java:47)
	at $PageMarkupRenderer_13264d9b38100886.renderPageMarkup(Unknown Source)
	at org.apache.tapestry5.internal.services.PageResponseRendererImpl.renderPageResponse(PageResponseRendererImpl.java:67)
	at $PageResponseRenderer_13264d9b38100816.renderPageResponse(Unknown Source)
	at org.apache.tapestry5.internal.services.DefaultRequestExceptionHandler.handleRequestException(DefaultRequestExceptionHandler.java:85)
	at $RequestExceptionHandler_13264d9b381007fe.handleRequestException(Unknown Source)
	at org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:42)
	at $RequestHandler_13264d9b38100800.service(Unknown Source)
	at org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:902)
	at $RequestHandler_13264d9b38100800.service(Unknown Source)
	at org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:892)
	at $RequestHandler_13264d9b38100800.service(Unknown Source)
	at org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:90)
	at $RequestHandler_13264d9b38100800.service(Unknown Source)
	at org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:105)
	at org.apache.tapestry5.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:95)
	at org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:85)
	at org.apache.tapestry5.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:119)
	at $RequestHandler_13264d9b38100800.service(Unknown Source)
	at $RequestHandler_13264d9b381007f1.service(Unknown Source)
	at org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:253)
	at org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at org.got5.tapestry5.jquery.services.AjaxUploadServletRequestFilter.service(AjaxUploadServletRequestFilter.java:26)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper$1.doFilter(HttpServletRequestFilterWrapper.java:56)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:108)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper.service(HttpServletRequestFilterWrapper.java:52)
	at $HttpServletRequestFilter_13264d9b381007ed.service(Unknown Source)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper$1.doFilter(HttpServletRequestFilterWrapper.java:56)
	at nu.localhost.tapestry5.springsecurity.services.internal.SpringSecurityExceptionTranslationFilter.doFilter(SpringSecurityExceptionTranslationFilter.java:89)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper.service(HttpServletRequestFilterWrapper.java:52)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper$1.doFilter(HttpServletRequestFilterWrapper.java:56)
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper.service(HttpServletRequestFilterWrapper.java:52)
	at $HttpServletRequestFilter_13264d9b381007ec.service(Unknown Source)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper$1.doFilter(HttpServletRequestFilterWrapper.java:56)
	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper.service(HttpServletRequestFilterWrapper.java:52)
	at $HttpServletRequestFilter_13264d9b381007eb.service(Unknown Source)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper$1.doFilter(HttpServletRequestFilterWrapper.java:56)
	at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper.service(HttpServletRequestFilterWrapper.java:52)
	at $HttpServletRequestFilter_13264d9b381007ea.service(Unknown Source)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper$1.doFilter(HttpServletRequestFilterWrapper.java:56)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper.service(HttpServletRequestFilterWrapper.java:52)
	at $HttpServletRequestFilter_13264d9b381007e9.service(Unknown Source)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper$1.doFilter(HttpServletRequestFilterWrapper.java:56)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:65)
	at nu.localhost.tapestry5.springsecurity.services.internal.HttpServletRequestFilterWrapper.service(HttpServletRequestFilterWrapper.java:52)
	at $HttpServletRequestFilter_13264d9b381007e8.service(Unknown Source)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at org.apache.tapestry5.upload.internal.services.MultipartServletRequestFilter.service(MultipartServletRequestFilter.java:44)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
	at $HttpServletRequestFilter_13264d9b381007ef.service(Unknown Source)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at org.apache.tapestry5.services.TapestryModule$1.service(TapestryModule.java:852)
	at $HttpServletRequestHandler_13264d9b381007f3.service(Unknown Source)
	at $HttpServletRequestHandler_13264d9b381007e6.service(Unknown Source)
	at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:171)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1494)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1494)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1486)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:540)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1096)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1030)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:201)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
	at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:317)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
	at org.eclipse.jetty.server.Server.handle(Server.java:445)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:268)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
	at java.lang.Thread.run(Thread.java:724)
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: BaseURLSource with access to current request

Posted by Andy Pahne <li...@bodenkurier.de>.
Am 22.09.2013 um 18:48 schrieb Nicolas Bouillon <ni...@bouil.org>:

> Hi,
> 
> You can try starting you application server with this JVM options :
> 
> -Dtapestry.hostport-secure=443 -Dtapestry.hostport=80
> 
> Nicolas.
> 

That is not really an option, because I don't want to deploy to multiple tomcat instances just in order to have multiple virtual hosts running the same application (each of the VirtualHosts having a different server name).



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


VS: BaseURLSource with access to current request

Posted by Ville Virtanen <vi...@orientimport.fi>.
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:lists@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"
<vi...@orientimport.fi>:

> 
>    public static void contributeServiceOverride(final 
> MappedConfiguration<Class,Object> configuration, final Request request) {
>        BaseURLSource source = new  BaseURLSource()
>    {
>         ...
>    
>        configuration.add(BaseURLSource.class, source);
>    }
> 
> Ville


---------------------------------------------------------------------
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: BaseURLSource with access to current request

Posted by Andy Pahne <li...@bodenkurier.de>.
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(MappedConfiguration, 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" <vi...@orientimport.fi>:

> 
>    public static void contributeServiceOverride(final
> MappedConfiguration<Class,Object> configuration, final Request request) {
>        BaseURLSource source = new  BaseURLSource()
>    {
>         ...
>    
>        configuration.add(BaseURLSource.class, source);
>    }
> 
> Ville


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


VS: BaseURLSource with access to current request

Posted by Ville Virtanen <vi...@orientimport.fi>.
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
MappedConfiguration<Class,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:nicolas@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(MappedConfiguration<Class,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-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



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


Re: BaseURLSource with access to current request

Posted by Nicolas Bouillon <ni...@bouil.org>.
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(MappedConfiguration<Class,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-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: BaseURLSource with access to current request

Posted by Andy Pahne <li...@bodenkurier.de>.
Thanks. 

I used
     configuration.addInstance(…, …)

I also had to change the constructor of my overriding service, the injected constructor parameter needed an explicit @InjectService("Request") annotation. Both changes together and there wasn't an Exception anymore.

Andy


Am 23.09.2013 um 11:20 schrieb Lance Java <la...@googlemail.com>:

> 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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


VS: BaseURLSource with access to current request

Posted by Ville Virtanen <vi...@orientimport.fi>.
Thanks!

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

Ville

-----Alkuperäinen viesti-----
Lähettäjä: Lance Java [mailto:lance.java@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: BaseURLSource with access to current request

Posted by Lance Java <la...@googlemail.com>.
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.