queue() {
+ return queue;
+ }
+}
diff --git a/example/src/main/java/io/netty/example/http2/server/HelloWorldHandler.java b/example/src/main/java/io/netty/example/http2/server/HelloWorldHandler.java
new file mode 100644
index 0000000000..11e45901ff
--- /dev/null
+++ b/example/src/main/java/io/netty/example/http2/server/HelloWorldHandler.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2014 The Netty Project
+ *
+ * The Netty Project licenses this file to you under the Apache License, version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package io.netty.example.http2.server;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerAdapter;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.http2.draft10.DefaultHttp2Headers;
+import io.netty.handler.codec.http2.draft10.Http2Headers;
+import io.netty.handler.codec.http2.draft10.frame.DefaultHttp2DataFrame;
+import io.netty.handler.codec.http2.draft10.frame.DefaultHttp2HeadersFrame;
+import io.netty.handler.codec.http2.draft10.frame.Http2DataFrame;
+import io.netty.handler.codec.http2.draft10.frame.Http2HeadersFrame;
+import io.netty.handler.codec.http2.draft10.frame.Http2StreamFrame;
+import io.netty.util.CharsetUtil;
+import io.netty.util.ReferenceCountUtil;
+
+/**
+ * A simple handler that responds with the message "Hello World!".
+ */
+public class HelloWorldHandler extends ChannelHandlerAdapter {
+ private static final byte[] RESPONSE_BYTES = "Hello World".getBytes(CharsetUtil.UTF_8);
+
+ @Override
+ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+ if (msg instanceof Http2StreamFrame) {
+ Http2StreamFrame frame = (Http2StreamFrame) msg;
+ if (frame.isEndOfStream()) {
+ sendResponse(ctx, frame.getStreamId());
+ }
+ }
+
+ ReferenceCountUtil.release(msg);
+ }
+
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+ cause.printStackTrace();
+ }
+
+ private void sendResponse(ChannelHandlerContext ctx, int streamId) {
+ ByteBuf content = ctx.alloc().buffer();
+ content.writeBytes(RESPONSE_BYTES);
+
+ // Send a frame for the response status
+ Http2Headers headers = DefaultHttp2Headers.newBuilder().setStatus("200").build();
+ Http2HeadersFrame headersFrame =
+ new DefaultHttp2HeadersFrame.Builder().setStreamId(streamId).setHeaders(headers)
+ .build();
+ ctx.write(headersFrame);
+
+ // Send a data frame with the response message.
+ Http2DataFrame data =
+ new DefaultHttp2DataFrame.Builder().setStreamId(streamId).setEndOfStream(true)
+ .setContent(content).build();
+ ctx.writeAndFlush(data);
+ }
+}
diff --git a/example/src/main/java/io/netty/example/http2/server/Http2Server.java b/example/src/main/java/io/netty/example/http2/server/Http2Server.java
new file mode 100644
index 0000000000..705cb531a9
--- /dev/null
+++ b/example/src/main/java/io/netty/example/http2/server/Http2Server.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2014 The Netty Project
+ *
+ * The Netty Project licenses this file to you under the Apache License,
+ * version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package io.netty.example.http2.server;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+
+/**
+ * A HTTP/2 Server that responds to requests with a Hello World.
+ *
+ * Once started, you can test the server with the example client.
+ */
+public class Http2Server {
+
+ private final int port;
+
+ public Http2Server(int port) {
+ this.port = port;
+ }
+
+ public void run() throws Exception {
+ // Configure the server.
+ EventLoopGroup bossGroup = new NioEventLoopGroup(1);
+ EventLoopGroup workerGroup = new NioEventLoopGroup();
+ try {
+ ServerBootstrap b = new ServerBootstrap();
+ b.option(ChannelOption.SO_BACKLOG, 1024);
+ b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
+ .childHandler(new Http2ServerInitializer());
+
+ Channel ch = b.bind(port).sync().channel();
+ ch.closeFuture().sync();
+ } finally {
+ bossGroup.shutdownGracefully();
+ workerGroup.shutdownGracefully();
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ int port;
+ if (args.length > 0) {
+ port = Integer.parseInt(args[0]);
+ } else {
+ port = 8443;
+ }
+
+ System.out.println("HTTP2 server started at port " + port + '.');
+
+ new Http2Server(port).run();
+ }
+}
diff --git a/example/src/main/java/io/netty/example/http2/server/Http2ServerInitializer.java b/example/src/main/java/io/netty/example/http2/server/Http2ServerInitializer.java
new file mode 100644
index 0000000000..aca941973c
--- /dev/null
+++ b/example/src/main/java/io/netty/example/http2/server/Http2ServerInitializer.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2014 The Netty Project
+ *
+ * The Netty Project licenses this file to you under the Apache License,
+ * version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package io.netty.example.http2.server;
+
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.codec.http2.draft10.connection.Http2ConnectionHandler;
+import io.netty.handler.codec.http2.draft10.frame.Http2FrameCodec;
+
+/**
+ * Sets up the Netty pipeline
+ */
+public class Http2ServerInitializer extends ChannelInitializer {
+ @Override
+ public void initChannel(SocketChannel ch) throws Exception {
+ ChannelPipeline p = ch.pipeline();
+
+ p.addLast("http2FrameCodec", new Http2FrameCodec());
+ p.addLast("http2ConnectionHandler", new Http2ConnectionHandler(true));
+ p.addLast("helloWorldHandler", new HelloWorldHandler());
+ }
+}