1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.openr66.protocol.http.rest;
21
22 import io.netty.channel.ChannelInitializer;
23 import io.netty.channel.ChannelPipeline;
24 import io.netty.channel.socket.SocketChannel;
25 import io.netty.handler.codec.http.HttpContentCompressor;
26 import io.netty.handler.codec.http.HttpServerCodec;
27 import io.netty.handler.ssl.SslHandler;
28 import io.netty.handler.stream.ChunkedWriteHandler;
29 import org.waarp.common.crypto.ssl.WaarpSslContextFactory;
30 import org.waarp.gateway.kernel.rest.RestConfiguration;
31
32
33
34
35 public class HttpRestR66Initializer extends ChannelInitializer<SocketChannel> {
36 private final boolean useHttpCompression;
37 private final WaarpSslContextFactory waarpSslContextFactory;
38 private final RestConfiguration restConfiguration;
39
40 public HttpRestR66Initializer(final boolean useHttpCompression,
41 final WaarpSslContextFactory waarpSslContextFactory,
42 final RestConfiguration configuration) {
43 this.waarpSslContextFactory = waarpSslContextFactory;
44 this.useHttpCompression = useHttpCompression;
45 restConfiguration = configuration;
46 }
47
48 @Override
49 protected void initChannel(final SocketChannel ch) {
50
51 final ChannelPipeline pipeline = ch.pipeline();
52
53
54 if (waarpSslContextFactory != null) {
55 final SslHandler handler =
56 waarpSslContextFactory.createHandlerServer(false, ch);
57 pipeline.addLast("ssl", handler);
58 }
59
60 pipeline.addLast("codec", new HttpServerCodec());
61 if (useHttpCompression) {
62 pipeline.addLast("deflater", new HttpContentCompressor());
63 }
64 pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
65 final HttpRestR66Handler r66handler =
66 new HttpRestR66Handler(restConfiguration);
67 pipeline.addLast("handler", r66handler);
68 }
69 }