dflorey     2004/08/09 03:03:52

  Modified:    webdavclient/clientlib/src/java/org/apache/webdav/lib
                        NotificationListener.java
  Log:
  fixed bugs #30528-#30530
  
  Revision  Changes    Path
  1.6       +29 -11    
jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/NotificationListener.java
  
  Index: NotificationListener.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/NotificationListener.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- NotificationListener.java 9 Aug 2004 04:53:24 -0000       1.5
  +++ NotificationListener.java 9 Aug 2004 10:03:52 -0000       1.6
  @@ -68,10 +68,13 @@
   
       protected static final Timer timer = new Timer();
   
  +    private final static int CONNECTION_TIMEOUT = 30000;
  +    
       private String notificationHost, repositoryHost, repositoryDomain;
       private int notificationPort, repositoryPort;
       private Protocol protocol;
       private Credentials credentials;
  +    private boolean udp = true;
       
       private List subscribers = new ArrayList();
       private String subscribersAsString;
  @@ -96,7 +99,8 @@
           this.repositoryPort = repositoryPort;
           this.protocol = protocol;
           this.repositoryDomain = repositoryDomain;
  -
  +        this.udp = udp;
  +        
           if ( udp ) {
               Thread listenerThread = new Thread(new Runnable() {
                   public void run() {
  @@ -159,14 +163,19 @@
        *                          (in seconds)
        * @param listener the Subscriber that is called on incomming notifications
        * @param credentials credentials for authentication on the server observed
  +     * @return boolean true if subscription succeeded, false if subscription failed
        *
        * @see WebdavResource#subscribeMethod
        * @see 
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/e2k3/e2k3/_webdav_subscribe.asp
        */
  -    public void subscribe(String method, String uri, int depth, int lifetime, int 
notificationDelay, Subscriber listener, Credentials credentials) {
  +    public boolean subscribe(String method, String uri, int depth, int lifetime, 
int notificationDelay, Subscriber listener, Credentials credentials) {
           SubscribeMethod subscribeMethod = new SubscribeMethod(repositoryDomain+uri);
           subscribeMethod.addRequestHeader(SubscribeMethod.H_NOTIFICATION_TYPE, 
method);
  -        subscribeMethod.addRequestHeader(SubscribeMethod.H_CALL_BACK, 
"httpu://"+notificationHost+":"+notificationPort);
  +        if ( udp ) {
  +             subscribeMethod.addRequestHeader(SubscribeMethod.H_CALL_BACK, 
"httpu://"+notificationHost+":"+notificationPort);
  +        } else {
  +             subscribeMethod.addRequestHeader(SubscribeMethod.H_CALL_BACK, 
"http://"+notificationHost+":"+notificationPort);
  +        }
           subscribeMethod.addRequestHeader(SubscribeMethod.H_NOTIFICATION_DELAY, 
String.valueOf(notificationDelay));
           subscribeMethod.addRequestHeader(SubscribeMethod.H_SUBSCRIPTION_LIFETIME, 
String.valueOf(lifetime));
           subscribeMethod.addRequestHeader(SubscribeMethod.H_DEPTH, 
String.valueOf(depth));
  @@ -174,7 +183,9 @@
               subscribeMethod.setDoAuthentication(true);
               HttpState httpState = new HttpState();
               httpState.setCredentials(null, repositoryHost, credentials);
  -            int state = subscribeMethod.execute(httpState, new 
HttpConnection(repositoryHost, repositoryPort, protocol));
  +            HttpConnection httpConnection = new HttpConnection(repositoryHost, 
repositoryPort, protocol);
  +            httpConnection.setConnectionTimeout(CONNECTION_TIMEOUT);
  +            int state = subscribeMethod.execute(httpState, httpConnection);
               if ( state == HttpStatus.SC_OK ) {
                   String subscriptionId = 
subscribeMethod.getResponseHeader(SubscribeMethod.H_SUBSCRIPTION_ID).getValue();
                   logger.log(Level.INFO, "Received subscription 
id="+subscriptionId+", listener: "+listener);
  @@ -185,15 +196,17 @@
                   } else {
                       subscribersAsString = subscribersAsString + ", 
"+String.valueOf(id);
                   }
  +                return true;
               } else {
                   logger.log(Level.SEVERE, "Subscription for uri='"+uri+"' failed. 
State: "+state);
               }
           } catch (IOException e) {
               logger.log(Level.SEVERE, "Subscription of listener '"+listener+"' 
failed!", e);
           }
  +        return false;
       }
   
  -    public void unsubscribe(String uri, Subscriber listener, Credentials 
credentials) {
  +    public boolean unsubscribe(String uri, Subscriber listener, Credentials 
credentials) {
           UnsubscribeMethod unsubscribeMethod = new 
UnsubscribeMethod(repositoryDomain+uri);
                for ( Iterator i = subscribers.iterator(); i.hasNext(); ) {
                        Subscription subscription = (Subscription)i.next();
  @@ -204,10 +217,12 @@
                                        unsubscribeMethod.setDoAuthentication(true);
                                        HttpState httpState = new HttpState();
                                        httpState.setCredentials(null, repositoryHost, 
credentials);
  -                                     int state = 
unsubscribeMethod.execute(httpState, new HttpConnection(repositoryHost, 
repositoryPort, protocol));
  +                         HttpConnection httpConnection = new 
HttpConnection(repositoryHost, repositoryPort, protocol);
  +                         httpConnection.setConnectionTimeout(CONNECTION_TIMEOUT);
  +                                     int state = 
unsubscribeMethod.execute(httpState, httpConnection);
                                        if ( state == HttpStatus.SC_OK ) {
                                                i.remove();
  -                                             return;
  +                                             return true;
                                        } else {
                                                logger.log(Level.SEVERE, 
"Unsubscription failed. State: "+state);
                                        }
  @@ -217,6 +232,7 @@
                        }
                }
                logger.log(Level.SEVERE, "Listener not unsubscribed!");
  +             return false;
       }
   
       public void fireEvent(Map information, Credentials credentials) throws 
IOException  {
  @@ -273,7 +289,9 @@
                   pollMethod.setDoAuthentication(true);
                   HttpState httpState = new HttpState();
                   httpState.setCredentials(null, repositoryHost, credentials);
  -                int state = pollMethod.execute(httpState, new 
HttpConnection(repositoryHost, repositoryPort, protocol));
  +                 HttpConnection httpConnection = new HttpConnection(repositoryHost, 
repositoryPort, protocol);
  +                 httpConnection.setConnectionTimeout(CONNECTION_TIMEOUT);
  +                int state = pollMethod.execute(httpState, httpConnection);
                   if ( state == HttpStatus.SC_MULTI_STATUS ) {
                       List events = pollMethod.getEvents();
                       for ( Iterator i = events.iterator(); i.hasNext(); ) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to