Skip to content
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

Closed
AmsterdamFilho opened this issue Sep 8, 2021 · 2 comments · Fixed by #21807
Closed

Add a reactive ClientHeadersFactory flavor #20001

AmsterdamFilho opened this issue Sep 8, 2021 · 2 comments · Fixed by #21807
Assignees
Labels
Milestone

Comments

@AmsterdamFilho
Copy link

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.

@AmsterdamFilho AmsterdamFilho added the kind/enhancement New feature or request label Sep 8, 2021
@michalszynkiewicz michalszynkiewicz changed the title Make ClientHeadersFactory reactive Add a reactive ClientHeadersFactory flavor Sep 8, 2021
@michalszynkiewicz michalszynkiewicz self-assigned this Nov 15, 2021
@geoand
Copy link
Contributor

geoand commented Nov 26, 2021

@michalszynkiewicz is this something you are working on (or planning to work on soon) or is it something @Sgitario could look into?

@michalszynkiewicz
Copy link
Member

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
@quarkus-bot quarkus-bot bot added this to the 2.6 - main milestone Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants