Writing a Java client for the REST POST web service

We will now add a test method in the CourseManagementClient class, in the CourseManagementRESTClient project:

  //Test addCourse method (JSON version) of CourseService 
  public static void testAddCourseJSON() { 
 
    //Create JAX-RS client 
    Client client = ClientBuilder.newClient(); 
 
    //Get WebTarget for a URL 
    WebTarget webTarget =  client.target("http://localhost:8600/CourseManagementREST/services/course/add"); 
 
    //Create JSON representation of Course, 
    //with course_name and credits fields. Instead of creating 
    //JSON manually, you could also use JAXB to create JSON from 
    //Java object. 
    String courseJSON = "{"course_name":"Course-4",  "credits":5}"; //Execute HTTP post method Response response = webTarget.request(). ...

Get Java EE 8 Development with Eclipse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.