Hi Pablo, If you use the MicroProfile Rest Client 1.2 APIs and CXF 3.3, there are some new features that will make this scenario a little simpler.
First, you can now get the java.lang.reflect.Method of the client interface being invoked using a ClientRequestFilter - there is an example from the TCK here: https://github.com/eclipse/microprofile-rest-client/blob/ffdddfe345fe88f30b4bc58ffcb55896a6edc309/tck/src/main/java/org/eclipse/microprofile/rest/client/tck/providers/InvokedMethodRequestFilter.java#L34 Creating and/or propagating headers is also simplified. You can read more details here: https://download.eclipse.org/microprofile/microprofile-rest-client-1.2.1/microprofile-rest-client-1.2.1.html#_specifying_additional_client_headers The basic idea is that you can specify the headers as annotations (or create a ClientHeadersFactory implementation) - one thing you could try would be: @Path("/JNAP/") @Consumes({ "application/json" }) @Produces({ "application/json" }) @ClientHeaderParam(name="X-JNAP-Authorization" value="{computeAuthHeader}") // compute Auth header for all methods in interface public interface JNAPClient { default String computeAuthHeader() { return SomeUtil.getAuthorizationHeader(); } @POST @Path("") @ClientHeaderParam(name= "X-JNAP-Action", value="router/GetWANStatus3") public WanStatus3 getWanStatus3(); @POST @Path("") @ClientHeaderParam(name= "X-JNAP-Action", value="router/blah") @JNAPAuthorization public BlahResponse doBlah(); Hope this helps, Andy On Tue, Mar 5, 2019 at 5:59 AM James Carman <[email protected]> wrote: > Those may not work on the client side. If that’s the case, I’d scrap using > client proxies and I’d just use the JAX-RS client api directly, unless > you’re using this as a tinkering opportunity. > > On Tue, Mar 5, 2019 at 6:46 AM James Carman <[email protected]> > wrote: > > > Did you try using @HeaderParam and @DefaultValue? > > On Tue, Mar 5, 2019 at 1:40 AM Pablo Caballero <[email protected]> > wrote: > > > >> Hi folks! > >> > >> I'm writing a REST client to interact with a service exposed by my home > >> router (*1). > >> > >> The service consist of a set of operations exposed in a unique URI ( > >> https://xxx.xxx.xxx.xxx/JNAP/). The operation being called depends on > the > >> value of a special http header (X-JNAP-Action). Some operations require > >> authentication and some don't (authentication works as http basic auth > but > >> using a custom header called X-JNAP-Authorization). You can read about > >> this > >> API in https://github.com/reujab/linksys. > >> > >> My idea is to use two custom annotations to: > >> - map the interface method to the correlated X-JNAP-Action value > >> - mark operations that need authentication > >> > >> and use an/two interceptor/interceptors to implement the logic. > >> > >> Something like this: > >> > >> @Path("/JNAP/") > >> @Consumes({ "application/json" }) > >> @Produces({ "application/json" }) > >> public interface JNAPClient { > >> > >> @POST > >> @Path("") > >> @JNAPAction(value="router/GetWANStatus3") > >> @JNAPAuthorization > >> public WanStatus3 getWanStatus3(); > >> > >> @POST > >> @Path("") > >> @JNAPAction(value="router/blah") > >> @JNAPAuthorization > >> public BlahResponse doBlah(); > >> > >> and so on... > >> > >> I read about using > message.getExchange().get(OperationResourceInfo.class) > >> (*2) to get access to the target method inside an interceptor and I > wrote > >> a > >> bit of code to test it but I couldn't make it work (I get a null value > as > >> a > >> result of calling message.getExchange()... ). So, I decided to take a > >> deeper look at the Message parameter inspecting its value and I figured > >> out > >> that there was a OperationResourceInfo element in the MessageImpl's > >> "contents" member. At this point I'm wondering if it's ok to cast the > >> "message" parameter to MessageImpl and use the getContent method to > access > >> the ori's info or if should find another solution. > >> > >> Thank you very much! > >> > >> Best regards > >> > >> (*1) https://www.linksys.com/us/p/P-EA9300/ > >> (*2) > >> > >> > https://stackoverflow.com/questions/4219093/determine-target-service-method-from-cxf-interceptor > >> > > >
