diff --git a/pom.xml b/pom.xml index d186d924cd7f594eb9043812089ab89058ba8fb5..ca216d5f782ed4b973ad07450013c98b93efe2b2 100644 --- a/pom.xml +++ b/pom.xml @@ -104,6 +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> diff --git a/src/main/java/java2/lab12/client/CourseClient.java b/src/main/java/java2/lab12/client/CourseClient.java new file mode 100644 index 0000000000000000000000000000000000000000..3738ab5d2ffd9694bb90456b8831cab0216ba6d0 --- /dev/null +++ b/src/main/java/java2/lab12/client/CourseClient.java @@ -0,0 +1,25 @@ +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 CourseClient { + + @GET + @Path("courses/") + @Produces(MediaType.APPLICATION_JSON) + Collection<Course> getCourses(); + + @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..f2315660c6bd628e934504407d002d86ef6ab50c 100644 --- a/src/main/java/java2/lab12/client/TableViewSample.java +++ b/src/main/java/java2/lab12/client/TableViewSample.java @@ -1,8 +1,12 @@ package java2.lab12.client; +import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; + import java.util.Collection; import java.util.Collections; +import org.apache.cxf.jaxrs.client.JAXRSClientFactory; + import javafx.application.Application; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.collections.FXCollections; @@ -26,7 +30,9 @@ import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.stage.Stage; import javafx.stage.WindowEvent; - +import lombok.extern.log4j.Log4j2; + +@Log4j2 public class TableViewSample extends Application { @@ -190,11 +196,18 @@ public class TableViewSample extends Application { } private Collection<Course> getCourses() { - return Collections.emptyList(); + return getClient().getCourses(); + } + + private CourseClient getClient() { + return JAXRSClientFactory.create("http://localhost:8080", + CourseClient.class, Collections.singletonList( + new JacksonJaxbJsonProvider())); } private void createCourse(Course course) { - // TODO + Long id = getClient().createCourse(course); + course.setId(id); } private void updateCourse(Course course) {