I am experimenting with microservices architecture and I have an issue. I have a Zuul gateway and client web application with login form and controllers inside in zuul gateway. Routes to the microservices are defined in Zuul application.yaml config. Microservices also register them selves to eureka server. Users is authenticated against database using jdbcAuthentication. When user enters http://localhost:8080 address in browser zuul displays login form. After successful login user is redirected to home page (index) controller. This controller additionally executes RestTemplate call to the user-info microservice that is under zuul proxy with address http://localhost:8080/user/ defined in config as /user route. Then instead of json response from microservice I am getting same login form html code. If I try to access http://localhost:8080/user/ rest endpoint from browser then I get a nice and clear object with attributes in JSON response. It looks like that RestTemplate losts or doesn't pass authentication or session information. I am adding my config code examples
@Controller
public class IndexController{
@Autowired
private RestTemplate restTemplate;
@RequestMapping("/")
public String index(ModelMap model, HttpServletRequest request, HttpServletResponse response) {
Long userId = 2L;
String user = restTemplate.getForObject("http://localhost:8080/user/find/{id}", String.class, userId);
// this is the place where I get html code of login form instead of JSON
return "index";
}
}
User microservice rest controller
@RestController
public class UserController {
@Autowired
private IUserService userService;
@RequestMapping("find/{id}")
public ResponseEntity<User> findById(@PathVariable long id) {
return new ResponseEntity<>(userService.findById(id), HttpStatus.OK);
}
}
I hope that I clearly explained my situation. Thanks for help in advance.
I am experimenting with microservices architecture and I have an issue. I have a Zuul gateway and client web application with login form and controllers inside in zuul gateway. Routes to the microservices are defined in Zuul application.yaml config. Microservices also register them selves to eureka server. Users is authenticated against database using jdbcAuthentication. When user enters http://localhost:8080 address in browser zuul displays login form. After successful login user is redirected to home page (index) controller. This controller additionally executes RestTemplate call to the user-info microservice that is under zuul proxy with address http://localhost:8080/user/ defined in config as /user route. Then instead of json response from microservice I am getting same login form html code. If I try to access http://localhost:8080/user/ rest endpoint from browser then I get a nice and clear object with attributes in JSON response. It looks like that RestTemplate losts or doesn't pass authentication or session information. I am adding my config code examples
ZUUL config
Zuul client web app controller controller
User microservice rest controller
I hope that I clearly explained my situation. Thanks for help in advance.