dflorey 2004/04/26 04:40:58
Modified: src/webdav/server/org/apache/slide/webdav/event
Subscriber.java NotificationTrigger.java
Log:
Added UDP notification for improved MS-Exchange compliance
Revision Changes Path
1.5 +7 -7
jakarta-slide/src/webdav/server/org/apache/slide/webdav/event/Subscriber.java
Index: Subscriber.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/event/Subscriber.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Subscriber.java 10 Mar 2004 18:10:04 -0000 1.4
+++ Subscriber.java 26 Apr 2004 11:40:58 -0000 1.5
@@ -39,13 +39,13 @@
public class Subscriber {
protected static final String LOG_CHANNEL = Subscriber.class.getName();
- private URL callback;
+ private String callback;
private String notificationType, uri;
private int depth, notificationDelay, subscriptionLifetime, id;
private List events = new ArrayList();
private TimerTask lifetime, notify;
- public Subscriber(String uri, String contentType, URL callback, String
notificationType, int notificationDelay, int subscriptionLifetime, int depth) {
+ public Subscriber(String uri, String contentType, String callback, String
notificationType, int notificationDelay, int subscriptionLifetime, int depth) {
this.callback = callback;
this.notificationType = notificationType;
this.notificationDelay = notificationDelay;
@@ -91,7 +91,7 @@
return matching;
}
- public URL getCallback() {
+ public String getCallback() {
return callback;
}
1.9 +31 -16
jakarta-slide/src/webdav/server/org/apache/slide/webdav/event/NotificationTrigger.java
Index: NotificationTrigger.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/webdav/server/org/apache/slide/webdav/event/NotificationTrigger.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- NotificationTrigger.java 22 Apr 2004 16:38:14 -0000 1.8
+++ NotificationTrigger.java 26 Apr 2004 11:40:58 -0000 1.9
@@ -34,7 +34,7 @@
import org.apache.slide.webdav.util.NotificationConstants;
import java.io.IOException;
-import java.net.URL;
+import java.net.*;
import java.util.*;
/**
@@ -44,21 +44,26 @@
public class NotificationTrigger implements NotificationConstants,
EventCollectionListener, Configurable {
protected static final String LOG_CHANNEL = NotificationTrigger.class.getName();
private final static String A_INCLUDE_EVENTS = "include-events";
- private final static String A_PROTOCOL = "protocol";
- private final static String TCP = "tcp";
- private final static String UDP = "udp";
+ private final static String TCP_PROTOCOL = "http://";
+ private final static String UDP_PROTOCOL = "httpu://";
protected static final Timer timer = new Timer();
protected List subscribers = new ArrayList();
protected int subscriberId = 0;
- protected String protocol = TCP;
protected boolean includeEvents = false;
+ protected DatagramSocket socket;
private static NotificationTrigger notificationTrigger = new
NotificationTrigger();
private NotificationTrigger() {
Domain.log("Creating notification trigger", LOG_CHANNEL, Logger.INFO);
+ try {
+ socket = new DatagramSocket();
+ } catch ( SocketException exception ) {
+ Domain.log("Server socket creation failed, no UDP notifications
available", LOG_CHANNEL, Logger.ERROR);
+ socket = null;
+ }
}
public static NotificationTrigger getInstance() {
@@ -155,7 +160,7 @@
}
for ( Iterator i = subscriberEnumerations.entrySet().iterator();
i.hasNext(); ) {
Map.Entry entry = (Map.Entry)i.next();
- URL callBack = (URL)entry.getKey();
+ String callBack = (String)entry.getKey();
List idList = (List)entry.getValue();
StringBuffer subscriberBuffer = new StringBuffer(128);
boolean firstSubscriber = true;
@@ -173,18 +178,29 @@
}
}
- private void notifySubscriber(URL callback, String subscribers) {
- if ( protocol.equals(TCP) ) {
+ private void notifySubscriber(String callback, String subscribers) {
+ if ( callback.startsWith(TCP_PROTOCOL) ) {
Domain.log("Notify subscribers with adress='"+callback+"' via TCP with
id's "+subscribers, LOG_CHANNEL, Logger.INFO);
NotifyMethod notifyMethod = new NotifyMethod(callback.toString());
notifyMethod.addRequestHeader(H_SUBSCRIPTION_ID_RESPONSE, subscribers);
try {
- int state = notifyMethod.execute(new HttpState(), new
HttpConnection(callback.getHost(), callback.getPort()));
+ URL url = new URL(callback);
+ int state = notifyMethod.execute(new HttpState(), new
HttpConnection(url.getHost(), url.getPort()));
} catch (IOException e) {
Domain.log("Notification of subscriber '"+callback.toString()+"'
failed!");
}
- } else if ( protocol.equals(TCP) ) {
- Domain.log("UDP not yet implemented...");
+ } else if ( callback.startsWith(UDP_PROTOCOL) && socket != null ) {
+ Domain.log("Notify subscribers with adress='"+callback+"' via UDP with
id's "+subscribers+"\n", LOG_CHANNEL, Logger.INFO);
+ try {
+ URL url = new
URL(TCP_PROTOCOL+callback.substring(UDP_PROTOCOL.length()));
+ String notification = "NOTIFY "+callback+"
HTTP/1.1\nSubscription-id: "+subscribers;
+ byte[] buf = notification.getBytes();
+ InetAddress address = InetAddress.getByName(url.getHost());
+ DatagramPacket packet = new DatagramPacket(buf, buf.length,
address, url.getPort());
+ socket.send(packet);
+ } catch (IOException e) {
+ Domain.log("Notification of subscriber '"+callback.toString()+"'
failed!", LOG_CHANNEL, Logger.ERROR);
+ }
}
}
@@ -202,7 +218,6 @@
public void configure(Configuration configuration) throws
ConfigurationException {
Configuration notification = configuration.getConfiguration("notification");
- protocol = notification.getAttribute(A_PROTOCOL, TCP);
includeEvents = notification.getAttributeAsBoolean(A_INCLUDE_EVENTS, false);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]