[Resource-container] Backported init fix to 1.1-rel
[platform/upstream/iotivity.git] / cloud / stack / src / main / java / org / iotivity / cloud / base / HttpServer.java
1 /*
2  * //****************************************************************** // //
3  * Copyright 2016 Samsung Electronics All Rights Reserved. //
4  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // //
5  * Licensed under the Apache License, Version 2.0 (the "License"); // you may
6  * not use this file except in compliance with the License. // You may obtain a
7  * copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // //
8  * Unless required by applicable law or agreed to in writing, software //
9  * distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT
10  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the
11  * License for the specific language governing permissions and // limitations
12  * under the License. //
13  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
14  */
15 // package org.iotivity.cloud.base;
16 //
17 // import java.net.InetSocketAddress;
18 // import java.security.cert.CertificateException;
19 // import java.util.ArrayList;
20 // import java.util.List;
21 //
22 // import javax.net.ssl.SSLException;
23 //
24 // import io.netty.bootstrap.ServerBootstrap;
25 // import io.netty.channel.ChannelFuture;
26 // import io.netty.channel.ChannelHandler;
27 // import io.netty.channel.ChannelInitializer;
28 // import io.netty.channel.ChannelPipeline;
29 // import io.netty.channel.EventLoopGroup;
30 // import io.netty.channel.nio.NioEventLoopGroup;
31 // import io.netty.channel.socket.SocketChannel;
32 // import io.netty.channel.socket.nio.NioServerSocketChannel;
33 // import io.netty.handler.codec.http.HttpRequestDecoder;
34 // import io.netty.handler.codec.http.HttpResponseEncoder;
35 // import io.netty.handler.logging.LogLevel;
36 // import io.netty.handler.logging.LoggingHandler;
37 // import io.netty.util.concurrent.GenericFutureListener;
38 //
39 // public class HttpServer {
40 //
41 // private static class HttpServerInitializer
42 // extends ChannelInitializer<SocketChannel> {
43 //
44 // private List<ChannelHandler> additionalHandlers = new
45 // ArrayList<ChannelHandler>();
46 //
47 // public HttpServerInitializer() {
48 // }
49 //
50 // public void addHandler(ChannelHandler handler) {
51 // additionalHandlers.add(handler);
52 // }
53 //
54 // @Override
55 // public void initChannel(SocketChannel ch) {
56 // ChannelPipeline p = ch.pipeline();
57 // /*
58 // * if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); }
59 // */
60 // p.addLast(new HttpRequestDecoder());
61 // // Uncomment the following line if you don't want to handle
62 // // HttpChunks.
63 // // p.addLast(new HttpObjectAggregator(1048576));
64 // p.addLast(new HttpResponseEncoder());
65 // // Remove the following line if you don't want automatic content
66 // // compression.
67 // // p.addLast(new HttpContentCompressor());
68 // for (ChannelHandler handler : additionalHandlers) {
69 // p.addLast(handler);
70 // }
71 // }
72 //
73 // }
74 //
75 // EventLoopGroup bossGroup = new NioEventLoopGroup(1);
76 //
77 // EventLoopGroup workerGroup = new NioEventLoopGroup();
78 //
79 // HttpServerInitializer initializer = new HttpServerInitializer();
80 //
81 // public void addHandler(ChannelHandler handler) {
82 // initializer.addHandler(handler);
83 // }
84 //
85 // public void startServer(InetSocketAddress inetSocketAddress)
86 // throws CertificateException, SSLException, InterruptedException {
87 //
88 // try {
89 // ServerBootstrap b = new ServerBootstrap();
90 // b.group(bossGroup, workerGroup);
91 // b.channel(NioServerSocketChannel.class);
92 // b.handler(new LoggingHandler(LogLevel.INFO));
93 //
94 // b.childHandler(initializer);
95 //
96 // ChannelFuture ch = b.bind(inetSocketAddress).sync();
97 // ch.addListener(new GenericFutureListener<ChannelFuture>() {
98 //
99 // @Override
100 // public void operationComplete(ChannelFuture future)
101 // throws Exception {
102 // // TODO Auto-generated method stub
103 // System.out
104 // .println("Connection status of TCP Http SERVER : "
105 // + future.isSuccess());
106 // }
107 //
108 // });
109 // } finally {
110 // }
111 //
112 // }
113 //
114 // public void stopServer() {
115 // // shut down all event loops
116 // if (bossGroup != null) {
117 // bossGroup.shutdownGracefully();
118 //
119 // try {
120 // bossGroup.terminationFuture().sync();
121 // } catch (InterruptedException e) {
122 // // TODO Auto-generated catch block
123 // e.printStackTrace();
124 // }
125 // }
126 //
127 // if (workerGroup != null) {
128 // workerGroup.shutdownGracefully();
129 //
130 // try {
131 // workerGroup.terminationFuture().sync();
132 // } catch (InterruptedException e) {
133 // // TODO Auto-generated catch block
134 // e.printStackTrace();
135 // }
136 // }
137 // }
138 //
139 // }