1

In Jetty 8, it was fairly easy to overwrite the standard server port and add an SSL connector in a custom jetty.xml file as follows:

<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <Call name="addConnector">
    <Arg>
      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <Set name="port">8984</Set>
        <Set name="confidentialPort">8986</Set>
      </New>
    </Arg>
  </Call>

  <Call name="addConnector">
    <Arg>
      <New class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
        <Set name="Port">8986</Set>
        <!-- keystore, password, keyPassword, ... -->
      </New>
    </Arg>
  </Call>
</Configure>

As this configuration is not accepted by Jetty 9 anymore, I have checked out the Jetty documentation and related StackOverflow issues (like How to override jetty.xml with jetty.port) without success.

How can the configuration be rewritten to do the same in Jetty 9?

Community
  • 1
  • 1
Christian Grün
  • 6,012
  • 18
  • 34
  • On jetty9, basex http server works for me using jetty.xml : https://gist.githubusercontent.com/apb2006/b24e92f84c42838ec7ef7de2cf937835/raw/65cf6ddb74e3e2cda17cc6883866c85e438a5c3b/jetty.xml refers to this as well: https://mailman.uni-konstanz.de/pipermail/basex-talk/2018-March/012977.html – digi Dec 12 '20 at 23:39
  • Yes, we found a solution that works pretty well (and we forgot to share this here). – Christian Grün Dec 13 '20 at 10:07

1 Answers1

1

There is little to no reason to be editing XML files anymore with Jetty 9.

Use the Jetty 9 module system and ${jetty.base} concepts.

$ cd /opt/jetty
$ tar -zxvf jetty-distribution-9.3.3.v20150827.tar.gz
$ mkdir my.base
$ cd my.base
$ java -jar ../jetty-distribution-9.3.3.v20150827/start.jar \
  --add-to-start=http,https,deploy,webapp
INFO: server          initialised (transitively) in ${jetty.base}/start.ini
INFO: http            initialised in ${jetty.base}/start.ini
INFO: ssl             initialised (transitively) in ${jetty.base}/start.ini
INFO: https           initialised in ${jetty.base}/start.ini
INFO: webapp          initialised in ${jetty.base}/start.ini
INFO: deploy          initialised in ${jetty.base}/start.ini
DOWNLOAD: http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/plain/jetty-server/src/test/config/etc/keystore?id=master to ${jetty.base}/etc/keystore
MKDIR: ${jetty.base}/webapps
INFO: Base directory was modified
$ ls -laF$ ls -laF
total 48
drwxrwxr-x.  4 joakim joakim  4096 Sep 23 06:01 ./
drwxr-xr-x. 22 joakim joakim 12288 Sep 23 06:00 ../
drwxrwxr-x.  2 joakim joakim  4096 Sep 23 06:01 etc/
-rw-rw-r--.  1 joakim joakim  5009 Sep 23 06:01 start.ini
drwxrwxr-x.  2 joakim joakim  4096 Sep 23 06:01 webapps/

At this point:

  • Replace the etc/keystore file with your SSL keystore.
  • Edit the start.ini for:
    • your http port (jetty.http.port)
    • your https port (jetty.https.port)
    • and your various SslContext / keystore values (see keys starting with jetty.sslContext.)

When complete, run Jetty ..

$ cd /opt/jetty/my.base
$ java -jar ../jetty-distribution-9.3.3.v20150827/start.jar
2015-09-23 06:05:40.619:INFO::main: Logging initialized @272ms
2015-09-23 06:05:40.764:INFO:oejs.Server:main: jetty-9.3.3.v20150827
2015-09-23 06:05:40.779:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///home/joakim/code/jetty/distros/my.base/webapps/] at interval 1
2015-09-23 06:05:40.790:INFO:oejs.ServerConnector:main: Started ServerConnector@1718d616{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2015-09-23 06:05:40.810:INFO:oejus.SslContextFactory:main: x509=X509@7e0babb1(jetty,h=[jetty.eclipse.org],w=[]) for SslContextFactory@6debcae2(file:///home/joakim/code/jetty/distros/my.base/etc/keystore,file:///home/joakim/code/jetty/distros/my.base/etc/keystore)
2015-09-23 06:05:40.810:INFO:oejus.SslContextFactory:main: x509=X509@5ba23b66(mykey,h=[],w=[]) for SslContextFactory@6debcae2(file:///home/joakim/code/jetty/distros/my.base/etc/keystore,file:///home/joakim/code/jetty/distros/my.base/etc/keystore)
2015-09-23 06:05:41.026:INFO:oejs.ServerConnector:main: Started ServerConnector@305fd85d{SSL,[ssl, http/1.1]}{0.0.0.0:8443}
2015-09-23 06:05:41.027:INFO:oejs.Server:main: Started @680ms

Curious what your server configuration looks like? Run this...

$ cd /opt/jetty/my.base
$ java -jar ../jetty-distribution-9.3.3.v20150827/start.jar --list-config
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • Thanks for your feedback! We are configuring and starting Jetty from another software (see https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/java/org/basex/BaseXHTTP.java), and we are using a self-contained [jetty.xml](https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/webapp/WEB-INF/jetty.xml) file to configure Jetty-specific settings. I am wondering if we can maintain a similar setting with Jetty 9? – Christian Grün Sep 25 '15 at 11:42
  • Here is some (basic) [user documentation](http://docs.basex.org/wiki/Web_Application) on how we use jetty.xml. – Christian Grün Sep 25 '15 at 11:45
  • Not without some serious code updates from BaseXdb (eg: it makes assumptions about the connectors and connector architecture that are not valid). There's no such thing as a SelectChannelConnector in Jetty 9+, as its moved on with the needs of the modern world (TLS/ALPN) and the updates that HTTP/2 bring to the table. The old SelectChannelConnector concept was insufficient to accomplish this. – Joakim Erdfelt Sep 25 '15 at 13:35