forked from tang-jie/NettyRPC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NettyRPC 2.2 server's interface ability show.
NettyRPC 2.2 server's interface ability show.
- Loading branch information
Showing
15 changed files
with
323 additions
and
25 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/com/newlandframework/rpc/netty/resolver/ApiEchoHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright (C) 2017 Newland Group Holding Limited | ||
* <p> | ||
* Licensed 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 com.newlandframework.rpc.netty.resolver; | ||
|
||
import com.newlandframework.rpc.core.AbilityDetailProvider; | ||
import io.netty.buffer.Unpooled; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelInboundHandlerAdapter; | ||
import io.netty.handler.codec.http.DefaultFullHttpResponse; | ||
import io.netty.handler.codec.http.FullHttpResponse; | ||
import io.netty.handler.codec.http.HttpRequest; | ||
|
||
import static io.netty.handler.codec.http.HttpResponseStatus.OK; | ||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; | ||
|
||
/** | ||
* @author tangjie<https://github.com/tang-jie> | ||
* @filename:ApiEchoHandler.java | ||
* @description:ApiEchoHandler功能模块 | ||
* @blogs http://www.cnblogs.com/jietang/ | ||
* @since 2017/5/2 | ||
*/ | ||
public class ApiEchoHandler extends ChannelInboundHandlerAdapter { | ||
private static final String CONTENT_TYPE = "Content-Type"; | ||
private static final String CONTENT_LENGTH = "Content-Length"; | ||
private static final String CONNECTION = "Connection"; | ||
private static final String KEEP_ALIVE = "keep-alive"; | ||
|
||
public ApiEchoHandler() { | ||
} | ||
|
||
@Override | ||
public void channelReadComplete(ChannelHandlerContext ctx) { | ||
ctx.flush(); | ||
} | ||
|
||
@Override | ||
public void channelRead(ChannelHandlerContext ctx, Object msg) { | ||
if (msg instanceof HttpRequest) { | ||
HttpRequest req = (HttpRequest) msg; | ||
AbilityDetailProvider provider = new AbilityDetailProvider(); | ||
byte[] content = provider.listAbilityDetail(true).toString().getBytes(); | ||
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(content)); | ||
response.headers().set(CONTENT_TYPE, "text/html"); | ||
response.headers().set(CONTENT_LENGTH, response.content().readableBytes()); | ||
response.headers().set(CONNECTION, KEEP_ALIVE); | ||
ctx.write(response); | ||
} | ||
} | ||
|
||
@Override | ||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { | ||
cause.printStackTrace(); | ||
ctx.close(); | ||
} | ||
} | ||
|
49 changes: 49 additions & 0 deletions
49
src/main/java/com/newlandframework/rpc/netty/resolver/ApiEchoInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (C) 2017 Newland Group Holding Limited | ||
* <p> | ||
* Licensed 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 com.newlandframework.rpc.netty.resolver; | ||
|
||
import io.netty.channel.ChannelInitializer; | ||
import io.netty.channel.ChannelPipeline; | ||
import io.netty.channel.socket.SocketChannel; | ||
import io.netty.handler.codec.http.HttpServerCodec; | ||
import io.netty.handler.ssl.SslContext; | ||
|
||
/** | ||
* @author tangjie<https://github.com/tang-jie> | ||
* @filename:ApiEchoInitializer.java | ||
* @description:ApiEchoInitializer功能模块 | ||
* @blogs http://www.cnblogs.com/jietang/ | ||
* @since 2017/5/2 | ||
*/ | ||
public class ApiEchoInitializer extends ChannelInitializer<SocketChannel> { | ||
|
||
private final SslContext sslCtx; | ||
|
||
public ApiEchoInitializer(SslContext sslCtx) { | ||
this.sslCtx = sslCtx; | ||
} | ||
|
||
@Override | ||
public void initChannel(SocketChannel ch) { | ||
ChannelPipeline p = ch.pipeline(); | ||
if (sslCtx != null) { | ||
p.addLast(sslCtx.newHandler(ch.alloc())); | ||
} | ||
p.addLast(new HttpServerCodec()); | ||
p.addLast(new ApiEchoHandler()); | ||
} | ||
} | ||
|
Oops, something went wrong.