Spring-cloud-netflix: Support multiple urls in @RequestMapping on FeingClient

Created on 31 Mar 2017  路  7Comments  路  Source: spring-cloud/spring-cloud-netflix

I am using Feign for requesting a MicroService route, but some params of the path variable are optional, i'm trying to define, multiple values for path value to handle with optional parameters, but when I do this I get an exception described below, i think this is a great and helpful feature when interfaces have optional parameters in path.

Spring Cloud Version: org.springframework.cloud:spring-cloud-dependencies:Brixton.SR6

Exception Recived with Mutiple paths:

Caused by: java.lang.IllegalStateException: Method createDocument can only contain at most 1 value field. Found: [/fields/{fieldName}/documents/create, grids/{gridIdentifier}/fields/{fieldName}/documents/create]

Feign client method definition:

@RequestMapping(
    method = POST,
    path = { "/fields/{fieldName}/documents/create", "grids/{gridIdentifier}/fields/{fieldName}/documents/create"},
    produces = APPLICATION_JSON_UTF8_VALUE,
    consumes = APPLICATION_JSON_UTF8_VALUE
  )
  ResponseEntity<ResourceContent<Document>> createDocument(
    @PathVariable("fieldName") String fieldName,
    @PathVariable(value = "gridIdentifier", required = false) String gridIdentifier,
    @RequestBody CreateDocument createDocument
  );
wontfix

Most helpful comment

Why you discourage sharing interfaces between server and client?

All 7 comments

Feign is a client. It can only use one path. We discourage sharing interfaces between server and client. What would be the use for having two values for path?

Because in server this route have an optional param gridIdentifier, and the rest of its parameters are the same.

Again:

We discourage sharing interfaces between server and client.

Which one would the client choose?

In case the optional parameter was sent, the path that makes use of it would be chosen, which is defined in @PathVariable, in the example above that I placed if the gridIdentfier parameter was sent the route that makes use of it would be chosen.

In the case of this example the chosen route would be: grids/{gridIdentifier}/fields/{fieldName}/documents/create

Today I have to create one more method in the feign client declaration for each optional parameter I have set on the server.

There could be multiple urls with gridIdentfier in them, which to choose? This is a client, not a server. You need to make two separate methods in your feign interface.

Why you discourage sharing interfaces between server and client?

There could be multiple urls with gridIdentfier in them, which to choose? This is a client, not a server. You need to make two separate methods in your feign interface.

I do not get your point, I think this is a really wise idea to map and use same controller / client for multiple URLs like if a resource mapped to multiple owners (yes I know many people thinks that bad design, but nobody had a good reason).
Oh and the client can chose pretty easy which URL to call, based on the provided path parameters.... those has names and all have to have unique name... so call the URL where the path parameters count and the names are same then in the URL

Was this page helpful?
0 / 5 - 0 ratings