users@jersey.java.net

[Jersey] Re: x-forwarded-proto and _at_Context

From: Robert DiFalco <robert.difalco_at_gmail.com>
Date: Thu, 6 Feb 2014 11:12:27 -0800

Okay, I figured out how to get this from @Context HttpHeaders, what I can't
figure out is the simplest/cleanest way to replace HTTP with this value
(say HTTPS) in a path from UriInfo.getAbsolutePathBuilder. I would like to
do the equivalent of this:

String fowardedProto = headers.getHeaderString( "x-forwarded-proto" );
String protocol = fowardedProto == null ? "http" : fowardedProto;

URI seeOtherLocation = uriInfo.getAbsolutePathBuilder().protocol( protocol
).path( userId.toString() ).build();

But of course there is no simple "protocol" method in UriBuilder. So what's
the best way?



On Thu, Feb 6, 2014 at 10:42 AM, Robert DiFalco <robert.difalco_at_gmail.com>wrote:

> Hi, my server sits on heroku which uses an SSL Endpoint. It looks like
> heroku handles the SSL itself and sends the requests on to my server as
> HTTP.
>
> I need to create a 303 location that knows if the request was HTTP or
> HTTPS. To do this I need to look at the x-forwarded-proto.
>
> How can I get this from within a REST call (for example a GET)? I need to
> make sure the location I give to the client for the 303 is properly
> specified as HTTP or HTTPS based on this.
>
> Thanks!
>