Ajax and Tomcat 6 - based on web-demo with a non embedded broker

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Ajax and Tomcat 6 - based on web-demo with a non embedded broker

patrice
Hi ,

I use activeMQ 5.4.2

I am trying to implement a simple web demo to show log message from different programs using ajax into a web page.

To do that, I use the basic broker, (tcp://localhost:61616).
The producer is a simple program with log4j configured to log on a jms appender, using topic (topic name is logTopic).
If I run the example consumer with the command "ant consumer -Dtopic=true -Dsubject=logTopic", I am able to get the log on the consumer side.

so now, the next step for me is to have the consumer into a WebApp which can "provide" the messages to the client into a webpage using ajax.

So I looked at the ajax page : http://activemq.apache.org/ajax.html and configure my web.xml as it is explain. The broker was not found, but I solved it by using context-param in my web.xml

my web.xml looks like that :
<web-app>
        <display-name>Archetype Created Web Application</display-name>

        <context-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>WEB-INF/spring.xml</param-value>
        </context-param>

       
        <listener>
                <listener-class>net.me.context.MyAppContextLoaderListener</listener-class>
        </listener>
        <context-param>
                <param-name>org.apache.activemq.brokerURL</param-name>
                <param-value>tcp://localhost:61616</param-value>
                <description>The URL of the Message Broker to connect to</description>
        </context-param>
        <context-param>
                <param-name>org.apache.activemq.embeddedBroker</param-name>
                <param-value>false</param-value>
                <description>Whether we should include an embedded broker or not</description>
        </context-param>

       
        <servlet>
                <servlet-name>AjaxServlet</servlet-name>
                <servlet-class>org.apache.activemq.web.AjaxServlet</servlet-class>
        </servlet>
        <servlet-mapping>
                <servlet-name>AjaxServlet</servlet-name>
                <url-pattern>/amq/*</url-pattern>
        </servlet-mapping>
</web-app>

The web page code is very simple, as the market portfolio example that comes with activeMQ distrib :

<html>
<head>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script><script type="text/javascript" src="js/amq_jquery_adapter.js"></script><script type="text/javascript" src="js/amq.js"></script><script type="text/javascript"> var amq = org.activemq.Amq; amq.init({ uri: 'amq', logging: true, timeout: 30, clientId:(new Date()).getTime().toString() }); </script><script type="text/javascript"> var myHandler = { rcvMessage: function(message) { amq.adapter.log('receive message' + message); var txt = document.createTextNode(message); document.getElementById('list').appendChild(txt); } }; amq.addListener('testID','topic://logTopic',myHandler.rcvMessage); </script></head>
<body>

Test !

<div id="list"></div>
</body>
</html>


but, it does not work. I traced request, there are send from the web page, but nothing is updated,...
looking at log file I can see the following error

java.lang.IllegalStateException: !(Jetty || Servlet 3.0 || ContinuationFilter)
    org.eclipse.jetty.continuation.ContinuationSupport.getContinuation(ContinuationSupport.java:145)
    org.apache.activemq.web.MessageListenerServlet.doMessages(MessageListenerServlet.java:301)
    org.apache.activemq.web.MessageListenerServlet.doGet(MessageListenerServlet.java:247)
    org.apache.activemq.web.AjaxServlet.doGet(AjaxServlet.java:47)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


I searched for a long time without find any solution to solve this problem.
So do you know how to configure Tomcat to make this sample works ?

Feel free to ask for more detail if needed.

Regards,
Pat
Reply | Threaded
Open this post in threaded view
|

Re: Ajax and Tomcat 6 - based on web-demo with a non embedded broker

Alex Dean-2

On Feb 9, 2011, at 11:00 AM, patrice wrote:

> but, it does not work. I traced request, there are send from the web page,
> but nothing is updated,...
> looking at log file I can see the following error
>
> java.lang.IllegalStateException: !(Jetty || Servlet 3.0 ||
> ContinuationFilter)
>
> org.eclipse.jetty.continuation.ContinuationSupport.getContinuation(ContinuationSupport.java:145)
>
> org.apache.activemq.web.MessageListenerServlet.doMessages(MessageListenerServlet.java:301)
>
> org.apache.activemq.web.MessageListenerServlet.doGet(MessageListenerServlet.java:247)
>    org.apache.activemq.web.AjaxServlet.doGet(AjaxServlet.java:47)
>    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
>    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Try a 5.5 snapshot instead of 5.4.2, and see if that resolves the issue.  We made some changes recently to address a similar problem.

alex
Reply | Threaded
Open this post in threaded view
|

Re: Ajax and Tomcat 6 - based on web-demo with a non embedded broker

patrice
Hi Alex,

Sorry to go back so late.

A quick message to let you informed

I changed my pom.xml as follow to use 5.5 snapshot

<dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-web</artifactId>
        <version>5.5-SNAPSHOT</version>
        <scope>compile</scope>
</dependency>


So now it works .... but only a certain duration ! (around 40 sec)

any idea ?

I'll continue to investigate
Reply | Threaded
Open this post in threaded view
|

Re: Ajax and Tomcat 6 - based on web-demo with a non embedded broker

patrice
I mean, the web client is able to get message for approximatively 40sec, after that, response send back by the
servlet is always the same as before

Pat
Reply | Threaded
Open this post in threaded view
|

Re: Ajax and Tomcat 6 - based on web-demo with a non embedded broker

jasonliao
This post has NOT been accepted by the mailing list yet.
In reply to this post by patrice
hi,

    could you provide you source code? i don't understand the uri:'amq'? how do you implement the action?

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

Re: Ajax and Tomcat 6 - based on web-demo with a non embedded broker

jaskaran
In reply to this post by Alex Dean-2
Hi ,

I am also getting the same error on starting Tomcat:

SEVERE: Servlet.service() for servlet AjaxServlet threw exception
java.lang.IllegalStateException: !(Jetty || Servlet 3.0 || ContinuationFilter)
        at org.eclipse.jetty.continuation.ContinuationSupport.getContinuation(ContinuationSupport.java:145)

I am using ActiveMQ 5.5.

Please help
Jaskaran
Reply | Threaded
Open this post in threaded view
|

Re: Ajax and Tomcat 6 - based on web-demo with a non embedded broker

dejanb
Hi,

Ajax feature is implemented using Jetty continuations so it's not possible
to use it in plain Tomcat.

Regards
--
Dejan Bosanac - http://twitter.com/dejanb
-----------------
The experts in open source integration and messaging - http://fusesource.com
ActiveMQ in Action - http://www.manning.com/snyder/
Blog - http://www.nighttale.net


On Sat, Jul 16, 2011 at 1:46 PM, jaskaran <[hidden email]> wrote:

> Hi ,
>
> I am also getting the same error on starting Tomcat:
>
> SEVERE: Servlet.service() for servlet AjaxServlet threw exception
> java.lang.IllegalStateException: !(Jetty || Servlet 3.0 ||
> ContinuationFilter)
>        at
>
> org.eclipse.jetty.continuation.ContinuationSupport.getContinuation(ContinuationSupport.java:145)
>
> I am using ActiveMQ 5.5.
>
> Please help
> Jaskaran
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Ajax-and-Tomcat-6-based-on-web-demo-with-a-non-embedded-broker-tp3297683p3671721.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Ajax and Tomcat 6 - based on web-demo with a non embedded broker

jaskaran
Hi Dejan

Thanks alot.
I will deploy on Jetty

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

Re: Ajax and Tomcat 6 - based on web-demo with a non embedded broker

liny
Hi,

You can add below into your application web.xml:
    <filter>
      <filter-name>session</filter-name>
      <filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class>
    </filter>

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

Don't forget put jetty jar file (mine is jetty-all-server-7.1.6.v20100715.jar) into lib directory.
Reply | Threaded
Open this post in threaded view
|

Re: Ajax and Tomcat 6 - based on web-demo with a non embedded broker

jaskaran
Hi Liny,

Thanks alot for replying. If i add the settings that you mentioned. Then will i be able to deploy the servlet on Tomcat.
I am trying to avoid setting up  a jetty server.

Thanks alot