Author: wikier
Date: Fri Oct 11 19:36:39 2013
New Revision: 1531400

URL: http://svn.apache.org/r1531400
Log:
STANBOL-1172: returning '406 Not Acceptable' when enhancements cannot be 
serialized in the requested format

Modified:
    
stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java

Modified: 
stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java
URL: 
http://svn.apache.org/viewvc/stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java?rev=1531400&r1=1531399&r2=1531400&view=diff
==============================================================================
--- 
stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java
 (original)
+++ 
stanbol/trunk/enhancer/jersey/src/main/java/org/apache/stanbol/enhancer/jersey/writers/ContentItemWriter.java
 Fri Oct 11 19:36:39 2013
@@ -63,6 +63,7 @@ import javax.ws.rs.ext.Provider;
 import org.apache.clerezza.rdf.core.TripleCollection;
 import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.clerezza.rdf.core.serializedform.Serializer;
+import 
org.apache.clerezza.rdf.core.serializedform.UnsupportedSerializationFormatException;
 import org.apache.commons.io.IOUtils;
 import org.apache.http.entity.mime.FormBodyPart;
 import org.apache.http.entity.mime.HttpMultipart;
@@ -158,21 +159,29 @@ public class ContentItemWriter implement
                 if (mediaType.isWildcardType() || 
                         TEXT_PLAIN_TYPE.isCompatible(mediaType) || 
                         APPLICATION_OCTET_STREAM_TYPE.isCompatible(mediaType)) 
{
-                    mediaType = new MediaType(APPLICATION_JSON_TYPE.getType(), 
-                        APPLICATION_JSON_TYPE.getSubtype(),
-                        //Clerezza serialisers are hard coded to use UTF-8
-                        Collections.singletonMap("charset", UTF8.toString()));
-                    httpHeaders.putSingle("Content-Type", 
mediaType.toString());
+                               mediaType = new 
MediaType(APPLICATION_JSON_TYPE.getType(), 
+                               APPLICATION_JSON_TYPE.getSubtype(),
+                               //Clerezza serialisers are hard coded to use 
UTF-8
+                               Collections.singletonMap("charset", 
UTF8.toString()));
+                               httpHeaders.putSingle("Content-Type", 
mediaType.toString());
+                }
+                try {
+                       getSerializer().serialize(entityStream, 
ci.getMetadata(), mediaType.toString());
+                } catch (UnsupportedSerializationFormatException e) {
+                    throw new WebApplicationException(
+                            Response.status(Response.Status.NOT_ACCEPTABLE)
+                            .entity("The enhancement results cannot be 
serialized in " +
+                                       "the requested media type: "+ 
mediaType.toString())
+                            .build());
                 }
-                getSerializer().serialize(entityStream, ci.getMetadata(), 
mediaType.toString());
             } else { //  (2) return a single content part
                 Entry<UriRef,Blob> contentPart = getBlob(ci, 
Collections.singleton(mediaType.toString()));
                 if(contentPart == null){ //no alternate content with the 
requeste media type
                     throw new WebApplicationException(
                         Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE)
                         .entity("The requested enhancement chain has not 
created an " +
-                                       "version of the parsed content in the 
reuqest media " +
-                                       "type "+mediaType.toString())
+                                       "version of the parsed content in the 
request media " +
+                                       "type "+ mediaType.toString())
                         .build());
                 } else { //found -> stream the content to the client
                     //NOTE: This assumes that the presence of a charset


Reply via email to