3

I am trying to use port unification for glassfish 4 to redirect any http request to https. I could easily do this with V3 but I am having issues with glassfish v4 - Java 1.7.

Commands that I executed in glassfish v4 -

asadmin create-protocol --securityenabled=false http-redirect asadmin create-protocol-filter --protocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpRedirectFilter redirect-filter

asadmin create-protocol --securityenabled=false pu-protocol asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-listener-2 --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-finder asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-redirect

set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=pu-protocol

All the above command execute without errors. However when I try accessing the web it throws exception and the http address does not launch - localhost:8080 fails

Exception in Glassfish -

WARNING: Exception during FilterChain execution java.lang.ClassCastException: org.glassfish.grizzly.memory.HeapMemoryManager$TrimmableHeapBuffer cannot be cast to org.glassfish.grizzly.http.HttpContent at org.glassfish.grizzly.config.portunif.HttpRedirectFilter.handleRead(HttpRedirectFilter.java:99) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.portunif.PUFilter.handleRead(PUFilter.java:231) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544) at java.lang.Thread.run(Thread.java:722)

Appreciate it if this can be resolved, is there any other way to do port redirection from http to https?

2 Answers 2

9

Make sure your last command includes "asadmin" as set is a DOS command.

This worked for me with GlassFish 4.0 when I used the following commands (although it looks pretty similar to yours):

asadmin create-protocol --securityenabled=false http-redirect

asadmin create-http-redirect --redirect-port 8181 --secure-redirect true http-redirect

asadmin create-protocol --securityenabled=false pu-protocol

asadmin create-protocol-filter --protocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpRedirectFilter redirect-filter

asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-listener-2 --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-finder

asadmin create-protocol-finder --protocol pu-protocol --targetprotocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-redirect

asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=pu-protocol

I have noticed that the this causes the HTTP tab for http-listener-1 (Configurations --> server-config --> Network Config --> Network Listeners --> http-listener-1 --> SSL tab) to no longer display. Not an issue for me.

3
  • 1
    Thanks for the reply, I will give it a try, Is there any documentation on this? which will help me understand the code
    – Mathew
    Sep 23, 2014 at 14:39
  • 1
    I can confirm that this works - saved me a lot of extra headache after a long day of trying hard and finally getting HTTPS to work, thanks!
    – ToVine
    Nov 6, 2014 at 18:55
  • Just one additional question, how to cancel all these 7 commands?
    – Hicham
    Mar 27, 2021 at 21:04
4

So I'm not sure why, but when I used the protocol name pu-protocol it would not configure correctly and it would not show up in the Admin console under the protocols list. All I had to do was use a different name for the protocol and everything worked fine. I used the name portunif-protocol and as soon as I ran the command to create it, it showed up in the Glassfish Admin console under the Protocols section as you would expect. Now I've got my site redirecting to https as desired!

Commands I used:

asadmin create-protocol --securityenabled=false http-redirect
asadmin create-http-redirect --redirect-port 443 --secure-redirect true http-redirect
asadmin create-protocol --securityenabled=false portunif-protocol
asadmin create-protocol-filter --protocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpRedirectFilter redirect-filter
asadmin create-protocol-finder --protocol portunif-protocol --targetprotocol http-listener-2 --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-finder
asadmin create-protocol-finder --protocol portunif-protocol --targetprotocol http-redirect --classname org.glassfish.grizzly.config.portunif.HttpProtocolFinder http-redirect
asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=portunif-protocol

Hope that helps anyone else that may have ran into the same issue I did.

1
  • Is this a good idea? For glassfish to even touch ports below 1024, it'll have to run with root priviges.
    – A.Grandt
    Feb 28, 2016 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.