From 2ad996eaa38614d343f5f3855560bce10ed11d0d Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Sat, 18 Jan 2020 20:17:49 +0200 Subject: [PATCH] BAEL-3660 - Final changes --- open-liberty/pom.xml | 4 ++-- .../person/resource/PersonResource.java | 19 ------------------- .../rest/consumes/RestConsumer.java | 12 ------------ .../src/main/liberty/config/server.xml | 7 +------ .../baeldung/openliberty/RestClientTest.java | 12 +----------- 5 files changed, 4 insertions(+), 50 deletions(-) diff --git a/open-liberty/pom.xml b/open-liberty/pom.xml index 1a9ebeeedb..b01811ff77 100644 --- a/open-liberty/pom.xml +++ b/open-liberty/pom.xml @@ -111,7 +111,7 @@ 8.0.0 3.2 - 10.15.1.3 + 10.14.2.0 3.1 2.10 3.2.3 @@ -125,6 +125,6 @@ openliberty 9080 9443 - 9080 + 7070 \ No newline at end of file diff --git a/open-liberty/src/main/java/com/baeldung/openliberty/person/resource/PersonResource.java b/open-liberty/src/main/java/com/baeldung/openliberty/person/resource/PersonResource.java index 506214229c..049f4761b5 100644 --- a/open-liberty/src/main/java/com/baeldung/openliberty/person/resource/PersonResource.java +++ b/open-liberty/src/main/java/com/baeldung/openliberty/person/resource/PersonResource.java @@ -1,12 +1,8 @@ package com.baeldung.openliberty.person.resource; -import java.util.Set; - import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.transaction.Transactional; -import javax.validation.ConstraintViolation; -import javax.validation.Validator; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; @@ -26,9 +22,6 @@ public class PersonResource { @Inject private PersonDao personDao; - @Inject - Validator validator; - @GET @Produces(MediaType.APPLICATION_JSON) public Person getPerson() { @@ -40,18 +33,6 @@ public class PersonResource { @Consumes(MediaType.APPLICATION_JSON) @Transactional public Response addPerson(Person person) { - Set> violations = validator.validate(person); - if (violations.size() > 0) { - StringBuilder sb = new StringBuilder(); - sb.append("Constraint Violation Found: ").append(System.lineSeparator()); - for (ConstraintViolation violation : violations) { - sb.append(violation.getPropertyPath()) - .append(" ") - .append(violation.getMessage()) - .append(System.lineSeparator()); - } - return Response.status(Response.Status.BAD_REQUEST).entity(sb.toString()).build(); - } personDao.createPerson(person); String respMessage = "Person #" + person.getId() + " created successfully."; return Response.status(Response.Status.OK).entity(respMessage).build(); diff --git a/open-liberty/src/main/java/com/baeldung/openliberty/rest/consumes/RestConsumer.java b/open-liberty/src/main/java/com/baeldung/openliberty/rest/consumes/RestConsumer.java index a3b548672b..8073c408dd 100644 --- a/open-liberty/src/main/java/com/baeldung/openliberty/rest/consumes/RestConsumer.java +++ b/open-liberty/src/main/java/com/baeldung/openliberty/rest/consumes/RestConsumer.java @@ -1,13 +1,9 @@ package com.baeldung.openliberty.rest.consumes; -import java.net.URI; - import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.core.Response; -import org.eclipse.microprofile.rest.client.RestClientBuilder; - public class RestConsumer { public static String consumeWithJsonb(String targetUrl) { @@ -19,12 +15,4 @@ public class RestConsumer { return result; } - public static String consumeWithRestBuilder(String targetUrl) { - URI target = URI.create(targetUrl); - PersonClient person = RestClientBuilder.newBuilder() - .baseUri(target) - .build(PersonClient.class); - return person.getPerson(); - } - } diff --git a/open-liberty/src/main/liberty/config/server.xml b/open-liberty/src/main/liberty/config/server.xml index fd970feb45..bc99905058 100644 --- a/open-liberty/src/main/liberty/config/server.xml +++ b/open-liberty/src/main/liberty/config/server.xml @@ -7,12 +7,8 @@ jsonb-1.0 cdi-2.0 jpa-2.2 - beanValidation-2.0 - mpRestClient-1.3 - - @@ -20,8 +16,7 @@ - - + diff --git a/open-liberty/src/test/java/com/baeldung/openliberty/RestClientTest.java b/open-liberty/src/test/java/com/baeldung/openliberty/RestClientTest.java index 7925dcad9e..ab024d788a 100644 --- a/open-liberty/src/test/java/com/baeldung/openliberty/RestClientTest.java +++ b/open-liberty/src/test/java/com/baeldung/openliberty/RestClientTest.java @@ -23,9 +23,8 @@ public class RestClientTest { @Test public void testSuite() { - //uncomment when liberty server starts + //run the test only when liberty server is started //this.whenConsumeWithJsonb_thenGetPerson(); - //this.whenConsumeWithRestBuilder_thenGetPerson(); } public void whenConsumeWithJsonb_thenGetPerson() { @@ -38,13 +37,4 @@ public class RestClientTest { assertEquals(person.getEmail(), "normanlewis@email.com"); } - public void whenConsumeWithRestBuilder_thenGetPerson() { - String result = RestConsumer.consumeWithRestBuilder(BASE_URL); - - Person person = JsonbBuilder.create().fromJson(result, Person.class); - assert person.getId() == 1; - assertEquals(person.getUsername(), "normanlewis"); - assertEquals(person.getEmail(), "normanlewis@email.com"); - } - }