2
votes

I am writing a feign client

@RequestMapping(
      path = "/TrackingServlet?CompanyName=Test&UserName=&BranchCode=",
      method = RequestMethod.GET,
      produces = MediaType.APPLICATION_JSON_VALUE
      )
  ResponseEntity<String> getInfo(
      @RequestParam("DocumentNumbers") String bill);

when it is invoked the url becomes /TrackingServlet?CompanyName=Test&UserName&BranchCode eliminating the = symbol, but the API needs it in that format, since its a third party API we cannot modify it.

Also tried

@RequestMapping(
      path = "/TrackingServlet?CompanyName=Test&UserName=",
      method = RequestMethod.GET,
      produces = MediaType.APPLICATION_JSON_VALUE
      )
  ResponseEntity<String> getInfo(
      @RequestParam("DocumentNumbers") String bill,
      @RequestParam(name = "BranchCode", required = true) String BranchCode);

  default ResponseEntity<String> getInfo(String bill) {
    return getInfo(bill, "");
  }

this will not even have the param BranchCode

I am using org.springframework.cloud:spring-cloud-starter-openfeign:2.1.1.RELEASE Spring boot version 2.1.4.RELEASE

is there anyway or workarounds for keeping empty params in urls as it is ?

1
What is the API you are trying to access and what parameter you want to send as a @RequestParam ? - I'm_Pratik
I want to hit /TrackingServlet?CompanyName=Test&UserName=&BranchCode=&DocumentNumbers=12345 - Jebil
I'd not put them in path but maybe try using a request interceptor or do as mentioned above and add them all as request parameters. - spencergibb
@spencergibb we tried adding in path and as request params, in both cases the = symbol is not there, even when we used newer versions. Now we are using spring request template, and it works fine with empty params in url, = symbol is not eliminated - Jebil
Sounds like a good plan to me - spencergibb

1 Answers

-1
votes

If your URL is http://localhost:8080/trackingServlet/testing?userName=pratik Use feign client:

@FeignClient(name = "tracking-servlet-service")
public interface TestFeignClient {

        @GetMapping("/trackingServlet/testing")
        public String getQueryParam(@RequestParam("userName") String name);

}

If you have 2 or more parameter then you can add same in @RequestParam

E.g URL http://localhost:8080/trackingServlet/testing?userName=pratik&companyName=Test

 @FeignClient(name = "tracking-servlet-service")
    public interface TestFeignClient {

            @GetMapping("/trackingServlet/testing")
            public String getQueryParam(@RequestParam("userName") String name, 
                                        @RequestParam("companyName") String companyName);

    }