For anyone who uses heroku to host their Jersey REST Server and uses a
Heroku SSL end-point you may find this interesting.
It may not be the BEST solution but it worked for me and made life much
simpler. Even though my clients used SSL my server got all requests using
the HTTP scheme, which made me give clients bad redirection URLS (like for
a Response.seeOther).
I just added this simple filter (again, maybe not the best solution) and it
fixed all my issues with only minimal code changes (and centralizing the
Heroku request filter code in case I needed to make any more changes).
@PreMatching
public class HerokuContainerRequestFilter implements ContainerRequestFilter {
@Override
public void filter( ContainerRequestContext ctx ) throws IOException {
List<String> schemes = ctx.getHeaders().get( "x-forwarded-proto" );
if ( schemes != null && !schemes.isEmpty() ) {
String scheme = schemes.get( 0 );
UriBuilder builder = ctx.getUriInfo().getRequestUriBuilder();
ctx.setRequestUri( builder.scheme( scheme ).build() );
}
}
}
Just register the above class with your RestConfig and you should be good
to go. Also, if anyone has any better suggestions or improvements let me
know. (Short of modifying the configuration of different web servers like
Jetty or Tomcat).