Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Cloud Feign not processing @RequestMapping UriTemplate

I have an existing Spring Cloud Feign client interface that has many mappings for my server-side API. I'm adding some new methods, and I'm suddenly running into an error. I'm trying to add a method of the form:

@RequestMapping(value = "/tasks/{id}", method = GET)
public Resource<Task> getTask(@PathVariable("id")Long id);

Everything compiles fine, but when I try to make a call to the getTask() method above, I always get a an IllegalArgumentException complaining about the URL not being valid. Which is true, because the URL still contains the UriTemplate {id}.

The full stack is:

java.lang.IllegalArgumentException: Illegal character in path at index 29: http://connect/connect/tasks/{id}
    at java.net.URI$Parser.fail(URI.java:2848)
    at java.net.URI$Parser.checkChars(URI.java:3021)
    at java.net.URI$Parser.parseHierarchical(URI.java:3105)
    at java.net.URI$Parser.parse(URI.java:3053)
    at java.net.URI.<init>(URI.java:588)
    at java.net.URI.create(URI.java:850)
    at feign.ribbon.RibbonClient.execute(RibbonClient.java:64)
    at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:92)
    at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:71)
    at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:94)
    at com.sun.proxy.$Proxy55.getTask(Unknown Source)

There are dozens of other methods in the same interface that use this exact same pattern, and everything runs fine. I cannot for the life of me figure out why Feign/Spring is suddenly having an issue with this method. I've tried every possible combination of settings and ways to write the method. If I simply remove the {id}, the call will go through, but obviously returns the wrong data, since its missing the id portion of the URI.

I'm using Spring Cloud Angel.SR6 with Spring Boot 1.2.8 and Feign 8.5.0.

like image 210
Marc Zampetti Avatar asked Sep 13 '26 06:09

Marc Zampetti


1 Answers

I resolve my issue. It turns out the error message was quite misleading. I turns out the method was being passed in a Null value, so there was nothing for the URI template to replace. Since its an interface, I cannot add logic to assert the Not Null requirement, at least as far as I know right now.

Once I figured that out and resolved it upstream of the call, the IllegalArgumentException was eliminated. Notice that no where is the fact that the input was NULL noted in the stack trace in my original note.

like image 86
Marc Zampetti Avatar answered Sep 16 '26 19:09

Marc Zampetti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!