You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by peibel <p....@ibermatica.com> on 2009/01/14 12:01:34 UTC
example BaseURLSource: T5
Hi,
Someone has an example using BaseURLSource, is very important, I'm tired and
I don´t get going from http to https from an http link to the page.
thanks for your help
--
View this message in context: http://www.nabble.com/example-BaseURLSource%3A-T5-tp21453809p21453809.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
Re: example BaseURLSource: T5
Posted by Howard Lewis Ship <hl...@gmail.com>.
Note that you can inject HttpServletRequest instead of RequestGlobals.
On Wed, Jan 14, 2009 at 3:50 AM, Onno Scheffers <on...@piraya.nl> wrote:
> This version prepends http or https before the url. In production mode it
> builds on a fixed url and in development mode it returns whatever you used
> to get to the page (localhost? IP?) and adds the right port-number to it. It
> is a stripped down version of my actual implementation, since that
> application can be accessed in different modes from different urls so I hope
> I didn't strip out to much :o)
>
> public class SSLBaseURLSource implements BaseURLSource {
> private boolean production;
> private RequestGlobals requestGlobals;
>
> public SSLBaseURLSource(
> final boolean production,
> final RequestGlobals requestGlobals) {
> this.production = production;
> this.requestGlobals = requestGlobals;
> }
>
> public String getBaseURL(final boolean secure) {
> StringBuilder result = new StringBuilder(secure ? "https://" :
> "http://");
> if(production) {
> result.append("www.myurl.com");
> } else {
> String requestURL =
> requestGlobals.getHTTPServletRequest().getRequestURL().toString();
> int index = requestURL.indexOf("://");
> if(index > 0) {
> requestURL = requestURL.substring(index + 3);
> }
> index = requestURL.indexOf(":");
> if(index > 0) {
> requestURL = requestURL.substring(0, index + 1);
> }
> result.append(requestURL).append(secure ? "8443" : "8080");
> }
> return result.toString();
> }
> }
>
> And then from the AppModule:
> public static void contributeAlias(
> @Symbol(SymbolConstants.PRODUCTION_MODE) final boolean
> productionMode,
> @InjectService("ApplicationStateManager") final
> ApplicationStateManager applicationStateManager,
> @InjectService("RequestGlobals") final RequestGlobals
> requestGlobals,
> final Configuration<AliasContribution> configuration) {
> AliasContribution<BaseURLSource> aliasContribution = new
> AliasContribution<BaseURLSource>(
> BaseURLSource.class,
> new SSLBaseURLSource(productionMode, requestGlobals)
> );
> configuration.add(aliasContribution);
> }
>
> Hope this helps.
>
> regards,
>
> Onno Scheffers
>
>
> On Wed, Jan 14, 2009 at 12:01 PM, peibel <p....@ibermatica.com> wrote:
>
>>
>>
>> Hi,
>>
>> Someone has an example using BaseURLSource, is very important, I'm tired
>> and
>> I don´t get going from http to https from an http link to the page.
>>
>> thanks for your help
>> --
>> View this message in context:
>> http://www.nabble.com/example-BaseURLSource%3A-T5-tp21453809p21453809.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
>>
>>
>
--
Howard M. Lewis Ship
Creator Apache Tapestry and Apache HiveMind
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: example BaseURLSource: T5
Posted by Onno Scheffers <on...@piraya.nl>.
This version prepends http or https before the url. In production mode it
builds on a fixed url and in development mode it returns whatever you used
to get to the page (localhost? IP?) and adds the right port-number to it. It
is a stripped down version of my actual implementation, since that
application can be accessed in different modes from different urls so I hope
I didn't strip out to much :o)
public class SSLBaseURLSource implements BaseURLSource {
private boolean production;
private RequestGlobals requestGlobals;
public SSLBaseURLSource(
final boolean production,
final RequestGlobals requestGlobals) {
this.production = production;
this.requestGlobals = requestGlobals;
}
public String getBaseURL(final boolean secure) {
StringBuilder result = new StringBuilder(secure ? "https://" :
"http://");
if(production) {
result.append("www.myurl.com");
} else {
String requestURL =
requestGlobals.getHTTPServletRequest().getRequestURL().toString();
int index = requestURL.indexOf("://");
if(index > 0) {
requestURL = requestURL.substring(index + 3);
}
index = requestURL.indexOf(":");
if(index > 0) {
requestURL = requestURL.substring(0, index + 1);
}
result.append(requestURL).append(secure ? "8443" : "8080");
}
return result.toString();
}
}
And then from the AppModule:
public static void contributeAlias(
@Symbol(SymbolConstants.PRODUCTION_MODE) final boolean
productionMode,
@InjectService("ApplicationStateManager") final
ApplicationStateManager applicationStateManager,
@InjectService("RequestGlobals") final RequestGlobals
requestGlobals,
final Configuration<AliasContribution> configuration) {
AliasContribution<BaseURLSource> aliasContribution = new
AliasContribution<BaseURLSource>(
BaseURLSource.class,
new SSLBaseURLSource(productionMode, requestGlobals)
);
configuration.add(aliasContribution);
}
Hope this helps.
regards,
Onno Scheffers
On Wed, Jan 14, 2009 at 12:01 PM, peibel <p....@ibermatica.com> wrote:
>
>
> Hi,
>
> Someone has an example using BaseURLSource, is very important, I'm tired
> and
> I don´t get going from http to https from an http link to the page.
>
> thanks for your help
> --
> View this message in context:
> http://www.nabble.com/example-BaseURLSource%3A-T5-tp21453809p21453809.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
>
>