3
votes

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.

1
That is strange. Have a project that reproduces the problem? - spencergibb
I agree its quite strange. I vaguely recall seeing this in the past, and I have a notion that it was a side effect of something else. The fact that the hostname/port aspect of the URL in the is wrong was also somewhat related. Unfortunately, it was long enough ago, and the code was not all that stable at that point, that I don't recall how it was resolved. I don't have code that I can publish anywhere, and I haven't had chance to try to reproduce with example code yet. I'm hoping someone else might be able to point me in the right direction. - Marc Zampetti
I just tried that method and it works for me using 1.1.0M5. Can you share your entire client class? - Newbie
Even more weird, I added additional methods to the interface for another set of endpoints, all using similar templates, and that all worked without incident. And even after that, the calls still fail. It appears that something about this particular endpoint is causing some sort of issue. Looks like I'm going to have to step through the processing to figure out why this is failing. - Marc Zampetti

1 Answers

6
votes

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.