diff --git a/jersey/pom.xml b/jersey/pom.xml
index cb09247773..9a212c6da1 100644
--- a/jersey/pom.xml
+++ b/jersey/pom.xml
@@ -100,7 +100,7 @@
- 2.38
+ 3.1.1
3.3.2
diff --git a/jersey/src/main/java/com/baeldung/jersey/client/JerseyClient.java b/jersey/src/main/java/com/baeldung/jersey/client/JerseyClient.java
index 88ad891411..3865e64aa0 100644
--- a/jersey/src/main/java/com/baeldung/jersey/client/JerseyClient.java
+++ b/jersey/src/main/java/com/baeldung/jersey/client/JerseyClient.java
@@ -1,19 +1,20 @@
package com.baeldung.jersey.client;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.Response;
-
import org.glassfish.jersey.client.ClientConfig;
import com.baeldung.jersey.client.filter.RequestClientFilter;
import com.baeldung.jersey.client.filter.ResponseClientFilter;
import com.baeldung.jersey.client.interceptor.RequestClientWriterInterceptor;
+import com.baeldung.jersey.server.Greetings;
+
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientBuilder;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.Response;
public class JerseyClient {
- private static final String URI_GREETINGS = "http://localhost:8080/jersey/greetings";
+ public static final String URI_GREETINGS = "http://localhost:8080/jersey/greetings";
public static String getHelloGreeting() {
return createClient().target(URI_GREETINGS)
@@ -38,6 +39,7 @@ public class JerseyClient {
config.register(RequestClientFilter.class);
config.register(ResponseClientFilter.class);
config.register(RequestClientWriterInterceptor.class);
+ config.register(Greetings.class);
return ClientBuilder.newClient(config);
}
diff --git a/jersey/src/main/java/com/baeldung/jersey/client/JerseyClientHeaders.java b/jersey/src/main/java/com/baeldung/jersey/client/JerseyClientHeaders.java
index 29db298e9e..f0d62111aa 100644
--- a/jersey/src/main/java/com/baeldung/jersey/client/JerseyClientHeaders.java
+++ b/jersey/src/main/java/com/baeldung/jersey/client/JerseyClientHeaders.java
@@ -9,17 +9,17 @@ import org.glassfish.jersey.client.oauth1.ConsumerCredentials;
import org.glassfish.jersey.client.oauth1.OAuth1ClientSupport;
import org.glassfish.jersey.client.oauth2.OAuth2ClientSupport;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.Feature;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.sse.InboundSseEvent;
-import javax.ws.rs.sse.SseEventSource;
-
import static org.glassfish.jersey.client.authentication.HttpAuthenticationFeature.*;
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientBuilder;
+import jakarta.ws.rs.client.Invocation;
+import jakarta.ws.rs.client.WebTarget;
+import jakarta.ws.rs.core.Feature;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.sse.InboundSseEvent;
+import jakarta.ws.rs.sse.SseEventSource;
+
public class JerseyClientHeaders {
private static final String BEARER_CONSUMER_SECRET = "my-consumer-secret";
diff --git a/jersey/src/main/java/com/baeldung/jersey/client/filter/AddHeaderOnRequestFilter.java b/jersey/src/main/java/com/baeldung/jersey/client/filter/AddHeaderOnRequestFilter.java
index a874928c16..61f2dfe475 100644
--- a/jersey/src/main/java/com/baeldung/jersey/client/filter/AddHeaderOnRequestFilter.java
+++ b/jersey/src/main/java/com/baeldung/jersey/client/filter/AddHeaderOnRequestFilter.java
@@ -1,9 +1,10 @@
package com.baeldung.jersey.client.filter;
-import javax.ws.rs.client.ClientRequestContext;
-import javax.ws.rs.client.ClientRequestFilter;
import java.io.IOException;
+import jakarta.ws.rs.client.ClientRequestContext;
+import jakarta.ws.rs.client.ClientRequestFilter;
+
public class AddHeaderOnRequestFilter implements ClientRequestFilter {
public static final String FILTER_HEADER_VALUE = "filter-header-value";
diff --git a/jersey/src/main/java/com/baeldung/jersey/client/filter/RequestClientFilter.java b/jersey/src/main/java/com/baeldung/jersey/client/filter/RequestClientFilter.java
index 8c6ac2c5fb..5d7d8be684 100644
--- a/jersey/src/main/java/com/baeldung/jersey/client/filter/RequestClientFilter.java
+++ b/jersey/src/main/java/com/baeldung/jersey/client/filter/RequestClientFilter.java
@@ -2,13 +2,13 @@ package com.baeldung.jersey.client.filter;
import java.io.IOException;
-import javax.ws.rs.client.ClientRequestContext;
-import javax.ws.rs.client.ClientRequestFilter;
-import javax.ws.rs.ext.Provider;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import jakarta.ws.rs.client.ClientRequestContext;
+import jakarta.ws.rs.client.ClientRequestFilter;
+import jakarta.ws.rs.ext.Provider;
+
@Provider
public class RequestClientFilter implements ClientRequestFilter {
diff --git a/jersey/src/main/java/com/baeldung/jersey/client/filter/ResponseClientFilter.java b/jersey/src/main/java/com/baeldung/jersey/client/filter/ResponseClientFilter.java
index 1676fa2094..4348937364 100644
--- a/jersey/src/main/java/com/baeldung/jersey/client/filter/ResponseClientFilter.java
+++ b/jersey/src/main/java/com/baeldung/jersey/client/filter/ResponseClientFilter.java
@@ -2,14 +2,14 @@ package com.baeldung.jersey.client.filter;
import java.io.IOException;
-import javax.ws.rs.client.ClientRequestContext;
-import javax.ws.rs.client.ClientResponseContext;
-import javax.ws.rs.client.ClientResponseFilter;
-import javax.ws.rs.ext.Provider;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import jakarta.ws.rs.client.ClientRequestContext;
+import jakarta.ws.rs.client.ClientResponseContext;
+import jakarta.ws.rs.client.ClientResponseFilter;
+import jakarta.ws.rs.ext.Provider;
+
@Provider
public class ResponseClientFilter implements ClientResponseFilter {
diff --git a/jersey/src/main/java/com/baeldung/jersey/client/interceptor/RequestClientWriterInterceptor.java b/jersey/src/main/java/com/baeldung/jersey/client/interceptor/RequestClientWriterInterceptor.java
index 7216cf18cc..3f55f56ec2 100644
--- a/jersey/src/main/java/com/baeldung/jersey/client/interceptor/RequestClientWriterInterceptor.java
+++ b/jersey/src/main/java/com/baeldung/jersey/client/interceptor/RequestClientWriterInterceptor.java
@@ -2,14 +2,14 @@ package com.baeldung.jersey.client.interceptor;
import java.io.IOException;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.ext.Provider;
-import javax.ws.rs.ext.WriterInterceptor;
-import javax.ws.rs.ext.WriterInterceptorContext;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.ext.Provider;
+import jakarta.ws.rs.ext.WriterInterceptor;
+import jakarta.ws.rs.ext.WriterInterceptorContext;
+
@Provider
public class RequestClientWriterInterceptor implements WriterInterceptor {
diff --git a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/ExceptionHandlingConfig.java b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/ExceptionHandlingConfig.java
index d4cc1a81a1..efe3b6877e 100644
--- a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/ExceptionHandlingConfig.java
+++ b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/ExceptionHandlingConfig.java
@@ -1,12 +1,12 @@
package com.baeldung.jersey.exceptionhandling;
-import javax.ws.rs.ApplicationPath;
-
import org.glassfish.jersey.server.ResourceConfig;
import com.baeldung.jersey.exceptionhandling.rest.exceptions.IllegalArgumentExceptionMapper;
import com.baeldung.jersey.exceptionhandling.rest.exceptions.ServerExceptionMapper;
+import jakarta.ws.rs.ApplicationPath;
+
@ApplicationPath("/exception-handling/*")
public class ExceptionHandlingConfig extends ResourceConfig {
diff --git a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/StocksResource.java b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/StocksResource.java
index 64b645a1c6..de21440049 100644
--- a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/StocksResource.java
+++ b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/StocksResource.java
@@ -2,19 +2,19 @@ package com.baeldung.jersey.exceptionhandling.rest;
import java.util.Optional;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
import com.baeldung.jersey.exceptionhandling.data.Stock;
import com.baeldung.jersey.exceptionhandling.repo.Db;
import com.baeldung.jersey.exceptionhandling.service.Repository;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
@Path("/stocks")
public class StocksResource {
private static final Db stocks = Repository.STOCKS_DB;
diff --git a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/WalletsResource.java b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/WalletsResource.java
index e5f8ddec06..667f721e4a 100644
--- a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/WalletsResource.java
+++ b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/WalletsResource.java
@@ -2,18 +2,6 @@ package com.baeldung.jersey.exceptionhandling.rest;
import java.util.Optional;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
import com.baeldung.jersey.exceptionhandling.data.Stock;
import com.baeldung.jersey.exceptionhandling.data.Wallet;
import com.baeldung.jersey.exceptionhandling.repo.Db;
@@ -21,6 +9,17 @@ import com.baeldung.jersey.exceptionhandling.rest.exceptions.InvalidTradeExcepti
import com.baeldung.jersey.exceptionhandling.rest.exceptions.RestErrorResponse;
import com.baeldung.jersey.exceptionhandling.service.Repository;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.PUT;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
@Path("/wallets")
public class WalletsResource {
private static final Db stocks = Repository.STOCKS_DB;
@@ -84,7 +83,7 @@ public class WalletsResource {
RestErrorResponse response = new RestErrorResponse();
response.setSubject(wallet);
response.setMessage("insufficient balance");
- throw new WebApplicationException(Response.status(Status.NOT_ACCEPTABLE)
+ throw new WebApplicationException(Response.status(Response.Status.NOT_ACCEPTABLE)
.entity(response)
.build());
}
diff --git a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/IllegalArgumentExceptionMapper.java b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/IllegalArgumentExceptionMapper.java
index b577121027..fdaeb218c0 100644
--- a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/IllegalArgumentExceptionMapper.java
+++ b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/IllegalArgumentExceptionMapper.java
@@ -1,8 +1,8 @@
package com.baeldung.jersey.exceptionhandling.rest.exceptions;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.ExceptionMapper;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.ext.ExceptionMapper;
public class IllegalArgumentExceptionMapper implements ExceptionMapper {
public static final String DEFAULT_MESSAGE = "an illegal argument was provided";
diff --git a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/InvalidTradeException.java b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/InvalidTradeException.java
index 11277c048a..966683dd6a 100644
--- a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/InvalidTradeException.java
+++ b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/InvalidTradeException.java
@@ -1,7 +1,7 @@
package com.baeldung.jersey.exceptionhandling.rest.exceptions;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Response;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.core.Response;
public class InvalidTradeException extends WebApplicationException {
private static final long serialVersionUID = 1L;
diff --git a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/ServerExceptionMapper.java b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/ServerExceptionMapper.java
index adfac000e8..f537c1756a 100644
--- a/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/ServerExceptionMapper.java
+++ b/jersey/src/main/java/com/baeldung/jersey/exceptionhandling/rest/exceptions/ServerExceptionMapper.java
@@ -1,19 +1,18 @@
package com.baeldung.jersey.exceptionhandling.rest.exceptions;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import javax.ws.rs.ext.ExceptionMapper;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.ext.ExceptionMapper;
public class ServerExceptionMapper implements ExceptionMapper {
public static final String HTTP_405_MESSAGE = "use one of";
@Override
public Response toResponse(final WebApplicationException exception) {
- String message = exception.getMessage();
+ String message;
Response response = exception.getResponse();
- Status status = response.getStatusInfo()
+ Response.Status status = response.getStatusInfo()
.toEnum();
switch (status) {
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/EchoHeaders.java b/jersey/src/main/java/com/baeldung/jersey/server/EchoHeaders.java
index a8df3c10a8..b3b03fbb4d 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/EchoHeaders.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/EchoHeaders.java
@@ -2,14 +2,17 @@ package com.baeldung.jersey.server;
import com.baeldung.jersey.client.filter.AddHeaderOnRequestFilter;
-import javax.annotation.security.RolesAllowed;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.*;
-import javax.ws.rs.sse.OutboundSseEvent;
-import javax.ws.rs.sse.Sse;
-import javax.ws.rs.sse.SseEventSink;
+import jakarta.annotation.security.RolesAllowed;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.sse.OutboundSseEvent;
+import jakarta.ws.rs.sse.Sse;
+import jakarta.ws.rs.sse.SseEventSink;
@Path("/echo-headers")
public class EchoHeaders {
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/Greetings.java b/jersey/src/main/java/com/baeldung/jersey/server/Greetings.java
index d0ea873db1..e753d34901 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/Greetings.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/Greetings.java
@@ -1,13 +1,12 @@
package com.baeldung.jersey.server;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
import com.baeldung.jersey.server.config.HelloBinding;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.core.Response;
+
@Path("/greetings")
public class Greetings {
@@ -26,7 +25,7 @@ public class Greetings {
@POST
@Path("/custom")
public Response getCustomGreeting(String name) {
- return Response.status(Status.OK.getStatusCode())
+ return Response.status(Response.Status.OK.getStatusCode())
.build();
}
}
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/ItemParam.java b/jersey/src/main/java/com/baeldung/jersey/server/ItemParam.java
index 0f60a20b92..6c05f5b650 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/ItemParam.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/ItemParam.java
@@ -1,8 +1,8 @@
package com.baeldung.jersey.server;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.PathParam;
+import jakarta.ws.rs.FormParam;
+import jakarta.ws.rs.HeaderParam;
+import jakarta.ws.rs.PathParam;
public class ItemParam {
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/Items.java b/jersey/src/main/java/com/baeldung/jersey/server/Items.java
index c24e6820f5..4aab765351 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/Items.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/Items.java
@@ -1,6 +1,15 @@
package com.baeldung.jersey.server;
-import javax.ws.rs.*;
+import jakarta.ws.rs.BeanParam;
+import jakarta.ws.rs.CookieParam;
+import jakarta.ws.rs.FormParam;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.HeaderParam;
+import jakarta.ws.rs.MatrixParam;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.QueryParam;
@Path("items")
public class Items {
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/Responder.java b/jersey/src/main/java/com/baeldung/jersey/server/Responder.java
index cb0c976fe3..3ce8e65bd0 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/Responder.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/Responder.java
@@ -2,11 +2,11 @@ package com.baeldung.jersey.server;
import com.baeldung.jersey.server.model.Person;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
@Path("/response")
public class Responder {
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/config/HelloBinding.java b/jersey/src/main/java/com/baeldung/jersey/server/config/HelloBinding.java
index 49b11adeab..f620514094 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/config/HelloBinding.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/config/HelloBinding.java
@@ -3,7 +3,7 @@ package com.baeldung.jersey.server.config;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
-import javax.ws.rs.NameBinding;
+import jakarta.ws.rs.NameBinding;
@NameBinding
@Retention(RetentionPolicy.RUNTIME)
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/config/HelloDynamicBinding.java b/jersey/src/main/java/com/baeldung/jersey/server/config/HelloDynamicBinding.java
index 19c407f80d..89b520bf97 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/config/HelloDynamicBinding.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/config/HelloDynamicBinding.java
@@ -1,13 +1,13 @@
package com.baeldung.jersey.server.config;
-import javax.ws.rs.container.DynamicFeature;
-import javax.ws.rs.container.ResourceInfo;
-import javax.ws.rs.core.FeatureContext;
-import javax.ws.rs.ext.Provider;
-
import com.baeldung.jersey.server.Greetings;
import com.baeldung.jersey.server.filter.ResponseServerFilter;
+import jakarta.ws.rs.container.DynamicFeature;
+import jakarta.ws.rs.container.ResourceInfo;
+import jakarta.ws.rs.core.FeatureContext;
+import jakarta.ws.rs.ext.Provider;
+
@Provider
public class HelloDynamicBinding implements DynamicFeature {
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/config/ServerConfig.java b/jersey/src/main/java/com/baeldung/jersey/server/config/ServerConfig.java
index 4670cc291c..c4db7df223 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/config/ServerConfig.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/config/ServerConfig.java
@@ -1,9 +1,9 @@
package com.baeldung.jersey.server.config;
-import javax.ws.rs.ApplicationPath;
-
import org.glassfish.jersey.server.ResourceConfig;
+import jakarta.ws.rs.ApplicationPath;
+
@ApplicationPath("/*")
public class ServerConfig extends ResourceConfig {
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/constraints/SerialNumber.java b/jersey/src/main/java/com/baeldung/jersey/server/constraints/SerialNumber.java
index ca49797e31..d18375c152 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/constraints/SerialNumber.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/constraints/SerialNumber.java
@@ -4,10 +4,10 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.regex.Pattern;
-import javax.validation.Constraint;
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import javax.validation.Payload;
+import jakarta.validation.Constraint;
+import jakarta.validation.ConstraintValidator;
+import jakarta.validation.ConstraintValidatorContext;
+import jakarta.validation.Payload;
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = { SerialNumber.Validator.class })
@@ -21,7 +21,7 @@ public @interface SerialNumber {
Class extends Payload>[] payload() default {};
- public class Validator implements ConstraintValidator {
+ class Validator implements ConstraintValidator {
@Override
public void initialize(final SerialNumber serial) {
}
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/filter/PrematchingRequestFilter.java b/jersey/src/main/java/com/baeldung/jersey/server/filter/PrematchingRequestFilter.java
index 181fa7f043..2c9da1afba 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/filter/PrematchingRequestFilter.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/filter/PrematchingRequestFilter.java
@@ -2,14 +2,15 @@ package com.baeldung.jersey.server.filter;
import java.io.IOException;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
-import javax.ws.rs.container.PreMatching;
-import javax.ws.rs.ext.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import jakarta.ws.rs.container.ContainerRequestContext;
+import jakarta.ws.rs.container.ContainerRequestFilter;
+import jakarta.ws.rs.container.PreMatching;
+import jakarta.ws.rs.ext.Provider;
+
@Provider
@PreMatching
public class PrematchingRequestFilter implements ContainerRequestFilter {
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/filter/ResponseServerFilter.java b/jersey/src/main/java/com/baeldung/jersey/server/filter/ResponseServerFilter.java
index de0dcbdce7..3e92b081fe 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/filter/ResponseServerFilter.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/filter/ResponseServerFilter.java
@@ -2,13 +2,13 @@ package com.baeldung.jersey.server.filter;
import java.io.IOException;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerResponseContext;
-import javax.ws.rs.container.ContainerResponseFilter;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import jakarta.ws.rs.container.ContainerRequestContext;
+import jakarta.ws.rs.container.ContainerResponseContext;
+import jakarta.ws.rs.container.ContainerResponseFilter;
+
public class ResponseServerFilter implements ContainerResponseFilter {
private static final Logger LOG = LoggerFactory.getLogger(ResponseServerFilter.class);
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/filter/RestrictedOperationsRequestFilter.java b/jersey/src/main/java/com/baeldung/jersey/server/filter/RestrictedOperationsRequestFilter.java
index cb0cd185f7..1064b04204 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/filter/RestrictedOperationsRequestFilter.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/filter/RestrictedOperationsRequestFilter.java
@@ -2,18 +2,18 @@ package com.baeldung.jersey.server.filter;
import java.io.IOException;
-import javax.annotation.Priority;
-import javax.ws.rs.Priorities;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baeldung.jersey.server.config.HelloBinding;
+import jakarta.annotation.Priority;
+import jakarta.ws.rs.Priorities;
+import jakarta.ws.rs.container.ContainerRequestContext;
+import jakarta.ws.rs.container.ContainerRequestFilter;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.ext.Provider;
+
@Provider
@Priority(Priorities.AUTHORIZATION)
@HelloBinding
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/http/EmbeddedHttpServer.java b/jersey/src/main/java/com/baeldung/jersey/server/http/EmbeddedHttpServer.java
index 1d75508c6d..8a696d8f34 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/http/EmbeddedHttpServer.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/http/EmbeddedHttpServer.java
@@ -19,10 +19,7 @@ public class EmbeddedHttpServer {
try {
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, new ViewApplicationConfig(), false);
- Runtime.getRuntime()
- .addShutdownHook(new Thread(() -> {
- server.shutdownNow();
- }));
+ Runtime.getRuntime().addShutdownHook(new Thread(server::shutdownNow));
server.start();
@@ -34,8 +31,8 @@ public class EmbeddedHttpServer {
}
- public static HttpServer startServer() {
+ public static HttpServer startServer(URI url) {
final ResourceConfig rc = new ResourceConfig().packages("com.baeldung.jersey.server");
- return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI.toString()), rc);
+ return GrizzlyHttpServerFactory.createHttpServer(URI.create(url.toString()), rc);
}
}
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/interceptor/RequestServerReaderInterceptor.java b/jersey/src/main/java/com/baeldung/jersey/server/interceptor/RequestServerReaderInterceptor.java
index e9cc57fc2a..9a11c212d7 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/interceptor/RequestServerReaderInterceptor.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/interceptor/RequestServerReaderInterceptor.java
@@ -7,14 +7,14 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.ext.Provider;
-import javax.ws.rs.ext.ReaderInterceptor;
-import javax.ws.rs.ext.ReaderInterceptorContext;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.ext.Provider;
+import jakarta.ws.rs.ext.ReaderInterceptor;
+import jakarta.ws.rs.ext.ReaderInterceptorContext;
+
@Provider
public class RequestServerReaderInterceptor implements ReaderInterceptor {
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/model/Fruit.java b/jersey/src/main/java/com/baeldung/jersey/server/model/Fruit.java
index 1a648290a3..83c96e2784 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/model/Fruit.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/model/Fruit.java
@@ -1,8 +1,8 @@
package com.baeldung.jersey.server.model;
-import javax.validation.constraints.Min;
-import javax.validation.constraints.Size;
-import javax.xml.bind.annotation.XmlRootElement;
+import jakarta.validation.constraints.Min;
+import jakarta.validation.constraints.Size;
+import jakarta.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Fruit {
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/providers/FruitExceptionMapper.java b/jersey/src/main/java/com/baeldung/jersey/server/providers/FruitExceptionMapper.java
index cea61c897b..10e1c6d60c 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/providers/FruitExceptionMapper.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/providers/FruitExceptionMapper.java
@@ -1,9 +1,9 @@
package com.baeldung.jersey.server.providers;
-import javax.validation.ConstraintViolation;
-import javax.validation.ConstraintViolationException;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.ExceptionMapper;
+import jakarta.validation.ConstraintViolation;
+import jakarta.validation.ConstraintViolationException;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.ext.ExceptionMapper;
public class FruitExceptionMapper implements ExceptionMapper {
diff --git a/jersey/src/main/java/com/baeldung/jersey/server/rest/FruitResource.java b/jersey/src/main/java/com/baeldung/jersey/server/rest/FruitResource.java
index 88692dcc55..3ee5de8073 100644
--- a/jersey/src/main/java/com/baeldung/jersey/server/rest/FruitResource.java
+++ b/jersey/src/main/java/com/baeldung/jersey/server/rest/FruitResource.java
@@ -5,20 +5,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.FormParam;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
import org.glassfish.jersey.server.mvc.ErrorTemplate;
import org.glassfish.jersey.server.mvc.Template;
import org.glassfish.jersey.server.mvc.Viewable;
@@ -27,6 +13,19 @@ import com.baeldung.jersey.server.constraints.SerialNumber;
import com.baeldung.jersey.server.model.Fruit;
import com.baeldung.jersey.service.SimpleStorageService;
+import jakarta.validation.Valid;
+import jakarta.validation.constraints.NotNull;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.FormParam;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.PUT;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
@Path("/fruit")
public class FruitResource {
@@ -66,7 +65,7 @@ public class FruitResource {
@Path("/create")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void createFruit(
- @NotNull(message = "Fruit name must not be null") @FormParam("name") String name,
+ @NotNull(message = "Fruit name must not be null") @FormParam("name") String name,
@NotNull(message = "Fruit colour must not be null") @FormParam("colour") String colour) {
Fruit fruit = new Fruit(name, colour);
@@ -94,7 +93,7 @@ public class FruitResource {
@Consumes(MediaType.APPLICATION_JSON)
public Response createNewFruit(@Valid Fruit fruit) {
String result = "Fruit saved : " + fruit;
- return Response.status(Status.CREATED.getStatusCode())
+ return Response.status(Response.Status.CREATED.getStatusCode())
.entity(result)
.build();
}
diff --git a/jersey/src/main/java/com/baeldung/jersey/service/SimpleStorageService.java b/jersey/src/main/java/com/baeldung/jersey/service/SimpleStorageService.java
index e21dd584a1..2c718c9d17 100644
--- a/jersey/src/main/java/com/baeldung/jersey/service/SimpleStorageService.java
+++ b/jersey/src/main/java/com/baeldung/jersey/service/SimpleStorageService.java
@@ -7,7 +7,7 @@ import com.baeldung.jersey.server.model.Fruit;
public class SimpleStorageService {
- private static final Map fruits = new HashMap();
+ private static final Map fruits = new HashMap<>();
public static void storeFruit(final Fruit fruit) {
fruits.put(fruit.getName(), fruit);
@@ -17,7 +17,7 @@ public class SimpleStorageService {
return fruits.entrySet()
.stream()
.filter(map -> name.equals(map.getKey()))
- .map(map -> map.getValue())
+ .map(Map.Entry::getValue)
.findFirst()
.get();
}
diff --git a/jersey/src/test/java/com/baeldung/jersey/client/JerseyClientIntegrationTest.java b/jersey/src/test/java/com/baeldung/jersey/client/JerseyClientIntegrationTest.java
index a6fd606e3f..e0166d0331 100644
--- a/jersey/src/test/java/com/baeldung/jersey/client/JerseyClientIntegrationTest.java
+++ b/jersey/src/test/java/com/baeldung/jersey/client/JerseyClientIntegrationTest.java
@@ -1,35 +1,53 @@
package com.baeldung.jersey.client;
-import javax.ws.rs.core.Response;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
+import java.net.URI;
+
+import org.glassfish.grizzly.http.server.HttpServer;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import com.baeldung.jersey.server.http.EmbeddedHttpServer;
+
+import jakarta.ws.rs.core.Response;
-@Ignore
public class JerseyClientIntegrationTest {
private static int HTTP_OK = 200;
+ private static HttpServer httpServer;
+
+ @BeforeAll
+ public static void beforeAllTests() {
+ httpServer = EmbeddedHttpServer.startServer(URI.create("http://localhost:8080/jersey"));
+ }
+
+ @AfterAll
+ public static void afterAllTests() {
+ httpServer.stop();
+ }
+
@Test
public void givenGreetingResource_whenCallingHelloGreeting_thenHelloReturned() {
String response = JerseyClient.getHelloGreeting();
- Assert.assertEquals("hello", response);
+ assertEquals("hello", response);
}
@Test
public void givenGreetingResource_whenCallingHiGreeting_thenHiReturned() {
String response = JerseyClient.getHiGreeting();
- Assert.assertEquals("hi", response);
+ assertEquals("hi", response);
}
@Test
public void givenGreetingResource_whenCallingCustomGreeting_thenCustomGreetingReturned() {
Response response = JerseyClient.getCustomGreeting();
- Assert.assertEquals(HTTP_OK, response.getStatus());
+ assertEquals(HTTP_OK, response.getStatus());
}
}
diff --git a/jersey/src/test/java/com/baeldung/jersey/exceptionhandling/rest/StocksResourceIntegrationTest.java b/jersey/src/test/java/com/baeldung/jersey/exceptionhandling/rest/StocksResourceIntegrationTest.java
index ceb59adc1f..eff5d5ae6e 100644
--- a/jersey/src/test/java/com/baeldung/jersey/exceptionhandling/rest/StocksResourceIntegrationTest.java
+++ b/jersey/src/test/java/com/baeldung/jersey/exceptionhandling/rest/StocksResourceIntegrationTest.java
@@ -2,31 +2,30 @@ package com.baeldung.jersey.exceptionhandling.rest;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashMap;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
+import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import com.baeldung.jersey.exceptionhandling.ExceptionHandlingConfig;
import com.baeldung.jersey.exceptionhandling.data.Stock;
import com.baeldung.jersey.exceptionhandling.data.Wallet;
import com.baeldung.jersey.exceptionhandling.rest.exceptions.IllegalArgumentExceptionMapper;
import com.baeldung.jersey.exceptionhandling.rest.exceptions.RestErrorResponse;
import com.baeldung.jersey.exceptionhandling.rest.exceptions.ServerExceptionMapper;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.client.Invocation;
+import jakarta.ws.rs.core.Application;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
public class StocksResourceIntegrationTest extends JerseyTest {
private static final Entity EMPTY_BODY = Entity.json("");
private static final Stock STOCK = new Stock("BAEL", 51.57);
@@ -36,8 +35,13 @@ public class StocksResourceIntegrationTest extends JerseyTest {
@Override
protected Application configure() {
- forceSet(TestProperties.CONTAINER_PORT, "0");
- return new ExceptionHandlingConfig();
+ final ResourceConfig resourceConfig = new ResourceConfig();
+ resourceConfig.register(StocksResource.class);
+ resourceConfig.register(WalletsResource.class);
+ resourceConfig.register(IllegalArgumentExceptionMapper.class);
+ resourceConfig.register(ServerExceptionMapper.class);
+ resourceConfig.packages("com.baeldung.jersey.exceptionhandling.rest");
+ return resourceConfig;
}
private Invocation.Builder stocks(String path) {
@@ -56,7 +60,7 @@ public class StocksResourceIntegrationTest extends JerseyTest {
public void whenMethodNotAllowed_thenCustomMessage() {
Response response = stocks("").get();
- assertEquals(Status.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatus());
+ assertEquals(Response.Status.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatus());
String content = response.readEntity(String.class);
assertThat(content, containsString(ServerExceptionMapper.HTTP_405_MESSAGE));
@@ -64,9 +68,9 @@ public class StocksResourceIntegrationTest extends JerseyTest {
@Test
public void whenTickerNotExists_thenRestErrorResponse() {
- Response response = stocks("/UNDEFINED").get();
+ Response response = stocks("/TEST").get();
- assertEquals(Status.EXPECTATION_FAILED.getStatusCode(), response.getStatus());
+ assertEquals(Response.Status.EXPECTATION_FAILED.getStatusCode(), response.getStatus());
RestErrorResponse content = response.readEntity(RestErrorResponse.class);
assertThat(content.getMessage(), startsWith(IllegalArgumentExceptionMapper.DEFAULT_MESSAGE));
@@ -77,7 +81,7 @@ public class StocksResourceIntegrationTest extends JerseyTest {
wallets("").post(entity(WALLET));
Response response = wallets("/%s/%d", MY_WALLET, INSUFFICIENT_AMOUNT).put(EMPTY_BODY);
- assertEquals(Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatus());
+ assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatus());
String content = response.readEntity(String.class);
assertThat(content, containsString(Wallet.MIN_CHARGE_MSG));
@@ -89,7 +93,7 @@ public class StocksResourceIntegrationTest extends JerseyTest {
wallets("").post(entity(WALLET));
Response response = wallets("/%s/buy/%s", MY_WALLET, STOCK.getId()).post(EMPTY_BODY);
- assertEquals(Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatus());
+ assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), response.getStatus());
RestErrorResponse content = response.readEntity(RestErrorResponse.class);
assertNotNull(content.getSubject());
diff --git a/jersey/src/test/java/com/baeldung/jersey/server/EchoHeadersUnitTest.java b/jersey/src/test/java/com/baeldung/jersey/server/EchoHeadersUnitTest.java
index 24552f6d81..96b5dfb260 100644
--- a/jersey/src/test/java/com/baeldung/jersey/server/EchoHeadersUnitTest.java
+++ b/jersey/src/test/java/com/baeldung/jersey/server/EchoHeadersUnitTest.java
@@ -6,8 +6,6 @@ import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Response;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
@@ -15,6 +13,9 @@ import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import jakarta.ws.rs.core.Application;
+import jakarta.ws.rs.core.Response;
+
public class EchoHeadersUnitTest extends JerseyTest {
private static final String SIMPLE_HEADER_KEY = "my-header-key";
diff --git a/jersey/src/test/java/com/baeldung/jersey/server/GreetingsResourceIntegrationTest.java b/jersey/src/test/java/com/baeldung/jersey/server/GreetingsResourceIntegrationTest.java
index 8953f4161c..97934369e2 100644
--- a/jersey/src/test/java/com/baeldung/jersey/server/GreetingsResourceIntegrationTest.java
+++ b/jersey/src/test/java/com/baeldung/jersey/server/GreetingsResourceIntegrationTest.java
@@ -2,16 +2,15 @@ package com.baeldung.jersey.server;
import static org.junit.Assert.assertEquals;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
+import jakarta.ws.rs.core.Application;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
public class GreetingsResourceIntegrationTest extends JerseyTest {
@Override
@@ -24,7 +23,7 @@ public class GreetingsResourceIntegrationTest extends JerseyTest {
Response response = target("/greetings/hi").request()
.get();
- assertEquals("Http Response should be 200: ", Status.OK.getStatusCode(), response.getStatus());
+ assertEquals("Http Response should be 200: ", Response.Status.OK.getStatusCode(), response.getStatus());
assertEquals("Http Content-Type should be: ", MediaType.TEXT_HTML, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
String content = response.readEntity(String.class);
diff --git a/jersey/src/test/java/com/baeldung/jersey/server/ItemsUnitTest.java b/jersey/src/test/java/com/baeldung/jersey/server/ItemsUnitTest.java
index b158d63720..9954c5bd53 100644
--- a/jersey/src/test/java/com/baeldung/jersey/server/ItemsUnitTest.java
+++ b/jersey/src/test/java/com/baeldung/jersey/server/ItemsUnitTest.java
@@ -1,35 +1,32 @@
package com.baeldung.jersey.server;
+import static com.baeldung.jersey.server.http.EmbeddedHttpServer.BASE_URI;
import static org.junit.Assert.assertEquals;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.WebTarget;
-
import org.glassfish.grizzly.http.server.HttpServer;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
-import org.junit.jupiter.api.Disabled;
import com.baeldung.jersey.server.http.EmbeddedHttpServer;
-@Disabled
-@Ignore
+import jakarta.ws.rs.client.ClientBuilder;
+import jakarta.ws.rs.client.WebTarget;
+
public class ItemsUnitTest {
private HttpServer server;
private WebTarget target;
@Before
- public void setUp() throws Exception {
- server = EmbeddedHttpServer.startServer();
- target = ClientBuilder.newClient().target(EmbeddedHttpServer.BASE_URI.toString());
+ public void setUp() {
+ server = EmbeddedHttpServer.startServer(BASE_URI);
+ target = ClientBuilder.newClient().target(BASE_URI.toString());
}
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
server.stop();
}
diff --git a/jersey/src/test/java/com/baeldung/jersey/server/rest/FruitResourceIntegrationTest.java b/jersey/src/test/java/com/baeldung/jersey/server/rest/FruitResourceIntegrationTest.java
index f7bb0df1ed..4f73c9df5b 100644
--- a/jersey/src/test/java/com/baeldung/jersey/server/rest/FruitResourceIntegrationTest.java
+++ b/jersey/src/test/java/com/baeldung/jersey/server/rest/FruitResourceIntegrationTest.java
@@ -5,13 +5,6 @@ import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.Application;
-import javax.ws.rs.core.Form;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.junit.Test;
@@ -20,6 +13,12 @@ import com.baeldung.jersey.server.config.ViewApplicationConfig;
import com.baeldung.jersey.server.model.Fruit;
import com.baeldung.jersey.server.providers.FruitExceptionMapper;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.core.Application;
+import jakarta.ws.rs.core.Form;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
public class FruitResourceIntegrationTest extends JerseyTest {
@Override
@@ -71,7 +70,7 @@ public class FruitResourceIntegrationTest extends JerseyTest {
Response response = target("fruit/created").request()
.post(Entity.json("{\"name\":\"strawberry\",\"weight\":20}"));
- assertEquals("Http Response should be 201 ", Status.CREATED.getStatusCode(), response.getStatus());
+ assertEquals("Http Response should be 201 ", Response.Status.CREATED.getStatusCode(), response.getStatus());
assertThat(response.readEntity(String.class), containsString("Fruit saved : Fruit [name: strawberry colour: null]"));
}