I can :) Should be fine now.

Dominique

On Tue, Mar 16, 2010 at 5:48 PM, Florent Guillaume <[email protected]> wrote:
> Argh yes, I missed that :)
> Do you want me to fix it or can you do it?
>
> Thanks,
> Florent
>
> 2010/3/16 Dominique Pfister <[email protected]>:
>> Hi Florent,
>>
>> Your valid mime-type check now produces a log messages for every
>> non-document or document that has no content stream mime type set
>> (cmis:contentStreamMimeType is null), such as:
>>
>> 17:22:52,231 ERROR [CMISObjectsCollection] Object
>> 2e683c0a-f0e3-43fd-bbef-4b88745275af has invalid
>> cmis:contentStreamMimeType 'null', will be served as
>> 'application/octet-stream'
>>
>> I guess the object value should first be checked against null, what do
>> you think?
>>
>> Kind regards
>> Dominique
>>
>> On Fri, Mar 12, 2010 at 1:17 PM,  <[email protected]> wrote:
>>> Author: fguillaume
>>> Date: Fri Mar 12 12:17:37 2010
>>> New Revision: 922231
>>>
>>> URL: http://svn.apache.org/viewvc?rev=922231&view=rev
>>> Log:
>>> CMIS-156: don't crash on invalid MIME types
>>>
>>> Modified:
>>>    
>>> 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/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
>>>
>>> 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=922231&r1=922230&r2=922231&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
>>>  Fri Mar 12 12:17:37 2010
>>> @@ -31,6 +31,7 @@ import java.util.LinkedList;
>>>  import java.util.List;
>>>  import java.util.Map;
>>>
>>> +import javax.activation.MimeType;
>>>  import javax.xml.namespace.QName;
>>>
>>>  import org.apache.abdera.factory.Factory;
>>> @@ -552,7 +553,7 @@ public abstract class CMISObjectsCollect
>>>         } catch (ResponseContextException e) {
>>>             return createErrorResponse(e);
>>>         } catch (IllegalArgumentException e) {
>>> -           return createErrorResponse(new ResponseContextException(400, 
>>> e));
>>> +            return createErrorResponse(new ResponseContextException(400, 
>>> e));
>>>         } catch (ConstraintViolationException e) {
>>>             return createErrorResponse(new ResponseContextException(409, 
>>> e));
>>>         } catch (CMISRuntimeException e) {
>>> @@ -758,7 +759,17 @@ public abstract class CMISObjectsCollect
>>>     @Override
>>>     public String getContentType(ObjectEntry object) {
>>>         try {
>>> -            return (String) 
>>> object.getValue(Property.CONTENT_STREAM_MIME_TYPE);
>>> +            String mimeType = (String) 
>>> object.getValue(Property.CONTENT_STREAM_MIME_TYPE);
>>> +            // make sure it's a valid MIME type otherwise Abdera will throw
>>> +            try {
>>> +                new MimeType(mimeType).toString();
>>> +            } catch (Exception e) {
>>> +                log.error("Object " + object.getId() + " has invalid "
>>> +                        + Property.CONTENT_STREAM_MIME_TYPE + " '" + 
>>> mimeType
>>> +                        + "', will be served as 
>>> 'application/octet-stream'");
>>> +                mimeType = "application/octet-stream";
>>> +            }
>>> +            return mimeType;
>>>         } catch (IllegalArgumentException e) {
>>>             return null;
>>>         }
>>>
>>> Modified: 
>>> incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
>>> URL: 
>>> http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java?rev=922231&r1=922230&r2=922231&view=diff
>>> ==============================================================================
>>> --- 
>>> incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
>>>  (original)
>>> +++ 
>>> incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
>>>  Fri Mar 12 12:17:37 2010
>>> @@ -83,6 +83,8 @@ public abstract class AtomPubServerTestC
>>>
>>>     protected static String doc3id;
>>>
>>> +    protected static String doc4id;
>>> +
>>>     protected RepositoryService repositoryService;
>>>
>>>     public Server server;
>>> @@ -188,6 +190,15 @@ public abstract class AtomPubServerTestC
>>>         doc3.save();
>>>         doc3id = doc3.getId();
>>>
>>> +        Document doc4 = folder2.newDocument("doc");
>>> +        doc4.setName("doc4");
>>> +        doc4.setValue("title", "doc 4 title");
>>> +        cs = new SimpleContentStream(TEST_FILE_CONTENT.getBytes("UTF-8"),
>>> +                "invalid_mime", "doc4.txt");
>>> +        doc4.setContentStream(cs);
>>> +        doc4.save();
>>> +        doc4id = doc4.getId();
>>> +
>>>         conn.close();
>>>         return repo;
>>>     }
>>> @@ -453,6 +464,17 @@ public abstract class AtomPubServerTestC
>>>         method.releaseConnection();
>>>     }
>>>
>>> +    public void testBadContentType() throws Exception {
>>> +        HttpMethod method = new GetMethod(base + "/file/" + doc4id);
>>> +        int status = new HttpClient().executeMethod(method);
>>> +        assertEquals(HttpStatus.SC_OK, status);
>>> +        assertEquals("application/octet-stream", method.getResponseHeader(
>>> +                "Content-Type").getValue());
>>> +        byte[] body = method.getResponseBody();
>>> +        assertEquals(TEST_FILE_CONTENT, new String(body, "UTF-8"));
>>> +        method.releaseConnection();
>>> +    }
>>> +
>>>     public void testQueryPOST() throws Exception {
>>>         EntityProvider provider = new QueryEntityProvider("SELECT * FROM 
>>> doc",
>>>                 true, null, null);
>>>
>>>
>>>
>>
>
>
>
> --
> Florent Guillaume, Director of R&D, Nuxeo
> Open Source, Java EE based, Enterprise Content Management (ECM)
> http://www.nuxeo.com   http://www.nuxeo.org   +33 1 40 33 79 87
>

Reply via email to