subscribe.getApplicationSession().invalidate();
return;
}
}
WatcherResource resource = _watcherInfo.get(uri);
String subscriberUri = null;
if (subscribe.getAddressHeader(Constants.P_ASSERTED_IDENTITY) != null)
subscriberUri = URIUtil.toCanonical(subscribe.getAddressHeader(Constants.P_ASSERTED_IDENTITY).getURI());
else
subscriberUri = URIUtil.toCanonical(subscribe.getFrom().getURI());
try
{
Subscription subscription = null;
if (expires == 0)
{
subscription = resource.removeSubscription(session.getId());
if (subscription == null)
subscription = new Subscription(resource, session, -1, subscriberUri);
else
{
subscription.setExpirationTime(System.currentTimeMillis());
if (_log.isDebugEnabled())
_log.debug("removed presence.winfo subscription {} to resource {}",
subscription.getSession().getId(), resource.getUri());
}
subscription.setState(Subscription.State.TERMINATED, Reason.TIMEOUT);
}
else
{
long now = System.currentTimeMillis();
subscription = resource.getSubscription(session.getId());
if (subscription == null)
{
subscription = new Subscription(resource, session, now + expires*1000, subscriberUri);
subscription.setState(State.ACTIVE, Reason.SUBSCRIBE);
resource.addSubscription(subscription);
session.setAttribute(Constants.SUBSCRIPTION_ATTRIBUTE, uri);
if (_log.isDebugEnabled())
_log.debug("added presence.winfo subscription {} to resource {}",
subscription.getSession().getId(), resource.getUri());
}
else
{
subscription.setExpirationTime(now + expires * 1000);
if (_log.isDebugEnabled())
_log.debug("refreshed presence.winfo subscription {} to resource {}",
subscription.getSession().getId(), resource.getUri());
}
}
int code = (subscription.getState() != Subscription.State.PENDING) ?
SipServletResponse.SC_OK : SipServletResponse.SC_ACCEPTED;