| 1 | # Jetty |
| 2 | |
| 3 | This extension provides a `JettyService`, a Servlet Context Container that can expose REST API on a Jersey based |
| 4 | WebServer. |
| 5 | |
| 6 | ## Terminate SSL in the connector runtime |
| 7 | |
| 8 | While it is generally advised to handle HTTPS/SSL/TLS termination through deployment mechanisms such as |
| 9 | Kubernetes, or an API gateway, there are situations where SSL termination directly in the connector is |
| 10 | needed. |
| 11 | |
| 12 | In order to do that, users must set up a Java keystore ( |
| 13 | see [Jetty documentation](https://www.eclipse.org/jetty/documentation/jetty-10/operations-guide/index.html#og-keystore)) |
| 14 | that contains the certificate. Both official and self-signed certificates work. |
| 15 | |
| 16 | The following Java properties can be used to configure Jetty to actually use the keystore: |
| 17 | |
| 18 | | Config Key | Description | Required | Default | |
| 19 | |-----------------------------------|---------------------------------------------------------------|----------|------------| |
| 20 | | `edc.web.https.keystore.password` | Password for the keystore | yes | "password" | |
| 21 | | `edc.web.https.keymanager.password` | Password for the private key | yes | "password" | |
| 22 | | `edc.web.https.keystore.path` | Absolute path on the filesystem where the keystore is located | yes | null | |
| 23 | | `edc.web.https.keystore.type` | Type of keystore, could be "JKS" or "PKCS12" | no | "PKCS12" | |
| 24 | |
| 25 | ## Expose different web contexts |
| 26 | |
| 27 | By default we have the `web.http.port` |
| 28 | and `web.http.path` config entry with the following default values: |
| 29 | |
| 30 | ```properties |
| 31 | web.http.port=8181 |
| 32 | web.http.path=/api |
| 33 | ``` |
| 34 | |
| 35 | That will expose any resource under `http://<host>:8181/api/*`. |
| 36 | |
| 37 | _Please note that under the hood `web.http.*` gets expanded to `web.http.default.*`_ |
| 38 | |
| 39 | In some situations it is required to expose a part of the public API under another port or path, which can be achieved |
| 40 | by using port mappings. First, a "named" |
| 41 | property group needs to be created using the following configuration. The example will create a port mapping with the |
| 42 | name/alias `"health"`: |
| 43 | |
| 44 | ```properties |
| 45 | web.http.health.port=9191 |
| 46 | web.http.health.path=/api/v1/health |
| 47 | ``` |
| 48 | |
| 49 | Second, the resource must be registered using that context alias (`"health"`): |
| 50 | |
| 51 | ```java |
| 52 | public class YourExtension { |
| 53 | |
| 54 | @Inject |
| 55 | private WebService webService; |
| 56 | |
| 57 | void initialize(ServiceExtensionContext context) { |
| 58 | //... |
| 59 | webService.registerResource("health", new HealthController()); |
| 60 | } |
| 61 | } |
| 62 | ``` |
| 63 | |
| 64 | which will expose any resources that the `HealthController` provides under `http://<host>:9191/api/v1/health/*` |
| 65 | |
| 66 | ## Best practice |
| 67 | |
| 68 | In situations where an API is made up of multiple controllers, it is best to expose the APIs base path using this |
| 69 | mechanism, register the controllers with the |
| 70 | port mapping's context alias and have the controllers themselves handle any sub-paths. |
| 71 | |
| 72 | ## Limitations |
| 73 | |
| 74 | - Attempting to register two port mappings with the same port will raise an exception. This also takes into account the |
| 75 | implicit default values |
| 76 | - Attempting to register two port mappings with the same path will raise an exception, even if different ports are used. |
| 77 | This has to do with the way how servlet |
| 78 | contexts are mapped internally and may change in future releases. |