throws InvalidMessageException, InvalidExpirationTimeException {
Subscription subscription = null;
OMElement notifyToElem;
if (envelope == null) {
log.error("No SOAP envelope was provided.");
throw new BuilderException("No SOAP envelope was provided.");
}
OMElement elem = null;
if (envelope.getBody() != null) {
elem = envelope.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) {
String ep = BuilderUtils.getEndpointFromWSAAddress(
notifyToElem.getFirstElement());
if (ep != null) {
subscription = new Subscription();
subscription.setEventSinkURL(ep);
}
} 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 dialectAttribute = filterElem.getAttribute(ATT_DIALECT);
if (dialectAttribute != null && dialectAttribute.getAttributeValue() != null) {
subscription.setEventFilter(
new EventFilter(dialectAttribute.getAttributeValue(),
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 {