2

I'm trying to use Atmosphere with spring in weblogic 11G (10.3.6), so I only have servlet 2.5 available.

I tried following the atmosphere tutorials in http://async-io.org/tutorial.html and https://github.com/Atmosphere/atmosphere/wiki/Configuring-Atmosphere-as-a-Spring-Bean

My relevant code

pom.xml

<dependency>
    <groupId>org.atmosphere</groupId>
    <artifactId>atmosphere-runtime</artifactId>
    <version>2.4.2</version>
</dependency>

<dependency>
    <groupId>org.atmosphere</groupId>
    <artifactId>atmosphere-spring</artifactId>
    <version>2.4.2</version>
</dependency>

servlet.xml

<bean id="framework" class="org.atmosphere.cpr.AtmosphereFramework">
    <constructor-arg index="0" value="false"/>
    <constructor-arg index="1" value="false"/>
</bean>

<bean class="org.atmosphere.spring.bean.AtmosphereSpringContext">
    <property name="config">
        <map>
            <entry key="org.atmosphere.cpr.broadcasterClass" value="org.atmosphere.cpr.DefaultBroadcaster" />
            <entry key="org.atmosphere.cpr.AtmosphereInterceptor" value="org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor, org.atmosphere.client.TrackMessageSizeInterceptor, org.atmosphere.interceptor.HeartbeatInterceptor, org.atmosphere.interceptor.SuspendTrackerInterceptor, org.atmosphere.config.managed.AnnotationServiceInterceptor"/>
            <entry key="org.atmosphere.cpr.broadcasterLifeCyclePolicy"
                    value="IDLE_DESTROY" />
        </map>
    </property>
</bean>

web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/root-context.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>callcenter-ui</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>callcenter-ui</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<servlet>
    <description>AtmosphereServlet</description>
    <servlet-name>AtmosphereServlet</servlet-name>
    <servlet-class>org.atmosphere.spring.bean.AtmosphereSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>AtmosphereServlet</servlet-name>
    <url-pattern>/chat/*</url-pattern>
</servlet-mapping>

Chat.java

@ManagedService(path = "/test", atmosphereConfig = MAX_INACTIVE + "=120000")
public class Chat {
    private final Logger logger = LoggerFactory.getLogger(Chat.class);

    @Heartbeat
    public void onHeartbeat(final AtmosphereResourceEvent event) {
        logger.trace("Heartbeat send by {}", event.getResource());
    }

    /**
     * Invoked when the connection has been fully established and suspended, that is, ready for receiving messages.
     *
     */
    @Ready
    public void onReady(/* In you don't want injection AtmosphereResource r */) {

    }

    /**
     * Invoked when the client disconnects or when the underlying connection is closed unexpectedly.
     *
     */
    @Disconnect
    public void onDisconnect(/** If you don't want to use injection AtmosphereResourceEvent event*/) {

    }

    /**
     * Simple annotated class that demonstrate how {@link org.atmosphere.config.managed.Encoder} and {@link org.atmosphere.config.managed.Decoder
     * can be used.
     *
     * @param message an instance of {@link Response}
     * @return
     * @throws IOException
     */
    @Message(encoders = {MessageEncoderDecoder.class}, decoders = {MessageEncoderDecoder.class})
    public Response onMessage(Response message) throws IOException {
        logger.info("{} just sent {}", message.getAuthor(), message.getMessage());
        return message;
    }

}

When I try to run the example it returns

Root cause of ServletException.
java.lang.NullPointerException
    at org.atmosphere.spring.bean.AtmosphereSpringServlet.init(AtmosphereSpringServlet.java:56)
    at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:283)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.StubSecurityHelper.createServlet(StubSecurityHelper.java:64)
    at weblogic.servlet.internal.StubLifecycleHelper.createOneInstance(StubLifecycleHelper.java:58)
    at weblogic.servlet.internal.StubLifecycleHelper.<init>(StubLifecycleHelper.java:48)
    at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:539)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:244)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
    at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
    at java.security.AccessController.doPrivileged(Native Method)
    at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:324)
    at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:460)
    at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
    at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
    at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
    at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:163)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:60)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3748)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3714)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2283)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2182)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1499)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:263)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)

Any pointers to what I'm doing wrong? I've tried the example using weblogic servlet and it works.

EDIT1 When using weblogic servelet I use

<dependency>
    <groupId>org.atmosphere</groupId>
    <artifactId>atmosphere-weblogic</artifactId>
    <version>2.4.2</version>
</dependency>

instead of the spring dependency. I have no configuration in the servlet.xml regarding atmosphere and the web.xml looks like this

<servlet>
    <servlet-name>callcenter-ui</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>callcenter-ui</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<servlet>
    <description>AtmosphereServlet</description>
    <servlet-name>AtmosphereServlet</servlet-name>
    <servlet-class>org.atmosphere.weblogic.AtmosphereWebLogicServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>AtmosphereServlet</servlet-name>
    <url-pattern>/chat/*</url-pattern>
</servlet-mapping>

The rest of the code is the same, in this case it works.

What I'm trying to achieve is that I have a MessageListener where I would like to access the BroadcasterFactory to broadcast to atmosphere when a message is received. From my understanding having the framework bean I should be able to achieve this.

sophy cat
  • 43
  • 4
  • "I've tried the example using weblogic servlet and it works" I don't understand on which environment it works. Can you precise both as the problem is here. – davidxxx Aug 18 '16 at 17:47
  • I've edited my original post with the code which is working, I hope this clarifies the question – sophy cat Aug 19 '16 at 10:55
  • Tx you. And why do you want to use the artifact 'atmosphere-weblogic' instead of which of spring? – davidxxx Aug 19 '16 at 15:37
  • I want to use the spring artifact, not the weblogic one. It simply was the first one I found and it seemed to work. Since my project is in spring it makes sense to use spring because when I used weblogic I cound't access the BroadcasterFactory in my spring beans. – sophy cat Aug 19 '16 at 16:31
  • I understand. root-context.xml is not referenced. I suppose that it' is servlet.xml. Isn't it ? And the spring context is correctly loaded ? Is the bean of `AtmosphereSpringContext `type is well loaded ? You can up the log level of spring to have more details. – davidxxx Aug 19 '16 at 20:47
  • root-context.xml is not referenced since it is empty, servlet.xml refers to -servlet.xml. I've increased the spring log level and all atmosphere referenced beans appear to be created, there are no errors and there is a message of Finished creating instance of bean – sophy cat Aug 23 '16 at 13:39

0 Answers0