public AtmosphereFilter(){ as = new AtmosphereServlet(true); }
/** * Initialize the {@link Filter} * * @param filterConfig * @throws ServletException */ public void init(final FilterConfig filterConfig) throws ServletException { AtmosphereServlet.logger.info("AtmosphereServlet running as a Filter"); as.init(new ServletConfig() { public String getServletName() { return filterConfig.getFilterName(); } public ServletContext getServletContext() { return filterConfig.getServletContext(); } public String getInitParameter(String name) { return filterConfig.getInitParameter(name); } public Enumeration<String> getInitParameterNames() { return filterConfig.getInitParameterNames(); } }); }
@Override public void destroy() { if (!destroyed) { this.destroyed = true; super.destroy(); } } }
private static void registerJavascriptServlet(ServletHost servletHost) { if (ServletFactory.javascriptServlet == null) { ServletFactory.javascriptServlet = new AtmosphereServlet(); ServletFactory.javascriptServlet.addInitParameter(PACKAGE_KEY, JS_PACKAGE); servletHost.addServletMapping(JS_PATH, javascriptServlet); } }
AtmosphereServlet s = new AtmosphereServlet(); AtmosphereFramework f = s.framework(); ReflectorServletProcessor r = new ReflectorServletProcessor(); r.setServletClassName("com.sun.jersey.spi.spring.container.servlet.SpringServlet"); f.addAtmosphereHandler("/api/*", r); ServletRegistration atmosphereServletRegistration = ctx.addServlet("AtmosphereServlet", s);
@Bean public AtmosphereFramework atmosphereFramework() { return atmosphereServlet().framework(); }
/** * Load the {@link AtmosphereHandler} associated with this AtmosphereServlet. * @param sc the {@link ServletContext} */ @Override public void init(ServletConfig sc) throws ServletException{ super.init(sc); try{ //TODO -> Add support for WEB-INF/lib/*.jar URL url = sc.getServletContext().getResource("/WEB-INF/classes/"); URLClassLoader urlC = new URLClassLoader(new URL[] {url}, Thread.currentThread().getContextClassLoader()); loadAtmosphereDotXml(sc.getServletContext(). getResourceAsStream("/META-INF/atmosphere.xml"), urlC); if (atmosphereHandlers.size() == 0){ logger.warning("Missing META-INF/atmosphere.xml." + " Will try to autodetect AtmosphereHandler"); autoDetectAtmosphereHandlers(sc.getServletContext(), urlC); } } catch (Throwable t){ throw new ServletException(t); } autoDetectContainer(); cometSupport.init(sc); initAtmosphereServletProcessor(sc); }
private void initializeAtmosphere(MultiBitExchangeApiConfiguration configuration, Environment environment) { FilterBuilder fconfig = environment.addFilter(CrossOriginFilter.class, "/stream"); fconfig.setInitParam(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*"); AtmosphereServlet atmosphereServlet = new AtmosphereServlet(); atmosphereServlet.framework().addInitParameter("com.sun.jersey.config.property.packages", ATMOSPHERE_RESOURCE_BASE_PACKAGE); atmosphereServlet.framework().addInitParameter("org.atmosphere.websocket.messageContentType", "application/json"); atmosphereServlet.framework().addInitParameter("com.sun.jersey.config.feature.DisableWADL", "true"); atmosphereServlet.framework().addInitParameter("org.atmosphere.cpr.AtmosphereInterceptor.disableDefaults", "true"); atmosphereServlet.framework().addInitParameter("org.atmosphere.cpr.broadcasterCacheClass", "org.atmosphere.cache.UUIDBroadcasterCache"); atmosphereServlet.framework().addInitParameter("org.atmosphere.cpr.sessionSupport", "true"); atmosphereServlet.framework().addInitParameter("org.atmosphere.cpr.AtmosphereResource.uniqueUUID", "true"); atmosphereServlet.framework().addInitParameter(ApplicationConfig.class.getName() + ".scanClassPath", "false"); environment.addServlet(atmosphereServlet, "/stream/*"); } }
public AtmosphereBridge(ServletContext context, String path) { AtmosphereServlet servlet = null; try { servlet = context.createServlet(AtmosphereServlet.class); } catch (ServletException e) { throw new RuntimeException(e); } AtmosphereFramework framework = servlet.framework(); framework.addAtmosphereHandler("/", new AtmosphereHandlerAdapter() { @Override public void onRequest(AtmosphereResource resource) throws IOException { if (resource.transport() == TRANSPORT.WEBSOCKET) { if (resource.getRequest().getMethod().equals("GET")) { wsActions.fire(new AtmosphereServerWebSocket(resource)); } } else { httpActions.fire(new AtmosphereServerHttpExchange(resource)); } } }); ServletRegistration.Dynamic reg = context.addServlet("wes#" + UUID.randomUUID(), servlet); reg.setAsyncSupported(true); reg.addMapping(path); }
private static String registerCometServlet(ServletHost servletHost) { if (ServletFactory.cometServlet == null) { ServletFactory.cometServlet = new AtmosphereServlet(); ServletFactory.cometServlet.addInitParameter(PACKAGE_KEY, HANDLER_PACKAGE); // ServletFactory.cometServlet.addInitParameter(FILTERS_KEY, FILTERS); String uri = servletHost.addServletMapping(PATH, cometServlet); return uri; } return null; }
@Override public void init(ServletConfig sc) throws ServletException { super.init(sc); logger.info("Swagger Socket installed {}", Version.getRawVersion()); } }
@Bean public AtmosphereServlet atmosphereServlet() { return new AtmosphereServlet(); }
private void installAtmosphere(ServletContext context, Options options) { AtmosphereServlet servlet = null; try { servlet = context.createServlet(AtmosphereServlet.class); } catch (ServletException e) { throw new IllegalStateException(e); } ServletRegistration.Dynamic registration = context.addServlet("portal#" + options.name(), servlet); registration.setLoadOnStartup(0); registration.setAsyncSupported(true); registration.addMapping(options.url()); registration.setInitParameter(ApplicationConfig.DISABLE_ATMOSPHEREINTERCEPTOR, Boolean.FALSE.toString()); modifyAtmosphereServletRegistration(registration); logger.info("AtmosphereServlet '{}' is installed in accordance with the registration '{}'", servlet, registration); framework = servlet.framework(); }
public void destroy() { as.destroy(); } }
@Override public void init(final ServletConfig sc) throws ServletException { if (!initialized) { super.init(new ServletConfigDefaultsFacade(sc, DEFAULT_INIT_PARAMETERS)); this.initialized = true; String mapping = (String) sc.getServletContext() .getAttribute(PushContextFactoryImpl.PUSH_HANDLER_MAPPING_ATTRIBUTE); if (mapping == null) { mapping = "*"; } ReflectorServletProcessor r = new ReflectorServletProcessor(this); r.setFilterClassName(PushHandlerFilter.class.getName()); framework().addAtmosphereHandler(mapping, r).initAtmosphereHandler(sc); } }
Server server = new Server(8080); //static files handler ResourceHandler resource_handler = new ResourceHandler(); resource_handler.setDirectoriesListed(true); resource_handler.setWelcomeFiles(new String[] { "index.html" }); resource_handler.setResourceBase("./src/main/webapp/"); ContextHandler context1 = new ContextHandler(); context1.setHandler(resource_handler); //Atmosphere AtmosphereServlet atmosphereServlet = new AtmosphereServlet(); ServletHolder servletHolder = new ServletHolder(atmosphereServlet); servletHolder.setInitParameter("com.sun.jersey.config.property.packages","org.atmosphere.samples.chat.jersey"); servletHolder.setInitParameter("org.atmosphere.websocket.messageContentType", "application/json"); servletHolder.setAsyncSupported(true); servletHolder.setInitParameter("org.atmosphere.useWebSocket","true"); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.addServlet(servletHolder, "/resources/*"); HandlerList handlers = new HandlerList(); handlers.addHandler(context1); handlers.addHandler(context); server.setHandler(handlers);
@Override public void destroy() { super.destroy(); } }
@Override public void init(final ServletConfig sc) throws ServletException { framework().interceptor(new CometdAtmosphereInterceptor()); framework().setUseStreamForFlushingComments(false); framework().addInitParameter("transports", WebSocketTransport.class.getName()); framework().addInitParameter(ApplicationConfig.WEBSOCKET_CONTENT_TYPE, "application/json"); super.init(sc); ReflectorServletProcessor r = new ReflectorServletProcessor(); r.setServletClassName(org.cometd.java.annotation.AnnotationCometdServlet.class.getName()); framework().addAtmosphereHandler("/*", r).initAtmosphereHandler(framework().getServletConfig()); }
AtmosphereServlet servlet = new AtmosphereServlet(); Field frameworkField = ReflectionUtils.findField(AtmosphereServlet.class, "framework"); ReflectionUtils.makeAccessible(frameworkField);
@Override public void init(ServletConfig sc) throws ServletException { super.init(sc); TrackMessageSizeInterceptor t = new TrackMessageSizeInterceptor(); t.excludedContentType("application/javascript").excludedContentType("text/html").excludedContentType("text/plain").messageDelimiter("<->"); t.configure(framework().getAtmosphereConfig()); framework().interceptor(t); framework().interceptor(new SwaggerSocketProtocolInterceptor()); logger.info("Swagger Socket installed {}", Version.getRawVersion()); } }