diff --git a/integration-tests/jpa-db2/pom.xml b/integration-tests/jpa-db2/pom.xml index 53c4faae983b6a..28d1dbb1da613b 100644 --- a/integration-tests/jpa-db2/pom.xml +++ b/integration-tests/jpa-db2/pom.xml @@ -20,15 +20,15 @@ io.quarkus - quarkus-undertow + quarkus-hibernate-orm io.quarkus - quarkus-hibernate-orm + quarkus-jdbc-db2 io.quarkus - quarkus-jdbc-db2 + quarkus-resteasy-reactive @@ -81,7 +81,7 @@ io.quarkus - quarkus-undertow-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-db2/src/main/java/io/quarkus/it/jpa/db2/JPAFunctionalityTestEndpoint.java b/integration-tests/jpa-db2/src/main/java/io/quarkus/it/jpa/db2/JPAFunctionalityTestEndpoint.java index a87e5568de2f54..c840c98c946fac 100644 --- a/integration-tests/jpa-db2/src/main/java/io/quarkus/it/jpa/db2/JPAFunctionalityTestEndpoint.java +++ b/integration-tests/jpa-db2/src/main/java/io/quarkus/it/jpa/db2/JPAFunctionalityTestEndpoint.java @@ -1,7 +1,6 @@ package io.quarkus.it.jpa.db2; import java.io.IOException; -import java.io.PrintWriter; import java.util.List; import java.util.UUID; @@ -13,36 +12,23 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; /** * Various tests covering JPA functionality. All tests should work in both standard JVM and native mode. */ -@SuppressWarnings("serial") -@WebServlet(name = "JPATestBootstrapEndpoint", urlPatterns = "/jpa/testfunctionality") -public class JPAFunctionalityTestEndpoint extends HttpServlet { +@Path("/jpa/testfunctionality") +@Produces(MediaType.TEXT_PLAIN) +public class JPAFunctionalityTestEndpoint { @Inject EntityManagerFactory entityManagerFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - doStuffWithHibernate(entityManagerFactory); - } catch (Exception e) { - reportException("An error occurred while performing Hibernate operations", e, resp); - } - resp.getWriter().write("OK"); - } - - /** - * Lists the various operations we want to test for: - */ - private static void doStuffWithHibernate(EntityManagerFactory entityManagerFactory) { - + @GET + public String test() throws IOException { //Cleanup any existing data: deleteAllPerson(entityManagerFactory); @@ -57,6 +43,7 @@ private static void doStuffWithHibernate(EntityManagerFactory entityManagerFacto deleteAllPerson(entityManagerFactory); + return "OK"; } private static void verifyJPANamedQuery(final EntityManagerFactory emf) { @@ -143,16 +130,4 @@ private static String randomName() { return UUID.randomUUID().toString(); } - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); - } - } diff --git a/integration-tests/jpa-derby/pom.xml b/integration-tests/jpa-derby/pom.xml index 6a13b889ab6bfe..37ec78874274de 100644 --- a/integration-tests/jpa-derby/pom.xml +++ b/integration-tests/jpa-derby/pom.xml @@ -26,7 +26,7 @@ io.quarkus - quarkus-undertow + quarkus-resteasy-reactive @@ -85,7 +85,7 @@ io.quarkus - quarkus-undertow-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-derby/src/main/java/io/quarkus/it/jpa/derby/JPAFunctionalityTestEndpoint.java b/integration-tests/jpa-derby/src/main/java/io/quarkus/it/jpa/derby/JPAFunctionalityTestEndpoint.java index 406f4bcf8eaf52..ceab219e922f33 100644 --- a/integration-tests/jpa-derby/src/main/java/io/quarkus/it/jpa/derby/JPAFunctionalityTestEndpoint.java +++ b/integration-tests/jpa-derby/src/main/java/io/quarkus/it/jpa/derby/JPAFunctionalityTestEndpoint.java @@ -1,7 +1,5 @@ package io.quarkus.it.jpa.derby; -import java.io.IOException; -import java.io.PrintWriter; import java.util.List; import java.util.UUID; @@ -13,36 +11,24 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; /** * Basic test running JPA with the Derby database. * The application can work in either standard JVM or in native mode, while we run H2 as a separate JVM process. */ -@WebServlet(name = "JPATestBootstrapEndpoint", urlPatterns = "/jpa-derby/testfunctionality") -public class JPAFunctionalityTestEndpoint extends HttpServlet { +@Path("/jpa-derby/testfunctionality") +@Produces(MediaType.TEXT_PLAIN) +public class JPAFunctionalityTestEndpoint { @Inject EntityManagerFactory entityManagerFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - doStuffWithHibernate(entityManagerFactory); - } catch (Exception e) { - reportException("An error occurred while performing Hibernate operations", e, resp); - } - resp.getWriter().write("OK"); - } - - /** - * Lists the various operations we want to test for: - */ - private static void doStuffWithHibernate(EntityManagerFactory entityManagerFactory) { - + @GET + public String test() { //Cleanup any existing data: deleteAllPerson(entityManagerFactory); @@ -59,11 +45,11 @@ private static void doStuffWithHibernate(EntityManagerFactory entityManagerFacto deleteAllPerson(entityManagerFactory); + return "OK"; } private static void verifyHqlFetch(EntityManagerFactory emf) { - EntityManager em = emf.createEntityManager(); - try { + try (EntityManager em = emf.createEntityManager()) { EntityTransaction transaction = em.getTransaction(); try { transaction.begin(); @@ -77,8 +63,6 @@ private static void verifyHqlFetch(EntityManagerFactory emf) { } throw e; } - } finally { - em.close(); } } @@ -161,16 +145,4 @@ private static String randomName() { return UUID.randomUUID().toString(); } - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); - } - } diff --git a/integration-tests/jpa-h2-embedded/pom.xml b/integration-tests/jpa-h2-embedded/pom.xml index 759784b2de62f1..c0e4c31552543f 100644 --- a/integration-tests/jpa-h2-embedded/pom.xml +++ b/integration-tests/jpa-h2-embedded/pom.xml @@ -26,7 +26,7 @@ io.quarkus - quarkus-undertow + quarkus-resteasy-reactive @@ -80,7 +80,7 @@ io.quarkus - quarkus-undertow-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-h2-embedded/src/main/java/io/quarkus/it/jpa/h2/DialectEndpoint.java b/integration-tests/jpa-h2-embedded/src/main/java/io/quarkus/it/jpa/h2/DialectEndpoint.java index 0a863c5f2f88a2..5c74ab76c647e4 100644 --- a/integration-tests/jpa-h2-embedded/src/main/java/io/quarkus/it/jpa/h2/DialectEndpoint.java +++ b/integration-tests/jpa-h2-embedded/src/main/java/io/quarkus/it/jpa/h2/DialectEndpoint.java @@ -1,44 +1,28 @@ package io.quarkus.it.jpa.h2; import java.io.IOException; -import java.io.PrintWriter; import jakarta.inject.Inject; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.hibernate.SessionFactory; import org.hibernate.engine.spi.SessionFactoryImplementor; import io.quarkus.hibernate.orm.runtime.config.DialectVersions; -@WebServlet(name = "DialectEndpoint", urlPatterns = "/dialect/version") -public class DialectEndpoint extends HttpServlet { +@Path("/dialect/version") +@Produces(MediaType.TEXT_PLAIN) +public class DialectEndpoint { @Inject SessionFactory sessionFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - var version = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); - resp.getWriter().write(DialectVersions.toString(version)); - } catch (Exception e) { - reportException("Failed to retrieve dialect version", e, resp); - } - } - - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); + @GET + public String test() throws IOException { + var version = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); + return DialectVersions.toString(version); } } diff --git a/integration-tests/jpa-h2-embedded/src/main/java/io/quarkus/it/jpa/h2/JPAFunctionalityTestEndpoint.java b/integration-tests/jpa-h2-embedded/src/main/java/io/quarkus/it/jpa/h2/JPAFunctionalityTestEndpoint.java index ae88d6721c91bd..1e88ef45ae992b 100644 --- a/integration-tests/jpa-h2-embedded/src/main/java/io/quarkus/it/jpa/h2/JPAFunctionalityTestEndpoint.java +++ b/integration-tests/jpa-h2-embedded/src/main/java/io/quarkus/it/jpa/h2/JPAFunctionalityTestEndpoint.java @@ -1,10 +1,8 @@ package io.quarkus.it.jpa.h2; import java.io.IOException; -import java.io.PrintWriter; import java.util.List; import java.util.UUID; -import java.util.function.Consumer; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; @@ -14,36 +12,24 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; /** * Basic test running JPA with the H2 database. * The application can work in either standard JVM or in native mode, embedding H2 within the application. */ -@WebServlet(name = "JPATestBootstrapEndpoint", urlPatterns = "/jpa-h2-embedded/testfunctionality") -public class JPAFunctionalityTestEndpoint extends HttpServlet { +@Path("/jpa-h2-embedded/testfunctionality") +@Produces(MediaType.TEXT_PLAIN) +public class JPAFunctionalityTestEndpoint { @PersistenceUnit EntityManagerFactory entityManagerFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - doStuffWithHibernate(entityManagerFactory); - } catch (Exception e) { - reportException("An error occurred while performing Hibernate operations", e, resp); - } - resp.getWriter().write("OK"); - } - - /** - * Lists the various operations we want to test for: - */ - private static void doStuffWithHibernate(EntityManagerFactory entityManagerFactory) { - + @GET + public String test() throws IOException { //Cleanup any existing data: deleteAllPerson(entityManagerFactory); @@ -60,11 +46,11 @@ private static void doStuffWithHibernate(EntityManagerFactory entityManagerFacto deleteAllPerson(entityManagerFactory); + return "OK"; } private static void verifyHqlFetch(EntityManagerFactory emf) { - EntityManager em = emf.createEntityManager(); - try { + try (EntityManager em = emf.createEntityManager()) { EntityTransaction transaction = em.getTransaction(); try { transaction.begin(); @@ -78,8 +64,6 @@ private static void verifyHqlFetch(EntityManagerFactory emf) { } throw e; } - } finally { - em.close(); } } @@ -162,35 +146,4 @@ private static String randomName() { return UUID.randomUUID().toString(); } - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); - } - - private static void doAsUnit(EntityManagerFactory emf, Consumer f) { - final EntityManager em = emf.createEntityManager(); - try { - EntityTransaction transaction = em.getTransaction(); - try { - transaction.begin(); - f.accept(em); - transaction.commit(); - } catch (Exception e) { - if (transaction.isActive()) { - transaction.rollback(); - } - throw e; - } - } finally { - em.close(); - } - } - } diff --git a/integration-tests/jpa-h2/pom.xml b/integration-tests/jpa-h2/pom.xml index f42c3a87201f20..6964791967d950 100644 --- a/integration-tests/jpa-h2/pom.xml +++ b/integration-tests/jpa-h2/pom.xml @@ -26,7 +26,7 @@ io.quarkus - quarkus-undertow + quarkus-resteasy-reactive @@ -85,7 +85,7 @@ io.quarkus - quarkus-undertow-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/DialectEndpoint.java b/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/DialectEndpoint.java index 0a863c5f2f88a2..5c74ab76c647e4 100644 --- a/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/DialectEndpoint.java +++ b/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/DialectEndpoint.java @@ -1,44 +1,28 @@ package io.quarkus.it.jpa.h2; import java.io.IOException; -import java.io.PrintWriter; import jakarta.inject.Inject; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.hibernate.SessionFactory; import org.hibernate.engine.spi.SessionFactoryImplementor; import io.quarkus.hibernate.orm.runtime.config.DialectVersions; -@WebServlet(name = "DialectEndpoint", urlPatterns = "/dialect/version") -public class DialectEndpoint extends HttpServlet { +@Path("/dialect/version") +@Produces(MediaType.TEXT_PLAIN) +public class DialectEndpoint { @Inject SessionFactory sessionFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - var version = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); - resp.getWriter().write(DialectVersions.toString(version)); - } catch (Exception e) { - reportException("Failed to retrieve dialect version", e, resp); - } - } - - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); + @GET + public String test() throws IOException { + var version = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); + return DialectVersions.toString(version); } } diff --git a/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/JPAFunctionalityTestEndpoint.java b/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/JPAFunctionalityTestEndpoint.java index 2cda46b09649e6..2b1874d3e72dcd 100644 --- a/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/JPAFunctionalityTestEndpoint.java +++ b/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/JPAFunctionalityTestEndpoint.java @@ -1,7 +1,6 @@ package io.quarkus.it.jpa.h2; import java.io.IOException; -import java.io.PrintWriter; import java.util.List; import java.util.UUID; import java.util.function.Consumer; @@ -14,10 +13,10 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.wildfly.common.Assert; @@ -25,27 +24,15 @@ * Basic test running JPA with the H2 database. * The application can work in either standard JVM or in native mode, while we run H2 as a separate JVM process. */ -@WebServlet(name = "JPATestBootstrapEndpoint", urlPatterns = "/jpa-h2/testfunctionality") -public class JPAFunctionalityTestEndpoint extends HttpServlet { +@Path("/jpa-h2/testfunctionality") +@Produces(MediaType.TEXT_PLAIN) +public class JPAFunctionalityTestEndpoint { @Inject EntityManagerFactory entityManagerFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - doStuffWithHibernate(entityManagerFactory); - } catch (Exception e) { - reportException("An error occurred while performing Hibernate operations", e, resp); - } - resp.getWriter().write("OK"); - } - - /** - * Lists the various operations we want to test for: - */ - private static void doStuffWithHibernate(EntityManagerFactory entityManagerFactory) { - + @GET + public String test() throws IOException { //Cleanup any existing data: deleteAllPerson(entityManagerFactory); @@ -65,6 +52,7 @@ private static void doStuffWithHibernate(EntityManagerFactory entityManagerFacto //Test capability to load enhanced proxies: verifyEnhancedProxies(entityManagerFactory); + return "OK"; } private static void verifyEnhancedProxies(EntityManagerFactory emf) { @@ -85,8 +73,7 @@ private static void verifyEnhancedProxies(EntityManagerFactory emf) { } private static void verifyHqlFetch(EntityManagerFactory emf) { - EntityManager em = emf.createEntityManager(); - try { + try (EntityManager em = emf.createEntityManager()) { EntityTransaction transaction = em.getTransaction(); try { transaction.begin(); @@ -100,8 +87,6 @@ private static void verifyHqlFetch(EntityManagerFactory emf) { } throw e; } - } finally { - em.close(); } } @@ -184,21 +169,8 @@ private static String randomName() { return UUID.randomUUID().toString(); } - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); - } - private static void doAsUnit(EntityManagerFactory emf, Consumer f) { - final EntityManager em = emf.createEntityManager(); - try { + try (EntityManager em = emf.createEntityManager()) { EntityTransaction transaction = em.getTransaction(); try { transaction.begin(); @@ -210,8 +182,6 @@ private static void doAsUnit(EntityManagerFactory emf, Consumer f } throw e; } - } finally { - em.close(); } } diff --git a/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/basicproxy/BasicProxyTestEndpoint.java b/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/basicproxy/BasicProxyTestEndpoint.java index 47a866369e6d5b..4183abf7519111 100644 --- a/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/basicproxy/BasicProxyTestEndpoint.java +++ b/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/basicproxy/BasicProxyTestEndpoint.java @@ -7,17 +7,18 @@ import jakarta.enterprise.event.Observes; import jakarta.inject.Inject; import jakarta.persistence.EntityManager; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import jakarta.transaction.Transactional; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import io.quarkus.runtime.StartupEvent; @ApplicationScoped -@WebServlet(urlPatterns = "/jpa-h2/testbasicproxy") -public class BasicProxyTestEndpoint extends HttpServlet { +@Path("/jpa-h2/testbasicproxy") +@Produces(MediaType.TEXT_PLAIN) +public class BasicProxyTestEndpoint { @Inject EntityManager entityManager; @@ -30,12 +31,12 @@ public void setup(@Observes StartupEvent startupEvent) { entityManager.persist(entity); } - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + @GET + public String test() throws IOException { final List list = entityManager.createQuery("from ConcreteEntity").getResultList(); if (list.size() != 1) { throw new RuntimeException("Expected 1 result, got " + list.size()); } - resp.getWriter().write("OK"); + return "OK"; } } diff --git a/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/proxy/ProxyTestEndpoint.java b/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/proxy/ProxyTestEndpoint.java index 9e592ac9e98c8b..95f1ac34efefe5 100644 --- a/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/proxy/ProxyTestEndpoint.java +++ b/integration-tests/jpa-h2/src/main/java/io/quarkus/it/jpa/h2/proxy/ProxyTestEndpoint.java @@ -6,19 +6,19 @@ import jakarta.enterprise.event.Observes; import jakarta.inject.Inject; import jakarta.persistence.EntityManager; -import jakarta.servlet.ServletException; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import jakarta.transaction.Transactional; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import io.quarkus.narayana.jta.runtime.TransactionConfiguration; import io.quarkus.runtime.StartupEvent; -@WebServlet(urlPatterns = "/jpa-h2/testproxy") @ApplicationScoped -public class ProxyTestEndpoint extends HttpServlet { +@Path("/jpa-h2/testproxy") +@Produces(MediaType.TEXT_PLAIN) +public class ProxyTestEndpoint { @Inject EntityManager entityManager; @@ -67,9 +67,8 @@ public void setup(@Observes StartupEvent startupEvent) { * * We need to do our own proxy generation at build time, so this tests that the logic matches what hibernate expects */ - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - + @GET + public String test() throws IOException { PetOwner owner = entityManager.find(PetOwner.class, 1); expectEquals("Stuart", owner.getName()); expectEquals("Generic pet noises", owner.getPet().makeNoise()); @@ -97,8 +96,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se expectFalse(owner.getPet() instanceof Pet); expectTrue(owner.getPet() instanceof DogProxy); - resp.getWriter().write("OK"); - + return "OK"; } void expectEquals(Object expected, Object actual) { diff --git a/integration-tests/jpa-mapping-xml/legacy-app/pom.xml b/integration-tests/jpa-mapping-xml/legacy-app/pom.xml index 265293dbdb9ceb..aa410b3d79cc47 100644 --- a/integration-tests/jpa-mapping-xml/legacy-app/pom.xml +++ b/integration-tests/jpa-mapping-xml/legacy-app/pom.xml @@ -16,7 +16,7 @@ io.quarkus - quarkus-resteasy + quarkus-resteasy-reactive io.quarkus @@ -93,7 +93,7 @@ io.quarkus - quarkus-resteasy-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-mapping-xml/modern-app/pom.xml b/integration-tests/jpa-mapping-xml/modern-app/pom.xml index 5c0efa36ec3c6a..2882e803599fa4 100644 --- a/integration-tests/jpa-mapping-xml/modern-app/pom.xml +++ b/integration-tests/jpa-mapping-xml/modern-app/pom.xml @@ -17,7 +17,7 @@ io.quarkus - quarkus-resteasy + quarkus-resteasy-reactive io.quarkus @@ -94,7 +94,7 @@ io.quarkus - quarkus-resteasy-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-mariadb/pom.xml b/integration-tests/jpa-mariadb/pom.xml index 90637bb628b28c..47d0357dff2c72 100644 --- a/integration-tests/jpa-mariadb/pom.xml +++ b/integration-tests/jpa-mariadb/pom.xml @@ -20,15 +20,15 @@ io.quarkus - quarkus-undertow + quarkus-hibernate-orm io.quarkus - quarkus-hibernate-orm + quarkus-jdbc-mariadb io.quarkus - quarkus-jdbc-mariadb + quarkus-resteasy-reactive @@ -82,7 +82,7 @@ io.quarkus - quarkus-undertow-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-mariadb/src/main/java/io/quarkus/it/jpa/mariadb/DialectEndpoint.java b/integration-tests/jpa-mariadb/src/main/java/io/quarkus/it/jpa/mariadb/DialectEndpoint.java index 1fec613561c17a..32ddb042c862f7 100644 --- a/integration-tests/jpa-mariadb/src/main/java/io/quarkus/it/jpa/mariadb/DialectEndpoint.java +++ b/integration-tests/jpa-mariadb/src/main/java/io/quarkus/it/jpa/mariadb/DialectEndpoint.java @@ -1,44 +1,28 @@ package io.quarkus.it.jpa.mariadb; import java.io.IOException; -import java.io.PrintWriter; import jakarta.inject.Inject; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.hibernate.SessionFactory; import org.hibernate.engine.spi.SessionFactoryImplementor; import io.quarkus.hibernate.orm.runtime.config.DialectVersions; -@WebServlet(name = "DialectEndpoint", urlPatterns = "/dialect/version") -public class DialectEndpoint extends HttpServlet { +@Path("/dialect/version") +@Produces(MediaType.TEXT_PLAIN) +public class DialectEndpoint { @Inject SessionFactory sessionFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - var version = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); - resp.getWriter().write(DialectVersions.toString(version)); - } catch (Exception e) { - reportException("Failed to retrieve dialect version", e, resp); - } - } - - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); + @GET + public String test() throws IOException { + var version = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); + return DialectVersions.toString(version); } } diff --git a/integration-tests/jpa-mariadb/src/main/java/io/quarkus/it/jpa/mariadb/JPAFunctionalityTestEndpoint.java b/integration-tests/jpa-mariadb/src/main/java/io/quarkus/it/jpa/mariadb/JPAFunctionalityTestEndpoint.java index acbaef9bc94552..88673c30d6cb4e 100644 --- a/integration-tests/jpa-mariadb/src/main/java/io/quarkus/it/jpa/mariadb/JPAFunctionalityTestEndpoint.java +++ b/integration-tests/jpa-mariadb/src/main/java/io/quarkus/it/jpa/mariadb/JPAFunctionalityTestEndpoint.java @@ -1,7 +1,6 @@ package io.quarkus.it.jpa.mariadb; import java.io.IOException; -import java.io.PrintWriter; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -18,17 +17,18 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; /** * Basic test running JPA with the MariaDB database. * The application can work in either standard JVM or in native mode. */ -@WebServlet(name = "JPATestBootstrapEndpoint", urlPatterns = "/jpa-mariadb/testfunctionality") -public class JPAFunctionalityTestEndpoint extends HttpServlet { +@Path("/jpa-mariadb/testfunctionality") +@Produces(MediaType.TEXT_PLAIN) +public class JPAFunctionalityTestEndpoint { @Inject EntityManagerFactory entityManagerFactory; @@ -36,21 +36,8 @@ public class JPAFunctionalityTestEndpoint extends HttpServlet { @Inject DataSource ds; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - doStuffWithHibernate(entityManagerFactory, ds); - } catch (Exception e) { - reportException("An error occurred while performing Hibernate operations", e, resp); - } - resp.getWriter().write("OK"); - } - - /** - * Lists the various operations we want to test for: - */ - private static void doStuffWithHibernate(EntityManagerFactory entityManagerFactory, DataSource ds) throws SQLException { - + @GET + public String test() throws IOException, SQLException { //Cleanup any existing data: deleteAllPerson(entityManagerFactory); @@ -68,6 +55,7 @@ private static void doStuffWithHibernate(EntityManagerFactory entityManagerFacto deleteAllPerson(entityManagerFactory); + return "OK"; } private static void verifyJPANamedQuery(final EntityManagerFactory emf) { @@ -149,18 +137,6 @@ private static String randomName() { return UUID.randomUUID().toString(); } - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); - } - private static void verifyGetPersonUsingSetObject(final DataSource ds) throws SQLException { getExistingPersonUsingSetObject(ds); } diff --git a/integration-tests/jpa-mssql/pom.xml b/integration-tests/jpa-mssql/pom.xml index 6fd97cf2bc75c5..69fe76e3b95c9d 100644 --- a/integration-tests/jpa-mssql/pom.xml +++ b/integration-tests/jpa-mssql/pom.xml @@ -33,7 +33,7 @@ io.quarkus - quarkus-undertow + quarkus-resteasy-reactive @@ -87,7 +87,7 @@ io.quarkus - quarkus-undertow-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/DialectEndpoint.java b/integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/DialectEndpoint.java index 984757375f66b0..b1c0029ca61f48 100644 --- a/integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/DialectEndpoint.java +++ b/integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/DialectEndpoint.java @@ -1,44 +1,28 @@ package io.quarkus.it.jpa.mssql; import java.io.IOException; -import java.io.PrintWriter; import jakarta.inject.Inject; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.hibernate.SessionFactory; import org.hibernate.engine.spi.SessionFactoryImplementor; import io.quarkus.hibernate.orm.runtime.config.DialectVersions; -@WebServlet(name = "DialectEndpoint", urlPatterns = "/dialect/version") -public class DialectEndpoint extends HttpServlet { +@Path("/dialect/version") +@Produces(MediaType.TEXT_PLAIN) +public class DialectEndpoint { @Inject SessionFactory sessionFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - var version = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); - resp.getWriter().write(DialectVersions.toString(version)); - } catch (Exception e) { - reportException("Failed to retrieve dialect version", e, resp); - } - } - - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); + @GET + public String test() throws IOException { + var version = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); + return DialectVersions.toString(version); } } diff --git a/integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/JPAFunctionalityTestEndpoint.java b/integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/JPAFunctionalityTestEndpoint.java index 97742a9c07f6d3..73061a55190797 100644 --- a/integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/JPAFunctionalityTestEndpoint.java +++ b/integration-tests/jpa-mssql/src/main/java/io/quarkus/it/jpa/mssql/JPAFunctionalityTestEndpoint.java @@ -1,7 +1,6 @@ package io.quarkus.it.jpa.mssql; import java.io.IOException; -import java.io.PrintWriter; import java.nio.charset.Charset; import java.util.List; import java.util.UUID; @@ -14,41 +13,26 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; /** * Basic test running JPA with the MS SQL database. * The application can work in either standard JVM or in native mode. */ -@WebServlet(name = "JPATestBootstrapEndpoint", urlPatterns = "/jpa-mssql/testfunctionality") -public class JPAFunctionalityTestEndpoint extends HttpServlet { +@Path("/jpa-mssql/testfunctionality") +@Produces(MediaType.TEXT_PLAIN) +public class JPAFunctionalityTestEndpoint { @Inject EntityManagerFactory entityManagerFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - checkCharacterSets(); - doStuffWithHibernate(entityManagerFactory); - } catch (Exception e) { - reportException("An error occurred while performing Hibernate operations", e, resp); - } - resp.getWriter().write("OK"); - } - - private void checkCharacterSets() { + @GET + public String test() throws IOException { if (!Charset.isSupported("Cp1252")) throw new IllegalStateException("You will very likely need support for Codepage Cp1252 to connect to SQL Server"); - } - - /** - * Lists the various operations we want to test for: - */ - private static void doStuffWithHibernate(EntityManagerFactory entityManagerFactory) { //Cleanup any existing data: deleteAllPerson(entityManagerFactory); @@ -66,6 +50,7 @@ private static void doStuffWithHibernate(EntityManagerFactory entityManagerFacto deleteAllPerson(entityManagerFactory); + return "OK"; } private static void verifyHqlFetch(EntityManagerFactory emf) { @@ -168,16 +153,4 @@ private static String randomName() { return UUID.randomUUID().toString(); } - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); - } - } diff --git a/integration-tests/jpa-mysql/pom.xml b/integration-tests/jpa-mysql/pom.xml index af53db1d55b3ad..b53b57ce3f8d94 100644 --- a/integration-tests/jpa-mysql/pom.xml +++ b/integration-tests/jpa-mysql/pom.xml @@ -20,15 +20,15 @@ io.quarkus - quarkus-undertow + quarkus-hibernate-orm io.quarkus - quarkus-hibernate-orm + quarkus-jdbc-mysql io.quarkus - quarkus-jdbc-mysql + quarkus-resteasy-reactive @@ -82,7 +82,7 @@ io.quarkus - quarkus-undertow-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/DialectEndpoint.java b/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/DialectEndpoint.java deleted file mode 100644 index 9ea55563941814..00000000000000 --- a/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/DialectEndpoint.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.quarkus.it.jpa.mysql; - -import java.io.IOException; -import java.io.PrintWriter; - -import jakarta.inject.Inject; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -import org.hibernate.SessionFactory; -import org.hibernate.engine.spi.SessionFactoryImplementor; - -import io.quarkus.hibernate.orm.runtime.config.DialectVersions; - -@WebServlet(name = "DialectEndpoint", urlPatterns = "/dialect/version") -public class DialectEndpoint extends HttpServlet { - @Inject - SessionFactory sessionFactory; - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - var version = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); - resp.getWriter().write(DialectVersions.toString(version)); - } catch (Exception e) { - reportException("Failed to retrieve dialect version", e, resp); - } - } - - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); - } - -} diff --git a/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/JPAFunctionalityTestEndpoint.java b/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/JPAFunctionalityTestEndpoint.java index 6fa74b7cd7a6c2..f21d9de96ee05a 100644 --- a/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/JPAFunctionalityTestEndpoint.java +++ b/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/JPAFunctionalityTestEndpoint.java @@ -1,7 +1,5 @@ package io.quarkus.it.jpa.mysql; -import java.io.IOException; -import java.io.PrintWriter; import java.util.List; import java.util.UUID; @@ -13,35 +11,24 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; /** * Basic test running JPA with the MySQL database. * The application can work in either standard JVM or in native mode. */ -@WebServlet(name = "JPATestBootstrapEndpoint", urlPatterns = "/jpa-mysql/testfunctionality") -public class JPAFunctionalityTestEndpoint extends HttpServlet { +@Path("/jpa-mysql/testfunctionality") +@Produces(MediaType.TEXT_PLAIN) +public class JPAFunctionalityTestEndpoint { @Inject EntityManagerFactory entityManagerFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - doStuffWithHibernate(entityManagerFactory); - } catch (Exception e) { - reportException("An error occurred while performing Hibernate operations", e, resp); - } - resp.getWriter().write("OK"); - } - - /** - * Lists the various operations we want to test for: - */ - private static void doStuffWithHibernate(EntityManagerFactory entityManagerFactory) { + @GET + public String test() { //Cleanup any existing data: deleteAllPerson(entityManagerFactory); @@ -57,6 +44,7 @@ private static void doStuffWithHibernate(EntityManagerFactory entityManagerFacto deleteAllPerson(entityManagerFactory); + return "OK"; } private static void verifyJPANamedQuery(final EntityManagerFactory emf) { @@ -138,16 +126,4 @@ private static String randomName() { return UUID.randomUUID().toString(); } - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); - } - } diff --git a/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/XaConnectionsEndpoint.java b/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/XaConnectionsEndpoint.java index d0598a29513f61..21f4a54a85e0c6 100644 --- a/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/XaConnectionsEndpoint.java +++ b/integration-tests/jpa-mysql/src/main/java/io/quarkus/it/jpa/mysql/XaConnectionsEndpoint.java @@ -5,24 +5,25 @@ import java.sql.SQLException; import jakarta.inject.Inject; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import io.agroal.api.AgroalDataSource; import io.agroal.api.configuration.AgroalConnectionFactoryConfiguration; import io.quarkus.agroal.DataSource; -@WebServlet(name = "XaConnectionEndpoint", urlPatterns = "/jpa-mysql/testxaconnection") -public class XaConnectionsEndpoint extends HttpServlet { +@Path("/jpa-mysql/testxaconnection") +@Produces(MediaType.TEXT_PLAIN) +public class XaConnectionsEndpoint { @Inject @DataSource("samebutxa") AgroalDataSource xaDatasource; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + @GET + public String test() throws IOException { // Test 1# // Verify that the connection can be obtained @@ -38,9 +39,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO .connectionFactoryConfiguration(); Class connectionProviderClass = cfg.connectionProviderClass(); if (connectionProviderClass.equals(com.mysql.cj.jdbc.MysqlXADataSource.class)) { - resp.getWriter().write("OK"); + return "OK"; } else { - resp.getWriter().write("Unexpected Driver class: " + connectionProviderClass.getName()); + return "Unexpected Driver class: " + connectionProviderClass.getName(); } } diff --git a/integration-tests/jpa-oracle/pom.xml b/integration-tests/jpa-oracle/pom.xml index 68ddee13237d04..20d193bf8f1911 100644 --- a/integration-tests/jpa-oracle/pom.xml +++ b/integration-tests/jpa-oracle/pom.xml @@ -39,7 +39,7 @@ io.quarkus - quarkus-undertow + quarkus-resteasy-reactive @@ -106,7 +106,7 @@ io.quarkus - quarkus-undertow-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/DialectEndpoint.java b/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/DialectEndpoint.java deleted file mode 100644 index 432aa7387552d5..00000000000000 --- a/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/DialectEndpoint.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.quarkus.example.jpaoracle; - -import java.io.IOException; -import java.io.PrintWriter; - -import jakarta.inject.Inject; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -import org.hibernate.SessionFactory; -import org.hibernate.engine.spi.SessionFactoryImplementor; - -import io.quarkus.hibernate.orm.runtime.config.DialectVersions; - -@WebServlet(name = "DialectEndpoint", urlPatterns = "/dialect/version") -public class DialectEndpoint extends HttpServlet { - @Inject - SessionFactory sessionFactory; - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - var version = sessionFactory.unwrap(SessionFactoryImplementor.class).getJdbcServices().getDialect().getVersion(); - resp.getWriter().write(DialectVersions.toString(version)); - } catch (Exception e) { - reportException("Failed to retrieve dialect version", e, resp); - } - } - - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); - } - -} diff --git a/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/JPAFunctionalityTestEndpoint.java b/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/JPAFunctionalityTestEndpoint.java index df7d6663dfa972..2a8e49ac2734a0 100644 --- a/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/JPAFunctionalityTestEndpoint.java +++ b/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/JPAFunctionalityTestEndpoint.java @@ -1,7 +1,5 @@ package io.quarkus.example.jpaoracle; -import java.io.IOException; -import java.io.PrintWriter; import java.util.List; import java.util.UUID; @@ -13,36 +11,24 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; /** * Basic test running JPA with the Oracle database. * The application can work in either standard JVM or SubstrateVM. */ -@WebServlet(name = "JPATestBootstrapEndpoint", urlPatterns = "/jpa-oracle/testfunctionality") -public class JPAFunctionalityTestEndpoint extends HttpServlet { +@Path("/jpa-oracle/testfunctionality") +@Produces(MediaType.TEXT_PLAIN) +public class JPAFunctionalityTestEndpoint { @Inject EntityManagerFactory entityManagerFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - doStuffWithHibernate(entityManagerFactory); - } catch (Exception e) { - reportException("An error occurred while performing Hibernate operations", e, resp); - } - resp.getWriter().write("OK"); - } - - /** - * Lists the various operations we want to test for: - */ - private static void doStuffWithHibernate(EntityManagerFactory entityManagerFactory) { - + @GET + public String test() { //Cleanup any existing data: deleteAllPerson(entityManagerFactory); @@ -59,11 +45,11 @@ private static void doStuffWithHibernate(EntityManagerFactory entityManagerFacto deleteAllPerson(entityManagerFactory); + return "OK"; } private static void verifyHqlFetch(EntityManagerFactory emf) { - EntityManager em = emf.createEntityManager(); - try { + try (EntityManager em = emf.createEntityManager()) { EntityTransaction transaction = em.getTransaction(); try { transaction.begin(); @@ -77,8 +63,6 @@ private static void verifyHqlFetch(EntityManagerFactory emf) { } throw e; } - } finally { - em.close(); } } @@ -161,16 +145,4 @@ private static String randomName() { return UUID.randomUUID().toString(); } - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); - } - } diff --git a/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/LdapUrlTestEndpoint.java b/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/LdapUrlTestEndpoint.java index bf1bc072350b97..b94af308d1b4c1 100644 --- a/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/LdapUrlTestEndpoint.java +++ b/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/LdapUrlTestEndpoint.java @@ -1,21 +1,21 @@ package io.quarkus.example.jpaoracle; -import java.io.IOException; import java.sql.SQLException; import jakarta.inject.Inject; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import org.jboss.logging.Logger; import io.agroal.api.AgroalDataSource; import io.quarkus.agroal.DataSource; -@WebServlet(name = "JPATestOracleLdap", urlPatterns = "/jpa-oracle/testldap") -public class LdapUrlTestEndpoint extends HttpServlet { +@Path("/jpa-oracle/testldap") +@Produces(MediaType.TEXT_PLAIN) +public class LdapUrlTestEndpoint { private final Logger LOG = Logger.getLogger(LdapUrlTestEndpoint.class.getName()); @@ -23,19 +23,8 @@ public class LdapUrlTestEndpoint extends HttpServlet { @DataSource("ldap") AgroalDataSource ds; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - final String output = ldap(); - resp.getWriter().write(output); - - } catch (Exception e) { - e.printStackTrace(resp.getWriter()); - } - } - - private String ldap() throws SQLException { - + @GET + public String test() throws SQLException { try { ds.getConnection().close(); } catch (SQLException e) { diff --git a/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/SerializationTestEndpoint.java b/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/SerializationTestEndpoint.java index 4b5f8c23ea2383..ff7132a9c93c56 100644 --- a/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/SerializationTestEndpoint.java +++ b/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/SerializationTestEndpoint.java @@ -6,26 +6,17 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; -@WebServlet(name = "JPATestOracleSerialization", urlPatterns = "/jpa-oracle/testserialization") -public class SerializationTestEndpoint extends HttpServlet { +@Path("/jpa-oracle/testserialization") +@Produces(MediaType.TEXT_PLAIN) +public class SerializationTestEndpoint { - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - final String output = serializedstring(); - resp.getWriter().write(output); - - } catch (Exception e) { - resp.getWriter().write("An error occurred while attempting serialization operations"); - } - } - - private String serializedstring() throws IOException, ClassNotFoundException { + @GET + public String test() throws IOException, ClassNotFoundException { byte[] bytes = null; try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos)) { diff --git a/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/procedurecall/ProcedureCallEndpoint.java b/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/procedurecall/ProcedureCallEndpoint.java index fd0d171782ad2d..3efe9dfe199c00 100644 --- a/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/procedurecall/ProcedureCallEndpoint.java +++ b/integration-tests/jpa-oracle/src/main/java/io/quarkus/example/jpaoracle/procedurecall/ProcedureCallEndpoint.java @@ -13,18 +13,18 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.ParameterMode; import jakarta.persistence.StoredProcedureQuery; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; import jakarta.transaction.Transactional; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +import org.jboss.resteasy.reactive.RestQuery; import io.agroal.api.AgroalDataSource; import io.quarkus.arc.Arc; import io.quarkus.runtime.StartupEvent; -@WebServlet("/jpa-oracle/procedure-call/") -public class ProcedureCallEndpoint extends HttpServlet { +@Path("/jpa-oracle/procedure-call/") +public class ProcedureCallEndpoint { private static final String PROCEDURE_NAME = "myproc"; @@ -59,10 +59,9 @@ private void persistEntity(String name) { em.persist(entity); } - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + @GET + public String test(@RestQuery String pattern) throws IOException { try { - String pattern = req.getParameter("pattern"); StoredProcedureQuery storedProcedure = em.createStoredProcedureQuery(PROCEDURE_NAME); storedProcedure.registerStoredProcedureParameter("p_pattern", String.class, ParameterMode.IN); storedProcedure.registerStoredProcedureParameter("p_cur", Object.class, ParameterMode.REF_CURSOR); @@ -74,7 +73,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO while (resultSet.next()) { result.add(resultSet.getString(1)); } - resp.getWriter().write(String.join("\n", result)); + return String.join("\n", result); } catch (SQLException e) { throw new RuntimeException(e); } diff --git a/integration-tests/jpa-oracle/src/test/java/io/quarkus/it/jpa/oracle/procedurecall/ProcedureCallTest.java b/integration-tests/jpa-oracle/src/test/java/io/quarkus/it/jpa/oracle/procedurecall/ProcedureCallTest.java index fbd8bd011752d5..30564563854743 100644 --- a/integration-tests/jpa-oracle/src/test/java/io/quarkus/it/jpa/oracle/procedurecall/ProcedureCallTest.java +++ b/integration-tests/jpa-oracle/src/test/java/io/quarkus/it/jpa/oracle/procedurecall/ProcedureCallTest.java @@ -19,7 +19,7 @@ public class ProcedureCallTest { @Test public void test() { - String response = given().param("pattern", "prefix%") + String response = given().queryParam("pattern", "prefix%") .when().get("/jpa-oracle/procedure-call/").then() .statusCode(200) .extract().body().asString(); diff --git a/integration-tests/jpa-postgresql-withxml/pom.xml b/integration-tests/jpa-postgresql-withxml/pom.xml index ae1238d34096f0..7d8d2690730a31 100644 --- a/integration-tests/jpa-postgresql-withxml/pom.xml +++ b/integration-tests/jpa-postgresql-withxml/pom.xml @@ -20,15 +20,15 @@ io.quarkus - quarkus-undertow + quarkus-hibernate-orm io.quarkus - quarkus-hibernate-orm + quarkus-jdbc-postgresql io.quarkus - quarkus-jdbc-postgresql + quarkus-resteasy-reactive io.quarkus @@ -76,7 +76,7 @@ io.quarkus - quarkus-undertow-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java b/integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java index 929091b87eed97..86bb7c2d7449b7 100644 --- a/integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java +++ b/integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java @@ -1,7 +1,5 @@ package io.quarkus.it.jpa.postgresql; -import java.io.IOException; -import java.io.PrintWriter; import java.io.StringReader; import java.sql.Connection; import java.sql.PreparedStatement; @@ -30,10 +28,10 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import io.quarkus.hibernate.orm.PersistenceUnit; import io.quarkus.it.jpa.postgresql.otherpu.EntityWithXmlOtherPU; @@ -43,8 +41,9 @@ * then we specifically focus on supporting the PgSQLXML mapping abilities for XML types: * both need to work. */ -@WebServlet(name = "JPATestBootstrapEndpoint", urlPatterns = "/jpa-withxml/testfunctionality") -public class JPAFunctionalityTestEndpoint extends HttpServlet { +@Path("/jpa-withxml/testfunctionality") +@Produces(MediaType.TEXT_PLAIN) +public class JPAFunctionalityTestEndpoint { @Inject EntityManagerFactory entityManagerFactory; @@ -55,15 +54,11 @@ public class JPAFunctionalityTestEndpoint extends HttpServlet { @Inject DataSource ds; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - doStuffWithHibernate(entityManagerFactory, otherEntityManagerFactory); - doStuffWithDatasource(); - } catch (Exception e) { - reportException("An error occurred while performing Hibernate operations", e, resp); - } - resp.getWriter().write("OK"); + @GET + public String test() throws SQLException, TransformerException { + doStuffWithHibernate(entityManagerFactory, otherEntityManagerFactory); + doStuffWithDatasource(); + return "OK"; } private void doStuffWithDatasource() throws SQLException, TransformerException { @@ -275,16 +270,4 @@ private static void doXmlStuff(EntityManagerFactory emf, EntityManagerFactory ot } } - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); - } - } diff --git a/integration-tests/jpa-postgresql/pom.xml b/integration-tests/jpa-postgresql/pom.xml index 73b860e0209f3b..236e61604bbe91 100644 --- a/integration-tests/jpa-postgresql/pom.xml +++ b/integration-tests/jpa-postgresql/pom.xml @@ -20,15 +20,15 @@ io.quarkus - quarkus-undertow + quarkus-hibernate-orm io.quarkus - quarkus-hibernate-orm + quarkus-jdbc-postgresql io.quarkus - quarkus-jdbc-postgresql + quarkus-resteasy-reactive io.quarkus @@ -86,7 +86,7 @@ io.quarkus - quarkus-undertow-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java b/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java index 1a12d2a3e72e20..63cb03c48644c0 100644 --- a/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java +++ b/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java @@ -1,7 +1,5 @@ package io.quarkus.it.jpa.postgresql; -import java.io.IOException; -import java.io.PrintWriter; import java.time.Duration; import java.time.LocalDate; import java.util.List; @@ -15,10 +13,10 @@ import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Root; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; import io.quarkus.hibernate.orm.PersistenceUnit; import io.quarkus.it.jpa.postgresql.otherpu.EntityWithJsonOtherPU; @@ -26,8 +24,9 @@ /** * Various tests covering JPA functionality. All tests should work in both standard JVM and in native mode. */ -@WebServlet(name = "JPATestBootstrapEndpoint", urlPatterns = "/jpa/testfunctionality") -public class JPAFunctionalityTestEndpoint extends HttpServlet { +@Path("/jpa/testfunctionality") +@Produces(MediaType.TEXT_PLAIN) +public class JPAFunctionalityTestEndpoint { @Inject EntityManagerFactory entityManagerFactory; @@ -35,22 +34,9 @@ public class JPAFunctionalityTestEndpoint extends HttpServlet { @PersistenceUnit("other") EntityManagerFactory otherEntityManagerFactory; - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - try { - doStuffWithHibernate(entityManagerFactory, otherEntityManagerFactory); - } catch (Exception e) { - reportException("An error occurred while performing Hibernate operations", e, resp); - } - resp.getWriter().write("OK"); - } - - /** - * Lists the various operations we want to test for: - */ - private static void doStuffWithHibernate(EntityManagerFactory entityManagerFactory, - EntityManagerFactory otherEntityManagerFactory) { - + @GET + @Path("base") + public String base() { //Cleanup any existing data: deleteAllPerson(entityManagerFactory); @@ -65,11 +51,7 @@ private static void doStuffWithHibernate(EntityManagerFactory entityManagerFacto deleteAllPerson(entityManagerFactory); - // Try an entity using a UUID - verifyUUIDEntity(entityManagerFactory); - - doJsonStuff(entityManagerFactory, otherEntityManagerFactory); - + return "OK"; } private static void verifyJPANamedQuery(final EntityManagerFactory emf) { @@ -157,8 +139,10 @@ private static String randomName() { return UUID.randomUUID().toString(); } - private static void verifyUUIDEntity(final EntityManagerFactory emf) { - EntityManager em = emf.createEntityManager(); + @GET + @Path("uuid") + public String uuid() { + EntityManager em = entityManagerFactory.createEntityManager(); EntityTransaction transaction = em.getTransaction(); transaction.begin(); MyUUIDEntity myEntity = new MyUUIDEntity(); @@ -167,7 +151,7 @@ private static void verifyUUIDEntity(final EntityManagerFactory emf) { transaction.commit(); em.close(); - em = emf.createEntityManager(); + em = entityManagerFactory.createEntityManager(); transaction = em.getTransaction(); transaction.begin(); myEntity = em.find(MyUUIDEntity.class, myEntity.getId()); @@ -176,10 +160,13 @@ private static void verifyUUIDEntity(final EntityManagerFactory emf) { } transaction.commit(); em.close(); + return "OK"; } - private static void doJsonStuff(EntityManagerFactory emf, EntityManagerFactory otherEmf) { - try (EntityManager em = emf.createEntityManager()) { + @GET + @Path("json") + public String json() { + try (EntityManager em = entityManagerFactory.createEntityManager()) { EntityTransaction transaction = em.getTransaction(); transaction.begin(); @@ -189,7 +176,7 @@ private static void doJsonStuff(EntityManagerFactory emf, EntityManagerFactory o transaction.commit(); } - try (EntityManager em = emf.createEntityManager()) { + try (EntityManager em = entityManagerFactory.createEntityManager()) { EntityTransaction transaction = em.getTransaction(); transaction.begin(); List entities = em @@ -201,14 +188,14 @@ private static void doJsonStuff(EntityManagerFactory emf, EntityManagerFactory o transaction.commit(); } - try (EntityManager em = emf.createEntityManager()) { + try (EntityManager em = entityManagerFactory.createEntityManager()) { EntityTransaction transaction = em.getTransaction(); transaction.begin(); em.createQuery("delete from EntityWithJson").executeUpdate(); transaction.commit(); } - try (EntityManager em = otherEmf.createEntityManager()) { + try (EntityManager em = otherEntityManagerFactory.createEntityManager()) { EntityTransaction transaction = em.getTransaction(); transaction.begin(); EntityWithJsonOtherPU otherPU = new EntityWithJsonOtherPU( @@ -231,18 +218,8 @@ private static void doJsonStuff(EntityManagerFactory emf, EntityManagerFactory o throw new AssertionError("flush failed for a different reason than expected.", exception); } } - } - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); - if (errorMessage != null) { - writer.write(errorMessage); - writer.write(" "); - } - writer.write(e.toString()); - writer.append("\n\t"); - e.printStackTrace(writer); - writer.append("\n\t"); + return "OK"; } } diff --git a/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPATestReflectionEndpoint.java b/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPATestReflectionEndpoint.java index 705eae8071deaf..fb8f6727847389 100644 --- a/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPATestReflectionEndpoint.java +++ b/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPATestReflectionEndpoint.java @@ -2,34 +2,46 @@ import java.io.IOException; import java.io.PrintWriter; +import java.io.StringWriter; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; -import jakarta.servlet.annotation.WebServlet; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; +import javax.xml.transform.TransformerException; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; /** * Various tests for the JPA integration. * WARNING: these tests will ONLY pass in native mode, as it also verifies reflection non-functionality. */ -@WebServlet(name = "JPATestReflectionEndpoint", urlPatterns = "/jpa/testreflection") -public class JPATestReflectionEndpoint extends HttpServlet { - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - makeSureNonEntityAreDCE(resp); - makeSureEntitiesAreAccessibleViaReflection(resp); - makeSureNonAnnotatedEmbeddableAreAccessibleViaReflection(resp); - makeSureAnnotatedEmbeddableAreAccessibleViaReflection(resp); +@Path("/jpa/testreflection") +@Produces(MediaType.TEXT_PLAIN) +public class JPATestReflectionEndpoint { + + @GET + public String test() throws SQLException, TransformerException, IOException { + List errors = new ArrayList<>(); + makeSureNonEntityAreDCE(errors); + makeSureEntitiesAreAccessibleViaReflection(errors); + makeSureNonAnnotatedEmbeddableAreAccessibleViaReflection(errors); + makeSureAnnotatedEmbeddableAreAccessibleViaReflection(errors); String packageName = this.getClass().getPackage().getName(); - makeSureClassAreAccessibleViaReflection(packageName + ".Human", "Unable to enlist @MappedSuperclass", resp); - makeSureClassAreAccessibleViaReflection(packageName + ".Animal", "Unable to enlist entity superclass", resp); - resp.getWriter().write("OK"); + makeSureClassAreAccessibleViaReflection(packageName + ".Human", "Unable to enlist @MappedSuperclass", errors); + makeSureClassAreAccessibleViaReflection(packageName + ".Animal", "Unable to enlist entity superclass", errors); + if (errors.isEmpty()) { + return "OK"; + } else { + return String.join("\n", errors); + } } - private void makeSureClassAreAccessibleViaReflection(String className, String errorMessage, HttpServletResponse resp) + private void makeSureClassAreAccessibleViaReflection(String className, String errorMessage, List errors) throws IOException { try { className = getTrickedClassName(className); @@ -37,11 +49,11 @@ private void makeSureClassAreAccessibleViaReflection(String className, String er Class custClass = Class.forName(className); Object instance = custClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { - reportException(errorMessage, e, resp); + reportException(errorMessage, e, errors); } } - private void makeSureEntitiesAreAccessibleViaReflection(HttpServletResponse resp) throws IOException { + private void makeSureEntitiesAreAccessibleViaReflection(List errors) throws IOException { try { String className = getTrickedClassName(Customer.class.getName()); @@ -50,20 +62,20 @@ private void makeSureEntitiesAreAccessibleViaReflection(HttpServletResponse resp Field id = custClass.getDeclaredField("id"); id.setAccessible(true); if (id.get(instance) != null) { - resp.getWriter().write("id should be reachable and null"); + errors.add("id should be reachable and null"); } Method setter = custClass.getDeclaredMethod("setName", String.class); Method getter = custClass.getDeclaredMethod("getName"); setter.invoke(instance, "Emmanuel"); if (!"Emmanuel".equals(getter.invoke(instance))) { - resp.getWriter().write("getter / setter should be reachable and usable"); + errors.add("getter / setter should be reachable and usable"); } } catch (Exception e) { - reportException(e, resp); + reportException(e, errors); } } - private void makeSureAnnotatedEmbeddableAreAccessibleViaReflection(HttpServletResponse resp) throws IOException { + private void makeSureAnnotatedEmbeddableAreAccessibleViaReflection(List errors) throws IOException { try { String className = getTrickedClassName(WorkAddress.class.getName()); @@ -73,14 +85,14 @@ private void makeSureAnnotatedEmbeddableAreAccessibleViaReflection(HttpServletRe Method getter = custClass.getDeclaredMethod("getCompany"); setter.invoke(instance, "Red Hat"); if (!"Red Hat".equals(getter.invoke(instance))) { - resp.getWriter().write("@Embeddable embeddable should be reachable and usable"); + errors.add("@Embeddable embeddable should be reachable and usable"); } } catch (Exception e) { - reportException(e, resp); + reportException(e, errors); } } - private void makeSureNonAnnotatedEmbeddableAreAccessibleViaReflection(HttpServletResponse resp) throws IOException { + private void makeSureNonAnnotatedEmbeddableAreAccessibleViaReflection(List errors) throws IOException { try { String className = getTrickedClassName(Address.class.getName()); @@ -90,19 +102,19 @@ private void makeSureNonAnnotatedEmbeddableAreAccessibleViaReflection(HttpServle Method getter = custClass.getDeclaredMethod("getStreet1"); setter.invoke(instance, "1 rue du General Leclerc"); if (!"1 rue du General Leclerc".equals(getter.invoke(instance))) { - resp.getWriter().write("Non @Embeddable embeddable getter / setter should be reachable and usable"); + errors.add("Non @Embeddable embeddable getter / setter should be reachable and usable"); } } catch (Exception e) { - reportException(e, resp); + reportException(e, errors); } } - private void makeSureNonEntityAreDCE(HttpServletResponse resp) { + private void makeSureNonEntityAreDCE(List errors) { try { String className = getTrickedClassName(NotAnEntityNotReferenced.class.getName()); Class custClass = Class.forName(className); - resp.getWriter().write("Should not be able to find a non referenced non entity class"); + errors.add("Should not be able to find a non referenced non entity class"); Object instance = custClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { // Expected outcome @@ -118,20 +130,24 @@ private String getTrickedClassName(String className) { return className; } - private void reportException(final Exception e, final HttpServletResponse resp) throws IOException { - reportException(null, e, resp); + private void reportException(final Exception e, final List errors) throws IOException { + reportException(null, e, errors); } - private void reportException(String errorMessage, final Exception e, final HttpServletResponse resp) throws IOException { - final PrintWriter writer = resp.getWriter(); + private void reportException(String errorMessage, final Exception e, final List errors) throws IOException { + StringWriter stringWriter = new StringWriter(); + final PrintWriter writer = new PrintWriter(stringWriter); if (errorMessage != null) { writer.write(errorMessage); writer.write(" "); } - writer.write(e.toString()); + if (e.getMessage() != null) { + writer.write(e.getMessage()); + } writer.append("\n\t"); e.printStackTrace(writer); writer.append("\n\t"); + errors.add(stringWriter.toString()); } } diff --git a/integration-tests/jpa-postgresql/src/test/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTest.java b/integration-tests/jpa-postgresql/src/test/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTest.java index 559b6451726ccf..0ccf51d52d76a4 100644 --- a/integration-tests/jpa-postgresql/src/test/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTest.java +++ b/integration-tests/jpa-postgresql/src/test/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTest.java @@ -14,8 +14,18 @@ public class JPAFunctionalityTest { @Test - public void testJPAFunctionalityFromServlet() throws Exception { - RestAssured.when().get("/jpa/testfunctionality").then().body(is("OK")); + public void base() { + RestAssured.when().get("/jpa/testfunctionality/base").then().body(is("OK")); + } + + @Test + public void uuid() { + RestAssured.when().get("/jpa/testfunctionality/uuid").then().body(is("OK")); + } + + @Test + public void json() { + RestAssured.when().get("/jpa/testfunctionality/json").then().body(is("OK")); } } diff --git a/integration-tests/jpa-without-entity/pom.xml b/integration-tests/jpa-without-entity/pom.xml index 11fdfcc39aaab5..c710184b9bd707 100644 --- a/integration-tests/jpa-without-entity/pom.xml +++ b/integration-tests/jpa-without-entity/pom.xml @@ -22,28 +22,29 @@ quarkus-hibernate-orm - io.quarkus - quarkus-resteasy + quarkus-jdbc-postgresql io.quarkus - quarkus-junit5 - test + quarkus-resteasy-reactive - io.rest-assured - rest-assured - test + io.quarkus + quarkus-resteasy-reactive-jackson + + io.quarkus - quarkus-jdbc-postgresql + quarkus-junit5 + test - io.quarkus - quarkus-resteasy-jackson + io.rest-assured + rest-assured + test @@ -75,7 +76,7 @@ io.quarkus - quarkus-resteasy-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test @@ -88,7 +89,7 @@ io.quarkus - quarkus-resteasy-jackson-deployment + quarkus-resteasy-reactive-jackson-deployment ${project.version} pom test diff --git a/integration-tests/jpa/pom.xml b/integration-tests/jpa/pom.xml index 25e7369b80cde6..da832c2141f6d9 100644 --- a/integration-tests/jpa/pom.xml +++ b/integration-tests/jpa/pom.xml @@ -13,10 +13,6 @@ Quarkus - Integration Tests - JPA - - io.quarkus - quarkus-resteasy - io.quarkus quarkus-hibernate-orm @@ -30,6 +26,10 @@ assertj-core compile + + io.quarkus + quarkus-resteasy-reactive + @@ -82,7 +82,7 @@ io.quarkus - quarkus-resteasy-deployment + quarkus-resteasy-reactive-deployment ${project.version} pom test diff --git a/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/attributeconverter/AttributeConverterResource.java b/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/attributeconverter/AttributeConverterResource.java index bcf2fdab0c75b0..3d6d9e17ae11ad 100644 --- a/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/attributeconverter/AttributeConverterResource.java +++ b/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/attributeconverter/AttributeConverterResource.java @@ -9,7 +9,7 @@ import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; -import org.jboss.resteasy.annotations.jaxrs.QueryParam; +import org.jboss.resteasy.reactive.RestQuery; @Path("/attribute-converter") @ApplicationScoped @@ -22,7 +22,7 @@ public class AttributeConverterResource { @Path("/with-cdi") @Produces(MediaType.TEXT_PLAIN) @Transactional - public String withCdi(@QueryParam String theData) { + public String withCdi(@RestQuery String theData) { EntityWithAttributeConverters entity = new EntityWithAttributeConverters(); entity.setMyDataRequiringCDI(new MyDataRequiringCDI(theData)); em.persist(entity); @@ -39,7 +39,7 @@ public String withCdi(@QueryParam String theData) { @Path("/without-cdi") @Produces(MediaType.TEXT_PLAIN) @Transactional - public String withoutCdi(@QueryParam String theData) { + public String withoutCdi(@RestQuery String theData) { EntityWithAttributeConverters entity = new EntityWithAttributeConverters(); entity.setMyDataNotRequiringCDI(new MyDataNotRequiringCDI(theData)); em.persist(entity); diff --git a/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/defaultcatalogandschema/DefaultCatalogAndSchemaResource.java b/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/defaultcatalogandschema/DefaultCatalogAndSchemaResource.java index 6e6fd83ed8575e..dee3fc27abd3f0 100644 --- a/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/defaultcatalogandschema/DefaultCatalogAndSchemaResource.java +++ b/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/defaultcatalogandschema/DefaultCatalogAndSchemaResource.java @@ -14,7 +14,7 @@ import org.hibernate.Session; import org.hibernate.type.StandardBasicTypes; -import org.jboss.resteasy.annotations.jaxrs.QueryParam; +import org.jboss.resteasy.reactive.RestQuery; @Path("/default-catalog-and-schema") @ApplicationScoped @@ -27,7 +27,7 @@ public class DefaultCatalogAndSchemaResource { @Path("/test") @Produces(MediaType.TEXT_PLAIN) @Transactional - public String test(@QueryParam String expectedSchema) { + public String test(@RestQuery String expectedSchema) { assertThat(findUsingNativeQuery(expectedSchema, "foo")).isEmpty(); EntityWithDefaultCatalogAndSchema entity = new EntityWithDefaultCatalogAndSchema(); diff --git a/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/elementcollection/OpeningTimes.java b/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/elementcollection/OpeningTimes.java index e4351539b54c2e..ac2bc3edb223a5 100644 --- a/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/elementcollection/OpeningTimes.java +++ b/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/elementcollection/OpeningTimes.java @@ -16,7 +16,6 @@ import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import jakarta.validation.constraints.NotNull; import org.hibernate.annotations.Cascade; import org.hibernate.annotations.GenericGenerator; @@ -28,7 +27,6 @@ public class OpeningTimes { @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator") private UUID id; - @NotNull private String name; private String description; private LocalTime timeFrom;