You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Bas Gooren <ba...@iswd.nl> on 2013/06/25 17:55:45 UTC

Multitenant app: what's a good place to perform account lookup?

Hi *,

One of our multi-tenant apps uses the incoming hostname to look up the 
account to "attach" to.
We've currently handled it like so:
- Request scoped guice provider, which performs the lookup (which can 
return Account.UNKNOWN)
- Base page class which "validates" the account returned by the provides 
at construction time

This works quite well for us, but it does mean that any component not 
extending the base page class will also need to validate the account.

I think a more logical place to perform the lookup (and cache it) is in 
a request cycle listener.
However, in case no matching account is found, we need to render a 404 page.
One way of handling that is by throwing an 
AbortWithHttpErrorCodeException in onRequestHandlerResolved, since that 
will also allow us to inspect the resolved handler and check if it's 
pointing to our 404 page (to prevent a loop).

Is there a better/cleaner way to handle such concerns?

-- 

Met vriendelijke groet,
Kind regards,

Bas Gooren


Re: Multitenant app: what's a good place to perform account lookup?

Posted by Bas Gooren <ba...@iswd.nl>.
Martin,

Thanks, that's another possible solution indeed.

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 26-6-2013 9:29, schreef Martin Grigorov:
> Hi,
>
> I think you can use custom root request mapper for this too.
> See
> https://github.com/apache/wicket/blob/master/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/LocaleFirstMapper.java?source=cc
> -
> it extracts the locale from the first url segment.
>
>
> On Tue, Jun 25, 2013 at 6:55 PM, Bas Gooren <ba...@iswd.nl> wrote:
>
>> Hi *,
>>
>> One of our multi-tenant apps uses the incoming hostname to look up the
>> account to "attach" to.
>> We've currently handled it like so:
>> - Request scoped guice provider, which performs the lookup (which can
>> return Account.UNKNOWN)
>> - Base page class which "validates" the account returned by the provides
>> at construction time
>>
>> This works quite well for us, but it does mean that any component not
>> extending the base page class will also need to validate the account.
>>
>> I think a more logical place to perform the lookup (and cache it) is in a
>> request cycle listener.
>> However, in case no matching account is found, we need to render a 404
>> page.
>> One way of handling that is by throwing an AbortWithHttpErrorCodeExceptio*
>> *n in onRequestHandlerResolved, since that will also allow us to inspect
>> the resolved handler and check if it's pointing to our 404 page (to prevent
>> a loop).
>>
>> Is there a better/cleaner way to handle such concerns?
>>
>> --
>>
>> Met vriendelijke groet,
>> Kind regards,
>>
>> Bas Gooren
>>
>>


Re: Multitenant app: what's a good place to perform account lookup?

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

I think you can use custom root request mapper for this too.
See
https://github.com/apache/wicket/blob/master/wicket-examples/src/main/java/org/apache/wicket/examples/requestmapper/LocaleFirstMapper.java?source=cc
-
it extracts the locale from the first url segment.


On Tue, Jun 25, 2013 at 6:55 PM, Bas Gooren <ba...@iswd.nl> wrote:

> Hi *,
>
> One of our multi-tenant apps uses the incoming hostname to look up the
> account to "attach" to.
> We've currently handled it like so:
> - Request scoped guice provider, which performs the lookup (which can
> return Account.UNKNOWN)
> - Base page class which "validates" the account returned by the provides
> at construction time
>
> This works quite well for us, but it does mean that any component not
> extending the base page class will also need to validate the account.
>
> I think a more logical place to perform the lookup (and cache it) is in a
> request cycle listener.
> However, in case no matching account is found, we need to render a 404
> page.
> One way of handling that is by throwing an AbortWithHttpErrorCodeExceptio*
> *n in onRequestHandlerResolved, since that will also allow us to inspect
> the resolved handler and check if it's pointing to our 404 page (to prevent
> a loop).
>
> Is there a better/cleaner way to handle such concerns?
>
> --
>
> Met vriendelijke groet,
> Kind regards,
>
> Bas Gooren
>
>