InvalidExpirationTimeException {
if (envelope == null) {
log.error("No SOAP envelope was provided.");
throw new BuilderException("No SOAP envelope was provided.");
}
Subscription subscription = new CarbonSubscription();
OMElement elem = null;
if (envelope.getHeader() != null) {
elem = envelope.getHeader().getFirstChildWithName(IDENTIFIER);
}
if (elem == null) {
log.error(
"Subscription Identifier is required as a header of the subscription message.");
throw new InvalidMessageException(
"Subscription Identifier is required as a header of the subscription message.");
}
String id = elem.getText().trim();
subscription.setId(id);
OMElement renewElem = envelope.getBody().getFirstChildWithName(RENEW);
if (renewElem != null) {
OMElement expiryElem = renewElem.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");
}
subscription.setExpires(calendarExpires);
} else {
log.error("The expiration time was not given");
throw new InvalidExpirationTimeException("The expiration time was not given");
}
}