public ServletContext injectable(AtmosphereConfig atmosphereConfig) { return atmosphereConfig.getServletContext(); } }
public static boolean isJetty(AtmosphereResource r) { final String container = r.getAtmosphereConfig().getServletContext().getServerInfo(); if (container != null && container.toLowerCase().indexOf("jetty") != -1) { return true; } return false; } }
@Override protected void configureDetectedFramework(ReflectorServletProcessor rsp, boolean isJersey) { if (isJersey) { logger.info("Configuring Guice for Atmosphere Jersey"); Injector injector = (Injector) getAtmosphereConfig().getServletContext().getAttribute(Injector.class.getName()); GuiceContainer guiceServlet = injector.getInstance(GuiceContainer.class); rsp.setServlet(guiceServlet); try { Map<String, String> props = injector.getInstance( Key.get(new TypeLiteral<Map<String, String>>() { }, Names.named(PROPERTIES))); if (props != null) { for (String p : props.keySet()) { addInitParameter(p, props.get(p)); } } } catch (Exception ex) { // Do not fail logger.debug("failed to add Jersey init parameters to Atmosphere servlet", ex.getCause()); } } } }
@Override protected void configureDetectedFramework(ReflectorServletProcessor rsp, boolean isJersey) { if (isJersey) { logger.info("Configuring Guice for Atmosphere Jersey"); Injector injector = (Injector) getAtmosphereConfig().getServletContext().getAttribute(Injector.class.getName()); GuiceContainer guiceServlet = injector.getInstance(GuiceContainer.class); rsp.setServlet(guiceServlet); try { Map<String, String> props = injector.getInstance( Key.get(new TypeLiteral<Map<String, String>>() { }, Names.named(PROPERTIES))); if (props != null) { for (String p : props.keySet()) { addInitParameter(p, props.get(p)); } } } catch (Exception ex) { // Do not fail logger.debug("failed to add Jersey init parameters to Atmosphere servlet", ex.getCause()); } } } }
private void ensureInitialized(AtmosphereResource resource) { if (userRepository == null) { Injector injector = (Injector) resource.getAtmosphereConfig().getServletContext().getAttribute(Injector.class.getName()); injector.injectMembers(this); } if (broadcastConsumer == null) { broadcastConsumer = new WorkQueueRepository.BroadcastConsumer() { @Override public void broadcastReceived(JSONObject json) { if (broadcaster != null) { broadcaster.broadcast(json.toString()); } } }; this.workQueueRepository.subscribeToBroadcastMessages(broadcastConsumer); } broadcaster = resource.getBroadcaster(); }
public JettyAsyncSupport(AtmosphereConfig config) { super(config); final WebSocketProcessor webSocketProcessor = WebSocketProcessorFactory.getDefault().getWebSocketProcessor(config.framework()); WebSocketFactory wsf; try { String[] jettyVersion = config.getServletContext().getServerInfo().substring(6).split("\\."); if (Integer.valueOf(jettyVersion[0]) > 7 || Integer.valueOf(jettyVersion[0]) == 7 && Integer.valueOf(jettyVersion[1]) > 4) { wsf = JettyWebSocketUtil.getFactory(config, webSocketProcessor); } else { wsf = null; } } catch (Throwable e) { // If we can't parse Jetty version, assume it's 8 and up. try { logger.trace("Unable to parse Jetty version {}", config.getServletContext().getServerInfo()); } catch (Throwable t) { } wsf = JettyWebSocketUtil.getFactory(config, webSocketProcessor); } webSocketFactory = wsf; }
@Override public void configure(AtmosphereConfig config) { if (config.getServletContext().getServerInfo().contains("jetty")) { config.framework().setAsyncSupport(new JettyAsyncSupport( config)); } }
if (load != null) { try { props.load(config.getServletContext().getResourceAsStream(load)); } catch (IOException e) { throw new RuntimeException(e);
@Ready public void onReady(AtmosphereResource resource) throws Exception { factory = resource.getAtmosphereConfig().getBroadcasterFactory(); resourceFactory = resource.getAtmosphereConfig().resourcesFactory(); notificationService = (NotificationService) resource.getAtmosphereConfig().getServletContext().getAttribute(AtmosphereModule.NOTIFICATION_SERVICE); if(!notificationService.subscribe(topicName, resource)) { logger.debug("Subscription to topic {} refused (resource: {})", topicName, resource); close(resource); } }
Injector injector = (Injector) framework().getAtmosphereConfig().getServletContext().getAttribute(Injector.class.getName()); GuiceContainer guiceServlet = injector.getInstance(GuiceContainer.class);
static void writeResponse(AtmosphereResource resource, Object message) throws IOException { try { RPCRequest rpcRequest = (RPCRequest) resource.getRequest().getAttribute(AtmospherePollService.GWT_REQUEST); String response = encodeResponse(rpcRequest, message); writeResponse(resource.getRequest(), resource.getResponse(), resource.getAtmosphereConfig().getServletContext(), response); } catch (IncompatibleRemoteServiceException ex) { try { String error = RPC.encodeResponseForFailure(null, ex); writeResponse(resource.getRequest(), resource.getResponse(), resource.getAtmosphereConfig().getServletContext(), error); } catch (SerializationException ex2) { throw new IOException(ex2); } } catch (SerializationException ex) { throw new IOException(ex); } }
@Override public Action inspect(AtmosphereResource r) { final SecurityContextRepository securityContextRepo = getSecurityContextRepository( r.getAtmosphereConfig().getServletContext()); if (securityContextRepo.containsContext(r.getRequest())) { LOGGER.trace("Loading the security context from the session"); final HttpRequestResponseHolder requestResponse = new HttpRequestResponseHolder(r.getRequest(), r.getResponse()); final SecurityContext securityContext = securityContextRepo.loadContext(requestResponse); SecurityContextHolder.setContext(securityContext); } return Action.CONTINUE; }
@Override public Action inspect(AtmosphereResource r) { final SecurityContextRepository securityContextRepo = getSecurityContextRepository( r.getAtmosphereConfig().getServletContext()); if (securityContextRepo.containsContext(r.getRequest())) { LOGGER.trace("Loading the security context from the session"); final HttpRequestResponseHolder requestResponse = new HttpRequestResponseHolder(r.getRequest(), r.getResponse()); final SecurityContext securityContext = securityContextRepo.loadContext(requestResponse); SecurityContextHolder.setContext(securityContext); } return Action.CONTINUE; }