Jersey 2: Do simple migrations
A few migrations are said to be simple since they have direct replacements
in Jersey 2 from Jersey 1.
This list includes:
- ServletContainer replaces SpringServlet.
- MultivaluedHashMap replaces MultivaluedMapImpl.
- ClientBuilder.newClient() replaces Client.create().
- WebTarget replaces WebResource.
- LoggingFeature replaces LoggingFilter
As a general reference: https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/migration.html#mig-1.x
diff --git a/core/src/main/java/de/ids_mannheim/korap/server/KustvaktBaseServer.java b/core/src/main/java/de/ids_mannheim/korap/server/KustvaktBaseServer.java
index 3c05116..a97873b 100644
--- a/core/src/main/java/de/ids_mannheim/korap/server/KustvaktBaseServer.java
+++ b/core/src/main/java/de/ids_mannheim/korap/server/KustvaktBaseServer.java
@@ -22,7 +22,7 @@
import org.eclipse.jetty.servlet.ServletHolder;
import org.springframework.web.context.ContextLoaderListener;
-import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
+import org.glassfish.jersey.servlet.ServletContainer;
import de.ids_mannheim.korap.config.KustvaktConfiguration;
import de.ids_mannheim.korap.encryption.RandomCodeGenerator;
@@ -109,7 +109,7 @@
contextHandler.addEventListener(listener);
contextHandler.setInitParameter("adminToken", adminToken);
- ServletHolder servletHolder = new ServletHolder(new SpringServlet());
+ ServletHolder servletHolder = new ServletHolder(new ServletContainer());
servletHolder.setInitParameter(
"com.sun.jersey.config.property.packages", rootPackages);
servletHolder.setInitOrder(1);
diff --git a/core/src/main/java/de/ids_mannheim/korap/service/SearchService.java b/core/src/main/java/de/ids_mannheim/korap/service/SearchService.java
index 6a7d90e..da1924a 100644
--- a/core/src/main/java/de/ids_mannheim/korap/service/SearchService.java
+++ b/core/src/main/java/de/ids_mannheim/korap/service/SearchService.java
@@ -12,6 +12,7 @@
import javax.annotation.PostConstruct;
import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder;
@@ -24,7 +25,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
//import de.ids_mannheim.de.init.VCLoader;
import de.ids_mannheim.korap.authentication.AuthenticationManager;
@@ -375,7 +375,7 @@
"raw not supported!");
}
- MultivaluedMap<String, String> map = new MultivaluedMapImpl();
+ MultivaluedMap<String, String> map = new MultivaluedHashMap<String, String>();
map.add("q", query);
map.add("count", String.valueOf(pageLength));
map.add("lctxs", String.valueOf(meta.getSpanContext().getLeftSize()));
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/ClientsHandler.java b/core/src/main/java/de/ids_mannheim/korap/web/ClientsHandler.java
index 0207c54..85f6f5f 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/ClientsHandler.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/ClientsHandler.java
@@ -1,14 +1,13 @@
package de.ids_mannheim.korap.web;
-import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.exceptions.StatusCodes;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MultivaluedMap;
import java.net.URI;
@@ -19,13 +18,12 @@
// use for Piotr Ps. rest api connection
public class ClientsHandler {
- private WebResource service;
+ private WebTarget service;
public ClientsHandler (URI address) {
- ClientConfig config = new DefaultClientConfig();
- Client client = Client.create(config);
- this.service = client.resource(address);
+ Client client = ClientBuilder.newClient();
+ this.service = client.target(address);
}
@@ -45,7 +43,7 @@
public String getResponse (MultivaluedMap map, String ... paths)
throws KustvaktException {
try {
- WebResource resource = service;
+ WebTarget resource = service;
for (String p : paths)
resource = resource.path(p);
resource = resource.queryParams(map);
diff --git a/core/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java b/core/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
index 88fde0d..2a7e1db 100644
--- a/core/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
+++ b/core/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
@@ -17,17 +17,19 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerRequestFilter;
import com.sun.jersey.spi.container.ContainerResponseFilter;
import com.sun.jersey.spi.container.ResourceFilter;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.logging.LoggingFeature;
+
import de.ids_mannheim.korap.authentication.AuthenticationManager;
import de.ids_mannheim.korap.config.Attributes;
import de.ids_mannheim.korap.exceptions.KustvaktException;
@@ -45,7 +47,7 @@
@Provider
public class PiwikFilter implements ContainerRequestFilter, ResourceFilter {
- private WebResource service;
+ private WebTarget service;
// private static final String SERVICE = "http://localhost:8888";
private static final String SERVICE = "http://10.0.10.13";
private static Logger jlog = LogManager.getLogger(PiwikFilter.class);
@@ -58,12 +60,12 @@
public PiwikFilter () {
// controller = BeansFactory.getKustvaktContext()
// .getAuthenticationManager();
- ClientConfig config = new DefaultClientConfig();
- Client client = Client.create(config);
+ ClientConfig clientConfig = new ClientConfig();
if (jlog.isDebugEnabled())
- client.addFilter(new LoggingFilter());
+ clientConfig.register(LoggingFeature.class);
+ Client client = ClientBuilder.newClient(clientConfig);
UriBuilder b = UriBuilder.fromUri(SERVICE);
- service = client.resource(b.build());
+ service = client.target(b.build());
this.customVars = new HashMap<>();
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/web/controller/AuthenticationController.java b/full/src/main/java/de/ids_mannheim/korap/web/controller/AuthenticationController.java
index bca7dc2..f41d4f8 100644
--- a/full/src/main/java/de/ids_mannheim/korap/web/controller/AuthenticationController.java
+++ b/full/src/main/java/de/ids_mannheim/korap/web/controller/AuthenticationController.java
@@ -26,7 +26,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
-import com.sun.jersey.spi.container.ContainerRequest;
+import org.glassfish.jersey.server.ContainerRequest;
import com.sun.jersey.spi.container.ResourceFilters;
import de.ids_mannheim.korap.authentication.AuthenticationManager;
diff --git a/full/src/test/java/de/ids_mannheim/korap/misc/MapUtilsTest.java b/full/src/test/java/de/ids_mannheim/korap/misc/MapUtilsTest.java
index 4a7317b..f302f31 100644
--- a/full/src/test/java/de/ids_mannheim/korap/misc/MapUtilsTest.java
+++ b/full/src/test/java/de/ids_mannheim/korap/misc/MapUtilsTest.java
@@ -4,12 +4,11 @@
import java.util.Map;
+import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import org.junit.Test;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-
import de.ids_mannheim.korap.web.utils.MapUtils;
import edu.emory.mathcs.backport.java.util.Arrays;
@@ -18,7 +17,7 @@
@SuppressWarnings("unchecked")
@Test
public void testConvertToMap () {
- MultivaluedMap<String, String> mm = new MultivaluedMapImpl();
+ MultivaluedMap<String, String> mm = new MultivaluedHashMap<String, String>();
mm.put("k1", Arrays.asList(new String[] { "a", "b", "c" }));
mm.put("k2", Arrays.asList(new String[] { "d", "e", "f" }));
@@ -35,7 +34,7 @@
@Test
public void testConvertEmptyMap () {
- MultivaluedMap<String, String> mm = new MultivaluedMapImpl();
+ MultivaluedMap<String, String> mm = new MultivaluedHashMap<String, String>();
Map<String, String> map = MapUtils.toMap(mm);
assertEquals(0, map.size());
}