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