I am trying to share data from one server(8081) to another(8082) in Spring Boot using ResponseEntity, but I am not able to built the body.
Here is the code which I have written,
Server 1-
@GetMapping("/redirect")
public ResponseEntity<Void> redirectPgServer(@RequestParam("txnId") String txnId,
@RequestParam("amount") String amount) {
// Redirect to server 2
ProductDetails ref=new ProductDetails();
ref.setTxnId("txnId");
ref.setAmount("amount);
HttpHeaders head = new HttpHeaders();
String url = "http://localhost:8082/redirect-server";
System.out.println(url);
head.setLocation(URI.create(url));
return new ResponseEntity<Void>(ref, head, HttpStatus.FOUND);
}
Server2-
@GetMapping(value = "/redirect-server")
public String validateData(@RequestBody ProductDetails ref)
{
//Server 2 receive data
System.out.println(ref.getAmount());
//Does not gives any output since it throws error Request Body Missing, also if I mention
post mapping above it throws error Request method 'GET' not supported]
return "index"; //Using Thymeleaf for displaying html page.
}
I am able to share the data using only header by manipulating the url and using PathVariable but I want to use Post Mapping as I want to hide the parameters in the Url which are visible to User at Browser. Also I have tried using RestTemplate which brings me back to Server 1 and it throws error- Spring rest template cannot convert from text/html utf8.