users@jersey.java.net

[Jersey] Re: UriInfo_at_getBaseUri() with a load balancer

From: Vetle Leinonen-Roeim <vetle_at_roeim.net>
Date: Wed, 05 Mar 2014 20:00:28 +0100

That depends! I took a look at the source code, and your result will
depend on how you deploy your Jersey application, and how your load
balancers are configured.

If you're deploying using the servlet container, the base URI is built
from HttpServletRequest.getRequestURL(), as seen in the code here:
https://github.com/jersey/jersey/blob/master/containers/jersey-servlet-core/src/main/java/org/glassfish/jersey/servlet/ServletContainer.java#L518

There's not really any way you'll find out what happens without testing
it, but if your load balancer and servlet container is configured
correctly, it should work fine. In this case Jersey and any other webapp
has to handle this the same way.

On 03/05/2014 06:47 PM, Eric Stein wrote:
> Thanks, Gili. My guess is the same as yours. I just don't want to have to set up a load balancer to confirm or refute it.
>
> I'm not sure how any of the UriInfo#getXXX() methods behave when there's a proxy or load balancer in the mix, and either I missed it or it's not in the docs.
>
> Thanks,
> Eric
>
> -----Original Message-----
> From: cowwoc [mailto:cowwoc_at_bbs.darktech.org]
> Sent: Wednesday, March 05, 2014 12:39 PM
> To: users_at_jersey.java.net
> Subject: [Jersey] Re: UriInfo_at_getBaseUri() with a load balancer
>
> I'm guessing this depends on the HOST header the client sends and whether anyone transforms it along the way. Meaning, in theory it would be the load-balancer address. That being said, this is a total guess.
> I'm curious what the JAX-RS authors have to say on this topic.
>
> Gili
>
> On 05/03/2014 12:14 PM, Eric Stein wrote:
>> Let's say I put a load balancer in front of my Jersey API server. So a client would call:
>>
>> http://mylb.example.com/api/resources/12
>>
>> which would push the call through to one of
>>
>> http://server1.example.com/api/resources/12
>> or
>> http://server2.example.com/api/resources/12
>>
>> When I call UriInfo#getBaseUri(), what will I see?
>> http://mylb.example.com/
>> or
>> http://server1.example.com/
>>
>> Thanks,
>> Eric
>>
>>
>
>