O'Reilly logo

Hands-On Enterprise Java Microservices with Eclipse MicroProfile by Scott Stark, Antoine Sabot-Durand, Pavol Loffay, Jeff Mesnil, Heiko W. Rupp, Cesar Saavedra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dealing with client headers

Let's say you want to specify credentials in the HTTP authorization header to a secure remote service, but you do not want to have a string authHeader parameter in the client interface method. The MP-RC @ClientHeaderParam annotation can be used to specify HTTP headers that should be sent without altering the client interface method signature.

The following example illustrates two uses of the @ClientHeaderParam annotation to provide a User-Agent HTTP header in a variation of the WorldClockApi interface:

WorldClockApiWithHeaders.javapublic interface WorldClockApiWithHeaders { static final String BASE_URL = "http://worldclockapi.com/api/json"; default String lookupUserAgent() { Config config = ConfigProvider.getConfig(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required