Code check-in for http://jira.baeldung.com/browse/BAEL-2012 (Set a Response body in JAX-RS) (#5009)

* abh.swar@gmail.com: Code check-in for article on Spring WebFlux
1. EmailWebClient is the client that subscribes to the data from WebFlux server
2. EmailGenerator generates one email per second randomly
3. EmailHandler and EmailRouter deal with handling of request of the subscriber
4. Email is the POJO for data transmitted by the server

* Code check-on for (http://jira.baeldung.com/browse/BAEL-1897) How to increment a Date by one day
- Added code and test to increment date by one day using java 8 and joda-time
- Added joda-time 2.10 dependency in pom.xml

* Revert "abh.swar@gmail.com: Code check-in for article on Spring WebFlux 1. EmailWebClient is the client that subscribes to the data from WebFlux server 2. EmailGenerator generates one email per second randomly 3. EmailHandler and EmailRouter deal with handling of request of the subscriber 4. Email is the POJO for data transmitted by the server"

This reverts commit 6254ad9

* Code check-on for (http://jira.baeldung.com/browse/BAEL-1897) How to increment a Date by one day
- Added code and test to increment date by one day using java.util.Calendar and ApacheCommons and unit tests for it
- Used properties for ${joda.version}
- Formatted the code using IntelliJ formatter
- Renamed DateIncrementerTest to DateIncrementerUnitTest
- Changed test method names to follow _given_when_then convention

* Code check-on for (http://jira.baeldung.com/browse/BAEL-1897) How to increment a Date by one day
- Removed unnecessary comment

* Code check-on for (http://jira.baeldung.com/browse/BAEL-1897) How to increment a Date by one day
- Corrected the order of parameters of assertEquals() method

* Code check-in for http://jira.baeldung.com/browse/BAEL-2012 (Set a Response body in JAX-RS)
- Added a Responder resource that has all the REST endpoints
- Added a POJO Person which will be used for JSON serialization

* Create test

* Delete test
This commit is contained in:
Abhinayak Swar 2018-09-01 12:35:42 +05:45 committed by Grzegorz Piwowarek
parent 5e3a0c7ad3
commit 8cbca2f805
2 changed files with 134 additions and 0 deletions

View File

@ -0,0 +1,102 @@
package com.baeldung.jersey.server;
import com.baeldung.jersey.server.model.Person;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/response")
public class Responder {
@GET
@Path("/ok")
public Response getOkResponse() {
String message = "This is a text response";
return Response
.status(Response.Status.OK)
.entity(message)
.build();
}
@GET
@Path("/not_ok")
public Response getNOkTextResponse() {
String message = "There was an internal server error";
return Response
.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(message)
.build();
}
@GET
@Path("/text_plain")
public Response getTextResponseTypeDefined() {
String message = "This is a plain text response";
return Response
.status(Response.Status.OK)
.entity(message)
.type(MediaType.TEXT_PLAIN)
.build();
}
@GET
@Path("/text_plain_annotation")
@Produces({ MediaType.TEXT_PLAIN })
public Response getTextResponseTypeAnnotated() {
String message = "This is a plain text response via annotation";
return Response
.status(Response.Status.OK)
.entity(message)
.build();
}
@GET
@Path("/pojo")
public Response getPojoResponse() {
Person person = new Person("Abh", "Nepal");
return Response
.status(Response.Status.OK)
.entity(person)
.build();
}
@GET
@Path("/json")
public Response getJsonResponse() {
String message = "{\"hello\": \"This is a JSON response\"}";
return Response
.status(Response.Status.OK)
.entity(message)
.type(MediaType.APPLICATION_JSON)
.build();
}
@GET
@Path("/xml")
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> This is a xml response </hello>";
}
@GET
@Path("/html")
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + " This is a html title </title>" + "<body><h1>" + " This is a html response body " + "</body></h1>" + "</html> ";
}
}

View File

@ -0,0 +1,32 @@
package com.baeldung.jersey.server.model;
public class Person {
String name;
String address;
public Person(String name, String address) {
this.name = name;
this.address = address;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "Person [name: " + getName() + " address: " + getAddress() + "]";
}
}