Create Jetty Connectors in Pax-Web

1k views Asked by At

Is there a possibility (API) to add Jetty connectors via Pax-Web programmatically. Pax-Web internally uses a nice JettyServer interface, but there seems to be no OSGi service available. The ports that must be available are not known in advance, so I cannot use jetty.xml for configuration purposes.

Has anybody an idea?

2

There are 2 answers

7
Achim Nierbeck On

As you just seem to want to change the port you should do it the OSGi way and just configure pax web with the appropriate configuration. See also here: https://ops4j1.jira.com/wiki/display/paxweb/Basic+Configuration

The configuration in question is org.osgi.service.http.port

This port can be configured by the config admin service. In case of a configuration change the jetty server will be restarted.

Regarding the initial question about a service, this is not possible right now but there is a JIRA issue for it available, and contributions are highly appreciated.

1
Louis S. On

Starting from PaxWeb 4.1.0 you can register the connectors you need by registering them as service (it allows for instance to exclude the SSL protocols against Poodle vulnerability)

    SslContextFactory contextFactory = new SslContextFactory();
    contextFactory.addExcludeProtocols("SSLv2Hello", "SSLv3");
    contextFactory.setKeyStorePath("PATH_TO_KEYSTORE");
    contextFactory.setKeyStorePassword("KEYSTORE_PASSWORD");
    contextFactory.setTrustStore("PATH_TO_TRUSTSTORE");
    contextFactory.setTrustStorePassword("TRUSTSTORE_PASSWORD");
    contextFactory.setNeedClientAuth(true);
    contextFactory.setWantClientAuth(true);

    Connector sc = new SslSelectChannelConnector(contextFactory);
    sc.setPort(8443);
    ServiceRegistration<Connector> registerService = bundleContext.registerService(Connector.class, sc, null);

Mainly taken from pax web documentation http://ops4j.github.io/pax/web/SNAPSHOT/