https://netty.io/4.1/xref/io/netty/example/proxy/package-summary.html

https://netty.io/4.1/xref/io/netty/example/proxy/HexDumpProxy.html

package com.test;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler; public class HexDumpProxyInitializer extends ChannelInitializer<SocketChannel> {
private final String remoteHost;
private final int remotePort; public HexDumpProxyInitializer(String remoteHost, int remotePort) {
this.remoteHost = remoteHost;
this.remotePort = remotePort;
} @Override
public void initChannel(SocketChannel ch) {
// 获取当前类名;
System.out.println(this.getClass());
ch.pipeline().addLast(
new LoggingHandler(LogLevel.INFO),
new HexDumpProxyInitializer(remoteHost, remotePort)
);
}
}
package com.test;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler; public class HexDumpProxy {
static final int LOCAL_PORT = Integer.parseInt(System.getProperty("localPort", "8443"));
static final String REMOTE_HOST = System.getProperty("remoteHost", "11.21.1.2");
static final int REMOTE_PORT = Integer.parseInt(System.getProperty("remotePort", "50000")); public static void main(String[] args) throws Exception {
System.err.println("Proxying *:" + LOCAL_PORT + " to " + REMOTE_HOST + ":" + REMOTE_PORT + "...");
// Configure the bootstrap
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new HexDumpProxyInitializer(REMOTE_HOST, REMOTE_PORT))
.childOption(ChannelOption.AUTO_READ, false)
.bind(LOCAL_PORT).sync().channel().closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
}

netty 网关 http请求 请求转发的更多相关文章

  1. selector.select(500); EventLoop及事件循环机制 netty 在半透明做代理网关下 对请求的批处理

    Netty框架学习之路(五)—— EventLoop及事件循环机制 - 懋懋之为 - CSDN博客 https://blog.csdn.net/tjreal/article/details/79751 ...

  2. jsp:和属性相关的方法,请求的转发,重定向

    jsp中与属性相关的方法: 方法: void setAttribute(String name, Object o): 设置属性 Object getAttribute(String name):获取 ...

  3. 技巧集:nginx作代理时,查看请求被转发到哪台服务器

    使用Nginx代理多台服务器实行负载的时候,如何查看某一个请求被转发到哪台服务器上呢? upstream demo { server 127.0.0.1:8781; server 127.0.0.1: ...

  4. javaWEB总结(14):请求的转发和重定向

    通俗理解请求转发与重定向的流程 通俗的来讲:我们可以把请求转发和重定向当成是一种借钱的情景模式. (1)请求的转发:A向B借钱,B自己没有钱,但是向C借到了钱,并且把钱借给了A.A只向B请求了一次. ...

  5. javaweb之请求的转发和重定向

    1.什么是请求转发和请求重定向? 请求转发: xxServlet收到请求,然后直接转发给yyServlet,然后yyServlet返回给客户端.整个过程中,客户端发出一个请求,收到一个响应. 重定向: ...

  6. 域对象的作用范围 & 请求的转发和重定向

    1. 和属性相关的方法: ①. 方法 void setAttribute(String name, Object o): 设置属性 Object getAttribute(String name): ...

  7. 基于Servlet体系的HTTP请求代理转发Spring Boot组件

    背景概述 两个项目组原本都是各自负责两个产品线(产品A.产品B),由于公司业务的发展,目前需要将两个产品合并成一个大产品(功能整合,部分做取舍,最终产出产品C),前后端代码必然也需要整合,包括两个产品 ...

  8. AJAX - 向服务器发送请求请求

    AJAX - 向服务器发送请求请求 XMLHttpRequest 对象用于和服务器交换数据.直线电机生产厂家 向服务器发送请求 如需将请求发送到服务器,我们使用 XMLHttpRequest 对象的 ...

  9. Bumblebee服务网关之统一请求验证

    对于微服务网关来说,统一请求验证是一个比较重要和常用的功能,通过网关验证后台服务就无须关注请求验证:对于多语言平台的服务而言制定验证方式和变更验证配置都是一件比较繁琐和工作量大的事情.Bumblebe ...

随机推荐

  1. Android Studio 更新gradle插件

    今天更新了CentOS, 更新了java版本. 然后gradle跪了..... 不吐槽java版本的兼容性问题了.... 反正有他自己的理由.... 那么就更新gradle咯.... 下面是方法... ...

  2. 419. Roman to Integer【medium】

    Given a roman numeral, convert it to an integer. The answer is guaranteed to be within the range fro ...

  3. IBM MQ 2035 或 2013认证错误的解决方法

    第一种方法: ALTER CHL(SYSTEM.BKR.CONFIG) CHLTYPE(SVRCONN) ALTER CHL(SYSTEM.ADMIN.SVRCONN) CHLTYPE(SVRCONN ...

  4. Linux网络编程wait()和waitpid()的讲解

    本文讲的是关于wait和waitpid两者的区别与联系.为避免僵尸进程的产生,无论我们什么时候创建子进程时,主进程都需要等待子进程返回,以便对子进程进行清理.为此,我们在服务器程序中添加SIGCHLD ...

  5. 16C554在LINUX上的移植(AT91)

    16C554在LINUX上的移植(AT91) linux版本:3.14.17 AT91SAMa5d36   EINTA_0   ARM-IO5        PA14         14 EINTA ...

  6. sudo非交互式输入密码

    sudo非交互式输入密码 编辑 删除 我们在使用sudo命令的时候,为了避免交互,可以使用 echo 'password' |sudo -S cmd 这样的方式,通过管道传入密码,就不用手动输入了. ...

  7. socket udp广播和多播的简单实现

    UDP广播与多播 作者:legend QQ:1327706646 使用UDP协议进行信息的传输之前不需要建议连接.换句话说就是客户端向服务器发送信息,客户端只需要给出服务器的ip地址和端口号,然后将信 ...

  8. linux -- Ubuntu修改静态IP地址重启后无法上网的解决

    ubuntu设置静态IP地址后,上不了网 文章中也提到,如果是在/etc/resolv.conf添加DNS,由于Ubuntu 有一个 resolvconf 服务,如果重启它,那么 /etc/resol ...

  9. 【BZOJ】2005: [Noi2010]能量采集(欧拉函数+分块)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2005 首先和某题一样应该一样可以看出每个点所在的线上有gcd(x,y)-1个点挡着了自己... 那么 ...

  10. 【BZOJ】1042: [HAOI2008]硬币购物(dp+容斥原理)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1042 一开始写了个O(nv)的背包,果断tle... 看了题解,,好神..用了组合数学中的多重集合方 ...