Ratpack HTTPS

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Ratpack HTTPS

LosPejos
Hi!
Am I able to run Ratpack so it serves HTTPS connections? Searched docs, tutorials, and nothing found (
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack HTTPS

zedar185
Yes, https is supported.
Examples of keystore and trustore configuration: https://github.com/ratpack/ratpack/blob/master/ratpack-core/src/test/groovy/ratpack/ssl/HttpsTruststoreSpec.groovy

Helper class for SSL configuration: https://github.com/ratpack/ratpack/blob/master/ratpack-core/src/main/java/ratpack/ssl/SSLContexts.java#L62

We extended support for keystore and trustore in 0.9.18.

BTW, ratpack's non-blocking HttpClient supports ssl context too.
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack HTTPS

LosPejos
Thank you very much. Could you please provide some example of how to setup ssl/https in ratpack.groovy file? Probably there is some sample project with https set in ratpack?
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack HTTPS

zedar185
If you have keystore on the class path, for example in src/main/resources/keystore.jks you can initialize ssl context as follows:

ratpack {
  serverConfig {
    ssl SSLContexts.sslContext(ServerConfig.class.getResource("/keystore.jks"), "password")
  }

  handlers {

    get("") {
      response.send "ok"
    }
  }
}

If you want to use keystore and truststore there is another method in SSLContexts helper class.
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack HTTPS

LosPejos
Added code to my ratpack/ratpack.groovy as described above:
        serverConfig {
                ssl SSLContexts.sslContext(ServerConfig.class.getResource("/keystore.jks"), "password")
        }

Got error:
groovy.lang.MissingPropertyException: No such property: SSLContexts for class: ratpack.server.internal.DefaultServerConfigBuilder

Am I missing something in build.gradle?
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack HTTPS

johnrengelman
SSLContexts is a class, so you need to import it just like a normal Java/Groovy class:

import ratpack.ssl.SSLContexts
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack HTTPS

LosPejos
Well, I've done import statement, but error still exists.
Probably I missed something else
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack HTTPS

yogesh
In reply to this post by zedar185
Hey, I am using ratpack with spring boot So my application main class is of spring boot as below

public static void main(String[] args) {
                SpringApplication.run(APIApplication.class, args);
}

and I am using @EnableRatpack annotation to enable ratpack within spring boot. So is there any way we can configure ssl with ratpack without affecting my spring boot application.

I am trying with
 RatpackServer.start(server -> server
                                 .serverConfig(ServerConfig.embedded().ssl(SSLContexts.sslContext(ServerConfig.class.getResource("/xyzkeystore"), "yogesh")))
                             .registry(spring(APIApplication.class))
                             .handlers(chains)
                );
but its effect my spring configuration beans . I mean beans are not initialized properly.

rus
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack HTTPS

rus
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack HTTPS

yogesh
Thanks rus it works
rus
Reply | Threaded
Open this post in threaded view
|

Re: Ratpack HTTPS

rus
Great!  

Please feel free to update the docs to be more helpful here :)