You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by su...@apache.org on 2012/12/13 15:50:56 UTC

svn commit: r1421321 - /stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/RestUtil.java

Author: suat
Date: Thu Dec 13 14:50:55 2012
New Revision: 1421321

URL: http://svn.apache.org/viewvc?rev=1421321&view=rev
Log:
STANBOL-840: A missing file in the previous commit


-Enabled CORS for all responses returning error codes e.g NOT_FOUND or BAD_REQUEST
-Added two additional method to the SemanticIndexManagerResource so that the parameters of the services provided by this resources are compatible. For instance while deleting an LDPath program, it is possible to specify the name of the program either as a QueryParam or a PathParam.
-Added a format parameter to the /metadata endpoint so that the metadata could be retrieved in the desired format

Modified:
    stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/RestUtil.java

Modified: stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/RestUtil.java
URL: http://svn.apache.org/viewvc/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/RestUtil.java?rev=1421321&r1=1421320&r2=1421321&view=diff
==============================================================================
--- stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/RestUtil.java (original)
+++ stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/RestUtil.java Thu Dec 13 14:50:55 2012
@@ -16,12 +16,20 @@
  */
 package org.apache.stanbol.contenthub.web.util;
 
+import static org.apache.stanbol.commons.web.base.CorsHelper.addCORSOrigin;
+
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.servlet.ServletContext;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.stanbol.commons.web.base.CorsHelper;
 
 /**
  * Utility class for REST services
@@ -93,4 +101,27 @@ public class RestUtil {
         }
         return acceptedMediaType;
     }
+
+    /**
+     * Create a {@link Response} with the given parameters. It also add the necessary headers for CORS by
+     * calling the {@link CorsHelper#addCORSOrigin(ServletContext, ResponseBuilder, HttpHeaders)} method.
+     * 
+     * @param servletContext
+     * @param status
+     * @param entity
+     * @param headers
+     * @return
+     */
+    public static Response createResponse(ServletContext servletContext,
+                                          Status status,
+                                          Object entity,
+                                          HttpHeaders headers) {
+        ResponseBuilder rb = Response.status(status);
+        addCORSOrigin(servletContext, rb, headers);
+        if (entity != null) {
+            return rb.entity(entity).build();
+        } else {
+            return rb.build();
+        }
+    }
 }
\ No newline at end of file