替换部分过期neety方法

master
星期八 5 years ago
parent ac67c48357
commit 7e3b699aae
  1. 2
      proxy-client/src/main/java/org/fengfei/lanproxy/client/ClientChannelMannager.java
  2. 2
      proxy-client/src/main/java/org/fengfei/lanproxy/client/ProxyClientContainer.java
  3. 2
      proxy-client/src/main/java/org/fengfei/lanproxy/client/handlers/ClientChannelHandler.java
  4. 6
      proxy-common/pom.xml
  5. 6
      proxy-common/src/main/java/org/fengfei/lanproxy/common/container/Container.java
  6. 1
      proxy-server/src/main/java/org/fengfei/lanproxy/server/ProxyServerContainer.java
  7. 1
      proxy-server/src/main/java/org/fengfei/lanproxy/server/SslContextCreator.java
  8. 8
      proxy-server/src/main/java/org/fengfei/lanproxy/server/config/ProxyConfig.java
  9. 2
      proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/ApiRoute.java
  10. 2
      proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/HttpRequestHandler.java
  11. 4
      proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/MimeType.java
  12. 9
      proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/routes/RouteConfig.java
  13. 6
      proxy-server/src/main/java/org/fengfei/lanproxy/server/handlers/ServerChannelHandler.java
  14. 6
      proxy-server/src/main/java/org/fengfei/lanproxy/server/handlers/UserChannelHandler.java

@ -70,7 +70,7 @@ public class ClientChannelMannager {
proxyChanel.close();
} else {
proxyChanel.config().setOption(ChannelOption.AUTO_READ, true);
proxyChanel.attr(Constants.NEXT_CHANNEL).remove();
proxyChanel.attr(Constants.NEXT_CHANNEL).set(null);
proxyChannelPool.offer(proxyChanel);
logger.debug("return ProxyChanel to the pool, channel is {}, pool size is {} ", proxyChanel, proxyChannelPool.size());
}

@ -68,6 +68,8 @@ public class ProxyClientContainer implements Container, ChannelStatusListener {
}
});
bootstrap = new Bootstrap();
bootstrap.group(workerGroup);
bootstrap.channel(NioSocketChannel.class);

@ -72,7 +72,7 @@ public class ClientChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
Channel realServerChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
logger.debug("handleDisconnectMessage, {}", realServerChannel);
if (realServerChannel != null) {
ctx.channel().attr(Constants.NEXT_CHANNEL).remove();
ctx.channel().attr(Constants.NEXT_CHANNEL).set(null);
ClientChannelMannager.returnProxyChanel(ctx.channel());
realServerChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}

@ -16,5 +16,11 @@
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.62</version>
</dependency>
</dependencies>
</project>

@ -2,7 +2,13 @@ package org.fengfei.lanproxy.common.container;
public interface Container {
/**
* 启动容器
*/
void start();
/**
* 停止容器
*/
void stop();
}

@ -92,6 +92,7 @@ public class ProxyServerContainer implements Container, ConfigChangedListener {
}
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
private void initializeSSLTCPTransport(String host, int port, final SSLContext sslContext) {
ServerBootstrap b = new ServerBootstrap();
b.group(serverBossGroup, serverWorkerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

@ -22,6 +22,7 @@ import org.fengfei.lanproxy.common.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")
public class SslContextCreator {
private static Logger logger = LoggerFactory.getLogger(SslContextCreator.class);

@ -183,8 +183,8 @@ public class ProxyConfig implements Serializable {
clients = new ArrayList<Client>();
}
Map<String, List<Integer>> clientInetPortMapping = new HashMap<String, List<Integer>>();
Map<Integer, String> inetPortLanInfoMapping = new HashMap<Integer, String>();
Map<String, List<Integer>> clientInetPortMapping = new HashMap<String, List<Integer>>(clients.size());
Map<Integer, String> inetPortLanInfoMapping = new HashMap<Integer, String>(clients.size());
// 构造端口映射关系
for (Client client : clients) {
@ -406,7 +406,9 @@ public class ProxyConfig implements Serializable {
*
*/
public static interface ConfigChangedListener {
/**
* 配置更新回调
*/
void onChanged();
}
}

@ -71,7 +71,7 @@ public class ApiRoute {
middleware.preRequest(request);
}
URI uri = new URI(request.getUri());
URI uri = new URI(request.uri());
RequestHandler handler = routes.get(uri.getPath());
ResponseInfo responseInfo = null;
if (handler != null) {

@ -104,7 +104,7 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequ
HttpResponse response = new DefaultHttpResponse(request.protocolVersion(), status);
response.headers().set(HttpHeaderNames.CONTENT_TYPE, mimeType);
boolean keepAlive = HttpHeaders.isKeepAlive(request);
boolean keepAlive = HttpUtil.isKeepAlive(request);
if (keepAlive) {
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, length);
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);

@ -7,7 +7,7 @@ import java.util.regex.Pattern;
public class MimeType {
final static Pattern pattern = Pattern.compile("\\S*[?]\\S*");
final static Pattern PATTERN = Pattern.compile("\\S*[?]\\S*");
private static Map<String, String> h = new HashMap<String, String>();
static {
@ -211,7 +211,7 @@ public class MimeType {
public static String parseSuffix(String url) {
try {
Matcher matcher = pattern.matcher(url);
Matcher matcher = PATTERN.matcher(url);
String[] spUrl = url.toString().split("/");
int len = spUrl.length;
String endUrl = spUrl[len - 1];

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import io.netty.handler.codec.http.HttpHeaderNames;
import org.fengfei.lanproxy.common.JsonUtil;
import org.fengfei.lanproxy.server.ProxyChannelManager;
import org.fengfei.lanproxy.server.config.ProxyConfig;
@ -50,7 +51,7 @@ public class RouteConfig {
@Override
public void preRequest(FullHttpRequest request) {
String cookieHeader = request.headers().get(HttpHeaders.Names.COOKIE);
String cookieHeader = request.headers().get(HttpHeaderNames.COOKIE);
boolean authenticated = false;
if (cookieHeader != null) {
String[] cookies = cookieHeader.split(";");
@ -64,7 +65,7 @@ public class RouteConfig {
}
}
String auth = request.headers().get(HttpHeaders.Names.AUTHORIZATION);
String auth = request.headers().get(HttpHeaderNames.AUTHORIZATION);
if (!authenticated && auth != null) {
String[] authArr = auth.split(" ");
if (authArr.length == 2 && authArr[0].equals(ProxyConfig.getInstance().getConfigAdminUsername()) && authArr[1].equals(ProxyConfig.getInstance().getConfigAdminPassword())) {
@ -72,11 +73,11 @@ public class RouteConfig {
}
}
if (!LOGIN_URL.equals(request.getUri()) && !authenticated) {
if (!LOGIN_URL.equals(request.uri()) && !authenticated) {
throw new ContextException(ResponseInfo.CODE_UNAUTHORIZED);
}
logger.info("handle request for api {}", request.getUri());
logger.info("handle request for api {}", request.uri());
}
});

@ -83,9 +83,9 @@ public class ServerChannelHandler extends SimpleChannelInboundHandler<ProxyMessa
if (userChannel != null) {
// 数据发送完成后再关闭连接,解决http1.0数据传输问题
userChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
ctx.channel().attr(Constants.NEXT_CHANNEL).remove();
ctx.channel().attr(Constants.CLIENT_KEY).remove();
ctx.channel().attr(Constants.USER_ID).remove();
ctx.channel().attr(Constants.NEXT_CHANNEL).set(null);
ctx.channel().attr(Constants.CLIENT_KEY).set(null);
ctx.channel().attr(Constants.USER_ID).set(null);
}
}

@ -94,9 +94,9 @@ public class UserChannelHandler extends SimpleChannelInboundHandler<ByteBuf> {
ProxyChannelManager.removeUserChannelFromCmdChannel(cmdChannel, userId);
Channel proxyChannel = userChannel.attr(Constants.NEXT_CHANNEL).get();
if (proxyChannel != null && proxyChannel.isActive()) {
proxyChannel.attr(Constants.NEXT_CHANNEL).remove();
proxyChannel.attr(Constants.CLIENT_KEY).remove();
proxyChannel.attr(Constants.USER_ID).remove();
proxyChannel.attr(Constants.NEXT_CHANNEL).set(null);
proxyChannel.attr(Constants.CLIENT_KEY).set(null);
proxyChannel.attr(Constants.USER_ID).set(null);
proxyChannel.config().setOption(ChannelOption.AUTO_READ, true);
// 通知客户端,用户连接已经断开

Loading…
Cancel
Save