final String finderClassname = finderConfig.getClassname();
try {
final ProtocolFinder protocolFinder = Utils.newInstance(habitat,
ProtocolFinder.class, finderClassname, finderClassname);
configureElement(habitat, networkListener, finderConfig, protocolFinder);
final Protocol subProtocol = finderConfig.findProtocol();
final FilterChainBuilder subProtocolFilterChainBuilder =
puFilter.getPUFilterChainBuilder();
// If subprotocol is secured - we need to wrap it under SSLProtocolFinder
if (Boolean.valueOf(subProtocol.getSecurityEnabled())) {
final PUFilter extraSslPUFilter = new PUFilter();
final Filter addedSSLFilter = configureSsl(
habitat, getSsl(subProtocol),
subProtocolFilterChainBuilder);
subProtocolFilterChainBuilder.add(extraSslPUFilter);
final FilterChainBuilder extraSslPUFilterChainBuilder =
extraSslPUFilter.getPUFilterChainBuilder();
try {
// temporary add SSL Filter, so subprotocol
// will see it
extraSslPUFilterChainBuilder.add(addedSSLFilter);
configureSubProtocol(habitat, networkListener,
subProtocol, extraSslPUFilterChainBuilder);
} finally {
// remove SSL Filter
extraSslPUFilterChainBuilder.remove(addedSSLFilter);
}
extraSslPUFilter.register(protocolFinder,
extraSslPUFilterChainBuilder.build());
puFilter.register(new SSLProtocolFinder(
new SSLConfigurator(habitat, subProtocol.getSsl())),
subProtocolFilterChainBuilder.build());
} else {
configureSubProtocol(habitat, networkListener,
subProtocol, subProtocolFilterChainBuilder);
puFilter.register(protocolFinder, subProtocolFilterChainBuilder.build());