I have developed 2 microservices in Spring:
- a UI-service
- a Login-service, which also has UI (html-form) for testing
The UI-service is consuming the Login-service.
UI-service (code)
@RequestMapping("/log")
public String abc(HttpServletRequest request) {
final String uri = "http://localhost:8093/accounts/login";
RestTemplate restTemplate = new RestTemplate();
String result = restTemplate.getForObject(uri, String.class);
return result;
//request.setAttribute("mode", "MODE_LOGIN");
}
@RequestMapping("/login-user")
private String getEmployees1(HttpServletRequest request) {
final String uri = "http://localhost:8093/login-user";
RestTemplate restTemplate = new RestTemplate();
String result = restTemplate.getForObject(uri, String.class);
return result;
}
Login-service (code)
I have this working on port 8093.
@RequestMapping("/accounts/login") //login
public String login(HttpServletRequest request) {
request.setAttribute("mode", "MODE_LOGIN");
return "login";
}
@RequestMapping ("/login-user") // checking user details in database
public String loginUser(@ModelAttribute User user, HttpServletRequest request) {
//ModelAndView model = new ModelAndView();
if(userService.findByEmailAndPassword(user.getEmail(), user.getPassword())!=null) {
return "index";
}
else {
request.setAttribute("error", "Invalid username and password!");
request.setAttribute("mode", "MODE_LOGIN");
return "login";
}
}
I have placed following attributes MODE_HOME
and MODE_LOGIN
in the JSP-page.
Same code if i test with Login Service with its UI, it is working fine but while consuming from UI service it is taking null
value. I am able to consume the service but following value is showing in the console (console.log
) when same service is used:
select user0_.id as id1_0_, user0_.`email` as email2_0_, user0_.`fname` as fname3_0_,
user0_.`lname` as lname4_0_, user0_.`pwd` as pwd5_0_, user0_.`phone` as phone6_0_ from user
user0_ where user0_.`email`=? and user0_.`pwd`=?
But when consuming the Login-service from another using restTemplate
:
select user0_.id as id1_0_, user0_.`email` as email2_0_, user0_.`fname` as fname3_0_,
user0_.`lname` as lname4_0_, user0_.`pwd` as pwd5_0_, user0_.`phone` as phone6_0_ from user user0_
where (user0_.`email` is null) and (user0_.`pwd` is null)
I am new to this.
What could be the issue?