abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From calav...@apache.org
Subject svn commit: r701370 - in /incubator/abdera/java/trunk: adapters/jcr/src/test/java/org/apache/abdera/jcr/ server/src/main/java/org/apache/abdera/protocol/server/impl/ server/src/test/java/org/apache/abdera/protocol/server/test/customer/
Date Fri, 03 Oct 2008 13:08:21 GMT
Author: calavera
Date: Fri Oct  3 06:08:20 2008
New Revision: 701370

URL: http://svn.apache.org/viewvc?rev=701370&view=rev
Log:
fixes ABDERA-179: AbstractEntityCollectionAdapter incorrectly returns relative URIs in Location
header. Thanks to Christopher Elkins.

Per section 14.30 of RFC 2616, the Location header "consists of a single absolute URI". However,
whether posting entry or media resources, AbstractEntityCollectionAdapter responds with a
relative URL in the Location header.

Modified:
    incubator/abdera/java/trunk/adapters/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionAdapterTest.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java

Modified: incubator/abdera/java/trunk/adapters/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionAdapterTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionAdapterTest.java?rev=701370&r1=701369&r2=701370&view=diff
==============================================================================
--- incubator/abdera/java/trunk/adapters/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionAdapterTest.java
(original)
+++ incubator/abdera/java/trunk/adapters/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionAdapterTest.java
Fri Oct  3 06:08:20 2008
@@ -108,11 +108,10 @@
     //prettyPrint(abdera, res.getDocument());
 
     IRI location = res.getLocation();
-    assertEquals("/feed/Some_Entry", location.toString());
+    assertEquals(base + "feed/Some_Entry", location.toString());
 
     // GET the entry
-    IRI entryIri = colUri.resolve(location);
-    res = client.get(entryIri.toString());
+    res = client.get(location.toString());
     assertEquals(200, res.getStatus());
 
     //prettyPrint(abdera, res.getDocument());
@@ -130,7 +129,7 @@
     entry.setSummary("New Summary");
     entry.setContent("New Content");
 
-    res = client.put(entryIri.resolve(location).toString(), entry, opts);
+    res = client.put(location.toString(), entry, opts);
     assertEquals(204, res.getStatus());
 
     res = client.get(colUri.toString());
@@ -141,7 +140,7 @@
     //prettyPrint(abdera, feed_doc);
 
     // test 404 not found
-    res = client.get(colUri.resolve(location).toString() + "Invalid");
+    res = client.get(location.toString() + "Invalid");
     assertEquals(404, res.getStatus());
   }
 

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java?rev=701370&r1=701369&r2=701370&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java
Fri Oct  3 06:08:20 2008
@@ -119,35 +119,7 @@
   }
 
   public ResponseContext postEntry(RequestContext request) {
-    try {
-      Entry entry = getEntryFromRequest(request);
-      if (entry != null) {
-        if (!ProviderHelper.isValidEntry(entry))
-          return new EmptyResponseContext(400);
-  
-        entry.setUpdated(new Date());
-        
-        
-          T entryObj = postEntry(entry.getTitle(),
-                                 entry.getId(),
-                                 entry.getSummary(),
-                                 entry.getUpdated(),
-                                 entry.getAuthors(),
-                                 entry.getContentElement(), request);
-          entry.getIdElement().setValue(getId(entryObj));
-        
-          IRI feedIri = getFeedIRI(entryObj, request);    
-          String link = getLink(entryObj, feedIri, request);
-          
-          entry.addLink(link, "edit");
-    
-          return buildCreateEntryResponse(link, entry);
-      } else {
-        return new EmptyResponseContext(400);
-      }
-    } catch (ResponseContextException e) {
-      return createErrorResponse(e);
-    }
+    return createNonMediaEntry(request);
   }
 
   protected String getLink(
@@ -155,7 +127,16 @@
     IRI feedIri, 
     RequestContext request) 
       throws ResponseContextException {
-    return getLink(getName(entryObj), entryObj, feedIri, request);
+    return getLink(entryObj, feedIri, request, false);
+  }
+
+  protected String getLink(
+    T entryObj, 
+    IRI feedIri, 
+    RequestContext request,
+    boolean absolute)
+      throws ResponseContextException {
+    return getLink(getName(entryObj), entryObj, feedIri, request, absolute);
   }
 
   protected String getLink(
@@ -163,9 +144,22 @@
     T entryObj, 
     IRI feedIri, 
     RequestContext request) {
+    return getLink(name, entryObj, feedIri, request, false);
+  }
+
+  protected String getLink(
+    String name, 
+    T entryObj, 
+    IRI feedIri, 
+    RequestContext request,
+    boolean absolute) {
       feedIri = feedIri.trailingSlash();
       IRI entryIri = feedIri.resolve(UrlEncoding.encode(name, Profile.PATH.filter()));
     
+      if (absolute) {
+          entryIri = request.getResolvedUri().resolve(entryIri);
+      }
+
       String link = entryIri.toString();
     
       String qp = getQueryParameters(entryObj, request);
@@ -646,7 +640,8 @@
       String link = addEntryDetails(request, entry, feedUri, entryObj);
       addMediaContent(feedUri, entry, entryObj, request);
 
-      return buildPostMediaEntryResponse(link, entry);
+      String location = getLink(entryObj, feedUri, request, true);
+      return buildPostMediaEntryResponse(location, entry);
     } catch (IOException e) {
       return new EmptyResponseContext(500);
     } catch (ResponseContextException e) {
@@ -658,7 +653,7 @@
    * Create a regular entry
    * @param request The request context
    */
-  protected ResponseContext createNonMediaEntry(RequestContext request) throws IOException
{
+  protected ResponseContext createNonMediaEntry(RequestContext request) {
     try {
       Entry entry = getEntryFromRequest(request);
       if (entry != null) {
@@ -682,7 +677,8 @@
         String link = getLink(entryObj, feedUri, request);
         entry.addLink(link, "edit");
 
-        return buildCreateEntryResponse(link, entry);
+        String location = getLink(entryObj, feedUri, request, true);
+        return buildCreateEntryResponse(location, entry);
       } else {
         return new EmptyResponseContext(400);
       }

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java?rev=701370&r1=701369&r2=701370&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
(original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
Fri Oct  3 06:08:20 2008
@@ -145,10 +145,10 @@
     //prettyPrint(abdera, res.getDocument());
 
     IRI location = res.getLocation();
-    assertEquals(base + "customers/1001-Dan_Diephouse", location.toString());
+    assertEquals(uri + "customers/1001-Dan_Diephouse", location.toString());
 
     // GET the entry
-    res = client.get(colUri.resolve(location.toString()).toString());
+    res = client.get(location.toString());
     assertEquals(200, res.getStatus());
     res.release();
 
@@ -159,7 +159,7 @@
     assertEquals(uri + "customers/1001-Dan_Diephouse", entry_doc.getRoot().getEditLinkResolvedHref().toString());
 
     // HEAD
-    res = client.head(colUri.resolve(location.toString()).toString());
+    res = client.head(location.toString());
     assertEquals(200, res.getStatus());
     assertEquals(0, res.getContentLength());
     res.release();



Mime
View raw message