diff --git a/pom.xml b/pom.xml index d186d924cd7f594eb9043812089ab89058ba8fb5..b3cfb86af5f2fa85d38d15eeb2f1d0c9643beec9 100644 --- a/pom.xml +++ b/pom.xml @@ -104,7 +104,12 @@ <artifactId>log4j-core</artifactId> <version>${log4j.version}</version> </dependency> - + <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-rs-client --> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-rs-client</artifactId> + <version>3.4.3</version> + </dependency> </dependencies> <build> <plugins> diff --git a/src/main/java/java2/lab12/client/CourseResourceClient.java b/src/main/java/java2/lab12/client/CourseResourceClient.java new file mode 100644 index 0000000000000000000000000000000000000000..f0e1e08997f1abe469ed9c0d03dac0f7d241faf5 --- /dev/null +++ b/src/main/java/java2/lab12/client/CourseResourceClient.java @@ -0,0 +1,24 @@ +package java2.lab12.client; + +import java.util.Collection; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/") +public interface CourseResourceClient { + + @GET + @Path("courses") + @Produces(MediaType.APPLICATION_JSON) + Collection<Course> allCourses(); + + @POST + @Path("course") + @Consumes(MediaType.APPLICATION_JSON) + Long createCourse(Course course); +} diff --git a/src/main/java/java2/lab12/client/TableViewSample.java b/src/main/java/java2/lab12/client/TableViewSample.java index cbb1718e833b99465dc2f0567b098a41ca9dd271..10d266f304ca3661fa06260acbb9826e4b72d14f 100644 --- a/src/main/java/java2/lab12/client/TableViewSample.java +++ b/src/main/java/java2/lab12/client/TableViewSample.java @@ -190,11 +190,12 @@ public class TableViewSample extends Application { } private Collection<Course> getCourses() { - return Collections.emptyList(); + return getClient().allCourses(); } private void createCourse(Course course) { - // TODO + long id = getClient().createCourse(course); + course.setId(id); } private void updateCourse(Course course) { @@ -204,4 +205,10 @@ public class TableViewSample extends Application { private void removeCourse(Course course) { // TODO } + + private CourseResourceClient getClient() { + return JAXRSClientFactory.create("http://localhost:8080", + CourseResourceClient.class, Collections.singletonList( + JacksonJaxbJsonProvider.class)); + } } \ No newline at end of file diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 76fb788065e5e48835c7bc99ebd8803a323536a1..fa09f6b9c028e5a0bce56653abf99c1973eebee4 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -10,4 +10,4 @@ quarkus: log: sql: true database: - generation: drop-and-create \ No newline at end of file + generation: update \ No newline at end of file