Search in sources :

Example 1 with JettyHTTPServerEngine

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

the class CxfCustomerStartStopTest method startAndStopService.

@Test
public void startAndStopService() throws Exception {
    CamelContext context = new DefaultCamelContext();
    // start a server    
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("cxf:http://localhost:" + PORT1 + "/test?serviceClass=org.apache.camel.component.cxf.HelloService").to("log:endpoint");
        }
    });
    context.start();
    Thread.sleep(300);
    context.stop();
    Bus bus = BusFactory.getDefaultBus();
    JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
    JettyHTTPServerEngine engine = factory.retrieveJettyHTTPServerEngine(PORT1);
    assertNotNull("Jetty engine should be found there", engine);
    // Need to call the bus shutdown ourselves.
    String orig = System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort", "false");
    bus.shutdown(true);
    System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort", orig == null ? "true" : "false");
    engine = factory.retrieveJettyHTTPServerEngine(PORT1);
    assertNull("Jetty engine should be removed", engine);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Bus(org.apache.cxf.Bus) RouteBuilder(org.apache.camel.builder.RouteBuilder) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) JettyHTTPServerEngineFactory(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 2 with JettyHTTPServerEngine

use of org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine in project tesb-rt-se by Talend.

the class ApplicationServer method startApplication.

private static Server startApplication(Application app) {
    RuntimeDelegate delegate = RuntimeDelegate.getInstance();
    JAXRSServerFactoryBean bean = delegate.createEndpoint(app, JAXRSServerFactoryBean.class);
    bean.setAddress("http://localhost:8080" + bean.getAddress());
    bean.setStart(false);
    Server server = bean.create();
    JettyHTTPDestination dest = (JettyHTTPDestination) server.getDestination();
    JettyHTTPServerEngine engine = (JettyHTTPServerEngine) dest.getEngine();
    engine.setSessionSupport(true);
    server.start();
    return server;
}
Also used : Server(org.apache.cxf.endpoint.Server) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) JettyHTTPDestination(org.apache.cxf.transport.http_jetty.JettyHTTPDestination) RuntimeDelegate(javax.ws.rs.ext.RuntimeDelegate)

Example 3 with JettyHTTPServerEngine

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

the class EJBEndpoint method setWorkManagerThreadPoolToJetty.

protected void setWorkManagerThreadPoolToJetty(Bus bus, String baseAddress) {
    JettyHTTPServerEngineFactory engineFactory = bus.getExtension(JettyHTTPServerEngineFactory.class);
    int port = getAddressPort(baseAddress);
    if (engineFactory.retrieveJettyHTTPServerEngine(port) != null) {
        return;
    }
    JettyHTTPServerEngine engine = new JettyHTTPServerEngine();
    engine.setThreadPool(new WorkManagerThreadPool(getWorkManager()));
    engine.setPort(port);
    List<JettyHTTPServerEngine> engineList = new ArrayList<>();
    engineList.add(engine);
    engineFactory.setEnginesList(engineList);
}
Also used : WorkManagerThreadPool(org.apache.cxf.jca.cxf.WorkManagerThreadPool) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) ArrayList(java.util.ArrayList) JettyHTTPServerEngineFactory(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory)

Example 4 with JettyHTTPServerEngine

use of org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine 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 5 with JettyHTTPServerEngine

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

the class HTTPJettyTransportActivator 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.createJettyHTTPServerEngine(host, port, "http");
        }
        JettyHTTPServerEngine e = factory.retrieveJettyHTTPServerEngine(port);
        configure(e, properties);
    } catch (GeneralSecurityException | IOException e) {
        throw new ConfigurationException(null, null, e);
    }
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) GeneralSecurityException(java.security.GeneralSecurityException) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) IOException(java.io.IOException) TLSServerParameters(org.apache.cxf.configuration.jsse.TLSServerParameters)

Aggregations

JettyHTTPServerEngine (org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine)9 Bus (org.apache.cxf.Bus)6 JettyHTTPServerEngineFactory (org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory)4 Test (org.junit.Test)4 JettyHTTPDestination (org.apache.cxf.transport.http_jetty.JettyHTTPDestination)3 ArrayList (java.util.ArrayList)2 TLSServerParameters (org.apache.cxf.configuration.jsse.TLSServerParameters)2 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)2 Handler (org.eclipse.jetty.server.Handler)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 GeneralSecurityException (java.security.GeneralSecurityException)1 TreeMap (java.util.TreeMap)1 RuntimeDelegate (javax.ws.rs.ext.RuntimeDelegate)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 QName (javax.xml.namespace.QName)1 CamelContext (org.apache.camel.CamelContext)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1