Search in sources :

Example 1 with NettyHttpServerEngine

use of org.apache.cxf.transport.http.netty.server.NettyHttpServerEngine in project cxf by apache.

the class NettyHttpServerEngineFactoryHolder method init.

public void init() {
    try {
        Element element = StaxUtils.read(new StringReader(parsedElement)).getDocumentElement();
        NettyHttpServerEngineFactoryConfigType config = (NettyHttpServerEngineFactoryConfigType) getJaxbObject(element, NettyHttpServerEngineFactoryConfigType.class);
        factory = new NettyHttpServerEngineFactory();
        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.setThreadPoolSize(threads.getThreadingParameters().getThreadPoolSize());
                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.setTlsServerParameters(sslMap);
        }
        // Engines
        List<NettyHttpServerEngine> engineList = new ArrayList<>();
        for (NettyHttpServerEngineConfigType engine : config.getEngine()) {
            NettyHttpServerEngine eng = new NettyHttpServerEngine();
            if (engine.getHost() != null && !StringUtils.isEmpty(engine.getHost())) {
                eng.setHost(engine.getHost());
            }
            if (engine.getReadIdleTime() != null) {
                eng.setReadIdleTime(engine.getReadIdleTime());
            }
            if (engine.getWriteIdleTime() != null) {
                eng.setWriteIdleTime(engine.getWriteIdleTime());
            }
            if (engine.getMaxChunkContentSize() != null) {
                eng.setMaxChunkContentSize(engine.getMaxChunkContentSize());
            }
            if (engine.getPort() != null) {
                eng.setPort(engine.getPort());
            }
            if (engine.isSessionSupport() != null) {
                eng.setSessionSupport(engine.isSessionSupport());
            }
            if (engine.getThreadingParameters() != null) {
                ThreadingParametersType threads = engine.getThreadingParameters();
                ThreadingParameters rThreads = new ThreadingParameters();
                rThreads.setThreadPoolSize(threads.getThreadPoolSize());
                eng.setThreadingParameters(rThreads);
            }
            // eng.setServer(engine.getTlsServerParameters());
            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 : NettyHttpServerEngineFactory(org.apache.cxf.transport.http.netty.server.NettyHttpServerEngineFactory) ThreadingParameters(org.apache.cxf.transport.http.netty.server.ThreadingParameters) ThreadingParametersType(org.apache.cxf.transports.http_netty_server.configuration.ThreadingParametersType) NettyHttpServerEngineFactoryConfigType(org.apache.cxf.transports.http_netty_server.configuration.NettyHttpServerEngineFactoryConfigType) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters) TLSServerParametersConfig(org.apache.cxf.configuration.jsse.TLSServerParametersConfig) JAXBException(javax.xml.bind.JAXBException) NettyHttpServerEngine(org.apache.cxf.transport.http.netty.server.NettyHttpServerEngine) NettyHttpServerEngineConfigType(org.apache.cxf.transports.http_netty_server.configuration.NettyHttpServerEngineConfigType) ThreadingParametersIdentifiedType(org.apache.cxf.transports.http_netty_server.configuration.ThreadingParametersIdentifiedType) StringReader(java.io.StringReader) TLSServerParametersIdentifiedType(org.apache.cxf.transports.http_netty_server.configuration.TLSServerParametersIdentifiedType)

Example 2 with NettyHttpServerEngine

use of org.apache.cxf.transport.http.netty.server.NettyHttpServerEngine 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 NettyHttpDestination);
    NettyHttpDestination jd = (NettyHttpDestination) d;
    assertEquals("foobar", jd.getServer().getContentEncoding());
    NettyHttpServerEngine engine = (NettyHttpServerEngine) jd.getEngine();
    assertEquals(120, engine.getThreadingParameters().getThreadPoolSize());
    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());
    NettyHttpDestination jd2 = (NettyHttpDestination) factory.getDestination(getEndpointInfo("foo", "bar", "http://localhost:9001"), bus);
    engine = (NettyHttpServerEngine) jd2.getEngine();
    assertEquals(40000, engine.getReadIdleTime());
    assertEquals(10000, engine.getMaxChunkContentSize());
    assertTrue("The engine should support session manager", engine.isSessionSupport());
    NettyHttpDestination jd3 = (NettyHttpDestination) factory.getDestination(getEndpointInfo("sna", "foo", "https://localhost:9002"), bus);
    engine = (NettyHttpServerEngine) jd3.getEngine();
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isWant(), true);
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isRequired(), true);
    NettyHttpDestination jd4 = (NettyHttpDestination) factory.getDestination(getEndpointInfo("sna", "foo2", "https://localhost:9003"), bus);
    engine = (NettyHttpServerEngine) jd4.getEngine();
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isWant(), false);
    assertEquals(engine.getTlsServerParameters().getClientAuthentication().isRequired(), false);
/*NettyHttpDestination jd5 =
            (NettyHttpDestination)factory.getDestination(
                getEndpointInfo("sna", "foo", "http://localhost:9100"));*/
/*engine = (NettyHttpServerEngine)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 : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) Destination(org.apache.cxf.transport.Destination) NettyHttpDestination(org.apache.cxf.transport.http.netty.server.NettyHttpDestination) NettyHttpServerEngine(org.apache.cxf.transport.http.netty.server.NettyHttpServerEngine) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) ConfigurerImpl(org.apache.cxf.configuration.spring.ConfigurerImpl) QName(javax.xml.namespace.QName) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) NettyHttpDestination(org.apache.cxf.transport.http.netty.server.NettyHttpDestination)

Aggregations

NettyHttpServerEngine (org.apache.cxf.transport.http.netty.server.NettyHttpServerEngine)2 StringReader (java.io.StringReader)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 TLSServerParameters (org.apache.cxf.configuration.jsse.TLSServerParameters)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 NettyHttpDestination (org.apache.cxf.transport.http.netty.server.NettyHttpDestination)1 NettyHttpServerEngineFactory (org.apache.cxf.transport.http.netty.server.NettyHttpServerEngineFactory)1