if (!hasTopic(topic))
throw new TopicNotSupportedFault("Topic not found: " + topic);
}
WsResource producer = getWsResource();
ResourceManager manager = producer.getResourceManager();
//
// create the resource to represent the subscription
//
String endpoint = getSubscriptionContextPath();
WsResource sub = null;
try
{
sub = (WsResource)manager.createResource(endpoint);
}
catch (SoapFault error)
{
throw new SubscribeCreationFailedFault(error);
}
//
// use the subscription capability to set all the subscription fields
//
SubscriptionManager subMgr =
(SubscriptionManager)sub.getCapability(WsnConstants.SUBSCRIPTION_MGR_URI);
EndpointReference producerEPR = producer.getEndpointReference();
subMgr.setProducerReference(producerEPR);
subMgr.setConsumerReference(consumer);
subMgr.setFilter(filter);
subMgr.setSubscriptionPolicy(policy);
try
{
sub.initialize();
manager.addResource(sub.getEndpointReference(), sub);
}
catch (SoapFault error)
{
throw new SubscribeCreationFailedFault(error);
}
//
// set termination time AFTER we initialize so that we can rely
// on the base Resource class' implementation of WS-RL (which
// tries to apply the change immediately, rather than storing it
// in a field and setting it during initialization)
//
if (sub.hasCapability(WsrlConstants.SCHEDULED_TERMINATION_URI))
{
ScheduledTermination wsrl = (ScheduledTermination)sub.getCapability(WsrlConstants.SCHEDULED_TERMINATION_URI);
try
{
wsrl.setTerminationTime(terminationTime);
}