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

Reply via email to