Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b438afa69 | ||
|
|
66961b94da |
@@ -35,11 +35,14 @@ import java.util.concurrent.Executor;
|
|||||||
@HttpMethod("POST")
|
@HttpMethod("POST")
|
||||||
public class RouteAction extends Action {
|
public class RouteAction extends Action {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(RouteAction.class);
|
private static final Logger LOG = LoggerFactory.getLogger(RouteAction.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean action(Request request, Response response) {
|
public boolean action(Request request, Response response) {
|
||||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
|
||||||
response.setContentType("application/octet-stream");
|
response.setContentType("application/octet-stream");
|
||||||
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
|
||||||
FullHttpRequest fullHttpRequest = (FullHttpRequest) request.getNettyRequest();
|
FullHttpRequest fullHttpRequest = (FullHttpRequest) request.getNettyRequest();
|
||||||
boolean b = false;
|
boolean b = false;
|
||||||
if ("web".equalsIgnoreCase(fullHttpRequest.headers().get("p"))) {
|
if ("web".equalsIgnoreCase(fullHttpRequest.headers().get("p"))) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Action处理单元
|
* Action处理单元
|
||||||
*
|
*
|
||||||
* @author Looly
|
* @author Looly
|
||||||
*/
|
*/
|
||||||
abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
|
abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
|
||||||
@@ -45,7 +45,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
|||||||
try {
|
try {
|
||||||
//do filter
|
//do filter
|
||||||
boolean isPass = this.doFilter(request, response);
|
boolean isPass = this.doFilter(request, response);
|
||||||
|
|
||||||
if(isPass){
|
if(isPass){
|
||||||
//do action
|
//do action
|
||||||
this.doAction(ctx, request, response);
|
this.doAction(ctx, request, response);
|
||||||
@@ -64,10 +64,10 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
|||||||
ctx.fireExceptionCaught(e);
|
ctx.fireExceptionCaught(e);
|
||||||
ctx.close();
|
ctx.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
super.exceptionCaught(ctx, cause);
|
super.exceptionCaught(ctx, cause);
|
||||||
@@ -75,7 +75,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
|||||||
Channel channel = ctx.channel();
|
Channel channel = ctx.channel();
|
||||||
if(channel.isActive())ctx.close();
|
if(channel.isActive())ctx.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------- Private method start
|
//---------------------------------------------------------------------------------------- Private method start
|
||||||
/**
|
/**
|
||||||
* 执行过滤
|
* 执行过滤
|
||||||
@@ -91,7 +91,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//自定义Path过滤器
|
//自定义Path过滤器
|
||||||
filter = ServerSetting.getFilter(request.getPath());
|
filter = ServerSetting.getFilter(request.getPath());
|
||||||
if(null != filter){
|
if(null != filter){
|
||||||
@@ -99,7 +99,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +110,10 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
|||||||
* @param response 响应对象
|
* @param response 响应对象
|
||||||
*/
|
*/
|
||||||
private void doAction(ChannelHandlerContext ctx, Request request, Response response){
|
private void doAction(ChannelHandlerContext ctx, Request request, Response response){
|
||||||
|
if( "/route".equalsIgnoreCase(request.getPath()) && "OPTIONS".equalsIgnoreCase(request.getMethod())){
|
||||||
|
handleOptions(ctx, request, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Action action;
|
Action action;
|
||||||
if (isValidePath(request.getPath())) {
|
if (isValidePath(request.getPath())) {
|
||||||
action = ServerSetting.getAction(request.getPath(), request.getMethod().toUpperCase());
|
action = ServerSetting.getAction(request.getPath(), request.getMethod().toUpperCase());
|
||||||
@@ -141,4 +145,11 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler<FullHttp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------------------- Private method start
|
//---------------------------------------------------------------------------------------- Private method start
|
||||||
|
|
||||||
|
|
||||||
|
private void handleOptions(ChannelHandlerContext ctx, Request request, Response response){
|
||||||
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
response.setHeader("Access-Control-Allow-Headers", "*");
|
||||||
|
response.send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1047,7 +1047,7 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
return ErrorCode.ERROR_CODE_GROUP_MUTED;
|
return ErrorCode.ERROR_CODE_GROUP_MUTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (member.getMemberId().equals(memberId) && member.getType() != GroupMemberType_Removed) {
|
if (member.getMemberId().equals(memberId) && member.getType() == GroupMemberType_Removed) {
|
||||||
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
return ErrorCode.ERROR_CODE_NOT_IN_GROUP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ public class NettyAcceptor implements ServerAcceptor {
|
|||||||
pipeline.addLast(new HttpServerCodec());
|
pipeline.addLast(new HttpServerCodec());
|
||||||
pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
|
pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
|
||||||
pipeline.addLast("webSocketHandler",
|
pipeline.addLast("webSocketHandler",
|
||||||
new WebSocketServerProtocolHandler("/org/fusesource/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
|
new WebSocketServerProtocolHandler("/", MQTT_SUBPROTOCOL_CSV_LIST));
|
||||||
pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
|
pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
|
||||||
pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
|
pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
|
||||||
pipeline.addFirst("idleStateHandler", new IdleStateHandler(nettyChannelTimeoutSeconds, 0, 0));
|
pipeline.addFirst("idleStateHandler", new IdleStateHandler(nettyChannelTimeoutSeconds, 0, 0));
|
||||||
|
|||||||
Reference in New Issue
Block a user