/** * Sole constructor which takes one or more {@code SockJSServiceFactory}. These factories will * later be used by the server to create the SockJS services that will be exposed by this server * * @param factories one or more {@link SockJsServiceFactory}s. */ public SockJsHandler(final SockJsServiceFactory... factories) { for (SockJsServiceFactory factory : factories) { this.factories.put(factory.config().prefix(), factory); } }
/** * Sole constructor which takes one or more {@code SockJSServiceFactory}. These factories will * later be used by the server to create the SockJS services that will be exposed by this server * * @param factories one or more {@link SockJsServiceFactory}s. */ public SockJsHandler(final SockJsServiceFactory... factories) { for (SockJsServiceFactory factory : factories) { this.factories.put(factory.config().prefix(), factory); } }
@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); }
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); } } }