3
votes

Describe the bug I'm using MP Rest Client to call another Rest Service from my service implementation and want to overwrite some header attributes by using @ClientsHeadersFactory, but when I using @Inject to use another CDI Beans then a NullpointerException is raised. With Micro Profile Rest Client 1.4 there is the possibility to use '@Inject' if your implementation is managed by CDI. This allows you to inject secrets for example or any other CDI bean to calculate a header value.

Expected behavior injected ConfigProperty is available and not null

Actual behavior NullpointerException is occur in update method of implementation of ClientHeadersFactory.

To Reproduce Steps to reproduce the behavior:

  1. Create a implementation class of ClientHeadersFactory and override update method
@ApplicationScoped
public class MyClientHeadersFactory implements ClientHeadersFactory {

  
    @Inject
    @ConfigProperty(name = "secrets.value")
    private String secretValue;

    @Override
    public MultivaluedMap<String, String> update(MultivaluedMap<String, String> incomingHeaders, MultivaluedMap<String, String> clientOutgoingHeaders) {

        System.out.println("--- Incoming headers of the JAX-RS environment");
        incomingHeaders.forEach((k, v) -> System.out.println(k + ":" + v));

        System.out.println("--- Specified outgoing headers of the Rest Client");
        clientOutgoingHeaders.forEach((k, v) -> System.out.println(k + ":" + v));

       
        MultivaluedMap<String, String> resultHeader = new MultivaluedHashMap();
        resultHeader.putAll(incomingHeaders);
        resultHeader.putAll(clientOutgoingHeaders);
        
        //here is the NullpointerException raised
        resultHeader.add("X-Secret-Header", secretValue);

        System.out.println("--- Header of the Rest Client after merging");
        resultHeader.forEach((k, v) -> System.out.println(k + ":" + v));

        return resultHeader;
    }

}

  1. Register your implemented ClientHeadersFactory in your Rest Client interface by using @RegisterClientHeaders()
@RegisterRestClient(configKey = "remote-restservice")
@RegisterClientHeaders(MyClientHeadersFactory.class)
public interface RemoteRestService
{

    @POST
    @Path("/doSomeStuff")
    @Consumes({ "application/json" })
    @Produces({ "application/json" })
    Response createStuff( @Valid Stuff stuff);
}

Configuration

# Add your application.properties here, if applicable.
remote-restservice/mp-rest/url=http://localhost:9090/service
secrets.value=test

Screenshots (If applicable, add screenshots to help explain your problem.)

Environment (please complete the following information):

  • Output of uname -a or ver:
  • Output of java -version:
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.5.2-FINAL
  • Build tool (ie. output of mvnw --version or gradlew --version):

Additional context (Add any other context about the problem here.)

1
did you fix it? - mroma95

1 Answers

0
votes

I had the same issue and it has been fixed in Quarkus 1.8.