Author: fguillaume
Date: Wed Dec 23 16:34:07 2009
New Revision: 893566
URL: http://svn.apache.org/viewvc?rev=893566&view=rev
Log:
Be more lenient on invalid AtomPub entries for compatibility with buggy clients
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/pom.xml
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml
Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/pom.xml?rev=893566&r1=893565&r2=893566&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/pom.xml
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/pom.xml Wed
Dec 23 16:34:07 2009
@@ -55,6 +55,10 @@
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
<dependency>
<groupId>junit</groupId>
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java?rev=893566&r1=893565&r2=893566&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
Wed Dec 23 16:34:07 2009
@@ -25,6 +25,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -68,12 +69,17 @@
import org.apache.chemistry.impl.simple.SimpleContentStream;
import org.apache.chemistry.util.GregorianCalendar;
import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* CMIS Collection for object entries.
*/
public abstract class CMISObjectsCollection extends
CMISCollection<ObjectEntry> {
+ private static final Log log =
LogFactory.getLog(CMISObjectsCollection.class);
+
public CMISObjectsCollection(String type, String name, String id,
Repository repository) {
super(type, name, id, repository);
@@ -217,9 +223,51 @@
protected PropertiesAndStream extractCMISProperties(RequestContext request,
String typeId) throws ResponseContextException {
boolean isNew = typeId == null;
- Entry entry = getEntryFromRequest(request);
- if (entry == null || !ProviderHelper.isValidEntry(entry)) {
- throw new ResponseContextException("Invalid entry", 400);
+ Entry entry;
+ try {
+ entry = getEntryFromRequest(request);
+ } catch (ResponseContextException e) {
+ if (!e.toString().contains("Undeclared namespace prefix
\"cmisra\"")) {
+ throw e;
+ }
+ // attempt to fixup missing cmisra ns for buggy clients
+ // (IBM Firefox plugin)
+ // TODO
+ entry = getEntryFromRequest(request);
+ }
+ if (entry == null) {
+ throw new ResponseContextException("Missing entry", 400);
+ }
+ if (!ProviderHelper.isValidEntry(entry)) {
+ List<String> errors = new LinkedList<String>();
+ // attempt to fixup entries for buggy clients
+ // (IBM Firefox plugin and others)
+ if (entry.getId() == null
+ || entry.getId().toString().trim().length() == 0) {
+ errors.add("missing atom:id");
+ }
+ if (entry.getUpdated() == null) {
+ errors.add("missing atom:updated");
+ }
+ if (entry.getAuthor() == null
+ && (entry.getSource() != null &&
entry.getSource().getAuthor() == null)) {
+ errors.add("missing atom:author");
+ }
+ Content content = entry.getContentElement();
+ if (content == null) {
+ if (entry.getAlternateLink() == null) {
+ errors.add("missing atom:link rel=alternate");
+ }
+ } else {
+ if ((content.getSrc() != null || content.getContentType() ==
Content.Type.MEDIA)
+ && entry.getSummaryElement() == null) {
+ errors.add("missing atom:summary");
+ }
+ }
+ if (!errors.isEmpty()) {
+ log.error("Invalid entry: " + StringUtils.join(errors, ", "));
+ // throw new ResponseContextException("Invalid entry", 400);
+ }
}
// get properties and type from entry
Modified:
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java?rev=893566&r1=893565&r2=893566&view=diff
==============================================================================
---
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
(original)
+++
incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
Wed Dec 23 16:34:07 2009
@@ -274,7 +274,9 @@
}
@POST
- @Consumes(AtomPub.MEDIA_TYPE_ATOM_ENTRY)
+ @Consumes( { AtomPub.MEDIA_TYPE_ATOM_ENTRY,
+ // IBM Firefox plugin compat, stupid RESTEasy
+ AtomPub.MEDIA_TYPE_ATOM_ENTRY + ";charset=UTF-8" })
@Path("children/{objectid}")
public Response doPostChildren() {
// objectid decoded by Abdera getCollectionAdapter
Modified: incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml?rev=893566&r1=893565&r2=893566&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-parent/pom.xml Wed Dec 23
16:34:07 2009
@@ -17,13 +17,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
-
+
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>6</version>
</parent>
-
+
<prerequisites>
<maven>2.0.9</maven>
</prerequisites>
@@ -35,7 +35,7 @@
<description>Parent POM for the Chemistry project gathering all common
settings</description>
<inceptionYear>2009</inceptionYear>
<packaging>pom</packaging>
-
+
<properties>
<cxf.version>2.2.2</cxf.version>
</properties>
@@ -69,7 +69,7 @@
<configuration>
<target>1.5</target>
<source>1.5</source>
- <encoding>UTF-8</encoding>
+ <encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- Enable maven-source-plugin -->
@@ -176,6 +176,11 @@
<version>1.1.1</version>
</dependency>
<dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<version>1.0.1</version>
@@ -191,9 +196,9 @@
<version>1.0</version>
</dependency>
<dependency>
- <groupId>org.apache.cxf</groupId>
- <artifactId>cxf-rt-frontend-jaxrs</artifactId>
- <version>${cxf.version}</version>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>