我试图在weblogic 11G(10.3.6)中使用带有弹簧的Atmosphere,所以我只提供了servlet 2.5。
我尝试按照http://async-io.org/tutorial.html和https://github.com/Atmosphere/atmosphere/wiki/Configuring-Atmosphere-as-a-Spring-Bean
中的氛围教程进行操作我的相关代码
的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;
}
}
当我尝试运行该示例时,它返回
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)
指出我做错了什么?我已经尝试过使用weblogic servlet的例子,它可以工作。
EDIT1 使用weblogic servelet时,我使用
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-weblogic</artifactId>
<version>2.4.2</version>
</dependency>
而不是spring依赖。 我在servlet.xml中没有关于氛围的配置,web.xml看起来像这样
<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>
其余的代码是相同的,在这种情况下它可以工作。
我想要实现的是我有一个MessageListener,我希望在收到消息时访问BroadcasterFactory以向大气广播。根据我对框架bean的理解,我应该能够实现这一点。