mirror of https://github.com/apache/activemq.git
Updates to AJAX exampes to make them work on IE 6
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@373776 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ad83b4da4f
commit
c6f73c56d1
|
@ -20,7 +20,9 @@ package org.apache.activemq.web;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -62,7 +64,7 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
|
|
||||||
private long defaultReadTimeout = -1;
|
private long defaultReadTimeout = -1;
|
||||||
|
|
||||||
private long maximumReadTimeout = 10000;
|
private long maximumReadTimeout = 25000;
|
||||||
|
|
||||||
private int maximumMessages = 100;
|
private int maximumMessages = 100;
|
||||||
|
|
||||||
|
@ -99,7 +101,7 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
synchronized (client) {
|
synchronized (client) {
|
||||||
|
|
||||||
// System.err.println("POST client="+client+" session="+request.getSession().getId()+" info="+request.getPathInfo()+" contentType="+request.getContentType());
|
// System.err.println("POST client="+client+" session="+request.getSession().getId()+" info="+request.getPathInfo()+" contentType="+request.getContentType());
|
||||||
|
// dump(request.getParameterMap());
|
||||||
String[] destinations = request.getParameterValues("destination");
|
String[] destinations = request.getParameterValues("destination");
|
||||||
String[] messages = request.getParameterValues("message");
|
String[] messages = request.getParameterValues("message");
|
||||||
String[] types = request.getParameterValues("type");
|
String[] types = request.getParameterValues("type");
|
||||||
|
@ -169,6 +171,10 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
throw new ServletException("JMS problem: " + e, e);
|
throw new ServletException("JMS problem: " + e, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
response.getWriter().print("<ajax-response></ajax-response>");
|
||||||
|
}
|
||||||
// System.err.println("==");
|
// System.err.println("==");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,26 +184,16 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
*/
|
*/
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
|
|
||||||
String end="--";
|
|
||||||
try {
|
try {
|
||||||
WebClient client = getWebClient(request);
|
WebClient client = getWebClient(request);
|
||||||
// System.err.println("GET client="+client+" session="+request.getSession().getId()+" uri="+request.getRequestURI()+" query="+request.getQueryString());
|
// System.err.println("GET client="+client+" session="+request.getSession().getId()+" uri="+request.getRequestURI()+" query="+request.getQueryString());
|
||||||
|
|
||||||
doMessages(client, request, response);
|
doMessages(client, request, response);
|
||||||
}
|
}
|
||||||
catch(RetryRequest r)
|
|
||||||
{
|
|
||||||
end="??";
|
|
||||||
throw r;
|
|
||||||
}
|
|
||||||
catch (JMSException e) {
|
catch (JMSException e) {
|
||||||
throw new ServletException("JMS problem: " + e, e);
|
throw new ServletException("JMS problem: " + e, e);
|
||||||
}
|
}
|
||||||
finally
|
// System.err.println("--");
|
||||||
{
|
|
||||||
// System.err.println(end);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -307,55 +303,6 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Subscribe or unsubscribe to a destination. The listen request parameter
|
|
||||||
* is used to indicate subscribe (tree) or unsubscribe (false).
|
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
* @param response
|
|
||||||
* @throws ServletException
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
protected void doSubscription(WebClient client, Destination destination, HttpServletRequest request, HttpServletResponse response) throws JMSException, ServletException, IOException {
|
|
||||||
|
|
||||||
// System.err.println("doSubscription destination="+destination);
|
|
||||||
String s = request.getParameter("listen");
|
|
||||||
if (s == null || s.length() == 0) {
|
|
||||||
log.warn("No listen paramenter for subscribe");
|
|
||||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No listen parameter");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
boolean listen = Boolean.valueOf(s).booleanValue();
|
|
||||||
|
|
||||||
String id = request.getParameter("id");
|
|
||||||
if (listen && (id == null || id.length() == 0)) {
|
|
||||||
log.warn("No id paramenter for subscribe");
|
|
||||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No id parameter");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Listener listener = getListener(request);
|
|
||||||
Map consumerIdMap = getConsumerIdMap(request);
|
|
||||||
|
|
||||||
synchronized (client) {
|
|
||||||
MessageAvailableConsumer consumer = (MessageAvailableConsumer) client.getConsumer(destination);
|
|
||||||
|
|
||||||
if (listen) {
|
|
||||||
consumer.setAvailableListener(listener);
|
|
||||||
consumerIdMap.put(consumer, id);
|
|
||||||
// System.err.println("Subscribed: "+consumer+" to
|
|
||||||
// "+destination);
|
|
||||||
} else {
|
|
||||||
// TODO should we destroy consumer on unsubscribe?
|
|
||||||
consumer.setAvailableListener(null);
|
|
||||||
consumerIdMap.remove(consumer);
|
|
||||||
// System.err.println("Unsubscribed: "+consumer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void writeMessageResponse(PrintWriter writer, Message message) throws JMSException, IOException {
|
protected void writeMessageResponse(PrintWriter writer, Message message) throws JMSException, IOException {
|
||||||
if (message instanceof TextMessage) {
|
if (message instanceof TextMessage) {
|
||||||
TextMessage textMsg = (TextMessage) message;
|
TextMessage textMsg = (TextMessage) message;
|
||||||
|
@ -441,4 +388,15 @@ public class MessageListenerServlet extends MessageServletSupport {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void dump(Map map)
|
||||||
|
{
|
||||||
|
Iterator iter=map.entrySet().iterator();
|
||||||
|
while(iter.hasNext())
|
||||||
|
{
|
||||||
|
Map.Entry entry=(Map.Entry)iter.next();
|
||||||
|
String k=(String)entry.getKey();
|
||||||
|
String[] v=(String[])entry.getValue();
|
||||||
|
System.err.println(k+":"+(v==null?"[]":Arrays.asList(v).toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2005-2006 The Apache Software Foundation
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.activemq.web;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.FilterConfig;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.ServletResponse;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ */
|
||||||
|
/** SessionFilter.
|
||||||
|
* Simple filter to ensure that all clients have a session.
|
||||||
|
* Prevents problems with AJAX requests.
|
||||||
|
*/
|
||||||
|
public class SessionFilter implements Filter{
|
||||||
|
|
||||||
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||||
|
HttpSession session=((HttpServletRequest)request).getSession(true);
|
||||||
|
// if (session.isNew())
|
||||||
|
// System.err.println("NEW SESSION "+session.getId()+" for "+((HttpServletRequest)request).getRequestURI());
|
||||||
|
chain.doFilter(request,response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroy() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -70,4 +70,13 @@
|
||||||
<url-pattern>/portfolioPublish</url-pattern>
|
<url-pattern>/portfolioPublish</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
|
<filter>
|
||||||
|
<filter-name>session</filter-name>
|
||||||
|
<filter-class>org.apache.activemq.web.SessionFilter</filter-class>
|
||||||
|
</filter>
|
||||||
|
|
||||||
|
<filter-mapping>
|
||||||
|
<filter-name>session</filter-name>
|
||||||
|
<url-pattern>/*</url-pattern>
|
||||||
|
</filter-mapping>
|
||||||
</web-app>
|
</web-app>
|
||||||
|
|
|
@ -58,9 +58,9 @@ var room =
|
||||||
$('join').className='';
|
$('join').className='';
|
||||||
$('joined').className='hidden';
|
$('joined').className='hidden';
|
||||||
$('username').focus();
|
$('username').focus();
|
||||||
room._username=null;
|
|
||||||
Behaviour.apply();
|
Behaviour.apply();
|
||||||
amq.sendMessage(chatMembership, "<message type='leave' from='" + room._username + "'/>");
|
amq.sendMessage(chatMembership, "<message type='leave' from='" + room._username + "'/>");
|
||||||
|
room._username=null;
|
||||||
},
|
},
|
||||||
|
|
||||||
chat: function()
|
chat: function()
|
||||||
|
|
|
@ -14,8 +14,6 @@ normal HTTP POST and to receive messages from a destination using a
|
||||||
HTTP GET.
|
HTTP GET.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p><b><font color="red">Currently only working with firefox!</font></b></p>
|
|
||||||
|
|
||||||
<h2>Market data example</h2>
|
<h2>Market data example</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -119,10 +119,13 @@ var amq =
|
||||||
{
|
{
|
||||||
new Ajax.Request('/amq', { method: 'post', postBody: 'destination='+destination+'&message='+message+'&type='+type});
|
new Ajax.Request('/amq', { method: 'post', postBody: 'destination='+destination+'&message='+message+'&type='+type});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_startPolling : function()
|
||||||
|
{
|
||||||
|
new Ajax.Request('/amq', { method: 'get', parameters: 'timeout=0', onSuccess: amq._pollHandler });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Behaviour.addLoadEvent(function(){new Ajax.Request('/amq', { method: 'get', parameters: 'timeout=0', onSuccess: amq._pollHandler });});
|
Behaviour.addLoadEvent(amq._startPolling);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Behaviour v1.0 by Ben Nolan, June 2005. Based largely on the work
|
Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work
|
||||||
of Simon Willison (see comments by Simon below).
|
of Simon Willison (see comments by Simon below).
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
License:
|
License:
|
||||||
|
|
||||||
My stuff is BSD licensed. Not sure about Simon's.
|
This file is entirely BSD licensed.
|
||||||
|
|
||||||
More information:
|
More information:
|
||||||
|
|
||||||
|
|
|
@ -40,12 +40,8 @@ function portfolioPoll(first)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function portfolioInit()
|
amq.addPollHandler(portfolioPoll);
|
||||||
{
|
|
||||||
amq.addPollHandler(portfolioPoll);
|
|
||||||
}
|
|
||||||
|
|
||||||
Behaviour.addLoadEvent(portfolioInit);
|
|
||||||
|
|
||||||
/// -----------------
|
/// -----------------
|
||||||
// Original code by Joe Walnes
|
// Original code by Joe Walnes
|
||||||
|
|
Loading…
Reference in New Issue