What is the java/scala configuration needed to integrate Atmosphere (version 1.0.13)?

StackOverflow https://stackoverflow.com/questions/17933900

  •  04-06-2022
  •  | 
  •  

سؤال

I'm sure this is something pretty simple, but I can't recall coming across a library that has more discrepancies between its documents, APIs and versions. (Though in all fairness, I'm sure they exist!) As far as I can tell from the resources I've looked through, I think this is pretty close to "current" but I'm getting an error (No AtmosphereHandler maps request for /path/to/service/point) and needing a little guidance on what I should try next.

I can re-post the verbose version, but in short...

1) the web.xml has this servlet entry (from latest? git chat sample):

<servlet>
    <description>AtmosphereServlet</description>
    <servlet-name>AtmosphereServlet</servlet-name>
    <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
    <async-supported>true</async-supported>
    <init-param>
        <param-name>org.atmosphere.cpr.Broadcaster.supportOutOfOrderBroadcast</param-name>
        <param-value>false</param-value>
    </init-param>
    <!--<init-param>-->
    <!--<param-name>org.atmosphere.cpr.broadcasterClass</param-name>-->
    <!--<param-value>org.atmosphere.util.SimpleBroadcaster</param-value>-->
    <!--</init-param>-->
    <load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>AtmosphereServlet</servlet-name>
    <url-pattern>/path/to/service/point</url-pattern>
</servlet-mapping>

2) the web-app has this class definition (in Scala):

@AtmosphereHandlerService(path = "/path/to/service/point")
class MyCustomAtmoHandler extends AtmosphereHandler with Logging with OtherStuff {
   override def onRequest {...}
   override def onStateChange {...}
   override def destroy {...}

Note: the document I was using as a guide did not contain the annotation parameter "path" - which I had to add in order to get it to compile.

EDIT: This is using Jetty version 9.0.4.v20130625

هل كانت مفيدة؟

المحلول

In answer to my own questions (in case some other wandering sole finds themselves in the same position) I had to do two things to solve the problem:

1) drop the AtmosphereHandlerService annotation, or least the "path" parameter. (It might be possible to operate the annotation using the rest of the parameters; not sure.)

2) add a file called atmosphere.xml to the META-INF folder, which contains something like:

<atmosphere-handlers>
    <atmosphere-handler support-session="false"
                    context-root="/websocket/path/to/processorA"
                    class-name="com.some.className">
    </atmosphere-handler>

    <atmosphere-handler support-session="true"
                    context-root="/websocket/optional/path/to/processorB"
                    class-name="com.some.other.className">
    </atmosphere-handler>
</atmosphere-handlers>

So...the web.xml (or whatever deployment file/architecture your servlet container uses) creates the "overall" context path for ALL handlers, whereas specific routes are bound to each individual Handler using the atmosphere.xml markup. (Something like "/websocket/*" should allow routing to both of those hypothetical Handlers.

There's probably better ways of stating this solution from a technical standpoint, but hopefully that layman's summary points you in the right direction.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top