[Bedework-commit] synch r25 - in trunk: . common/src/org/bedework/synch common/src/org/bedework/synch/cnctrs common/src/org/bedework/synch/cnctrs/bedework common/src/org/bedework/synch/cnctrs/exchange common/src/org/bedework/synch/cnctrs/exchange/responses common/src/org/bedework/synch/cnctrs/file resources/hibernate/hbms

svnadmin at bedework.org svnadmin at bedework.org
Tue Aug 23 15:42:28 EDT 2011


Author: douglm
Date: 2011-08-23 15:42:26 -0400 (Tue, 23 Aug 2011)
New Revision: 25

Added:
   trunk/common/src/org/bedework/synch/cnctrs/ConnectorCache.java
Modified:
   trunk/.classpath
   trunk/build.xml
   trunk/common/src/org/bedework/synch/CalWsHelper.java
   trunk/common/src/org/bedework/synch/SubscriptionConnectorInfo.java
   trunk/common/src/org/bedework/synch/SynchConfig.java
   trunk/common/src/org/bedework/synch/SynchConnector.java
   trunk/common/src/org/bedework/synch/SynchEngine.java
   trunk/common/src/org/bedework/synch/Synchling.java
   trunk/common/src/org/bedework/synch/cnctrs/Connector.java
   trunk/common/src/org/bedework/synch/cnctrs/ConnectorInstanceMap.java
   trunk/common/src/org/bedework/synch/cnctrs/ConnectorPropertyInfo.java
   trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkConnector.java
   trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkConnectorInstance.java
   trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkSubscriptionInfo.java
   trunk/common/src/org/bedework/synch/cnctrs/exchange/ExchangeConnector.java
   trunk/common/src/org/bedework/synch/cnctrs/exchange/XmlIcalConvert.java
   trunk/common/src/org/bedework/synch/cnctrs/exchange/responses/ExchangeResponse.java
   trunk/common/src/org/bedework/synch/cnctrs/file/FileConnector.java
   trunk/common/src/org/bedework/synch/cnctrs/file/FileConnectorInstance.java
   trunk/common/src/org/bedework/synch/cnctrs/file/FileSubscriptionInfo.java
   trunk/resources/hibernate/hbms/Subscription.hbm.xml
Log:
added a file connector to synch 

ical4j to xml conversion added to rpiutil.

Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/.classpath	2011-08-23 19:42:26 UTC (rev 25)
@@ -19,5 +19,7 @@
 	<classpathentry kind="lib" path="lib/spring-core-3.0.5.RELEASE.jar"/>
 	<classpathentry kind="lib" path="/bedework/projects/rpiutil/dist/rpiutil-3.7.jar" sourcepath="/bedework/projects/rpiutil/src"/>
 	<classpathentry kind="lib" path="lib/commons-codec-1.5.jar"/>
+	<classpathentry kind="lib" path="lib/bw-davio-3.7.jar"/>
+	<classpathentry kind="lib" path="lib/commons-httpclient-3.0.jar"/>
 	<classpathentry kind="output" path="bin/synch-trunk"/>
 </classpath>

Modified: trunk/build.xml
===================================================================
--- trunk/build.xml	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/build.xml	2011-08-23 19:42:26 UTC (rev 25)
@@ -96,6 +96,7 @@
               value="org.bedework.appjar" />
     
     <getJar name="commons-codec" version="1.5" />
+    <getJar name="commons-httpclient" version="3.0" />
     <getJar name="log4j" version="1.2.8" />
     <getJar name="servletapi" version="2.4" />
     <getJar name="ical4j" version="1.0-rc3-SNAPSHOT" />
@@ -115,6 +116,10 @@
             project="bwxml"
             projecthome="${project.home}/../bwxml" />
     
+    <getJar name="bw-davio" version="${org.bedework.davutil.version}" 
+            project="davutil"
+            projecthome="${project.home}/../bedework/projects/davutil" />
+    
     <getJar name="rpiutil" version="${org.bedework.rpiutil.version}" 
             project="rpiutil"
             projecthome="${project.home}/../bedework/projects/rpiutil" />

Modified: trunk/common/src/org/bedework/synch/CalWsHelper.java
===================================================================
--- trunk/common/src/org/bedework/synch/CalWsHelper.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/CalWsHelper.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -19,7 +19,6 @@
 package org.bedework.synch;
 
 import org.apache.log4j.Logger;
-import org.oasis_open.docs.ns.wscal.calws_soap.ObjectFactory;
 import org.w3c.dom.Document;
 
 import java.io.ByteArrayInputStream;
@@ -46,8 +45,6 @@
 public class CalWsHelper {
   protected transient Logger log;
 
-  private ObjectFactory calwsOf = new ObjectFactory();
-
   private MessageFactory soapMsgFactory;
 
   /** Trace a calws SOAP message
@@ -82,6 +79,12 @@
     trace(wtr.toString());
   }
 
+  /**
+   * @param o
+   * @param jaxbContextPath
+   * @return SOAPMessage
+   * @throws Throwable
+   */
   public SOAPMessage marshal(final Object o,
                                 final String jaxbContextPath) throws Throwable {
     if (soapMsgFactory == null) {

Modified: trunk/common/src/org/bedework/synch/SubscriptionConnectorInfo.java
===================================================================
--- trunk/common/src/org/bedework/synch/SubscriptionConnectorInfo.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/SubscriptionConnectorInfo.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -23,6 +23,8 @@
 import edu.rpi.sss.util.Util;
 
 import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
 import java.util.Properties;
 
 /** Serializable form of information for a connection to a system via a
@@ -37,6 +39,9 @@
 
   /* Loaded from the serialized form */
   private Properties properties;
+
+  private boolean changed;
+
   /**
    * @param val id
    */
@@ -60,8 +65,19 @@
 
   /**
    * @return serialized properties
+   * @throws SynchException
    */
-  public String getConnectorProperties() {
+  public String getConnectorProperties() throws SynchException {
+    if (changed) {
+      try {
+        Writer wtr = new StringWriter();
+
+        properties.store(wtr, null);
+        connectorProperties = wtr.toString();
+      } catch (Throwable t) {
+        throw new SynchException(t);
+      }
+    }
     return connectorProperties;
   }
 
@@ -87,45 +103,78 @@
     }
   }
 
-  /** Add a property to the internal properties
+  /** Set a property in the internal properties - loading them from the
+   * external value first if necessary.
+   *
    * @param name
    * @param val
+   * @throws SynchException
    */
-  public void addProperty(final String name, final String val) {
+  public void setProperty(final String name,
+                          final String val) throws SynchException {
     if (properties == null) {
-      properties = new Properties();
+      loadProperties();
     }
 
-    properties.setProperty(name, val);
+    if (val == null) {
+      properties.remove(name);
+    } else {
+      properties.setProperty(name, val);
+    }
+    changed = true;
   }
 
+  /** Get a property from the internal properties - loading them from the
+   * external value first if necessary.
+   *
+   * @param name
+   * @return val
+   * @throws SynchException
+   */
+  public String getProperty(final String name) throws SynchException {
+    if (properties == null) {
+      loadProperties();
+    }
+
+    return properties.getProperty(name);
+  }
+
   /* ====================================================================
    *                   Object methods
    * ==================================================================== */
 
   @Override
   public int hashCode() {
-    int res = getConnectorId().hashCode();
+    try {
+      int res = getConnectorId().hashCode();
 
-    if (getConnectorProperties() != null) {
-      res *= getConnectorProperties().hashCode();
+      if (getConnectorProperties() != null) {
+        res *= getConnectorProperties().hashCode();
+      }
+
+      return res;
+    } catch (Throwable t) {
+      throw new RuntimeException(t);
     }
+  }
 
-    return res;
-  }
   @Override
   public int compareTo(final SubscriptionConnectorInfo that) {
     if (this == that) {
       return 0;
     }
 
-    int res = getConnectorId().compareTo(that.getConnectorId());
-    if (res != 0) {
-      return res;
+    try {
+      int res = getConnectorId().compareTo(that.getConnectorId());
+      if (res != 0) {
+        return res;
+      }
+
+      return Util.compareStrings(getConnectorProperties(),
+                                 that.getConnectorProperties());
+    } catch (Throwable t) {
+      throw new RuntimeException(t);
     }
-
-    return Util.compareStrings(getConnectorProperties(),
-                               that.getConnectorProperties());
   }
 
   @Override
@@ -135,18 +184,22 @@
 
   @Override
   public String toString() {
-    StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append("{");
+    try {
+      StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append("{");
 
-    sb.append("connectorId= ");
-    sb.append(getConnectorId());
+      sb.append("connectorId= ");
+      sb.append(getConnectorId());
 
-    if (getConnectorProperties() != null) {
-      sb.append(", onnectorProperties = ");
-      sb.append(getConnectorProperties());
+      if (getConnectorProperties() != null) {
+        sb.append(", onnectorProperties = ");
+        sb.append(getConnectorProperties());
+      }
+
+      sb.append("}");
+      return sb.toString();
+    } catch (Throwable t) {
+      throw new RuntimeException(t);
     }
-
-    sb.append("}");
-    return sb.toString();
   }
 
 }

Modified: trunk/common/src/org/bedework/synch/SynchConfig.java
===================================================================
--- trunk/common/src/org/bedework/synch/SynchConfig.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/SynchConfig.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -38,6 +38,11 @@
   /* Path to keystore - null for use default */
   private String keystore;
 
+  /* Path to keystores  */
+  private String privKeys;
+  /* Path to keystores  */
+  private String pubKeys;
+
   private Map<String, String> connectors;
 
   /**
@@ -100,6 +105,38 @@
     return keystore;
   }
 
+  /**
+   *
+   * @param val    String
+   */
+  public void setPrivKeys(final String val) {
+    privKeys = val;
+  }
+
+  /**
+   *
+   * @return String
+   */
+  public String getPrivKeys() {
+    return privKeys;
+  }
+
+  /**
+   *
+   * @param val    String
+   */
+  public void setPubKeys(final String val) {
+    pubKeys = val;
+  }
+
+  /**
+   *
+   * @return String
+   */
+  public String getPubKeys() {
+    return pubKeys;
+  }
+
   /** Map of (name, className)
    *
    * @param val

Modified: trunk/common/src/org/bedework/synch/SynchConnector.java
===================================================================
--- trunk/common/src/org/bedework/synch/SynchConnector.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/SynchConnector.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -109,6 +109,11 @@
   }
 
   @Override
+  public SynchEngine getSyncher() {
+    return syncher;
+  }
+
+  @Override
   public List<ConnectorPropertyInfo> getPropertyInfo() {
     return propInfo;
   }
@@ -302,7 +307,7 @@
     return new Notification(sub, sresp);
   }
 
-  private SubscriptionConnectorInfo makeConnInfo(final ConnectorInfoType cinfo) {
+  private SubscriptionConnectorInfo makeConnInfo(final ConnectorInfoType cinfo) throws SynchException {
     SubscriptionConnectorInfo subCinfo = new SubscriptionConnectorInfo();
 
     subCinfo.setConnectorId(cinfo.getConnectorId());
@@ -312,7 +317,7 @@
     }
 
     for (SynchPropertyType sp: cinfo.getProperties().getProperty()) {
-      subCinfo.addProperty(sp.getName(), sp.getValue());
+      subCinfo.setProperty(sp.getName(), sp.getValue());
     }
 
     return subCinfo;
@@ -323,8 +328,8 @@
    * @param u
    * @throws SynchException
    */
-  public void unsubscribe(final HttpServletResponse resp,
-                          final UnsubscribeRequestType u) throws SynchException {
+  private void unsubscribe(final HttpServletResponse resp,
+                           final UnsubscribeRequestType u) throws SynchException {
     if (debug) {
       trace("Handle unsubscribe " +  u.getSubscriptionId());
     }

Modified: trunk/common/src/org/bedework/synch/SynchEngine.java
===================================================================
--- trunk/common/src/org/bedework/synch/SynchEngine.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/SynchEngine.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -22,11 +22,13 @@
 import org.bedework.synch.Notification.NotificationItem.ActionType;
 import org.bedework.synch.SynchDefs.SynchEnd;
 import org.bedework.synch.cnctrs.Connector;
+import org.bedework.synch.cnctrs.Connector.NotificationBatch;
 import org.bedework.synch.cnctrs.ConnectorInstance;
-import org.bedework.synch.cnctrs.Connector.NotificationBatch;
 import org.bedework.synch.exception.SynchException;
 
+import edu.rpi.cmt.security.PwEncryptionIntf;
 import edu.rpi.cmt.timezones.Timezones;
+import edu.rpi.sss.util.Util;
 
 import net.fortuna.ical4j.model.TimeZone;
 
@@ -117,6 +119,8 @@
 
   private ApplicationContext appContext;
 
+  private transient PwEncryptionIntf pwEncrypt;
+
   /* Map of currently active subscriptions - that is - we have traffic between
    * systems.
    */
@@ -131,9 +135,6 @@
 
   private SynchConfig config;
 
-  /* Max number of items we fetch at a time */
-  private final int getItemsBatchSize = 20;
-
   private static Object getSyncherLock = new Object();
 
   private static SynchEngine syncher;
@@ -425,6 +426,46 @@
     return config;
   }
 
+  /**
+   * @param val
+   * @return decrypted string
+   * @throws SynchException
+   */
+  public String decrypt(final String val) throws SynchException {
+    try {
+      return getEncrypter().decrypt(val);
+    } catch (SynchException se) {
+      throw se;
+    } catch (Throwable t) {
+      throw new SynchException(t);
+    }
+  }
+
+  /**
+   * @return en/decryptor
+   * @throws SynchException
+   */
+  public PwEncryptionIntf getEncrypter() throws SynchException {
+    if (pwEncrypt != null) {
+      return pwEncrypt;
+    }
+
+    try {
+      String pwEncryptClass = "edu.rpi.cmt.security.PwEncryptionDefault";
+      //String pwEncryptClass = getSysparsHandler().get().getPwEncryptClass();
+
+      pwEncrypt = (PwEncryptionIntf)Util.getObject(pwEncryptClass,
+                                                   PwEncryptionIntf.class);
+
+      pwEncrypt.init(config.getPrivKeys(), config.getPubKeys());
+
+      return pwEncrypt;
+    } catch (Throwable t) {
+      t.printStackTrace();
+      throw new SynchException(t);
+    }
+  }
+
   /** Gets an instance and implants it in the subscription object.
    * @param sub
    * @param end
@@ -475,6 +516,7 @@
    * @param notes
    * @throws SynchException
    */
+  @SuppressWarnings("unchecked")
   public void handleNotifications(
             final NotificationBatch<Notification> notes) throws SynchException {
     for (Notification note: notes.getNotifications()) {

Modified: trunk/common/src/org/bedework/synch/Synchling.java
===================================================================
--- trunk/common/src/org/bedework/synch/Synchling.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/Synchling.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -593,6 +593,7 @@
     getLogger().warn(msg);
   }
 
+  @SuppressWarnings("unused")
   private void error(final Throwable t) {
     getLogger().error(this, t);
   }

Modified: trunk/common/src/org/bedework/synch/cnctrs/Connector.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/Connector.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/Connector.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -20,9 +20,8 @@
 
 import org.bedework.synch.Notification;
 import org.bedework.synch.Subscription;
-import org.bedework.synch.SynchDefs;
+import org.bedework.synch.SynchDefs.SynchEnd;
 import org.bedework.synch.SynchEngine;
-import org.bedework.synch.SynchDefs.SynchEnd;
 import org.bedework.synch.exception.SynchException;
 
 import org.oasis_open.docs.ns.wscal.calws_soap.StatusType;
@@ -77,6 +76,11 @@
    */
   String getCallbackUri();
 
+  /**
+   * @return syncher provided at start
+   */
+  SynchEngine getSyncher();
+
   /** List the information about properties required for subscriptions via this
    * connector.
    *

Added: trunk/common/src/org/bedework/synch/cnctrs/ConnectorCache.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/ConnectorCache.java	                        (rev 0)
+++ trunk/common/src/org/bedework/synch/cnctrs/ConnectorCache.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -0,0 +1,63 @@
+/* ********************************************************************
+    Licensed to Jasig under one or more contributor license
+    agreements. See the NOTICE file distributed with this work
+    for additional information regarding copyright ownership.
+    Jasig licenses this file to you under the Apache License,
+    Version 2.0 (the "License"); you may not use this file
+    except in compliance with the License. You may obtain a
+    copy of the License at:
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on
+    an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied. See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+package org.bedework.synch.cnctrs;
+
+/** A cache for connectors and instances. When values are successfully retrieved
+ * from the cache the successfulFetch method should be called to update the last
+ * fetch time.
+ *
+ * <p>These caches will be attached to subscriptions.
+ *
+ * <p>The system map periodically flush caches and will do so according to the
+ * time since a cache was last successfully used.
+ *
+ * @author Mike Douglass
+ */
+public class ConnectorCache {
+  private String name;
+
+  private long lastFetch;
+
+  /**
+   * @param name - name for the cache
+   */
+  public ConnectorCache(final String name) {
+    this.name = name;
+  }
+
+  /**
+   * @return name
+   */
+  public String getName() {
+    return name;
+  }
+
+  /**
+   * @return last fetch time
+   */
+  public long getLastFetch() {
+    return lastFetch;
+  }
+
+  /**
+   */
+  public void successfulFetch() {
+    lastFetch = System.currentTimeMillis();
+  }
+}

Modified: trunk/common/src/org/bedework/synch/cnctrs/ConnectorInstanceMap.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/ConnectorInstanceMap.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/ConnectorInstanceMap.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -19,7 +19,6 @@
 package org.bedework.synch.cnctrs;
 
 import org.bedework.synch.Subscription;
-import org.bedework.synch.SynchDefs;
 import org.bedework.synch.SynchDefs.SynchEnd;
 import org.bedework.synch.exception.SynchException;
 

Modified: trunk/common/src/org/bedework/synch/cnctrs/ConnectorPropertyInfo.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/ConnectorPropertyInfo.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/ConnectorPropertyInfo.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -18,8 +18,6 @@
 */
 package org.bedework.synch.cnctrs;
 
-
-
 /** Information about a single connector property. This information will be
  * published by the system allowing clients to determine what properties are
  * needed.

Modified: trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkConnector.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkConnector.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkConnector.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -22,11 +22,11 @@
 import org.bedework.synch.Subscription;
 import org.bedework.synch.SynchDefs;
 import org.bedework.synch.SynchDefs.SynchEnd;
+import org.bedework.synch.SynchEngine;
 import org.bedework.synch.cnctrs.Connector;
 import org.bedework.synch.cnctrs.ConnectorInstanceMap;
 import org.bedework.synch.cnctrs.ConnectorPropertyInfo;
 import org.bedework.synch.exception.SynchException;
-import org.bedework.synch.SynchEngine;
 import org.bedework.synch.wsmessages.StartServiceNotificationType;
 import org.bedework.synch.wsmessages.StartServiceResponseType;
 import org.bedework.synch.wsmessages.SynchIdTokenType;
@@ -170,6 +170,11 @@
   }
 
   @Override
+  public SynchEngine getSyncher() {
+    return syncher;
+  }
+
+  @Override
   public List<ConnectorPropertyInfo> getPropertyInfo() {
     return propInfo;
   }

Modified: trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkConnectorInstance.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkConnectorInstance.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkConnectorInstance.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -325,7 +325,7 @@
    *                   Private methods
    * ==================================================================== */
 
-  SynchIdTokenType getIdToken() {
+  SynchIdTokenType getIdToken() throws SynchException {
     return cnctr.getIdToken(info.getPrincipalHref());
   }
 }

Modified: trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkSubscriptionInfo.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkSubscriptionInfo.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/bedework/BedeworkSubscriptionInfo.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -21,28 +21,14 @@
 import org.bedework.synch.SubscriptionConnectorInfo;
 import org.bedework.synch.exception.SynchException;
 
-/** Represents a subscription for the synch engine.
+/** Stores information about one end of a subscription for connector.
  *
- * <p>A subscription has 2 connectors for each end of the subscription, endA
- * and endB.
  *
- * <p>Each connector has a kind which is a name used to retrieve a connector
- * from the connector manager. The retrieved connector implements the SynchIntf
- * interface and provides a serializable object to store connection specific
- * properties such as id and password.
- *
- * <p>These properties are obtained by presenting the user with a list of
- * required properties and then encrypting and storing the response.
- *
  * @author Mike Douglass
  */
 public class BedeworkSubscriptionInfo {
   private SubscriptionConnectorInfo info;
 
-  private String calPath;
-
-  private String principalHref;
-
   /**
    * @param info
    * @throws SynchException
@@ -58,11 +44,12 @@
    * @param subscribe
    * @param calPath
    * @param principalHref
+   * @throws SynchException
    */
   public BedeworkSubscriptionInfo(final String subscriptionId,
                               final boolean subscribe,
                               final String calPath,
-                              final String principalHref) {
+                              final String principalHref) throws SynchException {
     info = new SubscriptionConnectorInfo();
 
     setPrincipalHref(principalHref);
@@ -72,34 +59,38 @@
   /** Path to this systems calendar collection.
    *
    * @param val    String
+   * @throws SynchException
    */
-  public void setCalPath(final String val) {
-    calPath = val;
+  public void setCalPath(final String val) throws SynchException {
+    info.setProperty(BedeworkConnector.propnameCalendarHref, val);
   }
 
   /** Path to this systems calendar collection
    *
    * @return String
+   * @throws SynchException
    */
-  public String getCalPath() {
-    return calPath;
+  public String getCalPath() throws SynchException {
+    return info.getProperty(BedeworkConnector.propnameCalendarHref);
   }
 
 
   /** Principal requesting synch service
    *
    * @param val    String
+   * @throws SynchException
    */
-  public void setPrincipalHref(final String val) {
-    principalHref = val;
+  public void setPrincipalHref(final String val) throws SynchException {
+    info.setProperty(BedeworkConnector.propnamePrincipal, val);
   }
 
   /** Principal requesting synch service
    *
    * @return String
+   * @throws SynchException
    */
-  public String getPrincipalHref() {
-    return principalHref;
+  public String getPrincipalHref() throws SynchException {
+    return info.getProperty(BedeworkConnector.propnamePrincipal);
   }
 
   /* ====================================================================
@@ -108,12 +99,16 @@
 
   protected void toStringSegment(final StringBuilder sb,
                               final String indent) {
-    sb.append(",\n");
-    sb.append(indent);
-    sb.append("calPath = ");
-    sb.append(getCalPath());
-    sb.append("principalHref = ");
-    sb.append(getPrincipalHref());
+    try {
+      sb.append(",\n");
+      sb.append(indent);
+      sb.append("calPath = ");
+      sb.append(getCalPath());
+      sb.append("principalHref = ");
+      sb.append(getPrincipalHref());
+    } catch (Throwable t) {
+      sb.append(t.getMessage());
+    }
   }
 
   /* ====================================================================
@@ -122,7 +117,7 @@
 
   @Override
   public String toString() {
-    StringBuilder sb = new StringBuilder("BedeworkSubscriptionInfo{");
+    StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append("{");
 
     toStringSegment(sb, "  ");
 

Modified: trunk/common/src/org/bedework/synch/cnctrs/exchange/ExchangeConnector.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/exchange/ExchangeConnector.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/exchange/ExchangeConnector.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -20,11 +20,11 @@
 
 import org.bedework.synch.Subscription;
 import org.bedework.synch.SynchDefs.SynchEnd;
+import org.bedework.synch.SynchEngine;
 import org.bedework.synch.cnctrs.Connector;
 import org.bedework.synch.cnctrs.ConnectorInstanceMap;
 import org.bedework.synch.cnctrs.ConnectorPropertyInfo;
 import org.bedework.synch.exception.SynchException;
-import org.bedework.synch.SynchEngine;
 
 import org.apache.log4j.Logger;
 import org.oasis_open.docs.ns.wscal.calws_soap.StatusType;
@@ -141,6 +141,11 @@
   }
 
   @Override
+  public SynchEngine getSyncher() {
+    return syncher;
+  }
+
+  @Override
   public List<ConnectorPropertyInfo> getPropertyInfo() {
     return propInfo;
   }
@@ -328,10 +333,12 @@
     return log;
   }
 
+  @SuppressWarnings("unused")
   private void trace(final String msg) {
     getLogger().debug(msg);
   }
 
+  @SuppressWarnings("unused")
   private void warn(final String msg) {
     getLogger().warn(msg);
   }

Modified: trunk/common/src/org/bedework/synch/cnctrs/exchange/XmlIcalConvert.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/exchange/XmlIcalConvert.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/exchange/XmlIcalConvert.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -115,6 +115,7 @@
    * @return Icalendar
    * @throws SynchException
    */
+  @SuppressWarnings("unchecked")
   public IcalendarType toXml(final CalendarItemType cal) throws SynchException {
     /* TODO
      * Transparency - derived from what?
@@ -550,8 +551,6 @@
   }
 
   private ItemType makeItemType(final String val) throws SynchException {
-    ItemType iytemType;
-
     String uval = val.toUpperCase();
 
     if (uval.equals("IPM.NOTE")) {

Modified: trunk/common/src/org/bedework/synch/cnctrs/exchange/responses/ExchangeResponse.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/exchange/responses/ExchangeResponse.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/exchange/responses/ExchangeResponse.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -42,6 +42,10 @@
 
   private MessageXml messageXml;
 
+  /**
+   * @param resp
+   * @throws SynchException
+   */
   public ExchangeResponse(final ResponseMessageType resp) throws SynchException {
     debug = getLogger().isDebugEnabled();
 

Modified: trunk/common/src/org/bedework/synch/cnctrs/file/FileConnector.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/file/FileConnector.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/file/FileConnector.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -21,11 +21,11 @@
 import org.bedework.synch.Notification;
 import org.bedework.synch.Subscription;
 import org.bedework.synch.SynchDefs.SynchEnd;
+import org.bedework.synch.SynchEngine;
 import org.bedework.synch.cnctrs.Connector;
 import org.bedework.synch.cnctrs.ConnectorInstanceMap;
 import org.bedework.synch.cnctrs.ConnectorPropertyInfo;
 import org.bedework.synch.exception.SynchException;
-import org.bedework.synch.SynchEngine;
 
 import org.apache.log4j.Logger;
 
@@ -45,8 +45,11 @@
   private transient Logger log;
 
   /** */
-  public static final String propnameCalendarHref = "calendar-href";
+  public static final String propnameUri = "uri";
 
+  /** lastmod in the file is accurate */
+  public static final String propnameUseLastmod = "use-lastmod";
+
   /** */
   public static final String propnamePrincipal = "principal";
 
@@ -57,7 +60,7 @@
       new ArrayList<ConnectorPropertyInfo>();
 
   static {
-    propInfo.add(new ConnectorPropertyInfo(propnameCalendarHref,
+    propInfo.add(new ConnectorPropertyInfo(propnameUri,
                                            false,
                                            ""));
 
@@ -108,6 +111,11 @@
   }
 
   @Override
+  public SynchEngine getSyncher() {
+    return syncher;
+  }
+
+  @Override
   public List<ConnectorPropertyInfo> getPropertyInfo() {
     return propInfo;
   }

Modified: trunk/common/src/org/bedework/synch/cnctrs/file/FileConnectorInstance.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/file/FileConnectorInstance.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/file/FileConnectorInstance.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -18,12 +18,19 @@
 */
 package org.bedework.synch.cnctrs.file;
 
+import org.bedework.http.client.dav.DavClient;
 import org.bedework.synch.Subscription;
 import org.bedework.synch.SynchDefs.SynchEnd;
 import org.bedework.synch.cnctrs.ConnectorInstance;
 import org.bedework.synch.exception.SynchException;
 import org.bedework.synch.wsmessages.SubscribeResponseType;
 
+import edu.rpi.cmt.calendar.IcalToXcal;
+
+import net.fortuna.ical4j.data.CalendarBuilder;
+import net.fortuna.ical4j.model.Calendar;
+
+import org.apache.commons.httpclient.Header;
 import org.apache.log4j.Logger;
 import org.oasis_open.docs.ns.wscal.calws_soap.AddItemResponseType;
 import org.oasis_open.docs.ns.wscal.calws_soap.BaseResponseType;
@@ -33,9 +40,12 @@
 
 import ietf.params.xml.ns.icalendar_2.IcalendarType;
 
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.servlet.http.HttpServletResponse;
+
 /** Calls from exchange synch processor to the service.
  *
  * @author Mike Douglass
@@ -55,6 +65,9 @@
 
   private SynchEnd end;
 
+  /* Only non-null if we actually fetched the data */
+  private IcalendarType fetchedIcal;
+
   FileConnectorInstance(final FileConnectorConfig config,
                             final FileConnector cnctr,
                             final Subscription sub,
@@ -186,4 +199,79 @@
   /* ====================================================================
    *                   Private methods
    * ==================================================================== */
+
+  /* Fetch the iCalendar for the subscription. If it fails set the status and
+   * return null. Unchanged data will return null with no status change.
+   */
+  private void getIcal() throws SynchException {
+    DavClient cl = null;
+
+    try {
+      cl = new DavClient(info.getUri(),
+                         15 * 1000);   // 15 seconds timeout
+
+      if (info.getPrincipalHref() != null) {
+        cl.setCredentials(info.getPrincipalHref(),
+                          cnctr.getSyncher().decrypt(info.getPassword()));
+      }
+
+      Header[] hdrs = null;
+
+      if (info.getEtag() != null) {
+        hdrs = new Header[] {
+          new Header("If-None-Match", info.getEtag())
+        };
+      }
+
+      int rc = cl.sendRequest("GET", info.getUri(), hdrs);
+      info.setLastRefreshStatus(String.valueOf(rc));
+
+      if (rc == HttpServletResponse.SC_NOT_MODIFIED) {
+        // Data unchanged.
+        if (debug) {
+          trace("data unchanged");
+        }
+        return;
+      }
+
+      if (rc != HttpServletResponse.SC_OK) {
+        info.setLastRefreshStatus(String.valueOf(rc));
+        if (debug) {
+          trace("Unsuccessful response from server was " + rc);
+        }
+        info.setEtag(null);  // Force refresh next time
+        return;
+      }
+
+      CalendarBuilder builder = new CalendarBuilder();
+
+      InputStream is = cl.getResponse().getContentStream();
+
+      Calendar ical = builder.build(is);
+
+      /* Convert each entity to XML */
+
+      fetchedIcal = IcalToXcal.fromIcal(ical, null);
+
+      /* Looks like we translated ok. Save any etag and delete everything in the
+       * calendar.
+       */
+
+      Header etag = cl.getResponse().getResponseHeader("Etag");
+      if (etag != null) {
+        info.setEtag(etag.getValue());
+      }
+
+//      fetchedIcal = ic;
+    } catch (SynchException se) {
+      throw se;
+    } catch (Throwable t) {
+      throw new SynchException(t);
+    } finally {
+      try {
+        cl.release();
+      } catch (Throwable t) {
+      }
+    }
+  }
 }

Modified: trunk/common/src/org/bedework/synch/cnctrs/file/FileSubscriptionInfo.java
===================================================================
--- trunk/common/src/org/bedework/synch/cnctrs/file/FileSubscriptionInfo.java	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/common/src/org/bedework/synch/cnctrs/file/FileSubscriptionInfo.java	2011-08-23 19:42:26 UTC (rev 25)
@@ -39,10 +39,14 @@
 public class FileSubscriptionInfo {
   private SubscriptionConnectorInfo info;
 
-  private String calPath;
+  /* properties saved by connector instance */
 
-  private String principalHref;
+  /** */
+  public static final String propnameEtag = "etag";
 
+  /** */
+  public static final String propnameLastRefreshStatus = "last-refresh-status";
+
   /**
    * @param info
    * @throws SynchException
@@ -56,64 +60,133 @@
    *
    * @param subscriptionId - null means generate one
    * @param subscribe
-   * @param calPath
+   * @param uri
    * @param principalHref
+   * @param password
+   * @throws SynchException
    */
   public FileSubscriptionInfo(final String subscriptionId,
                               final boolean subscribe,
-                              final String calPath,
-                              final String principalHref) {
+                              final String uri,
+                              final String principalHref,
+                              final String password) throws SynchException {
     info = new SubscriptionConnectorInfo();
 
+    setUri(uri);
     setPrincipalHref(principalHref);
-    setCalPath(calPath);
+    setPassword(password);
   }
 
-  /** Path to this systems calendar collection.
+  /** Path to the calendar collection.
    *
    * @param val    String
+   * @throws SynchException
    */
-  public void setCalPath(final String val) {
-    calPath = val;
+  public void setUri(final String val) throws SynchException {
+    info.setProperty(FileConnector.propnameUri, val);
   }
 
-  /** Path to this systems calendar collection
+  /** Path to the calendar collection
    *
    * @return String
+   * @throws SynchException
    */
-  public String getCalPath() {
-    return calPath;
+  public String getUri() throws SynchException {
+    return info.getProperty(FileConnector.propnameUri);
   }
 
-
   /** Principal requesting synch service
    *
    * @param val    String
+   * @throws SynchException
    */
-  public void setPrincipalHref(final String val) {
-    principalHref = val;
+  public void setPrincipalHref(final String val) throws SynchException {
+    info.setProperty(FileConnector.propnamePrincipal, val);
   }
 
   /** Principal requesting synch service
    *
    * @return String
+   * @throws SynchException
    */
-  public String getPrincipalHref() {
-    return principalHref;
+  public String getPrincipalHref() throws SynchException {
+    return info.getProperty(FileConnector.propnamePrincipal);
   }
 
+  /** Principals password
+   *
+   * @param val    String
+   * @throws SynchException
+   */
+  public void setPassword(final String val) throws SynchException {
+    info.setProperty(FileConnector.propnamePassword, val);
+  }
+
+  /** Principal password
+   *
+   * @return String
+   * @throws SynchException
+   */
+  public String getPassword() throws SynchException {
+    return info.getProperty(FileConnector.propnamePassword);
+  }
+
+  /** etag
+   *
+   * @param val    String
+   * @throws SynchException
+   */
+  public void setEtag(final String val) throws SynchException {
+    info.setProperty(propnameEtag, val);
+  }
+
+  /** Etag
+   *
+   * @return String
+   * @throws SynchException
+   */
+  public String getEtag() throws SynchException {
+    return info.getProperty(propnameEtag);
+  }
+
+  /** HTTP status or other appropriate value
+   * @param val
+   * @throws SynchException
+   */
+  public void setLastRefreshStatus(final String val) throws SynchException {
+    info.setProperty(propnameLastRefreshStatus, val);
+  }
+
+  /**
+   * @return String lastRefreshStatus
+   * @throws SynchException
+   */
+  public String getLastRefreshStatus() throws SynchException {
+    return info.getProperty(propnameLastRefreshStatus);
+  }
+
   /* ====================================================================
    *                   Convenience methods
    * ==================================================================== */
 
   protected void toStringSegment(final StringBuilder sb,
                               final String indent) {
-    sb.append(",\n");
-    sb.append(indent);
-    sb.append("calPath = ");
-    sb.append(getCalPath());
-    sb.append("principalHref = ");
-    sb.append(getPrincipalHref());
+    try {
+      sb.append(",\n");
+      sb.append(indent);
+      sb.append("uri = ");
+      sb.append(getUri());
+      sb.append("principalHref = ");
+      sb.append(getPrincipalHref());
+      sb.append("password = ");
+      sb.append(getPassword());
+      sb.append("etag = ");
+      sb.append(getEtag());
+      sb.append("lastRefreshStatus = ");
+      sb.append(getLastRefreshStatus());
+    } catch (Throwable t) {
+      sb.append(t.getMessage());
+    }
   }
 
   /* ====================================================================
@@ -122,7 +195,7 @@
 
   @Override
   public String toString() {
-    StringBuilder sb = new StringBuilder("BedeworkSubscriptionInfo{");
+    StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append("{");
 
     toStringSegment(sb, "  ");
 

Modified: trunk/resources/hibernate/hbms/Subscription.hbm.xml
===================================================================
--- trunk/resources/hibernate/hbms/Subscription.hbm.xml	2011-08-22 02:21:35 UTC (rev 24)
+++ trunk/resources/hibernate/hbms/Subscription.hbm.xml	2011-08-23 19:42:26 UTC (rev 25)
@@ -44,9 +44,21 @@
               not-null="true"
               index="bwsynidx_subid" />
 
-    <property name="endAConnectorInfo" column="bwsyn_endA" type="text" />
+    <component name="endAConnectorInfo"
+               class="org.bedework.synch.SubscriptionConnectorInfo" >
+      <property name="connectorId" column="bwsyn_connectorid_a" 
+                type="string" length="100" />
+      <property name="connectorProperties" column="bwsyn_conn_props_a" 
+                type="string" length="3000" />
+    </component>
 
-    <property name="endBConnectorInfo" column="bwsyn_endB" type="text" />
+    <component name="endBConnectorInfo"
+               class="org.bedework.synch.SubscriptionConnectorInfo" >
+      <property name="connectorId" column="bwsyn_connectorid_b" 
+                type="string" length="100" />
+      <property name="connectorProperties" column="bwsyn_conn_props_b" 
+                type="string" length="3000" />
+    </component>
 
     <property name="kind" column="bwsyn_kind" type="kind" length="25"
               not-null="true" />



More information about the Bedework-commit mailing list