[jboss-cvs] jboss-seam/src/main/org/jboss/seam/remoting ...
Shane Bryzak
Shane_Bryzak at symantec.com
Sun Oct 8 07:24:48 EDT 2006
User: sbryzak2
Date: 06/10/08 07:24:48
Modified: src/main/org/jboss/seam/remoting PollHandler.java
remote.js
Log:
Improved JMS exception handling
Revision Changes Path
1.6 +42 -10 jboss-seam/src/main/org/jboss/seam/remoting/PollHandler.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PollHandler.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/remoting/PollHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- PollHandler.java 4 Jul 2006 21:33:34 -0000 1.5
+++ PollHandler.java 8 Oct 2006 11:24:48 -0000 1.6
@@ -4,7 +4,6 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
-
import javax.faces.event.PhaseId;
import javax.jms.JMSException;
import javax.jms.Message;
@@ -21,10 +20,12 @@
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.jboss.seam.contexts.Lifecycle;
+import org.jboss.seam.remoting.messaging.PollError;
import org.jboss.seam.remoting.messaging.PollRequest;
import org.jboss.seam.remoting.wrapper.Wrapper;
/**
+ * Handles JMS Message poll requests.
*
* @author Shane Bryzak
*/
@@ -32,6 +33,17 @@
{
private static final Log log = LogFactory.getLog(SubscriptionHandler.class);
+ private static final byte[] ERRORS_TAG_OPEN_START = "<errors token=\"".getBytes();
+ private static final byte[] ERROR_TAG_OPEN_START = "<error code=\"".getBytes();
+ private static final byte[] ERROR_TAG_CLOSE = "</error>".getBytes();
+ private static final byte[] MESSAGES_TAG_OPEN_START = "<messages token=\"".getBytes();
+ private static final byte[] MESSAGES_TAG_CLOSE = "</messages>".getBytes();
+ private static final byte[] MESSAGE_TAG_OPEN = "<message type=\"".getBytes();
+ private static final byte[] MESSAGE_TAG_CLOSE = "</message>".getBytes();
+ private static final byte[] VALUE_TAG_OPEN = "<value>".getBytes();
+ private static final byte[] VALUE_TAG_CLOSE = "</value>".getBytes();
+ private static final byte[] TAG_OPEN_END = "".getBytes();
+
private ServletContext servletContext;
public void setServletContext(ServletContext ctx)
@@ -106,11 +118,21 @@
for (PollRequest req : reqs)
{
- if (req.getMessages() != null && req.getMessages().size() > 0)
+ if (req.getErrors() != null && req.getErrors().size() > 0)
{
- out.write("<messages token=\"".getBytes());
+ out.write(ERRORS_TAG_OPEN_START);
out.write(req.getToken().getBytes());
- out.write("\">".getBytes());
+ out.write(TAG_OPEN_END);
+ for (PollError err : req.getErrors())
+ {
+ writeError(err, out);
+ }
+ }
+ else if (req.getMessages() != null && req.getMessages().size() > 0)
+ {
+ out.write(MESSAGES_TAG_OPEN_START);
+ out.write(req.getToken().getBytes());
+ out.write(TAG_OPEN_END);
for (Message m : req.getMessages()) {
try {
writeMessage(m, out);
@@ -120,7 +142,7 @@
catch (IOException ex) {
}
}
- out.write("</messages>".getBytes());
+ out.write(MESSAGES_TAG_CLOSE);
}
}
@@ -132,7 +154,7 @@
private void writeMessage(Message m, OutputStream out)
throws IOException, JMSException
{
- out.write("<message type=\"".getBytes());
+ out.write(MESSAGE_TAG_OPEN);
// We need one of these to maintain a list of outbound references
CallContext ctx = new CallContext();
@@ -149,11 +171,11 @@
value = ((ObjectMessage) m).getObject();
}
- out.write("\">".getBytes());
+ out.write(TAG_OPEN_END);
- out.write("<value>".getBytes());
+ out.write(VALUE_TAG_OPEN);
ctx.createWrapperFromObject(value, "").marshal(out);
- out.write("</value>".getBytes());
+ out.write(VALUE_TAG_CLOSE);
out.write(REFS_TAG_OPEN);
@@ -173,6 +195,16 @@
out.write(REFS_TAG_CLOSE);
- out.write("</message>".getBytes());
+ out.write(MESSAGE_TAG_CLOSE);
+ }
+
+ private void writeError(PollError error, OutputStream out)
+ throws IOException
+ {
+ out.write(ERROR_TAG_OPEN_START);
+ out.write(error.getCode().getBytes());
+ out.write(TAG_OPEN_END);
+ out.write(error.getMessage().getBytes());
+ out.write(ERROR_TAG_CLOSE);
}
}
1.20 +32 -0 jboss-seam/src/main/org/jboss/seam/remoting/remote.js
(In the diff below, changes in quantity of whitespace are not shown.)
Index: remote.js
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/remoting/remote.js,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- remote.js 5 Jul 2006 03:13:52 -0000 1.19
+++ remote.js 8 Oct 2006 11:24:48 -0000 1.20
@@ -970,6 +970,8 @@
var node = body.childNodes.item(i);
if (node.tagName == "messages")
Seam.Remoting.processMessages(node);
+ else if (node.tagName == "errors")
+ Seam.Remoting.processPollErrors(node);
}
Seam.Remoting.pollTimeoutFunction = setTimeout("Seam.Remoting.poll()", Math.max(Seam.Remoting.pollInterval * 1000, 1000));
@@ -1024,6 +1026,36 @@
}
}
+Seam.Remoting.processErrors = function(errors)
+{
+ var token = errors.getAttribute("token");
+
+ // Unsubscribe to the topic
+ for (var i = 0; i < Seam.Remoting.subscriptionRegistry.length; i++)
+ {
+ if (Seam.Remoting.subscriptionRegistry[i].token == token)
+ {
+ Seam.Remoting.subscriptionRegistry.splice(i, 1);
+ break;
+ }
+ }
+
+ for (var i = 0; i < errors.childNodes.length; i++)
+ {
+ if (errors.childNodes.item(i).tagName == "error")
+ {
+ var errorNode = errors.childNodes.item(i);
+ var code = errorNode.getAttribute("code");
+ var message = errorNode.firstChild.nodeValue;
+
+ if (Seam.Remoting.onPollError)
+ Seam.Remoting.onPollError(code, message);
+ else
+ alert("A polling error occurred: " + code + " " + message);
+ }
+ }
+}
+
Seam.Remoting.ObjectMessage = function()
{
this.value = null;
More information about the jboss-cvs-commits
mailing list