Hi everyone,
I would like to report two bugs in the JAX-RS frontend, hope this is the right 
place in absence of a Jira Account.
Reproducers for both bugs can be found at 
https://github.com/Sola-ris/cxf-reproducers

CXF version: 4.1.0
Java version: Temurin-21.0.6+7

# CXF's implementation of EntityPart.Builder does not seem to work in a Java SE 
environment.

Attempting to build the EntityPart in a Java SE environment like e.g. a JUnit 
test always fails with a NullPointerException

Steps to reproduce:

EntityPart.withName("greeting")
        .content("hello")
        .build();

Stacktrace:
java.lang.NullPointerException: Cannot invoke 
"org.apache.cxf.message.Message.getExchange()" because "m" is null
        at 
org.apache.cxf.jaxrs.provider.ServerProviderFactory.getInstance(ServerProviderFactory.java:124)
        at 
org.apache.cxf.jaxrs.impl.EntityPartBuilderImpl.build(EntityPartBuilderImpl.java:111)
        at 
org.example.EntityPartReproducerTest.testBuildEntityPart(EntityPartReproducerTest.java:15)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

# When using the Microprofile RestClient, ClientRequestContext#getConfiguration 
always returns null

This makes it impossible to access properties set on the RestClientBuilder 
inside ClientRequest/ResponseFilters.

Steps to reproduce:

@Path("")
public interface GreetingClient {
    @GET
    Response greet();
}

public static class Filter implements ClientRequestFilter {
    @Override
    public void filter(ClientRequestContext requestContext) {
        
System.out.println(requestContext.getConfiguration().getProperty("foo"));
    }
}

RestClientBuilder.newBuilder()
        .baseUri(URI.create("http://localhost:8080";))
        .property("foo", "bar")
        .register(Filter.class)
        .build(GreetingClient.class)
        .greet();

Stacktrace:
jakarta.ws.rs.ProcessingException: java.lang.NullPointerException: Cannot 
invoke "jakarta.ws.rs.core.Configuration.getProperty(String)" because the 
return value of "jakarta.ws.rs.client.ClientRequestContext.getConfiguration()" 
is null
        at 
org.apache.cxf.jaxrs.client.AbstractClient.checkClientException(AbstractClient.java:645)
        at 
org.apache.cxf.jaxrs.client.AbstractClient.preProcessResult(AbstractClient.java:619)
        at 
org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(ClientProxyImpl.java:926)
        at 
org.apache.cxf.jaxrs.client.ClientProxyImpl.invoke(ClientProxyImpl.java:347)
        at 
org.apache.cxf.microprofile.client.proxy.MicroProfileClientProxyImpl.invokeActual(MicroProfileClientProxyImpl.java:496)
        at 
org.apache.cxf.microprofile.client.proxy.MicroProfileClientProxyImpl$Invoker.call(MicroProfileClientProxyImpl.java:515)
        at 
org.apache.cxf.microprofile.client.cdi.CDIInterceptorWrapper$BasicCDIInterceptorWrapper.invoke(CDIInterceptorWrapper.java:43)
        at 
org.apache.cxf.microprofile.client.proxy.MicroProfileClientProxyImpl.invoke(MicroProfileClientProxyImpl.java:492)
        at jdk.proxy2/jdk.proxy2.$Proxy21.greet(Unknown Source)
        at 
org.example.MpRestClientConfigurationReproducerTest.testAccessConfigurationInFilter(MpRestClientConfigurationReproducerTest.java:24)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.NullPointerException: Cannot invoke 
"jakarta.ws.rs.core.Configuration.getProperty(String)" because the return value 
of "jakarta.ws.rs.client.ClientRequestContext.getConfiguration()" is null
        at 
org.example.MpRestClientConfigurationReproducerTest$Filter.filter(MpRestClientConfigurationReproducerTest.java:38)
        at 
org.apache.cxf.jaxrs.client.spec.ClientRequestFilterInterceptor.handleMessage(ClientRequestFilterInterceptor.java:70)
        at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
        at 
org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:717)
        at 
org.apache.cxf.microprofile.client.proxy.MicroProfileClientProxyImpl.doRunInterceptorChain(MicroProfileClientProxyImpl.java:184)
        at 
org.apache.cxf.jaxrs.client.ClientProxyImpl.doChainedInvocation(ClientProxyImpl.java:924)
        ... 10 more

Best regards,
Sola-ris

Reply via email to