Git Product home page Git Product logo

Comments (8)

graemerocher avatar graemerocher commented on June 24, 2024 1

Right but why can't your customer define in configuration:

micronaut.http.services.client1.url=http://localhost

Then filter:

@ClientFilter(serviceId="client1")
public class ClientInterceptor1 {

    
    @RequestFilter
    @ExecuteOn(TaskExecutors.BLOCKING)
    public void filterRequest(MutableHttpRequest<?> request) {
      // some logic    
    }
}

Then inject:

@Inject @Client("client1") HttpClient client;

from micronaut-core.

graemerocher avatar graemerocher commented on June 24, 2024

what you are trying to do is not supported. See https://docs.micronaut.io/4.4.10/guide/#clientFilter section "Filter Matching By Annotation" on how to achieve what you are trying to achieve

from micronaut-core.

BharathMC avatar BharathMC commented on June 24, 2024

Hi @graemerocher,

Thanks for the response.

I have went through the documentation already. Not supported meaning: client filters are applied to ALL outgoing requests invoked via HttpClient instance and there is no way to avoid that, is that right ?

Thanks

from micronaut-core.

graemerocher avatar graemerocher commented on June 24, 2024

you are creating the client yourself manually, so that is bypassing any filters we would usually inject

from micronaut-core.

BharathMC avatar BharathMC commented on June 24, 2024

We have Springboot based application microservices and it supports specific filter/interceptor association to RestTemplate (http client) bean.

Can I create a feature request for this to support in micronaut ?

from micronaut-core.

graemerocher avatar graemerocher commented on June 24, 2024

I am failing to see from your example why you need to explicitly create the client and why the section "Filter Matching By Annotation" on the documentation does not meet your requirement. Can you explain why?

from micronaut-core.

BharathMC avatar BharathMC commented on June 24, 2024

Reason why client filter @ClientFilter(Filter.MATCH_ALL_PATTERN) with pattern matching cannot be used:

We have created a micronaut library which will be used by micronaut application microservices. So, within library, we have created filters which does some business operations for every outgoing request.

Now, when the enduser application uses our library, they will have some outgoing requests other than the one which needs filter and some requets which does not need filters to be applied. Since micronaut applies filter for all the requests, our library filters will be applied for all of it. Which is not intended.

That's where the requirement of HttpClient with different interceptors/filters association requirement comes in. If micronaut supports associating the HttpClient with respective filter, we can ask enduser to use our HttpClient bean created in library and for other uses, use default HttpClient

Now, coming to pattern matching, as this is library, we cannot restrict with a URL pattern hardcoding in library.

If you think of any other way to achieve this is micronaut, please let me know.

Thanks.

from micronaut-core.

BharathMC avatar BharathMC commented on June 24, 2024

Hi @graemerocher,

I think the solution provided perfectly fits our requirement. Thank you on that!

Regards,
Bharath

from micronaut-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.