JBossWeb SVN: r828 - trunk/java/org/apache/tomcat/bayeux.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-10-29 13:29:16 -0400 (Wed, 29 Oct 2008)
New Revision: 828
Modified:
trunk/java/org/apache/tomcat/bayeux/BayeuxServlet.java
trunk/java/org/apache/tomcat/bayeux/ClientImpl.java
trunk/java/org/apache/tomcat/bayeux/RequestBase.java
Log:
- Cleanup.
Modified: trunk/java/org/apache/tomcat/bayeux/BayeuxServlet.java
===================================================================
--- trunk/java/org/apache/tomcat/bayeux/BayeuxServlet.java 2008-10-29 15:34:21 UTC (rev 827)
+++ trunk/java/org/apache/tomcat/bayeux/BayeuxServlet.java 2008-10-29 17:29:16 UTC (rev 828)
@@ -18,17 +18,18 @@
import java.io.IOException;
-import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import org.apache.cometd.bayeux.Bayeux;
import org.apache.tomcat.util.json.JSONArray;
import org.apache.tomcat.util.json.JSONException;
import org.apache.tomcat.util.json.JSONObject;
+import org.jboss.logging.Logger;
import org.jboss.servlet.http.HttpEvent;
import org.jboss.servlet.http.HttpEventServlet;
@@ -38,26 +39,31 @@
* @author Guy Molinari
* @version 1.0
*/
-public class BayeuxServlet implements HttpEventServlet {
+public class BayeuxServlet extends HttpServlet implements HttpEventServlet {
+ private static Logger log = Logger.getLogger(BayeuxServlet.class);
+
+
/**
- * The debugging detail level for this servlet.
+ * The timeout.
*/
- protected int debug = 0;
+ protected int timeout = 0;
/**
+ * The reconnect interval.
+ */
+ protected int reconnectInterval = 0;
+
+
+ /**
* Attribute to hold the TomcatBayeux object in the servlet context
*/
public static final String TOMCAT_BAYEUX_ATTR = Bayeux.DOJOX_COMETD_BAYEUX;
-
+
+
/**
- * Servlet config - for future use
- */
- protected ServletConfig servletConfig;
-
- /**
* Reference to the global TomcatBayeux object
*/
protected TomcatBayeux tb;
@@ -67,10 +73,9 @@
* TomcatBayeux object and terminate any outstanding events.
*/
public void destroy() {
- servletConfig = null;
- //to do, close all outstanding comet events
+ // FIXME, close all outstanding comet events
//tb.destroy();
- tb = null;//TO DO, close everything down
+ tb = null;//FIXME, close everything down
}
@@ -81,53 +86,37 @@
* @return int - the timeout for a connection in milliseconds
*/
protected int getTimeout() {
- String timeoutS = servletConfig.getInitParameter("timeout");
- int timeout = 120*1000; //2 min
- try {
- timeout = Integer.parseInt(timeoutS);
- }catch (NumberFormatException nfe) {
- //ignore, we have a default value
- }
return timeout;
}
protected int getReconnectInterval() {
- String rs = servletConfig.getInitParameter("reconnectInterval");
- int rct = 1000; // 1 seconds
- try {
- rct = Integer.parseInt(rs);
- }catch (NumberFormatException nfe) {
- //ignore, we have a default value
- }
- return rct;
+ return reconnectInterval;
}
public void event(HttpEvent cometEvent) throws IOException, ServletException {
HttpEvent.EventType type = cometEvent.getType();
- if (debug > 0) {
- getServletConfig().getServletContext().log("["+Thread.currentThread().getName()+"] Received Comet Event type="+type);
+ if (log.isTraceEnabled()) {
+ log.trace("["+Thread.currentThread().getName()+"] Received Comet Event type="+type);
}
- synchronized (cometEvent) {
- switch (type) {
- case BEGIN:
- cometEvent.setTimeout(getTimeout());
- break;
- case READ:
- checkBayeux(cometEvent);
- break;
- case EOF:
- case EVENT:
- case WRITE:
- break;
- case ERROR:
- case END:
- case TIMEOUT:
- tb.remove(cometEvent);
- cometEvent.close();
- break;
- }
- }//synchronized
+ switch (type) {
+ case BEGIN:
+ cometEvent.setTimeout(getTimeout());
+ break;
+ case READ:
+ checkBayeux(cometEvent);
+ break;
+ case EOF:
+ case EVENT:
+ case WRITE:
+ break;
+ case ERROR:
+ case END:
+ case TIMEOUT:
+ tb.remove(cometEvent);
+ cometEvent.close();
+ break;
+ }
}//event
/**
@@ -137,30 +126,37 @@
* @throws IOException
* @throws UnsupportedOperationException
*/
- protected void checkBayeux(HttpEvent cometEvent) throws IOException, UnsupportedOperationException {
- //we actually have data.
- //data can be text/json or
- if (Bayeux.JSON_CONTENT_TYPE.equals(cometEvent.getHttpServletRequest().getContentType())) {
- //read and decode the bytes according to content length
- getServletConfig().getServletContext().log("["+Thread.currentThread().getName()+"] JSON encoding not supported, will throw an exception and abort the request.");
- int contentlength = cometEvent.getHttpServletRequest().getContentLength();
- throw new UnsupportedOperationException("Decoding "+Bayeux.JSON_CONTENT_TYPE+" not yet implemented.");
- } else { //GET method or application/x-www-form-urlencoded
- String message = cometEvent.getHttpServletRequest().getParameter(Bayeux.MESSAGE_PARAMETER);
- if (debug > 0) {
- getServletConfig().getServletContext().log("["+Thread.currentThread().getName()+"] Received JSON message:"+message);
+ protected void checkBayeux(HttpEvent cometEvent) throws IOException,
+ UnsupportedOperationException {
+ // we actually have data.
+ // data can be text/json or
+ if (Bayeux.JSON_CONTENT_TYPE.equals(cometEvent.getHttpServletRequest()
+ .getContentType())) {
+ // read and decode the bytes according to content length
+ int contentlength = cometEvent.getHttpServletRequest()
+ .getContentLength();
+ throw new UnsupportedOperationException("Decoding "
+ + Bayeux.JSON_CONTENT_TYPE + " not yet implemented.");
+ } else { // GET method or application/x-www-form-urlencoded
+ String message = cometEvent.getHttpServletRequest().getParameter(
+ Bayeux.MESSAGE_PARAMETER);
+ if (log.isTraceEnabled()) {
+ log.trace("[" + Thread.currentThread().getName()
+ + "] Received JSON message:" + message);
}
try {
int action = handleBayeux(message, cometEvent);
- if (debug > 0) {
- getServletConfig().getServletContext().log("["+Thread.currentThread().getName()+"] Bayeux handling complete, action result="+action);
+ if (log.isTraceEnabled()) {
+ log.trace("[" + Thread.currentThread().getName()
+ + "] Bayeux handling complete, action result="
+ + action);
}
- if (action<=0) {
+ if (action <= 0) {
cometEvent.close();
}
- }catch (Exception x) {
+ } catch (Exception e) {
tb.remove(cometEvent);
- getServletConfig().getServletContext().log(x, "Exception in check");
+ log.warn("Exception in check", e);
cometEvent.close();
}
}
@@ -176,63 +172,61 @@
for (int i = 0; i < jsArray.length(); i++) {
JSONObject msg = jsArray.getJSONObject(i);
- if (debug > 0) {
- getServletConfig().getServletContext().log("["+Thread.currentThread().getName()+"] Processing bayeux message:"+msg);
+ if (log.isTraceEnabled()) {
+ log.trace("["+Thread.currentThread().getName()+"] Processing bayeux message:"+msg);
}
request = RequestFactory.getRequest(tb,event,msg);
- if (debug > 0) {
- getServletConfig().getServletContext().log("["+Thread.currentThread().getName()+"] Processing bayeux message using request:"+request);
+ if (log.isTraceEnabled()) {
+ log.trace("["+Thread.currentThread().getName()+"] Processing bayeux message using request:"+request);
}
result = request.process(result);
- if (debug > 0) {
- getServletConfig().getServletContext().log("["+Thread.currentThread().getName()+"] Processing bayeux message result:"+result);
+ if (log.isTraceEnabled()) {
+ log.trace("["+Thread.currentThread().getName()+"] Processing bayeux message result:"+result);
}
}
if (result>0 && request!=null) {
event.getHttpServletRequest().setAttribute(BayeuxRequest.LAST_REQ_ATTR, request);
ClientImpl ci = (ClientImpl)tb.getClient(((RequestBase)request).getClientId());
ci.addCometEvent(event);
- if (debug > 0) {
- getServletConfig().getServletContext().log("["+Thread.currentThread().getName()+"] Done bayeux message added to request attribute");
+ if (log.isTraceEnabled()) {
+ log.trace("["+Thread.currentThread().getName()+"] Done bayeux message added to request attribute");
}
} else if (result == 0 && request!=null) {
RequestBase.deliver(event,(ClientImpl)tb.getClient(((RequestBase)request).getClientId()));
- if (debug > 0) {
- getServletConfig().getServletContext().log("["+Thread.currentThread().getName()+"] Done bayeux message, delivered to client");
+ if (log.isTraceEnabled()) {
+ log.trace("["+Thread.currentThread().getName()+"] Done bayeux message, delivered to client");
}
}
- }catch (JSONException x) {
- getServletConfig().getServletContext().log(x, "Error");//to do impl error handling
+ }catch (JSONException e) {
+ log.warn("Error", e);// FIXME impl error handling
result = -1;
- }catch (BayeuxException x) {
- getServletConfig().getServletContext().log(x, "Error"); //to do impl error handling
+ }catch (BayeuxException e) {
+ log.warn("Error", e); // FIXME impl error handling
result = -1;
}
return result;
}
- public ServletConfig getServletConfig() {
- return servletConfig;
- }
-
public String getServletInfo() {
return "Tomcat/BayeuxServlet/1.0";
}
- public void init(ServletConfig servletConfig) throws ServletException {
+ public void init() throws ServletException {
- this.servletConfig = servletConfig;
- ServletContext ctx = servletConfig.getServletContext();
+ if (getServletConfig().getInitParameter("timeout") != null) {
+ timeout = Integer.parseInt(getServletConfig().getInitParameter("timeout"));
+ }
+ if (getServletConfig().getInitParameter("reconnectInterval") != null) {
+ reconnectInterval = Integer.parseInt(getServletConfig().getInitParameter("reconnectInterval"));
+ }
+
+ ServletContext ctx = getServletConfig().getServletContext();
if (ctx.getAttribute(TOMCAT_BAYEUX_ATTR)==null)
ctx.setAttribute(TOMCAT_BAYEUX_ATTR,new TomcatBayeux());
this.tb = (TomcatBayeux)ctx.getAttribute(TOMCAT_BAYEUX_ATTR);
tb.setReconnectInterval(getReconnectInterval());
- if (servletConfig.getInitParameter("debug") != null)
- debug = Integer.parseInt(servletConfig.getInitParameter("debug"));
- if (debug > 0) {
- servletConfig.getServletContext().log("Init " + getServletInfo());
- }
+
}
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
Modified: trunk/java/org/apache/tomcat/bayeux/ClientImpl.java
===================================================================
--- trunk/java/org/apache/tomcat/bayeux/ClientImpl.java 2008-10-29 15:34:21 UTC (rev 827)
+++ trunk/java/org/apache/tomcat/bayeux/ClientImpl.java 2008-10-29 17:29:16 UTC (rev 828)
@@ -30,10 +30,13 @@
import org.apache.cometd.bayeux.Listener;
import org.apache.cometd.bayeux.Message;
import org.apache.tomcat.util.json.JSONObject;
+import org.jboss.logging.Logger;
import org.jboss.servlet.http.HttpEvent;
public class ClientImpl implements Client {
+ private static Logger log = Logger.getLogger(ClientImpl.class);
+
public static final int SUPPORT_CALLBACK_POLL = 0x1;
public static final int SUPPORT_LONG_POLL = 0x2;
@@ -139,9 +142,9 @@
map.put(Bayeux.CHANNEL_FIELD,message.getChannel().getId());
map.put(Bayeux.DATA_FIELD,message);
JSONObject json = new JSONObject(map);
- /*if (log.isDebugEnabled()) {
- log.debug("Message instantly delivered to remote client["+this+"] message:"+json);
- }*/
+ if (log.isTraceEnabled()) {
+ log.trace("Message instantly delivered to remote client["+this+"] message:"+json);
+ }
rq.addToDeliveryQueue(this, json);
//deliver the batch
if (i==(msgs.length-1)) {
@@ -150,18 +153,17 @@
removeCometEvent(event); //and delivered instantly
}
delivered = true;
- } catch (Exception x) {
+ } catch (Exception e) {
// TODO: fix
- x.printStackTrace();
- //log.error(x);
+ log.warn("Exception", e);
}
}
}
}
if (!delivered) {
- /*if (log.isDebugEnabled()) {
- log.debug("Message added to queue for remote client["+this+"] message:"+message);
- }*/
+ if (log.isTraceEnabled()) {
+ log.trace("Message added to queue for remote client["+this+"] message:"+message);
+ }
//queue the message for the next round
messages.add(message);
}
Modified: trunk/java/org/apache/tomcat/bayeux/RequestBase.java
===================================================================
--- trunk/java/org/apache/tomcat/bayeux/RequestBase.java 2008-10-29 15:34:21 UTC (rev 827)
+++ trunk/java/org/apache/tomcat/bayeux/RequestBase.java 2008-10-29 17:29:16 UTC (rev 828)
@@ -34,6 +34,7 @@
import org.apache.tomcat.util.json.JSONArray;
import org.apache.tomcat.util.json.JSONException;
import org.apache.tomcat.util.json.JSONObject;
+import org.jboss.logging.Logger;
import org.jboss.servlet.http.HttpEvent;
/**
@@ -46,6 +47,8 @@
*/
public abstract class RequestBase implements BayeuxRequest {
+ private static Logger log = Logger.getLogger(RequestBase.class);
+
protected static final SimpleDateFormat timestampFmt =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
static {
@@ -154,9 +157,9 @@
JSONArray jarray = getJSONArray(event,true);
if ( jarray == null ) throw new BayeuxException("No message to send!");
String jsonstring = jarray.toString();
- /*if (log.isDebugEnabled()) {
- log.debug("["+Thread.currentThread().getName()+"] Delivering message to[" + to + "] message:" + jsonstring);
- }*/
+ if (log.isTraceEnabled()) {
+ log.trace("["+Thread.currentThread().getName()+"] Delivering message to[" + to + "] message:" + jsonstring);
+ }
if (to!=null) {
if (to.useJsonFiltered()) {
@@ -193,7 +196,6 @@
out.flush();
event.getHttpServletResponse().flushBuffer();
-
}
protected static JSONArray getJSONArray(HttpEvent event, boolean nullok) {
16 years, 2 months
JBossWeb SVN: r827 - in trunk: java/org/apache/coyote/http11 and 1 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-10-29 11:34:21 -0400 (Wed, 29 Oct 2008)
New Revision: 827
Modified:
trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
trunk/java/org/apache/catalina/connector/InputBuffer.java
trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java
trunk/webapps/docs/changelog.xml
Log:
- Refactor processing of a READ event which could follow a BEGIN into the protocol handler.
Modified: trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
===================================================================
--- trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2008-10-29 15:31:36 UTC (rev 826)
+++ trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2008-10-29 15:34:21 UTC (rev 827)
@@ -151,7 +151,8 @@
request.setComet(false);
close = true;
}
- if (status == SocketStatus.OPEN_READ) {
+ switch (status) {
+ case OPEN_READ:
if (!request.isComet()) {
// The event has been closed asynchronously, so call end instead of
// read to cleanup the pipeline
@@ -181,7 +182,8 @@
return true;
}
}
- } else if (status == SocketStatus.OPEN_WRITE) {
+ break;
+ case OPEN_WRITE:
if (!request.isComet()) {
// The event has been closed asynchronously, so call end instead of
// read to cleanup the pipeline
@@ -190,7 +192,8 @@
} else {
request.getEvent().setType(HttpEvent.EventType.WRITE);
}
- } else if (status == SocketStatus.OPEN_CALLBACK) {
+ break;
+ case OPEN_CALLBACK:
if (!request.isComet()) {
// The event has been closed asynchronously, so call end instead of
// read to cleanup the pipeline
@@ -201,16 +204,17 @@
} else {
request.getEvent().setType(HttpEvent.EventType.EVENT);
}
- } else if (status == SocketStatus.DISCONNECT) {
+ break;
+ case DISCONNECT:
+ case ERROR:
request.getEvent().setType(HttpEvent.EventType.ERROR);
error = true;
- } else if (status == SocketStatus.ERROR) {
- request.getEvent().setType(HttpEvent.EventType.ERROR);
- error = true;
- } else if (status == SocketStatus.STOP) {
+ break;
+ case STOP:
request.getEvent().setType(HttpEvent.EventType.END);
close = true;
- } else if (status == SocketStatus.TIMEOUT) {
+ break;
+ case TIMEOUT:
if (!request.isComet()) {
// The event has been closed asynchronously, so call end instead of
// read to cleanup the pipeline
@@ -219,6 +223,7 @@
} else {
request.getEvent().setType(HttpEvent.EventType.TIMEOUT);
}
+ break;
}
req.getRequestProcessor().setWorkerThreadName(Thread.currentThread().getName());
@@ -327,14 +332,7 @@
if (request.isComet()) {
if (!response.isClosed() && !response.isError()) {
res.action(ActionCode.ACTION_COMET_BEGIN, null);
- if (request.ready()) {
- // Invoke a read event right away if there are available bytes
- if (event(req, res, SocketStatus.OPEN_READ)) {
- comet = true;
- }
- } else {
- comet = true;
- }
+ comet = true;
} else {
// Clear the filter chain, as otherwise it will not be reset elsewhere
// since this is a Comet request
Modified: trunk/java/org/apache/catalina/connector/InputBuffer.java
===================================================================
--- trunk/java/org/apache/catalina/connector/InputBuffer.java 2008-10-29 15:31:36 UTC (rev 826)
+++ trunk/java/org/apache/catalina/connector/InputBuffer.java 2008-10-29 15:34:21 UTC (rev 827)
@@ -278,7 +278,7 @@
return -1;
}
int available = 0;
- if (state == BYTE_STATE) {
+ if (state != CHAR_STATE) {
available = bb.getLength();
if (request.isComet() && available == 0) {
try {
@@ -289,7 +289,7 @@
// will occur elsewhere
}
}
- } else if (state == CHAR_STATE) {
+ } else {
available = cb.getLength();
if (request.isComet() && available == 0) {
try {
Modified: trunk/java/org/apache/coyote/http11/Http11AprProcessor.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 2008-10-29 15:31:36 UTC (rev 826)
+++ trunk/java/org/apache/coyote/http11/Http11AprProcessor.java 2008-10-29 15:34:21 UTC (rev 827)
@@ -364,6 +364,11 @@
}
+ public boolean getAvailable() {
+ return inputBuffer.available();
+ }
+
+
/**
* Return compression level.
*/
Modified: trunk/java/org/apache/coyote/http11/Http11AprProtocol.java
===================================================================
--- trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 2008-10-29 15:31:36 UTC (rev 826)
+++ trunk/java/org/apache/coyote/http11/Http11AprProtocol.java 2008-10-29 15:34:21 UTC (rev 827)
@@ -598,9 +598,15 @@
// processed by this thread will use either a new or a recycled
// processor.
connections.put(socket, processor);
- proto.endpoint.getCometPoller().add(socket, processor.getCometTimeout(),
- processor.getReadNotifications(), false, false);
- } else {
+ if (processor.getAvailable() && processor.getReadNotifications()) {
+ // Call a read event right away
+ state = event(socket, SocketStatus.OPEN_READ);
+ } else {
+ proto.endpoint.getCometPoller().add(socket, processor.getCometTimeout(),
+ processor.getReadNotifications(), false, false);
+ }
+ }
+ if (state != SocketState.LONG) {
recycledProcessors.offer(processor);
}
return state;
Modified: trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java
===================================================================
--- trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java 2008-10-29 15:31:36 UTC (rev 826)
+++ trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java 2008-10-29 15:34:21 UTC (rev 827)
@@ -314,6 +314,7 @@
lastActiveFilter = -1;
parsingHeader = true;
swallowInput = true;
+ available = false;
}
@@ -355,6 +356,7 @@
parsingHeader = true;
swallowInput = true;
nonBlocking = false;
+ available = false;
return (lastValid > 0);
@@ -749,6 +751,15 @@
}
+ /**
+ * Available bytes in the buffer ? (these may not translate to application
+ * readable data)
+ */
+ public boolean available() {
+ return (lastValid - pos > 0);
+ }
+
+
// ---------------------------------------------------- InputBuffer Methods
@@ -845,6 +856,7 @@
throw new IOException(sm.getString("iib.failedread"));
}
}
+ available = false;
}
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2008-10-29 15:31:36 UTC (rev 826)
+++ trunk/webapps/docs/changelog.xml 2008-10-29 15:34:21 UTC (rev 827)
@@ -117,6 +117,9 @@
<fix>
Cleanup some type oddities in MimeHeaders. (remm)
</fix>
+ <fix>
+ Refactor generation of the READ event which follows a BEGIN into the HTTP protocol handler. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
16 years, 2 months
JBossWeb SVN: r826 - trunk/java/org/apache/tomcat/bayeux.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-10-29 11:31:36 -0400 (Wed, 29 Oct 2008)
New Revision: 826
Modified:
trunk/java/org/apache/tomcat/bayeux/BayeuxServlet.java
Log:
- Debug param.
Modified: trunk/java/org/apache/tomcat/bayeux/BayeuxServlet.java
===================================================================
--- trunk/java/org/apache/tomcat/bayeux/BayeuxServlet.java 2008-10-29 15:16:52 UTC (rev 825)
+++ trunk/java/org/apache/tomcat/bayeux/BayeuxServlet.java 2008-10-29 15:31:36 UTC (rev 826)
@@ -228,6 +228,11 @@
ctx.setAttribute(TOMCAT_BAYEUX_ATTR,new TomcatBayeux());
this.tb = (TomcatBayeux)ctx.getAttribute(TOMCAT_BAYEUX_ATTR);
tb.setReconnectInterval(getReconnectInterval());
+ if (servletConfig.getInitParameter("debug") != null)
+ debug = Integer.parseInt(servletConfig.getInitParameter("debug"));
+ if (debug > 0) {
+ servletConfig.getServletContext().log("Init " + getServletInfo());
+ }
}
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
16 years, 2 months
JBossWeb SVN: r825 - in trunk: java/org/apache/tomcat/bayeux and 2 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-10-29 11:16:52 -0400 (Wed, 29 Oct 2008)
New Revision: 825
Modified:
trunk/build.xml
trunk/java/org/apache/tomcat/bayeux/TomcatBayeux.java
trunk/test/java/org/apache/jboss/web/comet/CometServletTest1.java
trunk/test/java/org/apache/jboss/web/comet/CometServletTest2.java
trunk/test/webapps/cometd/WEB-INF/web.xml
Log:
- Add some stuff to the Comet test.
- Make UUID identical to Tomcat (but & paste made it use another class, although it should not make any difference).
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2008-10-28 21:56:15 UTC (rev 824)
+++ trunk/build.xml 2008-10-29 15:16:52 UTC (rev 825)
@@ -835,7 +835,6 @@
source="${compile.source}"
optimize="${compile.optimize}"
classpath="${tomcat.classes}">
- <include name="org/apache/cometd/**" />
</javac>
</target>
Modified: trunk/java/org/apache/tomcat/bayeux/TomcatBayeux.java
===================================================================
--- trunk/java/org/apache/tomcat/bayeux/TomcatBayeux.java 2008-10-28 21:56:15 UTC (rev 824)
+++ trunk/java/org/apache/tomcat/bayeux/TomcatBayeux.java 2008-10-29 15:16:52 UTC (rev 825)
@@ -16,7 +16,6 @@
*/
package org.apache.tomcat.bayeux;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -147,9 +146,25 @@
public String createUUID(String idprefix) {
if (idprefix==null) idprefix="";
- return idprefix + Arrays.toString(UUIDGenerator.randomUUID(false));
+ return idprefix + TomcatBayeux.toString(UUIDGenerator.randomUUID(false));
}
+ protected static String toString(byte[] data) {
+ return toString(data,0,data!=null?data.length:0);
+ }
+
+ protected static String toString(byte[] data, int offset, int length) {
+ StringBuffer buf = new StringBuffer("{");
+ if ( data != null && length > 0 ) {
+ buf.append(data[offset++]);
+ for (int i = offset; i < length; i++) {
+ buf.append(", ").append(data[i]);
+ }
+ }
+ buf.append("}");
+ return buf.toString();
+ }
+
public List<Channel> getChannels() {
return java.util.Arrays.asList(channels.entrySet().toArray(new Channel[0]));
}
Modified: trunk/test/java/org/apache/jboss/web/comet/CometServletTest1.java
===================================================================
--- trunk/test/java/org/apache/jboss/web/comet/CometServletTest1.java 2008-10-28 21:56:15 UTC (rev 824)
+++ trunk/test/java/org/apache/jboss/web/comet/CometServletTest1.java 2008-10-29 15:16:52 UTC (rev 825)
@@ -31,14 +31,14 @@
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
-import org.jboss.web.comet.CometEvent;
-import org.jboss.web.comet.CometProcessor;
+import org.jboss.servlet.http.HttpEvent;
+import org.jboss.servlet.http.HttpEventServlet;
-public class CometServletTest1 extends HttpServlet implements CometProcessor {
+public class CometServletTest1 extends HttpServlet implements HttpEventServlet {
int count = 0;
- public void event(CometEvent event) throws IOException, ServletException {
+ public void event(HttpEvent event) throws IOException, ServletException {
System.out.println("[" + event.getHttpServletRequest().getSession(true).getId() + "] " + event.getType());
switch (event.getType()) {
case BEGIN:
@@ -55,7 +55,7 @@
// will cause the write to be performed in blocking mode.
// boolean b = true;
// while (b) {
- while (event.ready()) {
+ while (event.isWriteReady()) {
if (count % 100 == 0) {
os.println((count++) + " ");
} else {
Modified: trunk/test/java/org/apache/jboss/web/comet/CometServletTest2.java
===================================================================
--- trunk/test/java/org/apache/jboss/web/comet/CometServletTest2.java 2008-10-28 21:56:15 UTC (rev 824)
+++ trunk/test/java/org/apache/jboss/web/comet/CometServletTest2.java 2008-10-29 15:16:52 UTC (rev 825)
@@ -29,12 +29,14 @@
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
+import org.jboss.servlet.http.HttpEvent;
+import org.jboss.servlet.http.HttpEventServlet;
-public class CometServletTest2 extends HttpServlet implements CometProcessor {
+public class CometServletTest2 extends HttpServlet implements HttpEventServlet {
int count = 0;
- public void event(CometEvent event) throws IOException, ServletException {
+ public void event(HttpEvent event) throws IOException, ServletException {
System.out.println("[" + event.getHttpServletRequest().getSession(true).getId() + "] " + event.getType());
switch (event.getType()) {
case BEGIN:
@@ -51,7 +53,7 @@
// will cause the write to be performed in blocking mode.
// boolean b = true;
// while (b) {
- while (event.ready()) {
+ while (event.isWriteReady()) {
if (count % 100 == 0) {
writer.write((count++) + " \r\n");
} else {
Modified: trunk/test/webapps/cometd/WEB-INF/web.xml
===================================================================
--- trunk/test/webapps/cometd/WEB-INF/web.xml 2008-10-28 21:56:15 UTC (rev 824)
+++ trunk/test/webapps/cometd/WEB-INF/web.xml 2008-10-29 15:16:52 UTC (rev 825)
@@ -19,11 +19,19 @@
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
+ <servlet>
+ <servlet-name>comettest</servlet-name>
+ <servlet-class>org.jboss.web.comet.CometServletTest1</servlet-class>
+ </servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>comettest</servlet-name>
+ <url-pattern>/test/*</url-pattern>
+ </servlet-mapping>
<listener>
<listener-class>org.apache.cometd.bayeux.samples.EchoChatClient</listener-class>
16 years, 2 months
JBossWeb SVN: r824 - trunk.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-10-28 17:56:15 -0400 (Tue, 28 Oct 2008)
New Revision: 824
Modified:
trunk/build.xml
Log:
- Add a test target, which builds the bayeux test.
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2008-10-28 15:51:50 UTC (rev 823)
+++ trunk/build.xml 2008-10-28 21:56:15 UTC (rev 824)
@@ -813,4 +813,30 @@
</jar>
</target>
+ <target name="tests">
+ <antcall target="downloadgz">
+ <param name="sourcefile" value="${dojo-js.loc}"/>
+ <param name="destfile" value="${dojo-js.jar}"/>
+ </antcall>
+
+ <mkdir dir="${tomcat.build}/webapps/cometd"/>
+ <mkdir dir="${tomcat.build}/webapps/cometd/WEB-INF/classes"/>
+ <copy todir="${tomcat.build}/webapps/cometd">
+ <fileset dir="${basedir}/test/webapps/cometd">
+ </fileset>
+ <fileset dir="${dojo-js.home}">
+ <include name="dojo/**"/>
+ <include name="dojox/**"/>
+ </fileset>
+ </copy>
+ <javac srcdir="${basedir}/test/java" destdir="${tomcat.build}/webapps/cometd/WEB-INF/classes"
+ debug="${compile.debug}"
+ deprecation="${compile.deprecation}"
+ source="${compile.source}"
+ optimize="${compile.optimize}"
+ classpath="${tomcat.classes}">
+ <include name="org/apache/cometd/**" />
+ </javac>
+ </target>
+
</project>
16 years, 2 months
JBossWeb SVN: r823 - in trunk/test: java/org/apache/cometd and 7 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-10-28 11:51:50 -0400 (Tue, 28 Oct 2008)
New Revision: 823
Added:
trunk/test/java/org/apache/cometd/
trunk/test/java/org/apache/cometd/bayeux/
trunk/test/java/org/apache/cometd/bayeux/sample/
trunk/test/java/org/apache/cometd/bayeux/sample/BayeuxStockTicker.java
trunk/test/java/org/apache/cometd/bayeux/sample/EchoChatClient.java
trunk/test/webapps/cometd/
trunk/test/webapps/cometd/WEB-INF/
trunk/test/webapps/cometd/WEB-INF/web.xml
trunk/test/webapps/cometd/examples/
trunk/test/webapps/cometd/examples/simplechat/
trunk/test/webapps/cometd/examples/simplechat/cometdchat.htm
trunk/test/webapps/cometd/examples/simplechat/ticker.html
trunk/test/webapps/cometd/index.html
Log:
- Add the bayeux test webapp to have it around.
Added: trunk/test/java/org/apache/cometd/bayeux/sample/BayeuxStockTicker.java
===================================================================
--- trunk/test/java/org/apache/cometd/bayeux/sample/BayeuxStockTicker.java (rev 0)
+++ trunk/test/java/org/apache/cometd/bayeux/sample/BayeuxStockTicker.java 2008-10-28 15:51:50 UTC (rev 823)
@@ -0,0 +1,215 @@
+package org.apache.cometd.bayeux.samples;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletContextAttributeEvent;
+import org.apache.cometd.bayeux.Bayeux;
+
+import java.text.DecimalFormat;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.cometd.bayeux.Client;
+import org.apache.cometd.bayeux.Listener;
+import org.apache.cometd.bayeux.Message;
+import org.apache.cometd.bayeux.Channel;
+
+public class BayeuxStockTicker implements ServletContextListener,
+ ServletContextAttributeListener, Listener {
+
+ static AtomicInteger counter = new AtomicInteger(0);
+ protected int id;
+ protected Bayeux b;
+ protected Client c;
+ protected boolean alive = true;
+ protected boolean initialized = false;
+ protected TickerThread tt = new TickerThread();
+
+ public BayeuxStockTicker() {
+ id = counter.incrementAndGet();
+ System.out.println("new listener created with id:" + id);
+ }
+
+ public void contextDestroyed(ServletContextEvent servletContextEvent) {
+ alive = false;
+ tt.run = false;
+ tt.interrupt();
+ }
+
+ public void contextInitialized(ServletContextEvent servletContextEvent) {
+ }
+
+ public void attributeAdded(ServletContextAttributeEvent scae) {
+ if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
+ if (initialized) return;
+ initialized = true;
+ System.out.println("Starting stock ticker server client!");
+ b = (Bayeux) scae.getValue();
+ c = b.newClient("stock-ticker-", this);
+ tt.start();
+ }
+ }
+
+ public void attributeRemoved(ServletContextAttributeEvent scae) {
+ if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
+ initialized = false;
+ b = (Bayeux) scae.getValue();
+ List<Channel> chs = b.getChannels();
+ for (Channel ch : chs) {
+ ch.unsubscribe(c);
+ }
+ }
+ }
+
+ public void attributeReplaced(
+ ServletContextAttributeEvent servletContextAttributeEvent) {
+ }
+
+ public void removed(boolean timeout) {
+ System.out.println("Client removed.");
+ }
+
+ public void deliver(Message[] msgs) {
+ for (int i = 0; msgs != null && i < msgs.length; i++) {
+ Message msg = msgs[i];
+ System.out.println("[stock ticker server client ]received message:" + msg);
+ }
+ }
+
+ public class TickerThread extends Thread {
+ public boolean run = true;
+
+ public TickerThread() {
+ setName("Ticker Thread");
+ }
+
+ public void run() {
+ try {
+
+ Stock[] stocks = new Stock[] {
+ new Stock("GOOG", 435.43),
+ new Stock("YHOO", 27.88),
+ new Stock("SPRG", 1015.55), };
+ for (Stock s : stocks) {
+ Channel ch = b.getChannel("/stock/"+s.getSymbol(), true);
+ ch.subscribe(c);
+
+ }
+ Random r = new Random(System.currentTimeMillis());
+ while (run) {
+ for (int j = 0; j < 1; j++) {
+ int i = r.nextInt() % 3;
+ if (i < 0)
+ i = i * (-1);
+ Stock stock = stocks[i];
+ double change = r.nextDouble();
+ boolean plus = r.nextBoolean();
+ if (plus) {
+ stock.setValue(stock.getValue() + change);
+ } else {
+ stock.setValue(stock.getValue() - change);
+ }
+ Channel ch = b.getChannel("/stock/"+stock.getSymbol(), true);
+ Message m = b.newMessage(c);
+ m.put("stock", stock.toString());
+ m.put("symbol", stock.getSymbol());
+ m.put("price", stock.getValueAsString());
+ m.put("change", stock.getLastChangeAsString());
+ ch.publish(m);
+ System.out.println("Stock: "+stock.getSymbol()+" Price: "+stock.getValueAsString()+" Change: "+stock.getLastChangeAsString());
+ }
+ Thread.sleep(850);
+ }
+ } catch (InterruptedException ix) {
+
+ } catch (Exception x) {
+ x.printStackTrace();
+ }
+ }
+ }
+
+ public static class Stock {
+ protected static DecimalFormat df = new DecimalFormat("0.00");
+ protected String symbol = "";
+ protected double value = 0.0d;
+ protected double lastchange = 0.0d;
+ protected int cnt = 0;
+
+ public Stock(String symbol, double initvalue) {
+ this.symbol = symbol;
+ this.value = initvalue;
+ }
+
+ public void setCnt(int c) {
+ this.cnt = c;
+ }
+
+ public int getCnt() {
+ return cnt;
+ }
+
+ public String getSymbol() {
+ return symbol;
+ }
+
+ public double getValue() {
+ return value;
+ }
+
+ public void setValue(double value) {
+ double old = this.value;
+ this.value = value;
+ this.lastchange = value - old;
+ }
+
+ public String getValueAsString() {
+ return df.format(value);
+ }
+
+ public double getLastChange() {
+ return this.lastchange;
+ }
+
+ public void setLastChange(double lastchange) {
+ this.lastchange = lastchange;
+ }
+
+ public String getLastChangeAsString() {
+ return df.format(lastchange);
+ }
+
+ public int hashCode() {
+ return symbol.hashCode();
+ }
+
+ public boolean equals(Object other) {
+ if (other instanceof Stock) {
+ return this.symbol.equals(((Stock) other).symbol);
+ } else {
+ return false;
+ }
+ }
+
+ public String toString(){
+ StringBuffer buf = new StringBuffer("STOCK#");
+ buf.append(getSymbol());
+ buf.append("#");
+ buf.append(getValueAsString());
+ buf.append("#");
+ buf.append(getLastChangeAsString());
+ buf.append("#");
+ buf.append(String.valueOf(getCnt()));
+ return buf.toString();
+
+ }
+
+ public Object clone() {
+ Stock s = new Stock(this.getSymbol(), this.getValue());
+ s.setLastChange(this.getLastChange());
+ s.setCnt(this.cnt);
+ return s;
+ }
+ }
+
+}
\ No newline at end of file
Added: trunk/test/java/org/apache/cometd/bayeux/sample/EchoChatClient.java
===================================================================
--- trunk/test/java/org/apache/cometd/bayeux/sample/EchoChatClient.java (rev 0)
+++ trunk/test/java/org/apache/cometd/bayeux/sample/EchoChatClient.java 2008-10-28 15:51:50 UTC (rev 823)
@@ -0,0 +1,101 @@
+package org.apache.cometd.bayeux.samples;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletContextAttributeEvent;
+import org.apache.cometd.bayeux.Bayeux;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.cometd.bayeux.Client;
+import org.apache.cometd.bayeux.Listener;
+import org.apache.cometd.bayeux.Message;
+import org.apache.cometd.bayeux.Channel;
+
+public class EchoChatClient implements ServletContextListener, ServletContextAttributeListener, Listener {
+
+ static AtomicInteger counter = new AtomicInteger(0);
+ protected int id;
+ protected Bayeux b;
+ protected Client c;
+ protected boolean alive = true;
+ protected TimestampThread tt = new TimestampThread();
+
+ public EchoChatClient() {
+ id = counter.incrementAndGet();
+ System.out.println("new listener created with id:"+id);
+ }
+
+ public void contextDestroyed(ServletContextEvent servletContextEvent) {
+ alive = false;
+ tt.interrupt();
+ }
+
+ public void contextInitialized(ServletContextEvent servletContextEvent) {
+ }
+
+ public void attributeAdded(ServletContextAttributeEvent scae) {
+ if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
+ System.out.println("Starting echo chat client!");
+ b = (Bayeux)scae.getValue();
+ c = b.newClient("echochat-",this);
+ Channel ch = b.getChannel("/chat/demo",true);
+ ch.subscribe(c);
+ tt.start();
+ }
+ }
+
+ public void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) {
+ }
+
+ public void attributeReplaced(ServletContextAttributeEvent servletContextAttributeEvent) {
+ }
+
+ public void removed(boolean timeout) {
+ System.out.println("Client removed.");
+ }
+
+ public void deliver(Message[] msgs) {
+ for (int i=0; msgs!=null && i<msgs.length; i++) {
+ Message msg = msgs[i];
+ System.out.println("[echochatclient ]received message:" + msg);
+ Message m = b.newMessage(c);
+ m.putAll(msg);
+ //echo the same message
+ m.put("user", "echochatserver");
+ if (m.containsKey("msg")) {
+ //simple chat demo
+ String chat = (String) m.get("msg");
+ m.put("msg", "echochatserver|I received your message-" + chat.substring(chat.indexOf("|") + 1));
+ }
+ System.out.println("[echochatclient ]sending message:" + m);
+ msg.getChannel().publish(m);
+ }
+ }
+
+ public class TimestampThread extends Thread {
+ public TimestampThread() {
+ setDaemon(true);
+ }
+
+ public void run() {
+ while (alive) {
+ try {
+ sleep(5000);
+ Channel ch = b.getChannel("/chat/demo",false);
+ if (ch.getSubscribers().size()<=1) {
+ continue;
+ }
+ Message m = b.newMessage(c);
+ m.put("user","echochatserver");
+ m.put("chat","Time is:"+new java.sql.Date(System.currentTimeMillis()).toLocaleString());
+ m.put("join",false);
+ ch.publish(m);
+ }catch (InterruptedException ignore) {
+ Thread.currentThread().interrupted();
+ }catch (Exception x) {
+ x.printStackTrace();
+ }
+ }
+ }
+ }
+}
Added: trunk/test/webapps/cometd/WEB-INF/web.xml
===================================================================
--- trunk/test/webapps/cometd/WEB-INF/web.xml (rev 0)
+++ trunk/test/webapps/cometd/WEB-INF/web.xml 2008-10-28 15:51:50 UTC (rev 823)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<web-app
+ 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/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ version="2.5">
+ <display-name>Cometd Test WebApp</display-name>
+
+ <servlet>
+ <servlet-name>cometd</servlet-name>
+ <servlet-class>org.apache.tomcat.bayeux.BayeuxServlet</servlet-class>
+ <init-param>
+ <param-name>timeout</param-name>
+ <param-value>120000000</param-value>
+ </init-param>
+ <init-param>
+ <param-name>reconnectInterval</param-name>
+ <param-value>250</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>cometd</servlet-name>
+ <url-pattern>/cometd/*</url-pattern>
+ </servlet-mapping>
+
+ <listener>
+ <listener-class>org.apache.cometd.bayeux.samples.EchoChatClient</listener-class>
+ </listener>
+ <listener>
+ <listener-class>org.apache.cometd.bayeux.samples.BayeuxStockTicker</listener-class>
+ </listener>
+
+</web-app>
+
+
Added: trunk/test/webapps/cometd/examples/simplechat/cometdchat.htm
===================================================================
--- trunk/test/webapps/cometd/examples/simplechat/cometdchat.htm (rev 0)
+++ trunk/test/webapps/cometd/examples/simplechat/cometdchat.htm 2008-10-28 15:51:50 UTC (rev 823)
@@ -0,0 +1,114 @@
+<html>
+<header><title>Comet Simple Chat Application</title>
+
+<script type="text/javascript" src="../../dojo/dojo.js.uncompressed.js"></script>
+<script type="text/javascript" src="../../dojox/cometd.js"></script>
+<script type="text/javascript" src="../../dojox/cometd/_base.js"></script>
+
+<script type="text/javascript">
+
+dojo.require("dojox.cometd");
+
+dojo.addOnLoad(function() {
+ dojo.byId("message").style.visibility='hidden';
+ dojox.cometd.init("/cometd/cometd");
+});
+
+
+function trim(str) {
+ return str.replace(/(^\s+|\s+$)/g,'');
+}
+
+
+function clear() {
+ dojo.byId("msgtext").value = "";
+ dojo.byId("msgtext").focus();
+}
+
+
+function enterKeyHandler(e) {
+if (!e) e = window.event;
+ if (e.keyCode == 13) {
+ send(trim(dojo.byId("msgtext").value));
+ clear();
+ }
+
+}
+
+
+function connect() {
+ dojox.cometd.subscribe("/chat/demo", onMsgEvent);
+ dojo.byId("login").style.visibility='hidden';
+ dojo.byId("message").style.visibility='visible';
+ send("Has joined the chat room");
+ clear();
+ dojo.byId("msgtext").onkeydown = enterKeyHandler;
+ dojo.byId("myname").appendChild(document.createTextNode("-> " + dojo.byId("scrname").value + " <-"));
+}
+
+
+function onMsgEvent(event) {
+
+ // Break apart the text string into screen name and message parts.
+ var str = trim(event.data.msg);
+ var scrname = "";
+ if (str.match(/^.*[|].*$/)) {
+ var spl = str.split("|");
+ scrname = spl[0];
+ str = " - " + spl[1];
+ }
+
+ // Insert the screen name in red and the message black into the DOM
+ var newP = document.createElement("p");
+ var fnt1 = document.createElement("font");
+ var attr1 = document.createAttribute("color");
+ attr1.nodeValue = "red";
+ fnt1.setAttributeNode(attr1);
+
+ var newT = document.createTextNode(scrname);
+ fnt1.appendChild(newT);
+
+ newP.appendChild(fnt1);
+
+ var fnt2 = document.createElement("font");
+ var attr2 = document.createAttribute("color");
+ attr2.nodeValue = "black";
+ fnt2.setAttributeNode(attr2);
+
+ var newT2 = document.createTextNode(str);
+ fnt2.appendChild(newT2);
+
+ newP.appendChild(fnt2);
+
+ dojo.byId("dialog").appendChild(newP)
+}
+
+
+function send(msg) {
+ var scrname = dojo.byId("scrname").value;
+ var evt = {'data': { 'msg': trim(scrname) + '|' + msg }};
+ onMsgEvent(evt); // Echo local
+ dojox.cometd.publish("/chat/demo", evt.data);
+}
+
+
+</script>
+
+</head>
+</header>
+<body>
+<form>
+<div id="login">
+Screen name: <input type="text" id="scrname">
+<input type=Button Id=logbtn value=Connect onClick=connect()><br/>Type a screen name and click the 'Connect' button
+</div>
+
+<div id="dialog"></div>
+<hr/>
+<div id="message">
+<div id="myname"></div> Is my screen name<br/>
+<textarea rows="3" cols="50" id="msgtext"></textarea>[ENTER] sends message</div>
+</form>
+</body>
+</html>
+
Added: trunk/test/webapps/cometd/examples/simplechat/ticker.html
===================================================================
--- trunk/test/webapps/cometd/examples/simplechat/ticker.html (rev 0)
+++ trunk/test/webapps/cometd/examples/simplechat/ticker.html 2008-10-28 15:51:50 UTC (rev 823)
@@ -0,0 +1,128 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" >
+<title>Bayeux Stock Ticker</title>
+<script type="text/javascript" src="../../dojo/dojo.js.uncompressed.js"></script>
+<script type="text/javascript" src="../../dojox/cometd.js"></script>
+<script type="text/javascript" src="../../dojox/cometd/_base.js"></script>
+<script type="text/javascript">
+
+dojo.require("dojox.cometd");
+
+dojo.addOnUnload(function() {
+ dojox.cometd.init("/cometd/cometd");
+ dojox.cometd.startBatch();
+ dojox.cometd.unsubscribe("/stock/GOOG", this,"");
+ dojox.cometd.unsubscribe("/stock/YHOO", this,"");
+ dojox.cometd.unsubscribe("/stock/SPRG", this,"");
+ dojox.cometd.endBatch();
+ });
+
+
+dojo.addOnLoad(function() {
+ dojox.cometd.init("/cometd/cometd");
+ dojox.cometd.startBatch();
+ dojox.cometd.subscribe("/stock/GOOG", onMsgEvent);
+ dojox.cometd.subscribe("/stock/YHOO", onMsgEvent);
+ dojox.cometd.subscribe("/stock/SPRG", onMsgEvent);
+ dojox.cometd.endBatch();
+});
+
+
+function subscribe(box, symbol) {
+ if (box.checked) {
+ dojox.cometd.subscribe("/stock/"+symbol, onMsgEvent);
+ var rowCurrent = dojo.byId("row."+symbol);
+ rowCurrent.bgColor="white";
+ } else {
+ dojox.cometd.unsubscribe("/stock/"+symbol, onMsgEvent);
+ var rowCurrent = dojo.byId("row."+symbol);
+ rowCurrent.bgColor="gray";
+ }
+}
+
+function removeChildrenFromNode(node)
+{
+ if(node == undefined || node == null)
+ {
+ return;
+ }
+
+ var len = node.childNodes.length;
+
+ while (node.hasChildNodes())
+ {
+ node.removeChild(node.firstChild);
+ }
+}
+
+function onMsgEvent(event) {
+ // Break apart the text string into screen name and message parts.
+ var symbol = event.data.symbol;
+ var price = event.data.price;
+ var pricechange = event.data.change;
+ //alert("symbol: "+symbol+" price: "+price+" change: "+pricechange);
+
+ var pricenode = dojo.byId("price."+symbol);
+ var changenode = dojo.byId("change."+symbol);
+ removeChildrenFromNode(pricenode);
+ removeChildrenFromNode(changenode);
+ var pricelabel = document.createTextNode(price);
+ pricelabel.value = price;
+ var changelabel = document.createTextNode(pricechange);
+ changelabel.value = pricechange;
+ pricenode.appendChild(pricelabel);
+ changenode.appendChild(changelabel);
+
+ var table = dojo.byId("stocktable");
+ var rows = table.getElementsByTagName("tr");
+ for(i = 0; i < rows.length; i++){
+ if (rows[i].bgColor != "gray") {
+ rows[i].bgColor = "white";
+ }
+ }
+ //manipulate rows
+ var rowCurrent = dojo.byId("row."+symbol);
+ if (pricechange<=0) {
+ rowCurrent.bgColor = "red";
+ } else {
+ rowCurrent.bgColor = "cyan";
+ }
+}
+
+
+</script>
+</head>
+<body bgcolor="#ffffff">
+<h1 align="center">Bayeux Stock Ticker</h1>
+<h2 align="left"> </h2>
+<p>
+<table id="stocktable" cellspacing="0" cellpadding="3" width="100%" align="center" border="0">
+ <tr id="row.HEADER">
+ <td>SYMBOL</td>
+ <td>PRICE</td>
+ <td>LAST CHANGE</td>
+ <td>SUBSCRIBE</td></tr>
+ <tr id="row.SPRG">
+ <td>SPRG</td>
+ <td id="price.SPRG"></td>
+ <td id="change.SPRG"></td>
+ <td id="check.SPRG"><input type="checkbox" id="check.SPRG" checked onClick="subscribe(this,'SPRG')"></td>
+ </tr>
+ <tr id="row.GOOG">
+ <td>GOOG</td>
+ <td id="price.GOOG"></td>
+ <td id="change.GOOG"></td>
+ <td id="check.GOOG"><input type="checkbox" id="check.GOOG" checked onClick="subscribe(this,'GOOG')"></td>
+ </tr>
+ <tr id="row.YHOO">
+ <td>YHOO</td>
+ <td id="price.YHOO"></td>
+ <td id="change.YHOO"></td>
+ <td id="check.YHOO"><input type="checkbox" id="check.GOOG" checked onClick="subscribe(this,'YHOO')"></td>
+ </tr>
+</table>
+</p>
+</body>
+</html>
\ No newline at end of file
Added: trunk/test/webapps/cometd/index.html
===================================================================
--- trunk/test/webapps/cometd/index.html (rev 0)
+++ trunk/test/webapps/cometd/index.html 2008-10-28 15:51:50 UTC (rev 823)
@@ -0,0 +1,7 @@
+
+<h1>Cometd demo</h1>
+
+<p>
+Try the <a href="examples/simplechat/cometdchat.htm">Simple Chat Demo</a>.</br>
+Try the <a href="examples/simplechat/ticker.html">Stock Ticker Demo</a>.</br>
+</p>
16 years, 2 months
JBossWeb SVN: r822 - in trunk: java/org/apache/catalina/mbeans and 3 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-10-28 11:48:46 -0400 (Tue, 28 Oct 2008)
New Revision: 822
Removed:
trunk/java/org/apache/catalina/mbeans/DefaultContextMBean.java
Modified:
trunk/build.properties.default
trunk/java/org/apache/tomcat/util/http/MimeHeaders.java
trunk/webapps/docs/changelog.xml
trunk/webapps/docs/config/context.xml
trunk/webapps/docs/config/engine.xml
trunk/webapps/docs/config/globalresources.xml
trunk/webapps/docs/config/host.xml
Log:
- Update NSIS.
- Remove a remnant of DefaultContext.
Modified: trunk/build.properties.default
===================================================================
--- trunk/build.properties.default 2008-10-28 15:47:17 UTC (rev 821)
+++ trunk/build.properties.default 2008-10-28 15:48:46 UTC (rev 822)
@@ -59,12 +59,12 @@
commons-collections-src.loc=${base-commons.loc}/collections/source/commons-collections-3.2.1-src.tar.gz
# ----- NSIS, version 2.0 or later -----
-nsis.home=${base.path}/nsis-2.39
+nsis.home=${base.path}/nsis-2.40
nsis.exe=${nsis.home}/makensis.exe
nsis.installoptions.dll=${nsis.home}/Plugins/InstallOptions.dll
nsis.nsexec.dll=${nsis.home}/Plugins/nsExec.dll
nsis.nsisdl.dll=${nsis.home}/Plugins/NSISdl.dll
-nsis.loc=${base-sf.loc}/nsis/nsis-2.39.zip
+nsis.loc=${base-sf.loc}/nsis/nsis-2.40.zip
# ----- JBoss Native, version 2.0 or later -----
jbossnative.home=${base.path}/jboss-native-2.0.4
@@ -78,3 +78,8 @@
commons-daemon.jar=${commons-daemon.lib}/commons-daemon.jar
commons-daemon.loc=${base-commons.loc}/daemon/binaries/commons-daemon-1.0.1.tar.gz
commons-daemon.jsvc.tar.gz=${commons-daemon.lib}/bin/jsvc.tar.gz
+
+# ----- Dojo Toolkit (for test webapp) -----
+dojo-js.home=${base.path}/dojo-release-1.1.1
+dojo-js.loc=http://download.dojotoolkit.org/release-1.1.1/dojo-release-1.1.1.tar.gz
+dojo-js.jar=${dojo-js.home}/dojo/dojo.js
Deleted: trunk/java/org/apache/catalina/mbeans/DefaultContextMBean.java
===================================================================
--- trunk/java/org/apache/catalina/mbeans/DefaultContextMBean.java 2008-10-28 15:47:17 UTC (rev 821)
+++ trunk/java/org/apache/catalina/mbeans/DefaultContextMBean.java 2008-10-28 15:48:46 UTC (rev 822)
@@ -1,329 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.catalina.mbeans;
-
-import java.util.ArrayList;
-
-import javax.management.MBeanException;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import javax.management.RuntimeOperationsException;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.deploy.ContextEnvironment;
-import org.apache.catalina.deploy.ContextResource;
-import org.apache.catalina.deploy.ContextResourceLink;
-import org.apache.catalina.deploy.NamingResources;
-import org.apache.tomcat.util.modeler.BaseModelMBean;
-import org.apache.tomcat.util.modeler.ManagedBean;
-import org.apache.tomcat.util.modeler.Registry;
-
-/**
- * <p>A <strong>ModelMBean</strong> implementation for the
- * <code>org.apache.catalina.core.StandardDefaultContext</code> component.</p>
- *
- * @author Amy Roh
- * @version $Revision$ $Date$
- */
-
-public class DefaultContextMBean extends BaseModelMBean {
-
-
- // ----------------------------------------------------------- Constructors
-
-
- /**
- * Construct a <code>ModelMBean</code> with default
- * <code>ModelMBeanInfo</code> information.
- *
- * @exception MBeanException if the initializer of an object
- * throws an exception
- * @exception RuntimeOperationsException if an IllegalArgumentException
- * occurs
- */
- public DefaultContextMBean()
- throws MBeanException, RuntimeOperationsException {
-
- super();
-
- }
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- /**
- * The configuration information registry for our managed beans.
- */
- protected Registry registry = MBeanUtils.createRegistry();
-
- /**
- * The <code>ManagedBean</code> information describing this MBean.
- */
- protected ManagedBean managed =
- registry.findManagedBean("DefaultContext");
-
-
- // ------------------------------------------------------------- Attributes
-
-
- /**
- * Return the naming resources associated with this web application.
- */
- private NamingResources getNamingResources() {
-
- return ((Context)this.resource).getNamingResources();
-
- }
-
-
- /**
- * Return the MBean Names of the set of defined environment entries for
- * this web application
- */
- public String[] getEnvironments() {
- ContextEnvironment[] envs = getNamingResources().findEnvironments();
- ArrayList results = new ArrayList();
- for (int i = 0; i < envs.length; i++) {
- try {
- ObjectName oname =
- MBeanUtils.createObjectName(managed.getDomain(), envs[i]);
- results.add(oname.toString());
- } catch (MalformedObjectNameException e) {
- IllegalArgumentException iae = new IllegalArgumentException
- ("Cannot create object name for environment " + envs[i]);
- iae.initCause(e);
- throw iae;
- }
- }
- return ((String[]) results.toArray(new String[results.size()]));
-
- }
-
-
- /**
- * Return the MBean Names of all the defined resource references for this
- * application.
- */
- public String[] getResources() {
-
- ContextResource[] resources = getNamingResources().findResources();
- ArrayList results = new ArrayList();
- for (int i = 0; i < resources.length; i++) {
- try {
- ObjectName oname =
- MBeanUtils.createObjectName(managed.getDomain(), resources[i]);
- results.add(oname.toString());
- } catch (MalformedObjectNameException e) {
- IllegalArgumentException iae = new IllegalArgumentException
- ("Cannot create object name for resource " + resources[i]);
- iae.initCause(e);
- throw iae;
- }
- }
- return ((String[]) results.toArray(new String[results.size()]));
-
- }
-
-
- /**
- * Return the MBean Names of all the defined resource links for this
- * application
- */
- public String[] getResourceLinks() {
-
- ContextResourceLink[] links = getNamingResources().findResourceLinks();
- ArrayList results = new ArrayList();
- for (int i = 0; i < links.length; i++) {
- try {
- ObjectName oname =
- MBeanUtils.createObjectName(managed.getDomain(), links[i]);
- results.add(oname.toString());
- } catch (MalformedObjectNameException e) {
- IllegalArgumentException iae = new IllegalArgumentException
- ("Cannot create object name for resource " + links[i]);
- iae.initCause(e);
- throw iae;
- }
- }
- return ((String[]) results.toArray(new String[results.size()]));
-
- }
-
- // ------------------------------------------------------------- Operations
-
-
- /**
- * Add an environment entry for this web application.
- *
- * @param envName New environment entry name
- */
- public String addEnvironment(String envName, String type)
- throws MalformedObjectNameException {
-
- NamingResources nresources = getNamingResources();
- if (nresources == null) {
- return null;
- }
- ContextEnvironment env = nresources.findEnvironment(envName);
- if (env != null) {
- throw new IllegalArgumentException
- ("Invalid environment name - already exists '" + envName + "'");
- }
- env = new ContextEnvironment();
- env.setName(envName);
- env.setType(type);
- nresources.addEnvironment(env);
-
- // Return the corresponding MBean name
- ManagedBean managed = registry.findManagedBean("ContextEnvironment");
- ObjectName oname =
- MBeanUtils.createObjectName(managed.getDomain(), env);
- return (oname.toString());
-
- }
-
-
- /**
- * Add a resource reference for this web application.
- *
- * @param resourceName New resource reference name
- */
- public String addResource(String resourceName, String type)
- throws MalformedObjectNameException {
-
- NamingResources nresources = getNamingResources();
- if (nresources == null) {
- return null;
- }
- ContextResource resource = nresources.findResource(resourceName);
- if (resource != null) {
- throw new IllegalArgumentException
- ("Invalid resource name - already exists'" + resourceName + "'");
- }
- resource = new ContextResource();
- resource.setName(resourceName);
- resource.setType(type);
- nresources.addResource(resource);
-
- // Return the corresponding MBean name
- ManagedBean managed = registry.findManagedBean("ContextResource");
- ObjectName oname =
- MBeanUtils.createObjectName(managed.getDomain(), resource);
-
- return (oname.toString());
- }
-
-
- /**
- * Add a resource link for this web application.
- *
- * @param resourceLinkName New resource link name
- */
- public String addResourceLink(String resourceLinkName, String global,
- String name, String type) throws MalformedObjectNameException {
-
- NamingResources nresources = getNamingResources();
- if (nresources == null) {
- return null;
- }
- ContextResourceLink resourceLink =
- nresources.findResourceLink(resourceLinkName);
- if (resourceLink != null) {
- throw new IllegalArgumentException
- ("Invalid resource link name - already exists'" +
- resourceLinkName + "'");
- }
- resourceLink = new ContextResourceLink();
- resourceLink.setGlobal(global);
- resourceLink.setName(resourceLinkName);
- resourceLink.setType(type);
- nresources.addResourceLink(resourceLink);
-
- // Return the corresponding MBean name
- ManagedBean managed = registry.findManagedBean("ContextResourceLink");
- ObjectName oname =
- MBeanUtils.createObjectName(managed.getDomain(), resourceLink);
- return (oname.toString());
- }
-
-
- /**
- * Remove any environment entry with the specified name.
- *
- * @param envName Name of the environment entry to remove
- */
- public void removeEnvironment(String envName) {
-
- NamingResources nresources = getNamingResources();
- if (nresources == null) {
- return;
- }
- ContextEnvironment env = nresources.findEnvironment(envName);
- if (env == null) {
- throw new IllegalArgumentException
- ("Invalid environment name '" + envName + "'");
- }
- nresources.removeEnvironment(envName);
-
- }
-
-
- /**
- * Remove any resource reference with the specified name.
- *
- * @param resourceName Name of the resource reference to remove
- */
- public void removeResource(String resourceName) {
-
- resourceName = ObjectName.unquote(resourceName);
- NamingResources nresources = getNamingResources();
- if (nresources == null) {
- return;
- }
- ContextResource resource = nresources.findResource(resourceName);
- if (resource == null) {
- throw new IllegalArgumentException
- ("Invalid resource name '" + resourceName + "'");
- }
- nresources.removeResource(resourceName);
- }
-
-
- /**
- * Remove any resource link with the specified name.
- *
- * @param resourceLinkName Name of the resource reference to remove
- */
- public void removeResourceLink(String resourceLinkName) {
-
- resourceLinkName = ObjectName.unquote(resourceLinkName);
- NamingResources nresources = getNamingResources();
- if (nresources == null) {
- return;
- }
- ContextResourceLink resource = nresources.findResourceLink(resourceLinkName);
- if (resource == null) {
- throw new IllegalArgumentException
- ("Invalid resource name '" + resourceLinkName + "'");
- }
- nresources.removeResourceLink(resourceLinkName);
- }
-
-
-}
Modified: trunk/java/org/apache/tomcat/util/http/MimeHeaders.java
===================================================================
--- trunk/java/org/apache/tomcat/util/http/MimeHeaders.java 2008-10-28 15:47:17 UTC (rev 821)
+++ trunk/java/org/apache/tomcat/util/http/MimeHeaders.java 2008-10-28 15:48:46 UTC (rev 822)
@@ -99,24 +99,22 @@
* we want to keep add O(1).
*/
protected class NamesEnumerator implements Enumeration {
- int pos;
- int size;
- String next;
- MimeHeaders headers;
+ protected int pos;
+ protected int size;
+ protected String next;
- NamesEnumerator(MimeHeaders headers) {
- this.headers = headers;
+ protected NamesEnumerator() {
pos = 0;
- size = headers.size();
+ size = size();
findNext();
}
private void findNext() {
next = null;
for (; pos < size; pos++) {
- next = headers.getName(pos).toString();
+ next = getName(pos).toString();
for (int j = 0; j < pos; j++) {
- if (headers.getName(j).equalsIgnoreCase(next)) {
+ if (getName(j).equalsIgnoreCase(next)) {
// duplicate.
next = null;
break;
@@ -147,26 +145,24 @@
value element.
*/
protected class ValuesEnumerator implements Enumeration {
- int pos;
- int size;
- MessageBytes next;
- MimeHeaders headers;
- String name;
+ protected int pos;
+ protected int size;
+ protected MessageBytes next;
+ protected String name;
- ValuesEnumerator(MimeHeaders headers, String name) {
+ protected ValuesEnumerator(String name) {
this.name = name;
- this.headers = headers;
pos = 0;
- size = headers.size();
+ size = size();
findNext();
}
private void findNext() {
next = null;
for (; pos < size; pos++) {
- MessageBytes n1 = headers.getName(pos);
+ MessageBytes n1 = getName(pos);
if (n1.equalsIgnoreCase(name)) {
- next = headers.getValue(pos);
+ next = getValue(pos);
break;
}
}
@@ -320,11 +316,11 @@
* that multiple fields with that name exist in this header.
*/
public Enumeration names() {
- return new NamesEnumerator(this);
+ return new NamesEnumerator();
}
public Enumeration values(String name) {
- return new ValuesEnumerator(this, name);
+ return new ValuesEnumerator(name);
}
// -------------------- Adding headers --------------------
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2008-10-28 15:47:17 UTC (rev 821)
+++ trunk/webapps/docs/changelog.xml 2008-10-28 15:48:46 UTC (rev 822)
@@ -17,6 +17,13 @@
<body>
<section name="JBoss Web 2.1.1.GA (remm)">
+ <subsection name="General">
+ <changelog>
+ <update>
+ NSIS 2.40. (remm)
+ </update>
+ </changelog>
+ </subsection>
<subsection name="Catalina">
<changelog>
<fix>
@@ -58,6 +65,16 @@
<fix>
The default annotation name should be based on the class in which the annotation was found. (markt)
</fix>
+ <fix>
+ <bug>46075</bug>: Don't create ByteArrayOutputStream at maximum possible size. (markt)
+ </fix>
+ <fix>
+ <bug>46096</bug>: Support annotation processing whilst running under a security manager. (markt)
+ </fix>
+ <fix>
+ <bug>46085</bug>: Date handling in sessions should use int offsets, and longs can get
+ corrupted. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
@@ -97,6 +114,9 @@
<fix>
Add maxThreads warning. (markt)
</fix>
+ <fix>
+ Cleanup some type oddities in MimeHeaders. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
Modified: trunk/webapps/docs/config/context.xml
===================================================================
--- trunk/webapps/docs/config/context.xml 2008-10-28 15:47:17 UTC (rev 821)
+++ trunk/webapps/docs/config/context.xml 2008-10-28 15:48:46 UTC (rev 822)
@@ -158,10 +158,9 @@
<attribute name="override" required="false">
<p>Set to <code>true</code> to have explicit settings in this
- Context element override any corresponding settings in the
- <a href="defaultcontext.html">DefaultContext</a> element associated
- with our owning <a href="host.html">Host</a>. By default, settings
- in the DefaultContext element will be used.</p>
+ Context element override any corresponding settings in either the global
+ or <a href="host.html">Host</a> default contexts. By default, settings
+ from a default context will be used.</p>
<p>If a symbolic link is used for docBase then changes to the
symbolic link will only be effective after a JBoss Web restart or
by undeploying and redeploying the conext. A context reload is not
Modified: trunk/webapps/docs/config/engine.xml
===================================================================
--- trunk/webapps/docs/config/engine.xml 2008-10-28 15:47:17 UTC (rev 821)
+++ trunk/webapps/docs/config/engine.xml 2008-10-28 15:48:46 UTC (rev 822)
@@ -114,10 +114,6 @@
have a name that matches the name specified for the
<code>defaultHost</code> attribute, listed above.</p>
- <p>You can optional nest a <a href="defaultcontext.html">DefaultContext</a>
- element inside this <strong>Engine</strong> element, to define the default
- characteristics of web applications that are automatically deployed.</p>
-
<p>You can nest at most one instance of the following utility components
by nesting a corresponding element inside your <strong>Engine</strong>
element:</p>
Modified: trunk/webapps/docs/config/globalresources.xml
===================================================================
--- trunk/webapps/docs/config/globalresources.xml 2008-10-28 15:47:17 UTC (rev 821)
+++ trunk/webapps/docs/config/globalresources.xml 2008-10-28 15:48:46 UTC (rev 822)
@@ -203,21 +203,20 @@
<p>Use <a href="context.html#Resource Links"><ResourceLink></a>
elements to link resources from the global context into
per-web-application contexts. Here is an example of making a custom
- factory available to all applications in the server, based on the example
- definition in the
+ factory available to an application, based on the example definition in the
<a href="../jndi-resource-howto.html#Generic JavaBean Resources">
JNDI Resource HOW-TO</a>:
</p>
<source>
<![CDATA[
- <DefaultContext>
+ <Context>
<ResourceLink
name="bean/MyBeanFactory"
global="bean/MyBeanFactory"
type="com.mycompany.MyBean"
/>
- </DefaultContext>
+ </Context>
]]>
</source>
Modified: trunk/webapps/docs/config/host.xml
===================================================================
--- trunk/webapps/docs/config/host.xml 2008-10-28 15:47:17 UTC (rev 821)
+++ trunk/webapps/docs/config/host.xml 2008-10-28 15:48:46 UTC (rev 822)
@@ -520,8 +520,7 @@
considerations:</p>
<ul>
<li>Each user web application will be deployed with characteristics
- established by any <a href="defaultcontext.html">DefaultContext</a>
- element you have configured for this Host.</li>
+ established by the global and host level default context settings.</li>
<li>It is legal to include more than one instance of this Listener
element. This would only be useful, however, in circumstances
where you wanted to configure more than one "homeBase" directory.</li>
16 years, 2 months
JBossWeb SVN: r821 - trunk/java/org/apache/tomcat/util/http/fileupload.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-10-28 11:47:17 -0400 (Tue, 28 Oct 2008)
New Revision: 821
Modified:
trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java
Log:
- Memory fix for fileupload.
Modified: trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java
===================================================================
--- trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java 2008-10-28 15:41:35 UTC (rev 820)
+++ trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java 2008-10-28 15:47:17 UTC (rev 821)
@@ -84,7 +84,14 @@
super(threshold);
this.outputFile = outputFile;
- memoryOutputStream = new ByteArrayOutputStream(threshold);
+ if (threshold < DefaultFileItemFactory.DEFAULT_SIZE_THRESHOLD) {
+ // Small threshold, use it
+ memoryOutputStream = new ByteArrayOutputStream(threshold);
+ } else {
+ // Large threshold. Use default and array will expand if required
+ memoryOutputStream = new ByteArrayOutputStream(
+ DefaultFileItemFactory.DEFAULT_SIZE_THRESHOLD);
+ }
currentOutputStream = memoryOutputStream;
}
16 years, 2 months
JBossWeb SVN: r820 - trunk/java/org/apache/catalina/session.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-10-28 11:41:35 -0400 (Tue, 28 Oct 2008)
New Revision: 820
Modified:
trunk/java/org/apache/catalina/session/StandardSession.java
Log:
- Refactor accessTime as int since it has been alleged corrupted values could be read if using a long.
Modified: trunk/java/org/apache/catalina/session/StandardSession.java
===================================================================
--- trunk/java/org/apache/catalina/session/StandardSession.java 2008-10-28 15:40:02 UTC (rev 819)
+++ trunk/java/org/apache/catalina/session/StandardSession.java 2008-10-28 15:41:35 UTC (rev 820)
@@ -204,7 +204,7 @@
/**
* The last accessed time for this Session.
*/
- protected long lastAccessedTime = creationTime;
+ protected int lastAccessedTime = 0;
/**
@@ -279,7 +279,7 @@
/**
* The current accessed time for this session.
*/
- protected long thisAccessedTime = creationTime;
+ protected int thisAccessedTime = 0;
/**
@@ -326,8 +326,8 @@
public void setCreationTime(long time) {
this.creationTime = time;
- this.lastAccessedTime = time;
- this.thisAccessedTime = time;
+ this.lastAccessedTime = 0;
+ this.thisAccessedTime = 0;
}
@@ -440,7 +440,7 @@
(sm.getString("standardSession.getLastAccessedTime.ise"));
}
- return (this.lastAccessedTime);
+ return (lastAccessedTime + creationTime);
}
/**
@@ -448,7 +448,7 @@
* @see #getLastAccessedTime().
*/
public long getLastAccessedTimeInternal() {
- return (this.lastAccessedTime);
+ return (lastAccessedTime + creationTime);
}
/**
@@ -586,8 +586,8 @@
}
if (maxInactiveInterval >= 0) {
- long timeNow = System.currentTimeMillis();
- int timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L);
+ int offset = (int) (System.currentTimeMillis() - creationTime);
+ int timeIdle = (offset - thisAccessedTime) / 1000;
if (timeIdle >= maxInactiveInterval) {
expire(true);
}
@@ -618,7 +618,7 @@
public void access() {
this.lastAccessedTime = this.thisAccessedTime;
- this.thisAccessedTime = System.currentTimeMillis();
+ this.thisAccessedTime = (int) (System.currentTimeMillis() - creationTime);
if (ACTIVITY_CHECK) {
accessCount.incrementAndGet();
@@ -861,7 +861,7 @@
creationTime = 0L;
expiring = false;
id = null;
- lastAccessedTime = 0L;
+ lastAccessedTime = 0;
maxInactiveInterval = -1;
notes.clear();
setPrincipal(null);
@@ -1420,11 +1420,11 @@
// Deserialize the scalar instance variables (except Manager)
authType = null; // Transient only
creationTime = ((Long) stream.readObject()).longValue();
- lastAccessedTime = ((Long) stream.readObject()).longValue();
+ lastAccessedTime = (int) (((Long) stream.readObject()).longValue() - creationTime);
maxInactiveInterval = ((Integer) stream.readObject()).intValue();
isNew = ((Boolean) stream.readObject()).booleanValue();
isValid = ((Boolean) stream.readObject()).booleanValue();
- thisAccessedTime = ((Long) stream.readObject()).longValue();
+ thisAccessedTime = (int) (((Long) stream.readObject()).longValue() - creationTime);
principal = null; // Transient only
// setId((String) stream.readObject());
id = (String) stream.readObject();
@@ -1483,11 +1483,11 @@
// Write the scalar instance variables (except Manager)
stream.writeObject(new Long(creationTime));
- stream.writeObject(new Long(lastAccessedTime));
+ stream.writeObject(new Long(creationTime + lastAccessedTime));
stream.writeObject(new Integer(maxInactiveInterval));
stream.writeObject(new Boolean(isNew));
stream.writeObject(new Boolean(isValid));
- stream.writeObject(new Long(thisAccessedTime));
+ stream.writeObject(new Long(creationTime + thisAccessedTime));
stream.writeObject(id);
if (manager.getContainer().getLogger().isDebugEnabled())
manager.getContainer().getLogger().debug
16 years, 2 months
JBossWeb SVN: r819 - trunk/java/org/apache/catalina/core.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2008-10-28 11:40:02 -0400 (Tue, 28 Oct 2008)
New Revision: 819
Modified:
trunk/java/org/apache/catalina/core/DefaultInstanceManager.java
Log:
- Add PAs to annotation processing.
Modified: trunk/java/org/apache/catalina/core/DefaultInstanceManager.java
===================================================================
--- trunk/java/org/apache/catalina/core/DefaultInstanceManager.java 2008-10-27 16:54:26 UTC (rev 818)
+++ trunk/java/org/apache/catalina/core/DefaultInstanceManager.java 2008-10-28 15:40:02 UTC (rev 819)
@@ -26,6 +26,7 @@
import java.util.Map;
import java.util.Properties;
import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException;
import java.io.InputStream;
@@ -46,6 +47,7 @@
import org.apache.InstanceManager;
import org.apache.catalina.security.SecurityUtil;
import org.apache.catalina.ContainerServlet;
+import org.apache.catalina.Globals;
import org.apache.catalina.core.Constants;
import org.apache.catalina.util.StringManager;
@@ -150,14 +152,24 @@
* @throws java.lang.reflect.InvocationTargetException
* if call fails
*/
- protected void postConstruct(Object instance, Class<?> clazz)
+ protected void postConstruct(Object instance, final Class<?> clazz)
throws IllegalAccessException, InvocationTargetException {
Class<?> superClass = clazz.getSuperclass();
if (superClass != Object.class) {
postConstruct(instance, superClass);
}
- Method[] methods = clazz.getDeclaredMethods();
+ Method[] methods = null;
+ if (Globals.IS_SECURITY_ENABLED) {
+ methods = AccessController.doPrivileged(
+ new PrivilegedAction<Method[]>(){
+ public Method[] run(){
+ return clazz.getDeclaredMethods();
+ }
+ });
+ } else {
+ methods = clazz.getDeclaredMethods();
+ }
Method postConstruct = null;
for (Method method : methods) {
if (method.isAnnotationPresent(PostConstruct.class)) {
@@ -249,7 +261,18 @@
while (clazz != null) {
// Initialize fields annotations
- Field[] fields = clazz.getDeclaredFields();
+ Field[] fields = null;
+ if (Globals.IS_SECURITY_ENABLED) {
+ final Class<?> clazz2 = clazz;
+ fields = AccessController.doPrivileged(
+ new PrivilegedAction<Field[]>(){
+ public Field[] run(){
+ return clazz2.getDeclaredFields();
+ }
+ });
+ } else {
+ fields = clazz.getDeclaredFields();
+ }
for (Field field : fields) {
if (injections != null && injections.containsKey(field.getName())) {
lookupFieldResource(context, instance, field,
@@ -281,7 +304,18 @@
}
// Initialize methods annotations
- Method[] methods = clazz.getDeclaredMethods();
+ Method[] methods = null;
+ if (Globals.IS_SECURITY_ENABLED) {
+ final Class<?> clazz2 = clazz;
+ methods = AccessController.doPrivileged(
+ new PrivilegedAction<Method[]>(){
+ public Method[] run(){
+ return clazz2.getDeclaredMethods();
+ }
+ });
+ } else {
+ methods = clazz.getDeclaredMethods();
+ }
for (Method method : methods) {
String methodName = method.getName();
if (injections != null && methodName.startsWith("set") && methodName.length() > 3) {
16 years, 2 months