1 23 24 package org.apache.slide.webdav.method; 25 26 import org.apache.slide.common.NamespaceAccessToken; 27 import org.apache.slide.event.EventDispatcher; 28 import org.apache.slide.webdav.WebdavException; 29 import org.apache.slide.webdav.WebdavServletConfig; 30 import org.apache.slide.webdav.event.NotificationTrigger; 31 import org.apache.slide.webdav.event.Subscriber; 32 import org.apache.slide.webdav.event.WebdavEvent; 33 import org.apache.slide.webdav.util.NotificationConstants; 34 import org.apache.slide.webdav.util.WebdavStatus; 35 36 37 41 public class SubscribeMethod extends AbstractWebdavMethod implements NotificationConstants { 42 protected static final String LOG_CHANNEL = SubscribeMethod.class.getName(); 43 44 private final static int DEFAULT_SUBSCRIPTION_LIFETIME = 3600; 45 46 52 public SubscribeMethod(NamespaceAccessToken token, 53 WebdavServletConfig config) { 54 super(token, config); 55 } 56 57 protected void parseRequest() throws WebdavException { 58 } 59 60 protected void executeRequest() throws WebdavException { 61 try { 62 if ( WebdavEvent.SUBSCRIBE.isEnabled() ) EventDispatcher.getInstance().fireVetoableEvent(WebdavEvent.SUBSCRIBE, new WebdavEvent(this)); 63 String contentType = requestHeaders.getContentType(); 64 String callback = requestHeaders.getCallback(); 65 String notificationType = requestHeaders.getNotificationType(); 66 int notificationDelay = requestHeaders.getNotificationDelay(0); 67 int subscriptionLifetime = requestHeaders.getSubscriptionLifetime(DEFAULT_SUBSCRIPTION_LIFETIME); 68 int depth = requestHeaders.getDepth(INFINITY); 69 int []subscriptionIDs = requestHeaders.getSubscriptionId(); 70 71 if ( subscriptionIDs.length > 0 ) { 72 for ( int i = 0; i < subscriptionIDs.length; i++ ) { 74 Subscriber subscriber = NotificationTrigger.getInstance().getSubscriber(subscriptionIDs[i]); 75 if ( subscriber != null ) { 76 NotificationTrigger.getInstance().refreshSubscriber(subscriber, true); 77 } 78 } 79 } else { 80 if (notificationType == null) { 81 sendError(WebdavStatus.SC_BAD_REQUEST, "Notification-Type header missing."); 82 return; 83 } else { 84 } 86 Subscriber subscriber = new Subscriber(requestUri, callback, notificationType, notificationDelay, 87 subscriptionLifetime, depth); 88 int subscriptionID = NotificationTrigger.getInstance().addSubscriber(subscriber); 89 resp.setHeader(H_CALL_BACK, callback); 90 resp.setHeader(H_NOTIFICATION_TYPE, notificationType); 91 resp.setHeader(H_SUBSCRIPTION_LIFETIME, String.valueOf(subscriptionLifetime)); 92 resp.setHeader(H_SUBSCRIPTION_ID, String.valueOf(subscriptionID)); 93 resp.setHeader(H_CONTENT_LOCATION, 94 getSlideContextPath() + requestUri); 95 resp.setStatus(WebdavStatus.SC_OK); 96 } 97 } catch (Exception e) { 98 int statusCode = getErrorCode( (Exception )e ); 99 sendError( statusCode, e ); 100 throw new WebdavException( statusCode ); 101 } 102 } 103 } | Popular Tags |