Search in sources :

Example 11 with ReflectorServletProcessor

use of org.atmosphere.handler.ReflectorServletProcessor in project atmosphere by Atmosphere.

the class AtmosphereResourceTest method verifyTestCompletionAwareForSync.

private void verifyTestCompletionAwareForSync(boolean aware) throws IOException, ServletException {
    Servlet s = mock(Servlet.class);
    if (aware) {
        framework.addInitParameter(ApplicationConfig.RESPONSE_COMPLETION_AWARE, "true");
    }
    ReflectorServletProcessor handler = new ReflectorServletProcessor(s);
    handler.init(framework.getAtmosphereConfig());
    AtmosphereRequest request = new AtmosphereRequestImpl.Builder().pathInfo("/a").build();
    AtmosphereResponseImpl response = mock(AtmosphereResponseImpl.class);
    AtmosphereResourceImpl res = new AtmosphereResourceImpl();
    res.initialize(framework.getAtmosphereConfig(), framework.getBroadcasterFactory().get(), request, response, null, null);
    res.transport(AtmosphereResource.TRANSPORT.WEBSOCKET);
    request.setAttribute(FrameworkConfig.ATMOSPHERE_RESOURCE, res);
    request.setAttribute(FrameworkConfig.INJECTED_ATMOSPHERE_RESOURCE, res);
    handler.onRequest(res);
    verify(response, times(aware ? 1 : 0)).onComplete();
}
Also used : ReflectorServletProcessor(org.atmosphere.handler.ReflectorServletProcessor)

Example 12 with ReflectorServletProcessor

use of org.atmosphere.handler.ReflectorServletProcessor in project atmosphere by Atmosphere.

the class AtmosphereFramework method detectSupportedFramework.

/**
 * Auto-detect Jersey when no atmosphere.xml file is specified.
 *
 * @param sc {@link ServletConfig}
 * @return true if Jersey classes are detected
 * @throws ClassNotFoundException
 */
protected boolean detectSupportedFramework(ServletConfig sc) throws Exception {
    String broadcasterClassNameTmp = null;
    boolean isJersey;
    try {
        IOUtils.loadClass(getClass(), JERSEY_CONTAINER);
        isJersey = true;
        if (!isBroadcasterSpecified) {
            broadcasterClassNameTmp = lookupDefaultBroadcasterType(JERSEY_BROADCASTER);
            IOUtils.loadClass(getClass(), broadcasterClassNameTmp);
        }
        useStreamForFlushingComments = true;
        StringBuilder packagesInit = new StringBuilder();
        for (String s : packages) {
            packagesInit.append(s).append(",");
        }
        initParams.put(FrameworkConfig.JERSEY_SCANNING_PACKAGE, packagesInit.toString());
    } catch (Throwable t) {
        logger.trace("", t);
        return false;
    }
    logger.debug("Missing META-INF/atmosphere.xml but found the Jersey runtime. Starting Jersey");
    // Atmosphere 1.1 : could add regressions
    // Jersey will itself handle the headers.
    // initParams.put(WRITE_HEADERS, "false");
    ReflectorServletProcessor rsp = newClassInstance(ReflectorServletProcessor.class, ReflectorServletProcessor.class);
    if (broadcasterClassNameTmp != null)
        broadcasterClassName = broadcasterClassNameTmp;
    configureDetectedFramework(rsp, isJersey);
    sessionSupport(false);
    initParams.put(DISABLE_ONSTATE_EVENT, "true");
    String mapping = sc.getInitParameter(PROPERTY_SERVLET_MAPPING);
    if (mapping == null) {
        mapping = sc.getInitParameter(ATMOSPHERE_HANDLER_MAPPING);
        if (mapping == null) {
            mapping = Broadcaster.ROOT_MASTER;
        }
    }
    Class<? extends Broadcaster> bc = (Class<? extends Broadcaster>) IOUtils.loadClass(getClass(), broadcasterClassName);
    broadcasterFactory.destroy();
    broadcasterFactory = newClassInstance(BroadcasterFactory.class, DefaultBroadcasterFactory.class);
    broadcasterFactory.configure(bc, broadcasterLifeCyclePolicy, config);
    for (BroadcasterListener b : broadcasterListeners) {
        broadcasterFactory.addBroadcasterListener(b);
    }
    Broadcaster b;
    try {
        b = broadcasterFactory.get(bc, mapping);
    } catch (IllegalStateException ex) {
        logger.warn("Two Broadcaster's named {}. Renaming the second one to {}", mapping, sc.getServletName() + mapping);
        b = broadcasterFactory.get(bc, sc.getServletName() + mapping);
    }
    addAtmosphereHandler(mapping, rsp, b);
    return true;
}
Also used : ReflectorServletProcessor(org.atmosphere.handler.ReflectorServletProcessor)

Example 13 with ReflectorServletProcessor

use of org.atmosphere.handler.ReflectorServletProcessor in project atmosphere by Atmosphere.

the class MeteorServlet method loadDelegateViaConfig.

private void loadDelegateViaConfig(ServletConfig sc) throws ServletException {
    String servletClass = framework().getAtmosphereConfig().getInitParameter(SERVLET_CLASS);
    String mapping = framework().getAtmosphereConfig().getInitParameter(MAPPING);
    String filterClass = framework().getAtmosphereConfig().getInitParameter(FILTER_CLASS);
    String filterName = framework().getAtmosphereConfig().getInitParameter(FILTER_NAME);
    if (servletClass != null) {
        logger.info("Installed Servlet/Meteor {} mapped to {}", servletClass, mapping == null ? ROOT_MASTER : mapping);
    }
    if (filterClass != null) {
        logger.info("Installed Filter/Meteor {} mapped to /*", filterClass, mapping);
    }
    // The annotation was used.
    if (servletClass != null || filterClass != null) {
        ReflectorServletProcessor r = new ReflectorServletProcessor();
        r.setServletClassName(servletClass);
        r.addFilterClassName(filterClass, filterName);
        if (mapping == null) {
            mapping = Broadcaster.ROOT_MASTER;
            framework().getBroadcasterFactory().remove(Broadcaster.ROOT_MASTER);
        }
        framework().addAtmosphereHandler(mapping, r).initAtmosphereHandler(sc);
    }
}
Also used : ReflectorServletProcessor(org.atmosphere.handler.ReflectorServletProcessor)

Aggregations

ReflectorServletProcessor (org.atmosphere.handler.ReflectorServletProcessor)13 Test (org.testng.annotations.Test)4 Servlet (jakarta.servlet.Servlet)3 HttpServlet (jakarta.servlet.http.HttpServlet)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)2 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)2 LinkedList (java.util.LinkedList)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Servlet (javax.servlet.Servlet)2 MeteorService (org.atmosphere.config.service.MeteorService)2 AtmosphereInterceptor (org.atmosphere.cpr.AtmosphereInterceptor)2 Named (jakarta.inject.Named)1 Filter (jakarta.servlet.Filter)1 AsyncContext (javax.servlet.AsyncContext)1 MeteorServiceInterceptor (org.atmosphere.config.managed.MeteorServiceInterceptor)1 AtmosphereService (org.atmosphere.config.service.AtmosphereService)1 Singleton (org.atmosphere.config.service.Singleton)1 AtmosphereConfig (org.atmosphere.cpr.AtmosphereConfig)1 AtmosphereHandler (org.atmosphere.cpr.AtmosphereHandler)1 AtmosphereResource (org.atmosphere.cpr.AtmosphereResource)1