Integration of Struts 2 and Atmosphere 0.7.1

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

Integration of Struts 2 and Atmosphere 0.7.1

kosmoplan
Hi,

I'm currently trying to integrate Struts 2 and Atmosphere in my project. According to the white-paper, it's not possible to use Tomcat NIO if I make use of the atmosphere filter, but Struts 2 is based on the StrutsPrepareAndExecuteFilter.

How could I make use of the Tomcat NIO connector in my Struts 2 application? Somebody could help me?

Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

survivant

I, m using atmosphere with tomcat and struts2 without trouble.

The only difference is that i, m using it with Guice 3.0.

I will send you an example tonight.

On May 16, 2011 4:37 PM, "kosmoplan" <[hidden email]> wrote:
Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

kosmoplan
Thank you so much!
Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

survivant
here my web.xml


<?xml version="1.0"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee    http://java.sun.com/xml/ns/j2ee/web-app_3.0.xsd">
    <filter>
        <filter-name>guice</filter-name>
        <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>guice</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>com.jerabi.inject.GuiceListener</listener-class>
    </listener>
</web-app>


MY class to inject config

public class GuiceListener extends GuiceServletContextListener {

      public Injector getInjector() {
        return Guice.createInjector( new Struts2GuicePluginModule(), new ServletModule() {
                @Override
                protected void configureServlets() {     
                   
                    // ajout du EntityManager
                      
                  install(new JpaPersistModule("jpaconfig"));
                  filter("/*").through(PersistFilter.class);

                   
                  // Struts 2 setup
                  bind(StrutsPrepareAndExecuteFilter.class).in(Singleton.class);
                  filter("*.action").through(StrutsPrepareAndExecuteFilter.class);
                  filter("*.jsp").through(StrutsPrepareAndExecuteFilter.class);
       
                  // Our app-specific code
                 
                  bind(Bob.class).to(BobImpl.class);

                  // ATMOSPHERE
                 
                  Map<String, String> params = new HashMap<String, String>();
                  params.put("org.atmosphere.servlet", "org.atmosphere.samples.chat.MeteorChat");
                  params.put("org.atmosphere.useWebSocket", "true");
                  params.put("org.atmosphere.useNative", "true");
                 
                  bind(MeteorChat.class).in(Singleton.class);
                  bind(MeteorServlet.class).in(Singleton.class);
                  serve("/chat/*").with(MeteorServlet.class, params);
                 
                   
              }
            });
      }

    }





2011/5/17 kosmoplan <[hidden email]>
Thank you so much!

--
View this message in context: http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Integration-of-Struts-2-and-Atmosphere-0-7-1-tp6370294p6374445.html
Sent from the Atmosphere users mailling list mailing list archive at Nabble.com.



--
-------------
A+

Sébastien.

Vous pouvez me suivre sur Twitter / You can follow me on Twitter : http://twitter.com/survivant
Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

kosmoplan
Thanks again survivant, but I can't figure out how could I use a Meteor from within a struts 2 action. I've tested the MeteorChat but it's a class that extends directly from HttpServlet and has doGet and doPost methods.

Any idea?

Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

kosmoplan
I think I've not explained well what I want. In one word, I would like to use atmosphere from within a struts 2 action because I want to make use of Struts tags and it won't be possible if the request hasn't passed through the Struts servlet filter.

It is possible to use atmosphere with Tomcat NIO without avoiding the StrutsPrepareAndExecuteFilter?
Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

survivant

I'm using the Meteor in my struts action.   You have to create a Meteor in your actions and suspend it,  put the Meteor in the session.   In another action if you want. You resume it.

On May 19, 2011 8:10 AM, "kosmoplan" <[hidden email]> wrote:
> I think I've not explained well what I want. In one word, I would like to use
> atmosphere from within a struts 2 action because I want to make use of
> Struts tags and it won't be possible if the request hasn't passed through
> the Struts servlet filter.
>
> It is possible to use atmosphere with Tomcat NIO without avoiding the
> StrutsPrepareAndExecuteFilter?
>
> --
> View this message in context: http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Integration-of-Struts-2-and-Atmosphere-0-7-1-tp6370294p6381229.html
> Sent from the Atmosphere users mailling list mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

kosmoplan
Hi again survivant,

According to your post, you are using a Meteor from within a Struts (2?) action. On your web.xml I can see that you have configured the org.atmosphere.servlet with the servlet MeteorChat (from MeteorChat example I suppose).

That servlet is defined like this: public class MeteorChat extends HttpServlet {...} 

On the other hand, my struts 2 action is defined like this:

public class MonitorAction extends ActionSupport implements ServletRequestAware, ServletResponseAware, SessionAware {...},
Is a POJO totally decoupled from a Servlet. When I try to configure my Action on the web.xml, I get a ClassCastException because MonitorAction isn't a javax.servlet.Servlet. My web.xml is like this:

<servlet>
        <servlet-name>MeteorServlet</servlet-name>
        <servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>
        <init-param>
                <param-name>org.atmosphere.servlet</param-name>
                <param-value>...MonitorAction</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
        <servlet-name>MeteorServlet</servlet-name>
        <url-pattern>/monitor/*</url-pattern>
</servlet-mapping>

Please, can you show me the struts 2 action on what you are using a Meteor without trouble?
Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

survivant

I will try to package you a sample for tonight worst case tomorrow.   I have to create a new project for struts2 and atmosphere :)

On May 24, 2011 8:55 AM, "kosmoplan" <[hidden email]> wrote:
> Hi again survivant,
>
> According to your post, you are using a Meteor from within a Struts (2?)
> action. On your web.xml I can see that you have configured the
> org.atmosphere.servlet with the servlet MeteorChat (from MeteorChat example
> I suppose).
>
> That servlet is defined like this: public class MeteorChat extends
> HttpServlet {...}
>
> On the other hand, my struts 2 action is defined like this:
>
> public class MonitorAction extends ActionSupport implements
> ServletRequestAware, ServletResponseAware, SessionAware {...},
> Is a POJO totally decoupled from a Servlet. When I try to configure my
> Action on the web.xml, I get a ClassCastException because MonitorAction
> isn't a javax.servlet.Servlet. My web.xml is like this:
>
> <servlet>
> <servlet-name>MeteorServlet</servlet-name>
> <servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>
> <init-param>
> <param-name>org.atmosphere.servlet</param-name>
> <param-value>...MonitorAction</param-value>
> </init-param>
> <load-on-startup>0</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>MeteorServlet</servlet-name>
> <url-pattern>/monitor/*</url-pattern>
> </servlet-mapping>
>
> Please, can you show me the struts 2 action on what you are using a Meteor
> without trouble?
>
> --
> View this message in context: http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Integration-of-Struts-2-and-Atmosphere-0-7-1-tp6370294p6392497.html
> Sent from the Atmosphere users mailling list mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

survivant
OK, I think we have a problem with Struts2 with Meteor.

I thoough by using Guice I could hack something.. but nope..

JF, we need to check that.  for Struts 1, is easy.  Struts provide a Servlet that we include in web.xml

like that

<servlet>
        <servlet-name>MeteorServlet</servlet-name>
        <servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>
        <init-param>
            <param-name>org.atmosphere.servlet</param-name>
            <param-value>org.apache.struts.action.ActionServlet</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.useWebSocket</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.useNative</param-name>
            <param-value>true</param-value>
        </init-param>

        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>MeteorServlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

but with Struts 2

<filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>



here a sample that doesn't work.... YET.  :)


et j'ai absolument besoin que ca fonctionne pour mon projet :)



2011/5/24 Sebastien Dionne <[hidden email]>

I will try to package you a sample for tonight worst case tomorrow.   I have to create a new project for struts2 and atmosphere :)

On May 24, 2011 8:55 AM, "kosmoplan" <[hidden email]> wrote:
> Hi again survivant,
>
> According to your post, you are using a Meteor from within a Struts (2?)
> action. On your web.xml I can see that you have configured the
> org.atmosphere.servlet with the servlet MeteorChat (from MeteorChat example
> I suppose).
>
> That servlet is defined like this: public class MeteorChat extends
> HttpServlet {...}
>
> On the other hand, my struts 2 action is defined like this:
>
> public class MonitorAction extends ActionSupport implements
> ServletRequestAware, ServletResponseAware, SessionAware {...},
> Is a POJO totally decoupled from a Servlet. When I try to configure my
> Action on the web.xml, I get a ClassCastException because MonitorAction
> isn't a javax.servlet.Servlet. My web.xml is like this:
>
> <servlet>
> <servlet-name>MeteorServlet</servlet-name>
> <servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>
> <init-param>
> <param-name>org.atmosphere.servlet</param-name>
> <param-value>...MonitorAction</param-value>
> </init-param>
> <load-on-startup>0</load-on-startup>
> </servlet>
> <servlet-mapping>
> <servlet-name>MeteorServlet</servlet-name>
> <url-pattern>/monitor/*</url-pattern>
> </servlet-mapping>
>
> Please, can you show me the struts 2 action on what you are using a Meteor
> without trouble?
>
> --
> View this message in context: http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Integration-of-Struts-2-and-Atmosphere-0-7-1-tp6370294p6392497.html
> Sent from the Atmosphere users mailling list mailing list archive at Nabble.com.



--
-------------
A+

Sébastien.

Vous pouvez me suivre sur Twitter / You can follow me on Twitter : http://twitter.com/survivant

AtmoStruts2Blank.7z (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

kosmoplan
Thank you survivant,

If I can help with something let me know it. I'll continue trying to integrate both struts 2 and atmosphere.

Regards,
Rubén
Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

survivant

I got it.

In your pom. XML be sure to not included dependancies that use guice.   In web. XML remove struts2 filter and declared it in the init param of meteorsrtvlet

And be sure to map this servlet to /*

On May 25, 2011 8:20 AM, "kosmoplan" <[hidden email]> wrote:
> Thank you survivant,
>
> If I can help with something let me know it. I'll continue trying to
> integrate both struts 2 and atmosphere.
>
> Regards,
> Rubén
>
> --
> View this message in context: http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Integration-of-Struts-2-and-Atmosphere-0-7-1-tp6370294p6402429.html
> Sent from the Atmosphere users mailling list mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Integration of Struts 2 and Atmosphere 0.7.1

Jeanfrancois Arcand-4
The web.xml should looks like

> <web-app>
>
>       <servlet>
>         <servlet-name>MeteorServlet</servlet-name>
>         <servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>
>               <init-param>
>                   <param-name>org.atmosphere.filter</param-name>
>                   <param-value>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</param-value>
>             </init-param>
>         <init-param>
>             <param-name>org.atmosphere.useWebSocket</param-name>
>             <param-value>true</param-value>
>         </init-param>
>         <init-param>
>             <param-name>org.atmosphere.useNative</param-name>
>             <param-value>true</param-value>
>         </init-param>
>
>         <load-on-startup>0</load-on-startup>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>MeteorServlet</servlet-name>
>         <url-pattern>/*</url-pattern>
>     </servlet-mapping>
>
>   <!-- The Usual Welcome File List -->
>   <welcome-file-list>
>     <welcome-file>index.jsp</welcome-file>
>   </welcome-file-list>
> </web-app>

-- Jeanfrancois


On 11-05-27 3:03 PM, Sebastien Dionne wrote:

> I got it.
>
> In your pom. XML be sure to not included dependancies that use guice.
> In web. XML remove struts2 filter and declared it in the init param of
> meteorsrtvlet
>
> And be sure to map this servlet to /*
>
> On May 25, 2011 8:20 AM, "kosmoplan" <[hidden email]
> <mailto:[hidden email]>> wrote:
>  > Thank you survivant,
>  >
>  > If I can help with something let me know it. I'll continue trying to
>  > integrate both struts 2 and atmosphere.
>  >
>  > Regards,
>  > Rubén
>  >
>  > --
>  > View this message in context:
> http://atmosphere-users-mailling-list.2493822.n2.nabble.com/Integration-of-Struts-2-and-Atmosphere-0-7-1-tp6370294p6402429.html
>  > Sent from the Atmosphere users mailling list mailing list archive at
> Nabble.com.