Can guice work with atmopshere.xml ?

classic Classic list List threaded Threaded
6 messages Options
ale
Reply | Threaded
Open this post in threaded view
|

Can guice work with atmopshere.xml ?

ale
Hi, I'm using Atmosphere-Jersey and Atmosphere-Guice. Right now I have to use Atmosphere-GWT all in one project. I don't want to mix Jersey + Gwt. I just have only one handler for gwt and other for jersey.

I wonder,  If I use giuce. will I be able to use atmosphere.xml?

What I see in the source code of atmosphere is that, guice only runs when the detectSupportedFramework method of the class GuiceManagedAtmosphereServlet is called. This method (detectSupportedFramework) is called when there are no handlers . Is that right? The only way to use atmosphere-guice is with no handlers ?

protected void loadConfiguration(ServletConfig sc) throws ServletException {
...
 loadAtmosphereDotXml(sc.getServletContext().getResourceAsStream("/META-INF/atmosphere.xml"), urlC);
  if (atmosphereHandlers.size() == 0) {
     autoDetectAtmosphereHandlers(sc.getServletContext(), urlC);
        if (atmosphereHandlers.size() == 0) {
          detectSupportedFramework(sc); <---- ONLY CALLED WHEN NO HANDLERS EXIST.
       }
  }
...
}

i'd like to use something like this:
http://localhost/app/api/gwt/listen         <---- MyCustomAtmosphereGwtHandler
http://localhost/app/api/jersey/listen      <---- Some internal AtmosphereHandler

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Can guice work with atmopshere.xml ?

Jeanfrancois Arcand-4
Salut,

On 11-07-02 9:04 PM, ale wrote:
> Hi, I'm using Atmosphere-Jersey and Atmosphere-Guice. Right now I have to use
> Atmosphere-GWT all in one project. I don't want to mix Jersey + Gwt. I just
> have only one handler for gwt and other for jersey.
>
> I wonder,  If I use giuce. will I be able to use atmosphere.xml?

OK I've filled

http://java.net/jira/browse/ATMOSPHERE-140

and fixed it:

https://github.com/Atmosphere/atmosphere/commit/86621311a1db2c2ea7ee0455ff67b8362746aa9f

Now your scenario is supported. Just install Atmosphere 0.8-SNAPSHOT and
let me know.

Thanks!

-- Jeanfrancois



>
> What I see in the source code of atmosphere is that, guice only runs when
> the detectSupportedFramework method of the class
> GuiceManagedAtmosphereServlet is called. This method
> (detectSupportedFramework) is called when there are no handlers . Is that
> right? The only way to use atmosphere-guice is with no handlers ?




>
> protected void loadConfiguration(ServletConfig sc) throws ServletException {
> ...
>
> loadAtmosphereDotXml(sc.getServletContext().getResourceAsStream("/META-INF/atmosphere.xml"),
> urlC);
>    if (atmosphereHandlers.size() == 0) {
>       autoDetectAtmosphereHandlers(sc.getServletContext(), urlC);
>          if (atmosphereHandlers.size() == 0) {
>            detectSupportedFramework(sc);<---- ONLY CALLED WHEN NO HANDLERS
> EXIST.
>         }
>    }
> ...
> }
>
> i'd like to use something like this:
> http://localhost/app/api/gwt/listen<----
> MyCustomAtmosphereGwtHandler
> http://localhost/app/api/jersey/listen<---- Some internal
> AtmosphereHandler
>
> Thanks.
>
> --
> View this message in context: http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Can-guice-work-with-atmopshere-xml-tp6542181p6542181.html
> Sent from the Atmosphere users mailling list mailing list archive at Nabble.com.
>
ale
Reply | Threaded
Open this post in threaded view
|

Re: Can guice work with atmopshere.xml ?

ale
Thanks. !!

For now it seems to work, at least one part.

I can not test 100% because I do not know how to configure it.

e.g:
http://localhost/api/gwt/comet <---- MyCustomAtmosphereGwtHandler
http://localhost/api/rest/comet  <---- Rest (Jersey).

When I try "http://localhost/api/rest/comet" in the browser I get "Error 405: Method Not Allowed". This is fine because I execute a GET. When i test it with AHC this work fine.
But, when I run "http://localhost/api/gwt/comet" in the browser i get "Error 404: Not found". This is bad, because that means that there is no servlet catching the call.

What i'm doing wrong ?

My config:

/****************************
      WEB.XML
****************************/
<web-app>
  <filter>
    <filter-name>guiceFilter</filter-name>
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>guiceFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

/****************************
      ATMOSPHERE.XML
****************************/
<atmosphere-handlers>
  <atmosphere-handler context-root="/api/gwt/comet" class-name="com.test.AtmosphereHandler">
    <property name="heartbeat" value="20000" />
  </atmosphere-handler>
</atmosphere-handlers>


/****************************
    MYSERVLETMODULE.JAVA
****************************/
serve("/api/*").with(GuiceManagedAtmosphereServlet.class, new HashMap<String, String>() {
        {
                put(AtmosphereServlet.PROPERTY_NATIVE_COMETSUPPORT, "true");
                put(AtmosphereServlet.DISABLE_ONSTATE_EVENT, "true");
                put(PackagesResourceConfig.PROPERTY_PACKAGES, "com.s4s.server.mensajero");
        }
});
ale
Reply | Threaded
Open this post in threaded view
|

Re: Can guice work with atmopshere.xml ?

ale
Ok, I think I found the problem.

I change:
1) "/api/*" for "/api/gwt/*"
2) add the property: put(AtmosphereServlet.PROPERTY_SERVLET_MAPPING, "/api/rest/*");
3) add serve("/api/rest/*").with(GuiceContainer.class);

/****************************
    MYSERVLETMODULE.JAVA
****************************/
serve("/api/gwt/*").with(GuiceManagedAtmosphereServlet.class, new HashMap<String, String>() {
        {
                put(AtmosphereServlet.PROPERTY_NATIVE_COMETSUPPORT, "true");
                put(AtmosphereServlet.DISABLE_ONSTATE_EVENT, "true");
                put(AtmosphereServlet.PROPERTY_SERVLET_MAPPING, "/api/rest/*");
                put(PackagesResourceConfig.PROPERTY_PACKAGES, "com.s4s.server.mensajero");
        }
});

serve("/api/rest/*").with(GuiceContainer.class);

That works fine.
ale
Reply | Threaded
Open this post in threaded view
|

Re: Can guice work with atmopshere.xml ?

ale
Correction:

1) remove: serve("/api/rest/*").with(GuiceContainer.class);
2) add "/api/rest/*" to serve("/api/gwt/*", ....);

/****************************
    MYSERVLETMODULE.JAVA
****************************/
serve("/api/gwt/*", "/api/rest/*").with(GuiceManagedAtmosphereServlet.class, new HashMap<String, String>() {
        {
                put(AtmosphereServlet.PROPERTY_NATIVE_COMETSUPPORT, "true");
                put(AtmosphereServlet.DISABLE_ONSTATE_EVENT, "true");
                put(AtmosphereServlet.PROPERTY_SERVLET_MAPPING, "/api/rest/*");
                put(PackagesResourceConfig.PROPERTY_PACKAGES, "com.s4s.server.mensajero");
        }
});

With this configuration everything is working properly.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Can guice work with atmopshere.xml ?

Jeanfrancois Arcand-4
Thanks for confirming :-)

-- Jeanfrancois

On 11-07-05 9:17 PM, ale wrote:

> Correction:
>
> 1) remove: serve("/api/rest/*").with(GuiceContainer.class);
> 2) add "/api/rest/*" to serve("/api/gwt/*", ....);
>
> /****************************
>      MYSERVLETMODULE.JAVA
> ****************************/
> serve(*"/api/gwt/*",
> "/api/rest/*"*).with(GuiceManagedAtmosphereServlet.class, new
> HashMap&lt;String, String&gt;() {
>          {
>                  put(AtmosphereServlet.PROPERTY_NATIVE_COMETSUPPORT, "true");
>                  put(AtmosphereServlet.DISABLE_ONSTATE_EVENT, "true");
>                  put(AtmosphereServlet.PROPERTY_SERVLET_MAPPING,
> "/api/rest/*");
>                  put(PackagesResourceConfig.PROPERTY_PACKAGES,
> "com.s4s.server.mensajero");
>          }
> });
>
> With this configuration everything is working properly.
>
> Thanks
>
> --
> View this message in context: http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Can-guice-work-with-atmopshere-xml-tp6542181p6552680.html
> Sent from the Atmosphere users mailling list mailing list archive at Nabble.com.
>