Uploaded image for project: 'Spring Data GemFire'
  1. Spring Data GemFire
  2. SGF-930

Provide a method to retrieve the WebClient baseUrl

    XMLWordPrintable

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None

    Description

      Feature improvement

      1) Provide a method to retrieve the WebClient base URL.

      2) Provide a method to retrieve the original request URL from the ClientResponse.


      Description

      After configuring multiple web client beans, for instance, as follows:

      @Bean("recievePaymentApi")
      @Description("Recieve Payment Microservice")
      public WebClient recievePaymentWebClient(@Value("${recieve-payment-api.url}") String url) {
          return WebClient.builder()
                  .baseUrl(url)
                  .build();
      }
      

       

      Ther is no way to retrieve the base URL, for instance in a scenario like this:

      void onErrorLog(ClientResponse response) {
         final var status = response.statusCode();
         if (status.equals(UNAUTHORIZED) || status.equals(FORBIDDEN) {
            log.warn(buildLogMessage(response));
         }
      }
      
      String buildLogMessage(ClientResponse response)  {
         switch(response.statusCode()) {
            case UNAUTHORIZED: return "Unauthorized access to " + getOriginalRequestUrl();
            case FORBIDDEN:    return "Forbidden access to " + getClientBaseUrl();
            case default:      return "";
         }
      }
      
      String getClientBaseUrl() {
         // MISSING METHOD 1
         return myWebClient.getBaseUrl();  // e.g. https://recieve.payment-api.mycompany.com
      }
      
      String getOriginalRequestUrl(ClientResponse response) {
         // MISSING METHOD 2
         return response.getRequestUrl(); // e.g. [POST] https://recieve.payment-api.mycompany.com/recieve-payment
      }
      
      

      These are available through: DefaultWebClient.uriBuilderFactory.baseUri.<...>
      and: DefaultClientResponse.requestDescription

      However, due to encapsulation, these values are not accessible.

      Attachments

        Activity

          People

            jblum John Blum
            hayk Hayk Avetisyan
            Hayk Avetisyan Hayk Avetisyan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: