Skip to content

Commit b3bf3b3

Browse files
committed
update
1 parent 47ccab1 commit b3bf3b3

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package io.github.kimmking.gateway.filter;
22

33
import io.netty.channel.ChannelHandlerContext;
4+
import io.netty.handler.codec.http.DefaultHttpHeaders;
45
import io.netty.handler.codec.http.FullHttpRequest;
6+
import io.netty.handler.codec.http.HttpHeaders;
57

68
public class HttpRequestFilterImpl implements HttpRequestFilter {
79
@Override
810
public void filter(FullHttpRequest fullRequest, ChannelHandlerContext ctx) {
9-
fullRequest.headers().set("nio","wangyibing");
11+
String uri = fullRequest.uri();
12+
System.out.println("filter(FullHttpRequest fullRequest, ChannelHandlerContext ctx)接收到的请求,url:" + uri);
13+
HttpHeaders headers = fullRequest.headers();
14+
if (headers == null) {
15+
headers = new DefaultHttpHeaders();
16+
}
17+
headers.add("nio", "wangyibing");
18+
fullRequest.headers().set(headers);
1019
}
1120
}

02nio/nio02/src/main/java/io/github/kimmking/gateway/outbound/okhttp/OkhttpOutboundHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class OkhttpOutboundHandler {
3131

3232
public OkhttpOutboundHandler(String proxyServer) {
3333
this.proxyServer = proxyServer;
34-
RejectedExecutionHandler policy = new ThreadPoolExecutor.CallerRunsPolicy();
34+
RejectedExecutionHandler policy = new ThreadPoolExecutor.AbortPolicy();
3535
int cores = Runtime.getRuntime().availableProcessors() * 2;
3636
long keepAliveTime = 1000;
3737
int queueSize = 2048;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.github.yibing.spring.aop.jdkproxy;
2+
3+
public interface Animal {
4+
void breathe();
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.github.yibing.spring.aop.jdkproxy;
2+
3+
public class Bird implements Animal {
4+
@Override
5+
public void breathe() {
6+
System.out.println("animal can breathe..");
7+
}
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.github.yibing.spring.aop.jdkproxy;
2+
3+
import java.lang.reflect.InvocationHandler;
4+
import java.lang.reflect.Method;
5+
6+
public class BirdProxy implements InvocationHandler {
7+
8+
private Animal bird;
9+
10+
public BirdProxy(Animal bird) {
11+
this.bird = bird;
12+
}
13+
14+
@Override
15+
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
16+
System.out.println("before invoke ........");
17+
Object obj = method.invoke(bird, args);
18+
System.out.println("after invoke ....");
19+
return obj;
20+
}
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.github.yibing.spring.aop.jdkproxy;
2+
3+
import java.lang.reflect.Proxy;
4+
5+
public class JdkProxyDemo {
6+
public static void main(String[] args) {
7+
Animal bird = new Bird();
8+
BirdProxy birdProxy = new BirdProxy(bird);
9+
Animal instance = (Animal) Proxy.newProxyInstance(bird.getClass().getClassLoader(), bird.getClass().getInterfaces(), birdProxy);
10+
System.out.println("代理的类型:" + bird.getClass().getName());
11+
instance.breathe();
12+
}
13+
}

0 commit comments

Comments
 (0)