*
* @param mc The MessageContext from which to create the SynapseSubscription
* @return The SynapseSubscription
*/
public static SynapseSubscription createSubscription(MessageContext mc) {
SynapseSubscription subscription = null;
OMElement notifyToElem;
OMElement elem = mc.getEnvelope().getBody().getFirstChildWithName(SUBSCRIBE_QNAME);
if (elem != null) {
OMElement deliveryElem = elem.getFirstChildWithName(DELIVERY_QNAME);
if (deliveryElem != null) {
notifyToElem = deliveryElem.getFirstChildWithName(NOTIFY_TO_QNAME);
if (notifyToElem != null) {
subscription = new SynapseSubscription(
EventingConstants.WSE_DEFAULT_DELIVERY_MODE);
subscription.setAddressUrl(notifyToElem.getFirstElement().getText());
subscription.setEndpointUrl(notifyToElem.getFirstElement().getText());
subscription.setSubManUrl(mc.getTo().getAddress());
} else {
handleException("NotifyTo element not found in the subscription message");
}
} else {
handleException("Delivery element is not found in the subscription message");
}
OMElement filterElem = elem.getFirstChildWithName(FILTER_QNAME);
if (subscription != null && filterElem != null) {
OMAttribute dialectAttr = filterElem.getAttribute(ATT_DIALECT);
if (dialectAttr != null && dialectAttr.getAttributeValue() != null) {
subscription.setFilterDialect(dialectAttr.getAttributeValue());
subscription.setFilterValue(filterElem.getText());
} else {
handleException("Error in creating subscription. Filter dialect not defined");
}
}
OMElement expiryElem = elem.getFirstChildWithName(EXPIRES);
if (expiryElem != null) {
Calendar calendarExpires = null;
try {
if (expiryElem.getText().startsWith("P")) {
calendarExpires = ConverterUtil.convertToDuration(expiryElem.getText())
.getAsCalendar();
} else {
calendarExpires = ConverterUtil.convertToDateTime(expiryElem.getText());
}
} catch (Exception e) {
log.error("Error converting the expiration date ," + e.toString());
setExpirationFault(subscription);
}
Calendar calendarNow = Calendar.getInstance();
if ((isValidDate(expiryElem.getText(), calendarExpires)) &&
(calendarNow.before(calendarExpires))) {
subscription.setExpires(calendarExpires);
} else {
setExpirationFault(subscription);
}
}
} else {