Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client app in Zuul RestTemplate gets login page instead of JSON #411

Open
fr33land opened this issue Mar 9, 2018 · 2 comments
Open

Client app in Zuul RestTemplate gets login page instead of JSON #411

fr33land opened this issue Mar 9, 2018 · 2 comments
Labels

Comments

@fr33land
Copy link

fr33land commented Mar 9, 2018

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:
    routes:
       user:
            path: /user/**
            serviceId: user-service

Zuul client web app controller controller

@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.

@spencergibb
Copy link

Not the spring cloud Netflix issue tracker

Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants