in modules/core/src/main/java/org/apache/savan/atom/AtomSubscriptionProcessor.java [76:172]
public Subscriber getSubscriberFromMessage(SavanMessageContext smc) throws SavanException {
try {
ConfigurationManager configurationManager = (ConfigurationManager)smc
.getConfigurationContext().getProperty(SavanConstants.CONFIGURATION_MANAGER);
if (configurationManager == null)
throw new SavanException("Configuration Manager not set");
Protocol protocol = smc.getProtocol();
if (protocol == null)
throw new SavanException("Protocol not found");
SOAPEnvelope envelope = smc.getEnvelope();
if (envelope == null)
return null;
ServiceContext serviceContext = smc.getMessageContext().getServiceContext();
AtomDataSource dataSource =
(AtomDataSource)serviceContext.getProperty(AtomConstants.Properties.DataSource);
if (dataSource == null) {
dataSource = new AtomDataSource();
serviceContext.setProperty(AtomConstants.Properties.DataSource, dataSource);
}
String subscriberName = protocol.getDefaultSubscriber();
Subscriber subscriber = configurationManager.getSubscriberInstance(subscriberName);
if (!(subscriber instanceof AtomSubscriber)) {
String message =
"Savan only support implementations of Atom subscriber as Subscribers";
throw new SavanException(message);
}
//find the real path for atom feeds
File repositoryPath = smc.getConfigurationContext().getRealPath("/");
File realAtomPath = new File(repositoryPath.getAbsoluteFile(), "atom");
//Get the service URL from request
String serviceAddress = smc.getMessageContext().getTo().getAddress();
int cutIndex = serviceAddress.indexOf("services");
if (cutIndex > 0) {
serviceAddress = serviceAddress.substring(0, cutIndex - 1);
}
AtomSubscriber atomSubscriber = (AtomSubscriber)subscriber;
String id = UUIDGenerator.getUUID();
smc.setProperty(AtomConstants.TransferedProperties.SUBSCRIBER_UUID, id);
atomSubscriber.setId(new URI(id));
String atomFeedPath = id2Path(id);
atomSubscriber.setAtomFile(new File(realAtomPath, atomFeedPath));
atomSubscriber.setFeedUrl(serviceAddress + "/services/" + smc.getMessageContext()
.getServiceContext().getAxisService().getName() + "/atom?feed=" + atomFeedPath);
SOAPBody body = envelope.getBody();
CreateFeedDocument createFeedDocument =
CreateFeedDocument.Factory.parse(body.getFirstElement().getXMLStreamReader());
CreateFeed createFeed = createFeedDocument.getCreateFeed();
if (createFeed.getEndTo() != null) {
atomSubscriber.setEndToEPr(createFeed.getEndTo());
}
if (createFeed.getExpires() != null) {
atomSubscriber.setSubscriptionEndingTime(createFeed.getExpires().getTime());
}
if (createFeed.getFilter() != null) {
Filter filter = null;
String filterKey = createFeed.getFilter().getDialect();
filter = configurationManager.getFilterInstanceFromId(filterKey);
if (filter == null)
throw new SavanException("The Filter defined by the dialect is not available");
if (filter instanceof XPathBasedFilter) {
((XPathBasedFilter)filter)
.setXPathString(createFeed.getFilter().getStringValue());
} else {
throw new SavanException("Only Xpath fileters are supported");
}
atomSubscriber.setFilter(filter);
}
atomSubscriber
.init(dataSource, new URI(id), createFeed.getTitle(), createFeed.getAuthor());
smc.setProperty(AtomConstants.Properties.feedUrl, atomSubscriber.getFeedUrl());
return atomSubscriber;
} catch (AxisFault e) {
throw new SavanException(e);
} catch (OMException e) {
throw new SavanException(e);
} catch (XmlException e) {
throw new SavanException(e);
} catch (URISyntaxException e) {
throw new SavanException(e);
}
}