You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Naby <us...@abwesend.de> on 2006/05/04 11:12:12 UTC

Ajax post simulation with Java

Hi.

For our Ajax listeners we need a publisher written in Java. Our first
implemetation is posting a message to the Listener servlet but the message
doesn't reach the Ajax listener. The result code is 200.
A posting from a browser is working well.

Does anyone know the problem?

HttpClient httpclient = new HttpClient();
httpclient.setConnectionTimeout(10000);
                            
PostMethod httppost = new PostMethod(urlStr);
httppost.setRequestHeader("X-Requested-With", "XMLHttpRequest");
httppost.setRequestHeader("X-Prototype-Version", "1.4.0");
httppost.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
httppost.addParameter("destination", "topic://" + channelID);
httppost.addParameter("message", URLEncoder.encode("<message
type='chat'>Hallo</message>"));
httppost.addParameter("type", "send");
                            
httpclient.startSession(urlStr, 80);
result = httpclient.executeMethod(httppost);
httppost.releaseConnection();
--
View this message in context: http://www.nabble.com/Ajax-post-simulation-with-Java-t1555597.html#a4225552
Sent from the ActiveMQ - User forum at Nabble.com.


Re: Ajax post simulation with Java

Posted by Naby <us...@abwesend.de>.
> It could just be going to a strange queue/topic name or something.
> (enabling debug logging might help too)

The solution was quite different.
The request is urlencoded but it's not a good idea to extra encode the
message. The encoding seems to be internal.

Thanks again for your help James.



--
View this message in context: http://www.nabble.com/Ajax-post-simulation-with-Java-t1555597.html#a4271824
Sent from the ActiveMQ - User forum at Nabble.com.


Re: Ajax post simulation with Java

Posted by James Strachan <ja...@gmail.com>.
It could just be going to a strange queue/topic name or something. (enabling
debug logging might help too)

On 5/4/06, Naby <us...@abwesend.de> wrote:
>
>
> > You tried debugging it? Or looking at the broker in JMX to see if the
> > message is being sent but on a different topic/queue?
> > http://activemq.org/JMX
>
> I have debugged the Listener servlet.
> The post request has been processed and the message seemed to have been
> delivered to the broker.
> I haven't looked with JMX yet. I will do it asap.
> --
> View this message in context:
> http://www.nabble.com/Ajax-post-simulation-with-Java-t1555597.html#a4231874
> Sent from the ActiveMQ - User forum at Nabble.com.
>
>


--

James
-------
http://radio.weblogs.com/0112098/

Re: Ajax post simulation with Java

Posted by Naby <us...@abwesend.de>.
> You tried debugging it? Or looking at the broker in JMX to see if the
> message is being sent but on a different topic/queue?
> http://activemq.org/JMX

I have debugged the Listener servlet.
The post request has been processed and the message seemed to have been
delivered to the broker.
I haven't looked with JMX yet. I will do it asap.
--
View this message in context: http://www.nabble.com/Ajax-post-simulation-with-Java-t1555597.html#a4231874
Sent from the ActiveMQ - User forum at Nabble.com.


Re: Ajax post simulation with Java

Posted by James Strachan <ja...@gmail.com>.
You tried debugging it? Or looking at the broker in JMX to see if the
message is being sent but on a different topic/queue?
http://activemq.org/JMX

On 5/4/06, Naby <us...@abwesend.de> wrote:
>
>
> > What is urlStr
>
> String urlStr = "http://localhost/ACTIVEMQ/amq";
>
> > and what is your web.xml?
>
> It's the original one with vm://localhost. The servlets running in Tomcat
> with the context /ACTIVEMQ.
>
> > BTW have you tried out the
> > activemq-web-demo web application? You can use your browse to post/get
> > messages to test out the servlets.
>
> Yes, i did. The servlets are working. I tested it with a dummy web page
> which listen and send messages to a topic. Only the java publisher doesn't
> work :-(
>
>
> --
> View this message in context:
> http://www.nabble.com/Ajax-post-simulation-with-Java-t1555597.html#a4226664
> Sent from the ActiveMQ - User forum at Nabble.com.
>
>


--

James
-------
http://radio.weblogs.com/0112098/

Re: Ajax post simulation with Java

Posted by Naby <us...@abwesend.de>.
> What is urlStr 

String urlStr = "http://localhost/ACTIVEMQ/amq";

> and what is your web.xml? 

It's the original one with vm://localhost. The servlets running in Tomcat
with the context /ACTIVEMQ.

> BTW have you tried out the
> activemq-web-demo web application? You can use your browse to post/get
> messages to test out the servlets.

Yes, i did. The servlets are working. I tested it with a dummy web page
which listen and send messages to a topic. Only the java publisher doesn't
work :-(


--
View this message in context: http://www.nabble.com/Ajax-post-simulation-with-Java-t1555597.html#a4226664
Sent from the ActiveMQ - User forum at Nabble.com.


Re: Ajax post simulation with Java

Posted by James Strachan <ja...@gmail.com>.
What is urlStr and what is your web.xml? BTW have you tried out the
activemq-web-demo web application? You can use your browse to post/get
messages to test out the servlets.

On 5/4/06, Naby <us...@abwesend.de> wrote:
>
>
> Hi.
>
> For our Ajax listeners we need a publisher written in Java. Our first
> implemetation is posting a message to the Listener servlet but the message
> doesn't reach the Ajax listener. The result code is 200.
> A posting from a browser is working well.
>
> Does anyone know the problem?
>
> HttpClient httpclient = new HttpClient();
> httpclient.setConnectionTimeout(10000);
>
> PostMethod httppost = new PostMethod(urlStr);
> httppost.setRequestHeader("X-Requested-With", "XMLHttpRequest");
> httppost.setRequestHeader("X-Prototype-Version", "1.4.0");
> httppost.setRequestHeader("Content-Type",
> "application/x-www-form-urlencoded");
> httppost.addParameter("destination", "topic://" + channelID);
> httppost.addParameter("message", URLEncoder.encode("<message
> type='chat'>Hallo</message>"));
> httppost.addParameter("type", "send");
>
> httpclient.startSession(urlStr, 80);
> result = httpclient.executeMethod(httppost);
> httppost.releaseConnection();
> --
> View this message in context:
> http://www.nabble.com/Ajax-post-simulation-with-Java-t1555597.html#a4225552
> Sent from the ActiveMQ - User forum at Nabble.com.
>
>


--

James
-------
http://radio.weblogs.com/0112098/