BAEL-3660 - Final changes
This commit is contained in:
parent
ccdf5f0d9f
commit
2ad996eaa3
@ -111,7 +111,7 @@
|
||||
<!-- versions -->
|
||||
<version.jakarta.jakartaee-web-api>8.0.0</version.jakarta.jakartaee-web-api>
|
||||
<version.microprofile>3.2</version.microprofile>
|
||||
<version.derby>10.15.1.3</version.derby>
|
||||
<version.derby>10.14.2.0</version.derby>
|
||||
<version.liberty-maven-plugin>3.1</version.liberty-maven-plugin>
|
||||
<version.maven-dependency-plugin>2.10</version.maven-dependency-plugin>
|
||||
<version.maven-war-plugin>3.2.3</version.maven-war-plugin>
|
||||
@ -125,6 +125,6 @@
|
||||
<liberty.var.app.context.root>openliberty</liberty.var.app.context.root>
|
||||
<liberty.var.default.http.port>9080</liberty.var.default.http.port>
|
||||
<liberty.var.default.https.port>9443</liberty.var.default.https.port>
|
||||
<testServerHttpPort>9080</testServerHttpPort>
|
||||
<testServerHttpPort>7070</testServerHttpPort>
|
||||
</properties>
|
||||
</project>
|
@ -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<ConstraintViolation<Person>> violations = validator.validate(person);
|
||||
if (violations.size() > 0) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Constraint Violation Found: ").append(System.lineSeparator());
|
||||
for (ConstraintViolation<Person> 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();
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,12 +7,8 @@
|
||||
<feature>jsonb-1.0</feature>
|
||||
<feature>cdi-2.0</feature>
|
||||
<feature>jpa-2.2</feature>
|
||||
<feature>beanValidation-2.0</feature>
|
||||
<feature>mpRestClient-1.3</feature>
|
||||
</featureManager>
|
||||
|
||||
<keyStore id="defaultKeyStore" password="Liberty" />
|
||||
|
||||
<webApplication location="open-liberty.war" contextRoot="/" />
|
||||
|
||||
<logging traceSpecification="com.ibm.ws.microprofile.health.*=all" hideMessage="SRVE9967W" />
|
||||
@ -20,8 +16,7 @@
|
||||
<httpEndpoint host="*" httpPort="${default.http.port}" httpsPort="${default.https.port}" id="defaultHttpEndpoint" />
|
||||
|
||||
<library id="derbyJDBCLib">
|
||||
<!-- <fileset dir="${project.build.directory}/open-liberty/WEB-INF/lib" includes="derby*.jar" /> -->
|
||||
<fileset dir="/Users/anshulbansal/eclipse-workspace/tutorials/open-liberty/target/open-liberty/WEB-INF/lib" includes="derby*.jar" />
|
||||
<fileset dir="${shared.resource.dir}" includes="derby*.jar"/>
|
||||
</library>
|
||||
|
||||
<!-- Datasource Configuration -->
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user