Search in sources :

Example 6 with JettyHTTPServerEngineFactory

use of org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory in project cxf by apache.

the class JettyHTTPServerEngineFactoryHolder method init.

public void init() {
    try {
        Element element = StaxUtils.read(new StringReader(parsedElement)).getDocumentElement();
        JettyHTTPServerEngineFactoryConfigType config = getJaxbObject(element, JettyHTTPServerEngineFactoryConfigType.class);
        Bus defaultBus = BusFactory.getDefaultBus();
        factory = new JettyHTTPServerEngineFactory(defaultBus);
        Map<String, ThreadingParameters> threadingParametersMap = new TreeMap<>();
        if (config.getIdentifiedThreadingParameters() != null) {
            for (ThreadingParametersIdentifiedType threads : config.getIdentifiedThreadingParameters()) {
                ThreadingParameters rThreads = new ThreadingParameters();
                String id = threads.getId();
                if (threads.getThreadingParameters().getMaxThreads() != null) {
                    rThreads.setMaxThreads(threads.getThreadingParameters().getMaxThreads());
                }
                if (threads.getThreadingParameters().getMinThreads() != null) {
                    rThreads.setMinThreads(threads.getThreadingParameters().getMinThreads());
                }
                rThreads.setThreadNamePrefix(threads.getThreadingParameters().getThreadNamePrefix());
                threadingParametersMap.put(id, rThreads);
            }
            factory.setThreadingParametersMap(threadingParametersMap);
        }
        // SSL
        Map<String, TLSServerParameters> sslMap = new TreeMap<>();
        if (config.getIdentifiedTLSServerParameters() != null) {
            for (TLSServerParametersIdentifiedType t : config.getIdentifiedTLSServerParameters()) {
                try {
                    TLSServerParameters parameter = new TLSServerParametersConfig(t.getTlsServerParameters());
                    sslMap.put(t.getId(), parameter);
                } catch (Exception e) {
                    throw new RuntimeException("Could not configure TLS for id " + t.getId(), e);
                }
            }
            factory.setTlsServerParametersMap(sslMap);
        }
        // Engines
        List<JettyHTTPServerEngine> engineList = new ArrayList<>();
        for (JettyHTTPServerEngineConfigType engine : config.getEngine()) {
            JettyHTTPServerEngine eng = new JettyHTTPServerEngine(factory.getMBeanContainer(), engine.getHost(), engine.getPort());
            if (engine.getConnector() != null && connectorMap != null) {
                // we need to setup the Connector from the connectorMap
                Connector connector = connectorMap.get(engine.getPort().toString());
                if (connector != null) {
                    eng.setConnector(connector);
                } else {
                    throw new RuntimeException("Could not find the connector instance for engine with port" + engine.getPort().toString());
                }
            }
            if (engine.getHandlers() != null && handlersMap != null) {
                List<Handler> handlers = handlersMap.get(engine.getPort().toString());
                if (handlers != null) {
                    eng.setHandlers(handlers);
                } else {
                    throw new RuntimeException("Could not find the handlers instance for engine with port" + engine.getPort().toString());
                }
            }
            if (engine.isContinuationsEnabled() != null) {
                eng.setContinuationsEnabled(engine.isContinuationsEnabled());
            }
            if (engine.isSendServerVersion() != null) {
                eng.setSendServerVersion(engine.isSendServerVersion());
            }
            if (engine.getHost() != null && !StringUtils.isEmpty(engine.getHost())) {
                eng.setHost(engine.getHost());
            }
            if (engine.getMaxIdleTime() != null) {
                eng.setMaxIdleTime(engine.getMaxIdleTime());
            }
            if (engine.getPort() != null) {
                eng.setPort(engine.getPort());
            }
            if (engine.isReuseAddress() != null) {
                eng.setReuseAddress(engine.isReuseAddress());
            }
            if (engine.isSessionSupport() != null) {
                eng.setSessionSupport(engine.isSessionSupport());
            }
            if (engine.getSessionTimeout() != null) {
                eng.setSessionTimeout(engine.getSessionTimeout().intValue());
            }
            if (engine.getThreadingParameters() != null) {
                ThreadingParametersType threads = engine.getThreadingParameters();
                ThreadingParameters rThreads = new ThreadingParameters();
                if (threads.getMaxThreads() != null) {
                    rThreads.setMaxThreads(threads.getMaxThreads());
                }
                if (threads.getMinThreads() != null) {
                    rThreads.setMinThreads(threads.getMinThreads());
                }
                eng.setThreadingParameters(rThreads);
            }
            // eng.setServer(engine.getTlsServerParameters());
            if (engine.getTlsServerParameters() != null && (engine.getTlsServerParameters().getKeyManagers() != null || engine.getTlsServerParameters().getTrustManagers() != null)) {
                try {
                    TLSServerParameters parameter = new TLSServerParametersConfig(engine.getTlsServerParameters());
                    eng.setTlsServerParameters(parameter);
                } catch (Exception e) {
                    throw new RuntimeException("Could not configure TLS for engine on  " + eng.getHost() + ":" + eng.getPort(), e);
                }
            }
            eng.finalizeConfig();
            engineList.add(eng);
        }
        factory.setEnginesList(engineList);
        // Unravel this completely.
        factory.initComplete();
    } catch (Exception e) {
        throw new RuntimeException("Could not process configuration.", e);
    }
}
Also used : Bus(org.apache.cxf.Bus) ThreadingParameters(org.apache.cxf.transport.http_jetty.ThreadingParameters) JettyHTTPServerEngineConfigType(org.apache.cxf.transports.http_jetty.configuration.JettyHTTPServerEngineConfigType) Connector(org.eclipse.jetty.server.Connector) ThreadingParametersType(org.apache.cxf.transports.http_jetty.configuration.ThreadingParametersType) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Handler(org.eclipse.jetty.server.Handler) JettyHTTPServerEngineFactoryConfigType(org.apache.cxf.transports.http_jetty.configuration.JettyHTTPServerEngineFactoryConfigType) TreeMap(java.util.TreeMap) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) TLSServerParametersConfig(org.apache.cxf.configuration.jsse.TLSServerParametersConfig) JAXBException(javax.xml.bind.JAXBException) ThreadingParametersIdentifiedType(org.apache.cxf.transports.http_jetty.configuration.ThreadingParametersIdentifiedType) StringReader(java.io.StringReader) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) JettyHTTPServerEngineFactory(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory) TLSServerParametersIdentifiedType(org.apache.cxf.transports.http_jetty.configuration.TLSServerParametersIdentifiedType)

Example 7 with JettyHTTPServerEngineFactory

use of org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory in project cxf by apache.

the class TrustServerNoSpring method run.

protected void run() {
    Bus busLocal = BusFactory.getDefaultBus(true);
    setBus(busLocal);
    String address = "https://localhost:" + TrustManagerTest.PORT3 + "/SoapContext/HttpsPort";
    try {
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(ClassLoaderUtils.getResourceAsStream("keys/Bethal.jks", this.getClass()), "password".toCharArray());
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(keyStore, "password".toCharArray());
        TLSServerParameters tlsParams = new TLSServerParameters();
        tlsParams.setKeyManagers(kmf.getKeyManagers());
        ClientAuthentication clientAuthentication = new ClientAuthentication();
        clientAuthentication.setRequired(false);
        clientAuthentication.setWant(true);
        tlsParams.setClientAuthentication(clientAuthentication);
        Map<String, TLSServerParameters> map = new HashMap<>();
        map.put("tlsId", tlsParams);
        JettyHTTPServerEngineFactory factory = busLocal.getExtension(JettyHTTPServerEngineFactory.class);
        factory.setTlsServerParametersMap(map);
        factory.createJettyHTTPServerEngine("localhost", Integer.parseInt(TrustManagerTest.PORT3), "https", "tlsId");
        factory.initComplete();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    Endpoint.publish(address, new GreeterImpl());
}
Also used : Bus(org.apache.cxf.Bus) HashMap(java.util.HashMap) GreeterImpl(org.apache.cxf.systest.http.GreeterImpl) JettyHTTPServerEngineFactory(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory) KeyStore(java.security.KeyStore) ClientAuthentication(org.apache.cxf.configuration.security.ClientAuthentication) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 8 with JettyHTTPServerEngineFactory

use of org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory in project camel by apache.

the class CxfCustomerStartStopTest method startAndStopServiceFromSpring.

@Test
public void startAndStopServiceFromSpring() throws Exception {
    System.setProperty("CamelCxfConsumerContext.port2", Integer.toString(PORT2));
    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/CamelCxfConsumerContext.xml");
    Bus bus = applicationContext.getBean("cxf", Bus.class);
    // Bus shutdown will be called when the application context is closed.
    String orig = System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort", "false");
    IOHelper.close(applicationContext);
    System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort", orig == null ? "true" : "false");
    JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
    // test if the port is still used
    JettyHTTPServerEngine engine = factory.retrieveJettyHTTPServerEngine(PORT2);
    assertNull("Jetty engine should be removed", engine);
}
Also used : Bus(org.apache.cxf.Bus) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) JettyHTTPServerEngineFactory(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory) Test(org.junit.Test)

Aggregations

JettyHTTPServerEngineFactory (org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory)8 Bus (org.apache.cxf.Bus)6 TLSServerParameters (org.apache.cxf.configuration.jsse.TLSServerParameters)4 JettyHTTPServerEngine (org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine)4 KeyStore (java.security.KeyStore)3 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ClientAuthentication (org.apache.cxf.configuration.security.ClientAuthentication)2 Test (org.junit.Test)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)1 X509CertSelector (java.security.cert.X509CertSelector)1 TreeMap (java.util.TreeMap)1 CertPathTrustManagerParameters (javax.net.ssl.CertPathTrustManagerParameters)1 KeyManager (javax.net.ssl.KeyManager)1 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)1 JAXBElement (javax.xml.bind.JAXBElement)1