use of org.apache.cxf.transport.http_undertow.UndertowHTTPServerEngineFactory 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<>();
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());
}
if (threads.getThreadingParameters().getWorkerIOName() != null) {
rThreads.setWorkerIOName(threads.getThreadingParameters().getWorkerIOName());
}
if (threads.getThreadingParameters().getWorkerIOThreads() != null) {
rThreads.setWorkerIOThreads(threads.getThreadingParameters().getWorkerIOThreads());
}
rThreads.setWorkerIOThreads(threads.getThreadingParameters().getWorkerIOThreads());
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<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();
if (threads.getMaxThreads() != null) {
rThreads.setMaxThreads(threads.getMaxThreads());
}
if (threads.getMinThreads() != null) {
rThreads.setMinThreads(threads.getMinThreads());
}
if (threads.getWorkerIOThreads() != null) {
rThreads.setWorkerIOThreads(threads.getWorkerIOThreads());
}
if (threads.getWorkerIOName() != null) {
rThreads.setWorkerIOName(threads.getWorkerIOName());
}
eng.setThreadingParameters(rThreads);
}
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);
}
}
Aggregations