Skip to content
Snippets Groups Projects
Commit 3b1b3449 authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

Solution

parent b5751e85
No related merge requests found
Pipeline #111 failed with stages
in 0 seconds
......@@ -104,7 +104,13 @@
<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>
......
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);
}
package java2.lab12.client;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import javafx.application.Application;
import javafx.collections.FXCollections;
......@@ -24,7 +31,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 {
......@@ -158,8 +167,21 @@ public class TableViewSample extends Application {
System.exit(0);
}
private CourseClient getClient() {
Map<String, Object> properties = new HashMap<>();
CourseClient client = JAXRSClientFactory.create("http://localhost:8080",
CourseClient.class, Collections.singletonList(
new JacksonJaxbJsonProvider().disable(
SerializationFeature.WRAP_ROOT_VALUE).disable(
SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED)),
properties, true);
return client;
}
private Collection<Course> getCourses() {
return Collections.emptyList();
CourseClient client = getClient();
return client.getCourses();
}
private void createCourse(Course p) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment