use of org.jboss.netty.handler.ssl.SslHandler in project camel by apache.
the class DefaultServerPipelineFactory method getPipeline.
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline channelPipeline = Channels.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
// must close on SSL exception
sslHandler.setCloseOnSSLException(true);
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
addToPipeline("ssl", channelPipeline, sslHandler);
}
List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders();
for (int x = 0; x < encoders.size(); x++) {
ChannelHandler encoder = encoders.get(x);
if (encoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
}
addToPipeline("encoder-" + x, channelPipeline, encoder);
}
List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
if (decoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
}
addToPipeline("decoder-" + x, channelPipeline, decoder);
}
if (consumer.getConfiguration().isOrderedThreadPoolExecutor()) {
// this must be added just before the ServerChannelHandler
// use ordered thread pool, to ensure we process the events in order, and can send back
// replies in the expected order. eg this is required by TCP.
// and use a Camel thread factory so we have consistent thread namings
ExecutionHandler executionHandler = new ExecutionHandler(consumer.getEndpoint().getComponent().getExecutorService());
addToPipeline("executionHandler", channelPipeline, executionHandler);
LOG.debug("Using OrderedMemoryAwareThreadPoolExecutor with core pool size: {}", consumer.getConfiguration().getMaximumPoolSize());
}
// our handler must be added last
addToPipeline("handler", channelPipeline, new ServerChannelHandler(consumer));
LOG.trace("Created ChannelPipeline: {}", channelPipeline);
return channelPipeline;
}
use of org.jboss.netty.handler.ssl.SslHandler in project camel by apache.
the class HttpClientPipelineFactory method getPipeline.
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
SslHandler sslHandler = configureClientSSLOnDemand();
if (sslHandler != null) {
// must close on SSL exception
sslHandler.setCloseOnSSLException(true);
LOG.debug("Client SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("http", new HttpClientCodec());
List<ChannelHandler> decoders = producer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
if (decoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
}
pipeline.addLast("decoder-" + x, decoder);
}
List<ChannelHandler> encoders = producer.getConfiguration().getEncoders();
for (int x = 0; x < encoders.size(); x++) {
ChannelHandler encoder = encoders.get(x);
if (encoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
}
pipeline.addLast("encoder-" + x, encoder);
}
if (producer.getConfiguration().getRequestTimeout() > 0) {
if (LOG.isTraceEnabled()) {
LOG.trace("Using request timeout {} millis", producer.getConfiguration().getRequestTimeout());
}
ChannelHandler timeout = new ReadTimeoutHandler(producer.getEndpoint().getTimer(), producer.getConfiguration().getRequestTimeout(), TimeUnit.MILLISECONDS);
pipeline.addLast("timeout", timeout);
}
// handler to route Camel messages
pipeline.addLast("handler", new HttpClientChannelHandler(producer));
return pipeline;
}
use of org.jboss.netty.handler.ssl.SslHandler in project camel by apache.
the class HttpServerPipelineFactory method getPipeline.
@Override
public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = Channels.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
// must close on SSL exception
sslHandler.setCloseOnSSLException(true);
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
if (decoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
}
pipeline.addLast("decoder-" + x, decoder);
}
pipeline.addLast("aggregator", new HttpChunkAggregator(configuration.getChunkedMaxContentLength()));
pipeline.addLast("encoder", new HttpResponseEncoder());
List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders();
for (int x = 0; x < encoders.size(); x++) {
ChannelHandler encoder = encoders.get(x);
if (encoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
}
pipeline.addLast("encoder-" + x, encoder);
}
if (supportCompressed()) {
pipeline.addLast("deflater", new HttpContentCompressor());
}
if (consumer.getConfiguration().isOrderedThreadPoolExecutor()) {
// this must be added just before the HttpServerMultiplexChannelHandler
// use ordered thread pool, to ensure we process the events in order, and can send back
// replies in the expected order. eg this is required by TCP.
// and use a Camel thread factory so we have consistent thread namings
ExecutionHandler executionHandler = new ExecutionHandler(consumer.getEndpoint().getComponent().getExecutorService());
pipeline.addLast("executionHandler", executionHandler);
LOG.debug("Using OrderedMemoryAwareThreadPoolExecutor with core pool size: {}", consumer.getConfiguration().getMaximumPoolSize());
}
int port = consumer.getConfiguration().getPort();
ChannelHandler handler = consumer.getEndpoint().getComponent().getMultiplexChannelHandler(port).getChannelHandler();
pipeline.addLast("handler", handler);
return pipeline;
}
use of org.jboss.netty.handler.ssl.SslHandler in project cdap by caskdata.
the class HttpRequestHandler method messageReceived.
@Override
public void messageReceived(final ChannelHandlerContext ctx, MessageEvent event) throws Exception {
if (channelClosed) {
return;
}
final Channel inboundChannel = event.getChannel();
Object msg = event.getMessage();
if (msg instanceof HttpChunk) {
// This case below should never happen this would mean we get Chunks before HTTPMessage.
if (chunkSender == null) {
throw new HandlerException(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Chunk received and event sender is null");
}
chunkSender.send(msg);
} else if (msg instanceof HttpRequest) {
// Discover and forward event.
HttpRequest request = (HttpRequest) msg;
request = applyProxyRules(request);
// Suspend incoming traffic until connected to the outbound service.
inboundChannel.setReadable(false);
WrappedDiscoverable discoverable = getDiscoverable(request, (InetSocketAddress) inboundChannel.getLocalAddress());
// If no event sender, make new connection, otherwise reuse existing one.
MessageSender sender = discoveryLookup.get(discoverable);
if (sender == null || !sender.isConnected()) {
InetSocketAddress address = discoverable.getSocketAddress();
ChannelFuture future = clientBootstrap.connect(address);
final Channel outboundChannel = future.getChannel();
outboundChannel.getPipeline().addAfter("request-encoder", "outbound-handler", new OutboundHandler(inboundChannel));
if (Arrays.equals(Constants.Security.SSL_URI_SCHEME.getBytes(), discoverable.getPayload())) {
SSLContext clientContext;
try {
clientContext = SSLContext.getInstance("TLS");
clientContext.init(null, PermissiveTrustManagerFactory.getTrustManagers(), null);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new RuntimeException("SSL is enabled for app-fabric but failed to create SSLContext in the router " + "client.", e);
}
SSLEngine engine = clientContext.createSSLEngine();
engine.setUseClientMode(true);
engine.setEnabledProtocols(new String[] { "TLSv1.2", "TLSv1.1", "TLSv1" });
outboundChannel.getPipeline().addFirst("ssl", new SslHandler(engine));
LOG.trace("Adding ssl handler to the pipeline.");
}
sender = new MessageSender(inboundChannel, future);
discoveryLookup.put(discoverable, sender);
// Remember the in-flight outbound channel
inboundChannel.setAttachment(outboundChannel);
outboundChannel.getCloseFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
inboundChannel.getPipeline().execute(new Runnable() {
@Override
public void run() {
// close the inbound channel as well if it carries the in-flight request
if (outboundChannel.equals(inboundChannel.getAttachment())) {
closeOnFlush(inboundChannel);
}
}
});
}
});
} else {
Channel outboundChannel = (Channel) inboundChannel.getAttachment();
if (outboundChannel != null) {
// Set outbound channel to be readable in case previous request has set it as non-readable
outboundChannel.setReadable(true);
}
}
// Send the message.
sender.send(request);
inboundChannel.setReadable(true);
//Save the channelFuture for subsequent chunks
if (request.isChunked()) {
chunkSender = sender;
}
} else {
super.messageReceived(ctx, event);
}
}
use of org.jboss.netty.handler.ssl.SslHandler in project opennms by OpenNMS.
the class AsyncBasicDetectorNettyImpl method isServiceDetected.
/**
* {@inheritDoc}
*/
@Override
public final DetectFuture isServiceDetected(final InetAddress address) {
DetectFuture detectFuture = new DetectFutureFailedImpl(this, new IllegalStateException());
try {
ClientBootstrap bootstrap = new ClientBootstrap(m_factory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline retval = Channels.pipeline();
// Upstream handlers
// retval.addLast("retryHandler", new RetryChannelHandler());
appendToPipeline(retval);
// Downstream handlers
retval.addLast("detectorHandler", getDetectorHandler(getConversation()));
if (isUseSSLFilter()) {
// Use a relaxed SSL context
retval.addLast("sslHandler", new SslHandler(createClientSSLContext().createSSLEngine()));
}
return retval;
}
});
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("keepAlive", true);
SocketAddress remoteAddress = new InetSocketAddress(address, getPort());
ChannelFuture future = bootstrap.connect(remoteAddress);
future.addListener(new RetryChannelFutureListener(remoteAddress, this.getRetries()));
detectFuture = new DetectFutureNettyImpl(this, future);
} catch (Throwable e) {
detectFuture = new DetectFutureFailedImpl(this, e);
}
return detectFuture;
}
Aggregations