return;
}
try {
String actionType = Util.getParameter(req, "ActionType", "NONE");
MethodName action;
try {
action = MethodName.toMethodName(actionType);
}
catch (IllegalArgumentException ie) {
throw new Exception("Unknown or missing 'ActionType=" + actionType + "' please choose 'subscribe' 'unSubscribe' 'erase' etc.");
}
// Extract the message data
String oid = Util.getParameter(req, "key.oid", null);
if (oid != null) oid = Global.decode(oid, ENCODING);
String key = Util.getParameter(req, "key", null);
if (key != null) {
key = Global.decode(key, ENCODING);
if (log.isLoggable(Level.FINEST)) log.finest("key=\n'" + key + "'");
}
String content = Util.getParameter(req, "content", null);
if (content != null) {
content = Global.decode(content, ENCODING);
}
else
content = "";
if (log.isLoggable(Level.FINEST)) log.finest("content=\n'" + content + "'");
String qos = Util.getParameter(req, "qos", null);
if (qos != null) {
qos = Global.decode(qos, ENCODING);
}
else
qos = "";
if (log.isLoggable(Level.FINEST)) log.finest("qos=\n'" + qos + "'");
if (action.equals(MethodName.SUBSCRIBE)) { // "subscribe"
log.fine("subscribe arrived ...");
if (oid != null) {
SubscribeKey xmlKey = new SubscribeKey(glob, oid);
SubscribeReturnQos ret = xmlBlaster.subscribe(xmlKey.toXml(), qos);
log.info("Subscribed to simple key.oid=" + oid + ": " + ret.getSubscriptionId());
}
else if (key != null) {
SubscribeReturnQos ret = xmlBlaster.subscribe(key, qos);
log.info("Subscribed to " + key + ": SubscriptionId=" + ret.getSubscriptionId() + " qos=" + qos);
}
else {
String str = "Please call servlet with some 'key.oid=...' or 'key=<key ...' when subscribing";
log.severe(str);
htmlOutput(str, res);
return;
}
}
else if (action.equals(MethodName.UNSUBSCRIBE)) { // "unSubscribe"
log.fine("unSubscribe arrived ...");
//UnSubscribeReturnQos[] ret;
if (oid != null) {
UnSubscribeKey xmlKey = new UnSubscribeKey(glob, oid);
/*ret = */xmlBlaster.unSubscribe(xmlKey.toXml(), qos);
}
else if (key != null) {
/*ret = */xmlBlaster.unSubscribe(key, qos);
}
else {
String str = "Please call servlet with some 'key.oid=...' or 'key=<key ...' when unsubscribing";
log.severe(str);
htmlOutput(str, res);
return;
}
}
else if (action.equals(MethodName.GET)) { // "get"
throw new Exception("Synchronous ActionType=get is not supported");
}
else if (action.equals(MethodName.PUBLISH)) { // "publish"
log.fine("publish arrived ...");
if (key == null) {
String str = "Please call servlet with some key when publishing";
log.severe(str);
htmlOutput(str, res);
return;
}
if (content == null)
content = "";
log.info("Publishing '" + key + "'");
MsgUnit msgUnit = new MsgUnit(glob, key, content.getBytes(), qos);
try {
PublishReturnQos prq = xmlBlaster.publish(msgUnit);
log.fine("Success: Publishing done, returned oid=" + prq.getKeyOid());
} catch(XmlBlasterException e) {
log.warning("XmlBlasterException: " + e.getMessage());
}
}
else if (action.equals(MethodName.ERASE)) { // "erase"
log.fine("erase arrived ...");
//EraseReturnQos[] ret;
if (oid != null) {
EraseKey ek = new EraseKey(glob, oid);
/*ret =*/ xmlBlaster.erase(ek.toXml(), qos);
}
else if (key != null) {
/*ret =*/ xmlBlaster.erase(key, qos);
}
else {
String str = "Please call servlet with some 'key.oid=...' or 'key=<key ...' when subscribing";
log.severe(str);
htmlOutput(str, res);
return;
}
}
else if (action.equals(MethodName.PING)) { // "ping"
log.fine("ping arrived, doing nothing ...");
//String ret = xmlBlaster.ping(qos);
}
else {