/** * Convenience method that tests if a class with the given FQN is present on the classpath. * * @param testClass * @return true if the class is present */ protected boolean testClassExists(final String testClass) { try { final boolean exists = testClass != null && testClass.length() > 0 && IOUtils.loadClass(null, testClass) != null; logger.debug(exists ? "Found {}" : "Not found {}", testClass); return exists; } catch (Exception ex) { return false; } }
@Override public void postInspect(AtmosphereResource r) { if (r.getRequest().getMethod().equalsIgnoreCase("POST")) { AtmosphereRequest request = r.getRequest(); Object o; try { o = readEntirely(r); } catch (IOException e) { logger.warn("", e); return; } if (isBodyEmpty(o)) { logger.warn("{} received an empty body", request); return; } r.getBroadcaster().broadcast(o); } } }
public static Object readEntirely(AtmosphereResource r) throws IOException { AtmosphereRequest request = r.getRequest(); return isBodyBinary(request) ? readEntirelyAsByte(r) : readEntirelyAsString(r).toString(); }
protected void loadMetaService() { try { Map<String, MetaServiceAction> config = (Map<String, MetaServiceAction>) servletConfig.getServletContext().getAttribute(AtmosphereFramework.MetaServiceAction.class.getName()); if (config == null) { config = IOUtils.readServiceFile(metaServicePath + AtmosphereFramework.class.getName()); } for (final Map.Entry<String, MetaServiceAction> action : config.entrySet()) { final Class c = IOUtils.loadClass(AtmosphereFramework.class, action.getKey()); action.getValue().apply(this, c); } } catch (Exception ex) { logger.error("", ex); } }
protected void autoConfigureService(ServletContext sc) throws IOException { String path = handlersPath != DEFAULT_HANDLER_PATH ? handlersPath : realPath(sc, handlersPath); try { annotationProcessor = newClassInstance(AnnotationProcessor.class, (Class<AnnotationProcessor>) IOUtils.loadClass(getClass(), annotationProcessorClassName)); logger.info("Atmosphere is using {} for processing annotation", annotationProcessorClassName); String pathLibs = libPath != DEFAULT_LIB_PATH ? libPath : realPath(sc, DEFAULT_LIB_PATH); if (pathLibs != null) { File libFolder = new File(pathLibs);
@Override public void onRequest(AtmosphereResource resource) throws IOException { String body = IOUtils.readEntirely(resource).toString(); if (!body.isEmpty()) { resource.getBroadcaster().broadcast(body); } } };
Object body = null; if (onPostMethod != null) { body = readEntirely(resource); if (body != null && String.class.isAssignableFrom(body.getClass())) { resource.getRequest().body((String) body); r = resourcesFactory.find(resource.uuid()); IOUtils.deliver(new Managed(e.encodedObject), null, e.methodInfo.deliverTo, r);
@Override public byte[] transformPayload(AtmosphereResponse response, byte[] responseDraft, byte[] data) throws IOException { boolean writeAsBytes = IOUtils.isBodyBinary(response.request()); if (writeAsBytes) { logger.warn("Cannot use TrackMessageSizeInterceptor with binary write. Writing the message as it is.");
servletPath = IOUtils.guestServletPath(config); if (servletPath.equals("") || servletPath.equals("/") || servletPath.equals("/*")) { servletPath = PATH +"}"; logger.warn("Duplicate Servlet Mapping Path {}. Use {} init-param to prevent this message", servletPath, ApplicationConfig.JSR356_MAPPING_PATH); logger.trace("", e); servletPath = IOUtils.guestServletPath(config); logger.warn("Duplicate guess {}", servletPath, e); b.setLength(0);
public static byte[] readEntirelyAsByte(AtmosphereResource r) throws IOException { boolean readGetBody = r.getAtmosphereConfig().getInitParameter(ApplicationConfig.READ_GET_BODY, false); if (!readGetBody && AtmosphereResourceImpl.class.cast(r).getRequest(false).getMethod().equalsIgnoreCase("GET")) { logger.debug("Blocking an I/O read operation from a GET request. To enable GET + body, set {} to true", ApplicationConfig.READ_GET_BODY); return new byte[0]; } return forceReadEntirelyAsByte(r); }
protected void processReady(AtmosphereResource r) { final DeliverTo deliverTo; final Ready ready = onReadyMethod.getAnnotation(Ready.class); // Keep backward compatibility if (ready.value() != Ready.DELIVER_TO.RESOURCE) { if (IAE == null) { IAE = new IllegalArgumentException(); } logger.warn("Since 2.2, delivery strategy must be specified with @DeliverTo, not with a value in the @Ready annotation.", IAE); deliverTo = new DeliverTo() { @Override public DELIVER_TO value() { switch (ready.value()) { case ALL: return DELIVER_TO.ALL; case BROADCASTER: return DELIVER_TO.BROADCASTER; } return null; } @Override public Class<? extends Annotation> annotationType() { return null; } }; } else { deliverTo = onReadyMethod.getAnnotation(DeliverTo.class); } IOUtils.deliver(message(onReadyMethod, r), deliverTo, DeliverTo.DELIVER_TO.RESOURCE, r); }
logger.trace("Unable to read META-INF/services/{} from class loader", path, e); } finally { close(is, reader);
public static AtmosphereFramework newAtmosphereFramework(ServletContext sc, boolean isFilter, boolean autoDetectHandlers) { String metaServicePath = sc.getInitParameter(META_SERVICE_PATH) == null ? META_SERVICE : sc.getInitParameter(META_SERVICE_PATH); try { final Map<String, AtmosphereFramework.MetaServiceAction> config = IOUtils.readServiceFile(metaServicePath + AtmosphereFramework.class.getName()); sc.setAttribute(AtmosphereFramework.MetaServiceAction.class.getName(), config); for (final Map.Entry<String, AtmosphereFramework.MetaServiceAction> action : config.entrySet()) { final Class c = IOUtils.loadClass(AtmosphereFramework.class, action.getKey()); if (AtmosphereFramework.class.isAssignableFrom(c)) { logger.info("Found a definition of AtmosphereFramework {} under {}", c, metaServicePath); return newAtmosphereFramework(c, isFilter, autoDetectHandlers); } } } catch (Exception ex) { logger.error("", ex); } return newAtmosphereFramework(AtmosphereFramework.class, isFilter, autoDetectHandlers, sc); }
private Action injectMessage(AtmosphereResource r) { final AtmosphereResponse response = r.getResponse(); final AtmosphereRequest request = r.getRequest(); try { String body = IOUtils.readEntirely(r).toString(); if (!body.isEmpty() && body.startsWith("d=")) { body = URLDecoder.decode(body, "UTF-8"); body = body.substring(2); response.setStatus(200); response.write("ok", true).flushBuffer(); reInject(request, response, body); } else { String[] messages = parseMessageString(body); for (String m : messages) { if (m == null) continue; reInject(request, response, m); } response.setStatus(204); } } catch (Exception e) { logger.error("", e); } return Action.CANCELLED; }
AtmosphereRequest request = resource.getRequest(); boolean writeAsBytes = IOUtils.isBodyBinary(request); if (message == null) { logger.trace("Message was null for AtmosphereEvent {}", event);
servletPath = IOUtils.guestServletPath(framework.getAtmosphereConfig());
bytes = IOUtils.forceReadEntirelyAsByte(r); } catch (IOException e) { logger.warn("", e);
@Override public void reportTypeAnnotation(Class<? extends Annotation> annotation, String className) { try { coreAnnotationsFound.set(true); handler.handleProcessor(loadClass(getClass(), className)); } catch (Exception e) { logger.warn("Error scanning @AtmosphereAnnotation", e); } } };
o = request.getInputStream(); } else if (o == null) { o = readEntirely(resource); if (isBodyEmpty(o)) { logger.warn("{} received an empty body", request); return null;
public void onRequest(final AtmosphereResource resource) throws IOException { final AtmosphereRequest request = resource.getRequest(); String body = IOUtils.readEntirely(resource).toString();