简体   繁体   中英

How to access configurations specified in XML of a jetty server from code

I've a jetty Server, what I want to configure for HTTPS traffic, I could do this, just simply modified some XML, and ini files (since this IoC is the preferred way), however I would like to access to some of these things which were configured in the xml from other classes, this is in the xml:

<Configure id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
  <Set name="KeyStoreType">PKCS12</Set>
  <Set name="KeyStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.keystore" default="etc/keystore"/></Set>
  <Set name="KeyStorePassword"><Property name="jetty.keystore.password" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
...

What I want is to call the sslContextFactory.getKeyStorePath() function somewhere in my codebase. But where is this sslContextFactory instance, where can I find it, how can I have a reference to it?

I am not entirely clear on what you are asking, but I am going to take a stab at it anyway. It sounds like you are familiar with running Jetty as a distribution and editing Jetty XML and ini files but now want to use some of the Jetty functionality as part of your embedded code?

For SSLContextFactory specifically, the class is included as part of the jetty-util jar file that comes with the distribution . You could also download that jar file by itself on Maven Central .

The official documentation for Jetty includes several examples of embedded Jetty functionality. This page may help you, specifically the example on Multiple Connectors , which uses SSL.

In fact it is not likely to be able to access the jetty standalone server's SSLContextFactory. Jetty by definition can host multiple applications at the same time, and acts like a container for those java web applications.

One option may be to use the embedded jetty server ( a solution here ), where you can start the jetty server within a java application (eg a jar package) and hold the references to your SSLContextFactory instance so that you can reload it whenever you like.

Another option may be using the maven jetty runner, again from another customized application, controlling the SslContextFactory yourself. This I cannot confirm at the moment, bu will update you as soon as I try it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM