@Override public void messageReceived(final ChannelHandlerContext ctx, final FullHttpRequest request) throws Exception { final String path = new QueryStringDecoder(request.getUri()).path(); for (SockJsServiceFactory factory : factories.values()) { if (path.startsWith(factory.config().prefix())) { handleService(factory, request, ctx); return; } } writeNotFoundResponse(request, ctx); }
@Override public void messageReceived(final ChannelHandlerContext ctx, final FullHttpRequest request) throws Exception { final String path = new QueryStringDecoder(request.getUri()).path(); for (SockJsServiceFactory factory : factories.values()) { if (path.startsWith(factory.config().prefix())) { handleService(factory, request, ctx); return; } } writeNotFoundResponse(request, ctx); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof SessionNotFoundException) { final SessionNotFoundException se = (SessionNotFoundException) cause; logger.debug("Could not find session [{}]", se.sessionId()); writeNotFoundResponse(se.httpRequest(), ctx); } else { logger.error("exception caught:", cause); ctx.fireExceptionCaught(cause); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (cause instanceof SessionNotFoundException) { final SessionNotFoundException se = (SessionNotFoundException) cause; logger.debug("Could not find session [{}]", se.sessionId()); writeNotFoundResponse(se.httpRequest(), ctx); } else { logger.error("exception caught:", cause); ctx.fireExceptionCaught(cause); } }
private static void handleService(final SockJsServiceFactory factory, final FullHttpRequest request, final ChannelHandlerContext ctx) throws Exception { if (logger.isDebugEnabled()) { logger.debug("RequestUri : [{}]", request.getUri()); } final String pathWithoutPrefix = request.getUri().replaceFirst(factory.config().prefix(), ""); final String path = new QueryStringDecoder(pathWithoutPrefix).path(); if (Greeting.matches(path)) { writeResponse(ctx.channel(), request, Greeting.response(request)); } else if (Info.matches(path)) { writeResponse(ctx.channel(), request, Info.response(factory.config(), request)); } else if (Iframe.matches(path)) { writeResponse(ctx.channel(), request, Iframe.response(factory.config(), request)); } else if (Transports.Type.WEBSOCKET.path().equals(path)) { addTransportHandler(new RawWebSocketTransport(factory.config(), factory.create()), ctx); ctx.fireChannelRead(request.retain()); } else { final PathParams sessionPath = matches(path); if (sessionPath.matches()) { handleSession(factory, request, ctx, sessionPath); } else { writeNotFoundResponse(request, ctx); } } }
private static void handleService(final SockJsServiceFactory factory, final FullHttpRequest request, final ChannelHandlerContext ctx) throws Exception { if (logger.isDebugEnabled()) { logger.debug("RequestUri : [{}]", request.getUri()); } final String pathWithoutPrefix = request.getUri().replaceFirst(factory.config().prefix(), ""); final String path = new QueryStringDecoder(pathWithoutPrefix).path(); if (Greeting.matches(path)) { writeResponse(ctx.channel(), request, Greeting.response(request)); } else if (Info.matches(path)) { writeResponse(ctx.channel(), request, Info.response(factory.config(), request)); } else if (Iframe.matches(path)) { writeResponse(ctx.channel(), request, Iframe.response(factory.config(), request)); } else if (Transports.Type.WEBSOCKET.path().equals(path)) { addTransportHandler(new RawWebSocketTransport(factory.config(), factory.create()), ctx); ctx.fireChannelRead(request.retain()); } else { final PathParams sessionPath = matches(path); if (sessionPath.matches()) { handleSession(factory, request, ctx, sessionPath); } else { writeNotFoundResponse(request, ctx); } } }