subscription.setEndpointUrl(ep);
subscription.setAddressUrl(notifyToElem.getFirstElement().getText().trim());
}
} else {
log.error("NotifyTo element not found in the subscription message.");
throw new InvalidMessageException(
"NotifyTo element not found in the subscription message.");
}
} else {
log.error("Delivery element is not found in the subscription message.");
throw new InvalidMessageException(
"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().trim());
} else {
log.error("Error in creating subscription. Filter dialect not defined.");
throw new BuilderException(
"Error in creating subscription. Filter dialect not defined.");
}
} else if (subscription == null) {
log.error("Error in creating subscription.");
throw new BuilderException("Error in creating subscription.");
}
OMElement expiryElem = elem.getFirstChildWithName(EXPIRES);
if (expiryElem != null) {
Calendar calendarExpires;
try {
String expiryText = expiryElem.getText().trim();
if (expiryText.startsWith("P")) {
calendarExpires = ConverterUtil.convertToDuration(expiryText)
.getAsCalendar();
} else {
calendarExpires = ConverterUtil.convertToDateTime(expiryText);
}
} catch (Exception e) {
log.error("Error converting the expiration date.", e);
throw new InvalidExpirationTimeException(
"Error converting the expiration date.", e);
}
Calendar calendarNow = Calendar.getInstance();
if (calendarNow.before(calendarExpires)) {
subscription.setExpires(calendarExpires);
} else {
log.error("The expiration time has passed.");
throw new InvalidExpirationTimeException("The expiration time has passed.");
}
}
} else {
log.error("Subscribe element is required as the payload of the subscription message.");
throw new InvalidMessageException(
"Subscribe element is required as the payload of the subscription message.");
}
return subscription;
}