Websocket 休息资源中的大气资源

Websocket 休息资源中的大气资源,websocket,jersey,jax-rs,long-polling,atmosphere,Websocket,Jersey,Jax Rs,Long Polling,Atmosphere,如何在现有rest资源中获取AtmosphereResource 我试过这个: atmosphere.xml <atmosphere-handlers> <atmosphere-handler context-root="/*" class-name="org.atmosphere.handler.ReflectorServletProcessor"> <property name="servletClass"

如何在现有rest资源中获取AtmosphereResource
我试过这个:

atmosphere.xml

<atmosphere-handlers>
    <atmosphere-handler context-root="/*"
        class-name="org.atmosphere.handler.ReflectorServletProcessor">
        <property name="servletClass"
            value="com.sun.jersey.spi.container.servlet.ServletContainer" />
    </atmosphere-handler>
</atmosphere-handlers>
<servlet>
        <servlet-name>jaxrs</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.atmos.rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>jaxrs</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

    <servlet>
        <description>AtmosphereServlet</description>
        <servlet-name>AtmosphereServlet</servlet-name>
        <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
        <init-param>
            <param-name>org.atmosphere.cpr.Broadcaster.supportOutOfOrderBroadcast</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
            <param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value>
        </init-param>
        <!-- Reduce memory usage by sharing ExecutorServices -->
        <init-param>
            <param-name>org.atmosphere.cpr.broadcaster.shareableThreadPool</param-name>
            <param-value>true</param-value>
        </init-param>
        <!-- Automatically free Broadcaster objects when the last client on the 
            Broadcaster's channel disconnects -->
        <init-param>
            <param-name>org.atmosphere.cpr.broadcasterLifeCyclePolicy</param-name>
            <param-value>EMPTY_DESTROY</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.cpr.broadcaster.maxProcessingThreads</param-name>
            <param-value>50</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.cpr.broadcaster.maxAsyncWriteThreads</param-name>
            <param-value>50</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>AtmosphereServlet</servlet-name>
        <!-- Any mapping -->
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
调用rest资源时,我将上述代码中的atmosphereResource变量设置为null
我想我可能在web.xml或atmosphere.xml中做错了什么
我想在应用程序中现有的rest资源中使用Atmosphere runtime
非常感谢您的帮助。提前感谢。

根据此:

有时需要在资源中注入大气成分。可以使用@Context、@PathParam@QueryParam、@MatrixParam、@HeaderParam、@CookieParam、@FormParam等注释注入以下组件

您可以注入:AtmosphereResource、Broadcaster、BroadcasterFactory

@Context AtmosphereResource resource
@PathParam
public String inject(@PathParam("test") Broadcaster broadcaster) {
  ...
}
据此:

有时需要在资源中注入大气成分。可以使用@Context、@PathParam@QueryParam、@MatrixParam、@HeaderParam、@CookieParam、@FormParam等注释注入以下组件

您可以注入:AtmosphereResource、Broadcaster、BroadcasterFactory

@Context AtmosphereResource resource
@PathParam
public String inject(@PathParam("test") Broadcaster broadcaster) {
  ...
}

谢谢你指向医生。用答案更新了问题,谢谢你指向文档。使用@Context AtmosphereResource
code
@GET@Path(“/receive”)公共响应接收(@Context AtmosphereResource AtmosphereResource){//挂起响应AtmosphereResource.suspend),使用answerInject大气资源更新了问题(超时,TimeUnit.MINUTES);返回Response.ok().build();}
code
使用@Context atmosphereSource
code
@GET@Path(“/receive”)公共响应接收注入大气资源(@Context-AtmosphereResource AtmosphereResource){//suspend响应AtmosphereResource.suspend(timeout,TimeUnit.MINUTES);return response.ok().build();}
code