users@servlet-spec.java.net

[servlet-spec users] [jsr340-experts] Re: New API ServletContext#addVirtualHostName

From: Greg Wilkins <gregw_at_intalio.com>
Date: Wed, 27 Feb 2013 08:19:56 +1100

Remy,

My understanding of this method is that it is on the servlet context,
thus it is available when there is no request (eg in the init method),
hence it is more than just syntax sugar over getHeader("Host").

I don't actually see a huge need for either the single valued method
or the multivalued one, as any usage of them for prepreparing URIs
etc. risks being wrong if the client uses a name mapping unknown to
the server. Ie the host header should always be used for generating
URIs in the name space of the client.

But the single valued one may be useful for logging or selecting a DB
partition or otherwise parameterizing configuration. I can't think of
any really good reasons for the multivalued one, but then I don't see
any reason to hide this information. Containers will have a list of
virtual names aliases (or patterns?) so why not expose this in a
standard way.

If we go with only the single valued one, then the javadoc should note
that multiple virtual host names may be configured for the context and
the method returns the preferred one (or at least the first).

cheers



On 26 February 2013 19:47, Rémy Maucherat <rmaucher_at_redhat.com> wrote:
> On 02/26/2013 02:59 AM, Greg Wilkins wrote:
>>
>> Shing,
>>
>> Contexts often have multiple virtual names, so I think this method
>> should have a multi-valued varient:
>>
>> Collection<String> getVirtualHostNames();
>>
>> I think the single valued one is also good as typically there is one
>> prime name and several aliases.
>
> I was about to send a comment that the proposed API should probably return
> the main name of the vhost (by opposition to the aliases). Another
> alternative is to return the content of the host header (but I'm not
> convinced this is really useful, after all the header is available already).
> So this should be clarified.
>
> The main question about that collection API is if there is a benefit for the
> webapp to know all the aliases for its vhost ? (and then the webapp won't
> know the "main" name of the vhost)
>
> Rémy
>



-- 
Greg Wilkins <gregw_at_intalio.com>
http://www.webtide.com
Developer advice and support from the Jetty & CometD experts.
Intalio, the modern way to build business applications.