abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r599187 - in /incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client: AbderaClient.java EntityProvider.java RequestOptions.java
Date Wed, 28 Nov 2007 23:07:35 GMT
Author: jmsnell
Date: Wed Nov 28 15:07:35 2007
New Revision: 599187

URL: http://svn.apache.org/viewvc?rev=599187&view=rev
Log:
Provide support for automatic Lost-Update detection.  When doing a PUT with a Document or
an EntityProvider, allow for automatic use of If-Match/If-Unmodified-Since if an ETag or Last-Modified
date is available

Modified:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/EntityProvider.java
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java?rev=599187&r1=599186&r2=599187&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
Wed Nov 28 15:07:35 2007
@@ -44,6 +44,7 @@
 import org.apache.abdera.protocol.error.Error;
 import org.apache.abdera.protocol.error.ProtocolException;
 import org.apache.abdera.protocol.util.CacheControlUtil;
+import org.apache.abdera.util.EntityTag;
 import org.apache.abdera.util.ServiceUtil;
 import org.apache.abdera.util.Version;
 import org.apache.commons.httpclient.Cookie;
@@ -67,6 +68,7 @@
 /**
  * An Atom Publishing Protocol client.
  */
+@SuppressWarnings("unchecked") 
 public class AbderaClient {
 
   public static final String DEFAULT_USER_AGENT = 
@@ -180,6 +182,15 @@
     String uri, 
     EntityProvider provider, 
     RequestOptions options) {
+      if (options == null) options = getDefaultRequestOptions();
+      if (options.isConditionalPut()) {
+        EntityTag etag = provider.getEntityTag();
+        if (etag != null) options.setIfMatch(etag);
+        else {
+          Date lm = provider.getLastModified();
+          if (lm != null) options.setIfUnmodifiedSince(lm);
+        }
+      }
       return put(
         uri, 
         new EntityProviderRequestEntity(
@@ -208,11 +219,19 @@
       String uri, 
       Base base, 
       RequestOptions options) {
+    if (options == null) options = getDefaultRequestOptions();
     if (base instanceof Document) {
       Document d = (Document) base;
       if (options.getSlug() == null && 
           d.getSlug() != null) 
         options.setSlug(d.getSlug());
+      
+      if (options.isConditionalPut()) {
+        if (d.getEntityTag() != null)
+          options.setIfMatch(d.getEntityTag());
+        else if (d.getLastModified() != null)
+          options.setIfUnmodifiedSince(d.getLastModified());
+      }
     }
     return execute("PUT", uri, new BaseRequestEntity(base, options.isUseChunked()), options);
   }

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/EntityProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/EntityProvider.java?rev=599187&r1=599186&r2=599187&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/EntityProvider.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/EntityProvider.java
Wed Nov 28 15:07:35 2007
@@ -17,6 +17,9 @@
 */
 package org.apache.abdera.protocol.client;
 
+import java.util.Date;
+
+import org.apache.abdera.util.EntityTag;
 import org.apache.abdera.writer.StreamWriter;
 
 /**
@@ -24,21 +27,31 @@
  * interface.  The EntityProvider interface can be implemented by client applications
  * to provide an efficient means of serializing non-FOM objects to Atom/XML. 
  */
-public interface EntityProvider {
+public abstract class EntityProvider {
 
   /**
    * Write to the specified StreamWriter
    */
-  void writeTo(StreamWriter sw);
+  public abstract void writeTo(StreamWriter sw);
  
   /**
    * True if the serialization is repeatable. 
    */
-  boolean isRepeatable();
+  public abstract boolean isRepeatable();
   
   /**
    * Return the mime content type of the serialized entity
    */
-  String getContentType();
+  public abstract String getContentType();
+  
+  /**
+   * Return the EntityTag of the entity,
+   */
+  public EntityTag getEntityTag() { return null; }
+  
+  /**
+   * Return the Last-Modified date of the entity
+   */
+  public Date getLastModified() { return null; }
   
 }

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java?rev=599187&r1=599186&r2=599187&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java
Wed Nov 28 15:07:35 2007
@@ -48,6 +48,7 @@
   private boolean requestException4xx = false;
   private boolean requestException5xx = false;
   private boolean useExpectContinue = true;
+  private boolean useConditional = true;
   
   private final Map<String,String[]> headers = new HashMap<String,String[]>();
 
   
@@ -526,5 +527,23 @@
    */
   public boolean isUseExpectContinue() {
     return this.useExpectContinue;
+  }
+  
+  /**
+   * True if HTTP Conditional Requests should be used automatically.
+   * This only has an effect when putting a Document that has an 
+   * ETag or Last-Modified date present
+   */
+  public boolean isConditionalPut() {
+    return this.useConditional;
+  }
+  
+  /**
+   * True if HTTP Conditinal Request should be used automatically.
+   * This only has an effect when putting a Document that has an
+   * ETag or Last-Modified date present
+   */
+  public void setConditionalPut(boolean conditional) {
+    this.useConditional = conditional;
   }
 }



Mime
View raw message