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.