Search in sources :

Example 1 with UndertowHTTPServerEngine

use of org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngine in project cxf by apache.

the class ApplicationContextTest method checkContext.

private void checkContext(TestApplicationContext ctx) throws Exception {
    ConfigurerImpl cfg = new ConfigurerImpl(ctx);
    EndpointInfo info = getEndpointInfo("bla", "Foo", "http://localhost:9000");
    Bus bus = (Bus) ctx.getBean(Bus.DEFAULT_BUS_ID);
    bus.setExtension(cfg, Configurer.class);
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    DestinationFactory factory = dfm.getDestinationFactory("http://cxf.apache.org/transports/http");
    Destination d = factory.getDestination(info, bus);
    assertTrue(d instanceof UndertowHTTPDestination);
    UndertowHTTPDestination jd = (UndertowHTTPDestination) d;
    assertEquals("foobar", jd.getServer().getContentEncoding());
    UndertowHTTPServerEngine engine = (UndertowHTTPServerEngine) jd.getEngine();
    assertEquals(111, engine.getThreadingParameters().getMinThreads());
    assertEquals(120, engine.getThreadingParameters().getMaxThreads());
    ConduitInitiatorManager cim = bus.getExtension(ConduitInitiatorManager.class);
    ConduitInitiator ci = cim.getConduitInitiator("http://cxf.apache.org/transports/http");
    HTTPConduit conduit = (HTTPConduit) ci.getConduit(info, bus);
    assertEquals(97, conduit.getClient().getConnectionTimeout());
    info.setName(new QName("urn:test:ns", "Bar"));
    conduit = (HTTPConduit) ci.getConduit(info, bus);
    assertEquals(79, conduit.getClient().getConnectionTimeout());
    UndertowHTTPDestination jd2 = (UndertowHTTPDestination) factory.getDestination(getEndpointInfo("foo", "bar", "http://localhost:9001"), bus);
    engine = (UndertowHTTPServerEngine) jd2.getEngine();
    assertEquals(40000, engine.getMaxIdleTime());
    assertEquals(99, engine.getThreadingParameters().getMinThreads());
    assertEquals(777, engine.getThreadingParameters().getMaxThreads());
    assertNotNull("The handlers should not be null", engine.getHandlers());
    assertEquals(1, engine.getHandlers().size());
    UndertowHTTPDestination jd3 = (UndertowHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo", "https://localhost:9002"), bus);
    engine = (UndertowHTTPServerEngine) jd3.getEngine();
    assertEquals(111, engine.getThreadingParameters().getMinThreads());
    assertEquals(120, engine.getThreadingParameters().getMaxThreads());
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isWant(), true);
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isRequired(), true);
    UndertowHTTPDestination jd4 = (UndertowHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo2", "https://localhost:9003"), bus);
    engine = (UndertowHTTPServerEngine) jd4.getEngine();
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isWant(), false);
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isRequired(), false);
    UndertowHTTPDestination jd5 = (UndertowHTTPDestination) factory.getDestination(getEndpointInfo("sna", "foo", "http://localhost:9100"), bus);
    engine = (UndertowHTTPServerEngine) jd5.getEngine();
    String r = "expected fallback thread parameters configured for port 0";
    assertNotNull(r, engine.getThreadingParameters());
    assertEquals(r, 21, engine.getThreadingParameters().getMinThreads());
    assertEquals(r, 389, engine.getThreadingParameters().getMaxThreads());
}
Also used : UndertowHTTPServerEngine(org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngine) Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) Destination(org.apache.cxf.transport.Destination) UndertowHTTPDestination(org.apache.cxf.transport.http_undertow.UndertowHTTPDestination) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) ConfigurerImpl(org.apache.cxf.configuration.spring.ConfigurerImpl) UndertowHTTPDestination(org.apache.cxf.transport.http_undertow.UndertowHTTPDestination) QName(javax.xml.namespace.QName) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator)

Example 2 with UndertowHTTPServerEngine

use of org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngine in project cxf by apache.

the class HTTPUndertowTransportActivator method updated.

public void updated(String pid, Dictionary<String, ?> properties) throws ConfigurationException {
    if (pid == null) {
        return;
    }
    int port = Integer.parseInt((String) properties.get("port"));
    String host = (String) properties.get("host");
    try {
        TLSServerParameters tls = createTlsServerParameters(properties);
        if (tls != null) {
            factory.setTLSServerParametersForPort(host, port, tls);
        } else {
            factory.createUndertowHTTPServerEngine(host, port, "http");
        }
        UndertowHTTPServerEngine e = factory.retrieveUndertowHTTPServerEngine(port);
        configure(e, properties);
    } catch (GeneralSecurityException e) {
        throw new ConfigurationException(null, null, e);
    } catch (IOException e) {
        throw new ConfigurationException(null, null, e);
    }
}
Also used : UndertowHTTPServerEngine(org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngine) ConfigurationException(org.osgi.service.cm.ConfigurationException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters)

Example 3 with UndertowHTTPServerEngine

use of org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngine in project cxf by apache.

the class UndertowHTTPServerEngineFactoryHolder method init.

public void init() {
    try {
        Element element = StaxUtils.read(new StringReader(parsedElement)).getDocumentElement();
        UndertowHTTPServerEngineFactoryConfigType config = getJaxbObject(element, UndertowHTTPServerEngineFactoryConfigType.class);
        factory = new UndertowHTTPServerEngineFactory();
        Map<String, ThreadingParameters> threadingParametersMap = new TreeMap<String, ThreadingParameters>();
        if (config.getIdentifiedThreadingParameters() != null) {
            for (ThreadingParametersIdentifiedType threads : config.getIdentifiedThreadingParameters()) {
                ThreadingParameters rThreads = new ThreadingParameters();
                String id = threads.getId();
                rThreads.setMaxThreads(threads.getThreadingParameters().getMaxThreads());
                rThreads.setMinThreads(threads.getThreadingParameters().getMinThreads());
                rThreads.setWorkerIOThreads(threads.getThreadingParameters().getWorkerIOThreads());
                threadingParametersMap.put(id, rThreads);
            }
            factory.setThreadingParametersMap(threadingParametersMap);
        }
        // SSL
        Map<String, TLSServerParameters> sslMap = new TreeMap<String, TLSServerParameters>();
        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<UndertowHTTPServerEngine> engineList = new ArrayList<>();
        for (UndertowHTTPServerEngineConfigType engine : config.getEngine()) {
            UndertowHTTPServerEngine eng = new UndertowHTTPServerEngine();
            if (engine.getHandlers() != null && handlersMap != null) {
                List<CXFUndertowHttpHandler> 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.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.getThreadingParameters() != null) {
                ThreadingParametersType threads = engine.getThreadingParameters();
                ThreadingParameters rThreads = new ThreadingParameters();
                rThreads.setMaxThreads(threads.getMaxThreads());
                rThreads.setMinThreads(threads.getMinThreads());
                rThreads.setWorkerIOThreads(threads.getWorkerIOThreads());
                eng.setThreadingParameters(rThreads);
            }
            if (engine.getTlsServerParameters() != null) {
                TLSServerParameters parameter = null;
                try {
                    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 : UndertowHTTPServerEngine(org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngine) ThreadingParameters(org.apache.cxf.transport.http_undertow.ThreadingParameters) ThreadingParametersType(org.apache.cxf.transports.http_undertow.configuration.ThreadingParametersType) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) UndertowHTTPServerEngineFactoryConfigType(org.apache.cxf.transports.http_undertow.configuration.UndertowHTTPServerEngineFactoryConfigType) TreeMap(java.util.TreeMap) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) TLSServerParametersConfig(org.apache.cxf.configuration.jsse.TLSServerParametersConfig) JAXBException(javax.xml.bind.JAXBException) CXFUndertowHttpHandler(org.apache.cxf.transport.http_undertow.CXFUndertowHttpHandler) UndertowHTTPServerEngineFactory(org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngineFactory) ThreadingParametersIdentifiedType(org.apache.cxf.transports.http_undertow.configuration.ThreadingParametersIdentifiedType) UndertowHTTPServerEngineConfigType(org.apache.cxf.transports.http_undertow.configuration.UndertowHTTPServerEngineConfigType) StringReader(java.io.StringReader) TLSServerParametersIdentifiedType(org.apache.cxf.transports.http_undertow.configuration.TLSServerParametersIdentifiedType)

Aggregations

UndertowHTTPServerEngine (org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngine)3 TLSServerParameters (org.apache.cxf.configuration.jsse.TLSServerParameters)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 QName (javax.xml.namespace.QName)1 Bus (org.apache.cxf.Bus)1 TLSServerParametersConfig (org.apache.cxf.configuration.jsse.TLSServerParametersConfig)1 ConfigurerImpl (org.apache.cxf.configuration.spring.ConfigurerImpl)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)1 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)1 Destination (org.apache.cxf.transport.Destination)1 DestinationFactory (org.apache.cxf.transport.DestinationFactory)1 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)1 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)1