users@grizzly.java.net

Re: How to redirect HTTP to HTTPS

From: Oleksiy Stashok <oleksiy.stashok_at_oracle.com>
Date: Mon, 27 Jan 2014 17:45:49 -0800

On 27.01.14 17:24, Joe Lin wrote:
> Thanks for the reply
>
> You mention to register a regular HttpHandler on port 80. According to
> Grizzly API, it seems that we can only register a handler based on
> request path?
It could be "" (default) path and if you don't register other
HttpHandlers on this HttpServer - the default HttpHandler will be
invoked for all requests.

WBR,
Alexey.

>
> Regards,
> Joe
>
>
> On Fri, Jan 24, 2014 at 10:35 PM, Oleksiy Stashok
> <oleksiy.stashok_at_oracle.com <mailto:oleksiy.stashok_at_oracle.com>> wrote:
>
> Hi Joe,
>
> IMO the easiest way to solve this is to register HttpHandler on
> port 80 and make it return HTTP response with status 301, and
> Location header redirecting the client to port 443.
>
> new HttpHandler() {
>
> @Override
> public void service(Request request, Response
> response) throws Exception {
> response.setStatus(HttpStatus.MOVED_PERMANENTLY_301);
> response.setHeader(Header.Location, "https://..."
> <https://...>);
> }
> }
>
> Hope that helps.
>
> WBR,
> Alexey.
>
>
> On 24.01.14 21:24, Joe Lin wrote:
>> Hi,
>>
>> I'm running Grizzily 2.3.7. My question is how can I redirect all
>> normal HTTP at 80 traffic to HTTPS at 443?
>>
>> Thanks.
>> Joe
>
>