From 7b28b198633d01121cda58b08dcbb73c5580f376 Mon Sep 17 00:00:00 2001
From: Alexander Kiy <alekiy@uni-potsdam.de>
Date: Thu, 25 Apr 2019 15:40:20 +0200
Subject: [PATCH] added correct cors filter and removed old implementation

---
 .../unipotsdam/cs/toolup/util/JerseyUtil.java | 19 -------------------
 .../ws/resource/ApplicationResource.java      | 12 +++++-------
 .../toolup/ws/resource/CategoryResource.java  | 10 ++++------
 .../toolup/ws/resource/FeatureResource.java   |  8 ++------
 .../cs/toolup/ws/resource/LookupResource.java |  9 ++-------
 .../cs/toolup/ws/resource/SearchResource.java |  4 +---
 6 files changed, 14 insertions(+), 48 deletions(-)
 delete mode 100644 src/main/java/de/unipotsdam/cs/toolup/util/JerseyUtil.java

diff --git a/src/main/java/de/unipotsdam/cs/toolup/util/JerseyUtil.java b/src/main/java/de/unipotsdam/cs/toolup/util/JerseyUtil.java
deleted file mode 100644
index b34c404..0000000
--- a/src/main/java/de/unipotsdam/cs/toolup/util/JerseyUtil.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package de.unipotsdam.cs.toolup.util;
-
-import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.sql.SQLException;
-
-/**
- * Created by Thiemo on 15.03.2016.
- */
-public class JerseyUtil {
-
-    public static final String ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
-    public static final String ALL = "*";
-
-    public static Response createResponseOk(Object responseEntity) throws IOException, SQLException {
-        return Response.ok(responseEntity).header(ACCESS_CONTROL_ALLOW_ORIGIN, ALL).build();
-    }
-
-}
diff --git a/src/main/java/de/unipotsdam/cs/toolup/ws/resource/ApplicationResource.java b/src/main/java/de/unipotsdam/cs/toolup/ws/resource/ApplicationResource.java
index ce9144a..0c1f9ee 100644
--- a/src/main/java/de/unipotsdam/cs/toolup/ws/resource/ApplicationResource.java
+++ b/src/main/java/de/unipotsdam/cs/toolup/ws/resource/ApplicationResource.java
@@ -7,8 +7,6 @@ import javax.ws.rs.*;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-import static de.unipotsdam.cs.toolup.util.JerseyUtil.createResponseOk;
-
 
 @Path("application")
 public class ApplicationResource {
@@ -16,35 +14,35 @@ public class ApplicationResource {
     @GET
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response getAll() throws Exception {
-        return createResponseOk(ApplicationBean.getAllApplications());
+        return Response.ok(ApplicationBean.getAllApplications()).build();
     }
 
     @GET
     @Path("/{id}")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response get(@PathParam("id") String id) throws Exception {
-        return createResponseOk(ApplicationBean.getBean(id));
+        return Response.ok(ApplicationBean.getBean(id)).build();
     }
 
     @POST
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response post(Application app) throws Exception {
-        return createResponseOk(ApplicationBean.createApplication(app));
+        return Response.ok(ApplicationBean.createApplication(app)).build();
     }
 
     @PATCH
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response patch(Application app) throws Exception {
-        return createResponseOk(ApplicationBean.createApplication(app));
+        return Response.ok(ApplicationBean.createApplication(app)).build();
     }
 
     @DELETE
     @Path("/{id}")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response delete(@PathParam("id") String id) throws Exception {
-        return createResponseOk(ApplicationBean.deleteApplication(id));
+        return Response.ok(ApplicationBean.deleteApplication(id)).build();
     }
 
 }
diff --git a/src/main/java/de/unipotsdam/cs/toolup/ws/resource/CategoryResource.java b/src/main/java/de/unipotsdam/cs/toolup/ws/resource/CategoryResource.java
index d3af1cf..fbda3a6 100644
--- a/src/main/java/de/unipotsdam/cs/toolup/ws/resource/CategoryResource.java
+++ b/src/main/java/de/unipotsdam/cs/toolup/ws/resource/CategoryResource.java
@@ -9,8 +9,6 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-import static de.unipotsdam.cs.toolup.util.JerseyUtil.createResponseOk;
-
 
 @Path("category")
 public class CategoryResource {
@@ -19,28 +17,28 @@ public class CategoryResource {
     @Path("/")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response getAll() throws Exception {
-        return createResponseOk(CategoryBean.getAllCategories());
+        return Response.ok(CategoryBean.getAllCategories()).build();
     }
 
     @GET
     @Path("/{id}")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response get(@PathParam("id") String id) throws Exception{
-        return createResponseOk(CategoryBean.getBean(id));
+        return Response.ok(CategoryBean.getBean(id)).build();
     }
 
     @GET
     @Path("/withApplication")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response getAllWithApplication() throws Exception {
-        return  createResponseOk(CategoryBean.getAllCategoriesWithApplication());
+        return  Response.ok(CategoryBean.getAllCategoriesWithApplication()).build();
     }
 
     @GET
     @Path("/toplevel")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response getTopLevelCategories() throws Exception {
-        return createResponseOk(CategoryBean.getTopLevelCategories());
+        return Response.ok(CategoryBean.getTopLevelCategories()).build();
     }
 
 }
diff --git a/src/main/java/de/unipotsdam/cs/toolup/ws/resource/FeatureResource.java b/src/main/java/de/unipotsdam/cs/toolup/ws/resource/FeatureResource.java
index fba402d..54bff03 100644
--- a/src/main/java/de/unipotsdam/cs/toolup/ws/resource/FeatureResource.java
+++ b/src/main/java/de/unipotsdam/cs/toolup/ws/resource/FeatureResource.java
@@ -8,10 +8,6 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
-import java.io.IOException;
-import java.sql.SQLException;
-
-import static de.unipotsdam.cs.toolup.util.JerseyUtil.createResponseOk;
 
 
 @Path("feature")
@@ -21,14 +17,14 @@ public class FeatureResource {
     @Path("/")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response getAll() throws Exception {
-        return createResponseOk(FeatureBean.getAllFeatures());
+        return Response.ok(FeatureBean.getAllFeatures()).build();
     }
 
     @GET
     @Path("/{id}")
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response get(@PathParam("id") String id) throws Exception {
-        return createResponseOk(FeatureBean.getBean(id));
+        return Response.ok(FeatureBean.getBean(id)).build();
     }
 
 }
diff --git a/src/main/java/de/unipotsdam/cs/toolup/ws/resource/LookupResource.java b/src/main/java/de/unipotsdam/cs/toolup/ws/resource/LookupResource.java
index 5b88420..f9415bd 100644
--- a/src/main/java/de/unipotsdam/cs/toolup/ws/resource/LookupResource.java
+++ b/src/main/java/de/unipotsdam/cs/toolup/ws/resource/LookupResource.java
@@ -9,8 +9,6 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-import static de.unipotsdam.cs.toolup.util.JerseyUtil.createResponseOk;
-
 
 @Path("lookup")
 public class LookupResource {
@@ -18,10 +16,7 @@ public class LookupResource {
     @POST
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response post(@FormParam("features") String features) throws Exception {
-        return createResponseOk(LookupResultBean.getBean(features));
+        return Response.ok(LookupResultBean.getBean(features)).build();
     }
 
-
-}
-
-
+}
\ No newline at end of file
diff --git a/src/main/java/de/unipotsdam/cs/toolup/ws/resource/SearchResource.java b/src/main/java/de/unipotsdam/cs/toolup/ws/resource/SearchResource.java
index edb8037..cd96bfa 100644
--- a/src/main/java/de/unipotsdam/cs/toolup/ws/resource/SearchResource.java
+++ b/src/main/java/de/unipotsdam/cs/toolup/ws/resource/SearchResource.java
@@ -1,6 +1,5 @@
 package de.unipotsdam.cs.toolup.ws.resource;
 
-
 import de.unipotsdam.cs.toolup.ws.beans.ApplicationBean;
 
 import javax.ws.rs.FormParam;
@@ -10,7 +9,6 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-import static de.unipotsdam.cs.toolup.util.JerseyUtil.createResponseOk;
 
 @Path("search")
 public class SearchResource {
@@ -26,6 +24,6 @@ public class SearchResource {
     @POST
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response post(@FormParam("search string") String searchString) throws Exception {
-        return createResponseOk(ApplicationBean.searchFor(searchString));
+        return Response.ok(ApplicationBean.searchFor(searchString)).build();
     }
 }
-- 
GitLab