Compare commits

...
2 Commits
Author SHA1 Message Date
heavyrain.lee 4b438afa69 fix issue 2019-06-30 10:31:12 +08:00
imndx 66961b94da route接口允许跨域访问 2019-06-29 16:42:55 +08:00
4 changed files with 23 additions and 9 deletions
@@ -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"))) {
@@ -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));