-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a reactive ClientHeadersFactory flavor #20001
Comments
michalszynkiewicz
changed the title
Make ClientHeadersFactory reactive
Add a reactive ClientHeadersFactory flavor
Sep 8, 2021
@michalszynkiewicz is this something you are working on (or planning to work on soon) or is it something @Sgitario could look into? |
I'd be really happy if @Sgitario could take this one :) |
Sgitario
added a commit
to Sgitario/quarkus
that referenced
this issue
Nov 30, 2021
Added reactive flavor of `ClientHeadersFactory` that allows doing blocking operations. For example: [source, java] ---- package org.acme.rest.client; import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory; import javax.enterprise.context.ApplicationScoped; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; import java.util.UUID; @ApplicationScoped public class GetTokenReactiveClientHeadersFactory extends ReactiveClientHeadersFactory { @Inject Service service; @OverRide public Uni<MultivaluedMap<String, String>> getHeaders(MultivaluedMap<String, String> incomingHeaders) { return Uni.createFrom().item(() -> { MultivaluedHashMap<String, String> newHeaders = new MultivaluedHashMap<>(); // perform blocking call newHeaders.add(HEADER_NAME, service.getToken()); return newHeaders; }); } } ---- Fixes quarkusio#20001
Sgitario
added a commit
to Sgitario/quarkus
that referenced
this issue
Nov 30, 2021
Added reactive flavor of `ClientHeadersFactory` that allows doing blocking operations. For example: [source, java] ---- package org.acme.rest.client; import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory; import javax.enterprise.context.ApplicationScoped; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; import java.util.UUID; @ApplicationScoped public class GetTokenReactiveClientHeadersFactory extends ReactiveClientHeadersFactory { @Inject Service service; @OverRide public Uni<MultivaluedMap<String, String>> getHeaders(MultivaluedMap<String, String> incomingHeaders) { return Uni.createFrom().item(() -> { MultivaluedHashMap<String, String> newHeaders = new MultivaluedHashMap<>(); // perform blocking call newHeaders.add(HEADER_NAME, service.getToken()); return newHeaders; }); } } ---- Fixes quarkusio#20001
Sgitario
added a commit
to Sgitario/quarkus
that referenced
this issue
Nov 30, 2021
Added reactive flavor of `ClientHeadersFactory` that allows doing blocking operations. For example: [source, java] ---- package org.acme.rest.client; import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory; import javax.enterprise.context.ApplicationScoped; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; import java.util.UUID; @ApplicationScoped public class GetTokenReactiveClientHeadersFactory extends ReactiveClientHeadersFactory { @Inject Service service; @OverRide public Uni<MultivaluedMap<String, String>> getHeaders(MultivaluedMap<String, String> incomingHeaders) { return Uni.createFrom().item(() -> { MultivaluedHashMap<String, String> newHeaders = new MultivaluedHashMap<>(); // perform blocking call newHeaders.add(HEADER_NAME, service.getToken()); return newHeaders; }); } } ---- Fixes quarkusio#20001
Sgitario
added a commit
to Sgitario/quarkus
that referenced
this issue
Nov 30, 2021
Added reactive flavor of `ClientHeadersFactory` that allows doing blocking operations. For example: [source, java] ---- package org.acme.rest.client; import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory; import javax.enterprise.context.ApplicationScoped; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; import java.util.UUID; @ApplicationScoped public class GetTokenReactiveClientHeadersFactory extends ReactiveClientHeadersFactory { @Inject Service service; @OverRide public Uni<MultivaluedMap<String, String>> getHeaders(MultivaluedMap<String, String> incomingHeaders) { return Uni.createFrom().item(() -> { MultivaluedHashMap<String, String> newHeaders = new MultivaluedHashMap<>(); // perform blocking call newHeaders.add(HEADER_NAME, service.getToken()); return newHeaders; }); } } ---- Fixes quarkusio#20001
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Currently, org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory is used to intercept calls and add entries in the client request header.
A very common scenario is to integrate with an api that is secured by a token, that is generated by calling a specific endpoint. The current approach does not support this scenario, because it expects a sync response.
We need to support this use case.
Implementation ideas
A good way to implement this would be to create something similar to org.jboss.resteasy.reactive.server.ServerRequestFilter.
That is an annotation that supports many kinds of responses. We could create a ClientRequestFilter annotation that would support the client request context in the method parameters and allow returning a Uni, so the request could be updated in an async way.
The text was updated successfully, but these errors were encountered: