1

I have a microservices scenario where a Sidecar (spring boot app) maps the endpoints of a python webserver.

The python server listens on 5000 and executes a calculation, so we decided to map its homepage with "calc" prefix in the URI, so we have the following configuration:

eureka:
  [omissis] #it works
sidecar:
   port: 5000
   health-uri: http://${sidecar.hostname}:${sidecar.port}/health.json
   home-page-uri: http://${sidecar.hostname}:${sidecar.port}/
   hostname: localhost
server:
  port: 2323
  servlet:
    context-path: /pye

zuul:
  routes:
      calc:
          url: localhost:5000/

Then, I introduced a new REST controller inside Sidecar microservice, that is:

@RestController
@RequestMapping("git")
public class GitController {

@GetMapping("/")
public List<String> getBranchesAlias(@RequestHeader("Authorization") String oauth2Token,
        @RequestHeader(value = "OIDC_access_token", required = false) String oidAccessToken) {
        //returns a list of branches from a git repository
    return getBranches(oauth2Token, oidAccessToken);
   }
}

And, finally, I wrote a FeignClient that SHOULD allow me to call microservice's endpoints from other microservices, like this:

@FeignClient(name = "python-engine")
public interface PythonEngineClient {
@GetMapping(value = "/pye/git/", produces = MediaType.APPLICATION_JSON_VALUE)
List<String> getBranches(@RequestHeader("Authorization") String oauth2Token,
        @RequestHeader(value = "OIDC_access_token", required = false) String oidAccessToken);
}

What I obtain calling the FeignClient is that URIs starting with "/git" are redirected to localhost:/5000 instead of localhost:/2323, with the following log:

DEBUG s.n.w.p.http.HttpURLConnection - sun.net.www.MessageHeader@647d9996 pairs: {GET /pye/git/branches HTTP/1.1: null}{Accept: application/json}{Authorization: Bearer [omissis] }{User-Agent: Java/1.8.0_232}{Host: localhost:5000}{Connection: keep-alive}
DEBUG s.n.w.p.http.HttpURLConnection - sun.net.www.MessageHeader@88037215 pairs: {null: HTTP/1.1 404 NOT FOUND}{Content-Length: 232}{Content-Type: text/html}{Date: Fri, 14 Feb 2020 08:53:49 GMT}{Server: waitress}
ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is 
feign.FeignException: status 404 reading PythonEngineClient#getBranches(String,String)] with root cause
feign.FeignException: status 404 reading PythonEngineClient#getBranches(String,String)
at feign.FeignException.errorStatus(FeignException.java:78)

As we can see in the first log line, the Host is "localhost:5000". What I want to do is that call to "/git/**" are NOT redirected to python, but served by RestController.

How can I obtain that? Thanks!

1 Answers1

0

My final solution is that this is impossible: Sidecar can not work properly if one inserts a RestController, too.