Main Content

Magnolia Community Forums: Get help with Magnolia: Add headers using the REST client module


  • kyriakos-schwarz
    kyriakos-schwarz
    Full name: Kyriakos Schwarz
    Posts: 7
    Last post: Jan 6, 2017 4:32:10 PM
    Registered on: Feb 1, 2016
    Add headers using the REST client module
    #1 by kyriakos-schwarz on Jan 3, 2017 5:03:47 PM

    How do I add Headers to my Rest requests using the REST client module? https://documentation.magnolia-cms.com/display/DOCS/REST+client+module

  • cmeier
    cmeier
    Full name: Christoph Meier
    Posts: 193
    Last post: Mar 22, 2017 3:53:09 AM
    Re: Add headers using the REST client module
    #2 by cmeier on Jan 4, 2017 4:53:52 AM

    Hello Kyriakos

    I haven't tried out yet, but concerning the docu (which you have linked above) you can configure a list of "components". Such a component can be a ClientRequestFilter or ClientResponseFilter.

    Also check the resteasy-docu (https://goo.gl/Yu2LII) "Client Side Filters".

    kind regards,
    Christoph

  • kyriakos-schwarz
    kyriakos-schwarz
    Full name: Kyriakos Schwarz
    Posts: 7
    Last post: Jan 6, 2017 4:32:10 PM
    Registered on: Feb 1, 2016
    Re: Add headers using the REST client module
    #3 by kyriakos-schwarz on Jan 4, 2017 10:33:21 AM

    Hi Christoph

    Thank you for your quick reply!

    I have created this class:

    package ch.ff;

    public class AccessTokenClientRequestFilter implements javax.ws.rs.client.ClientRequestFilter {
    @Override public void filter(ClientRequestContext requestContext)
    throws IOException {
    String accessToken = "blahblah";
    requestContext.getHeaders().add("Authorization", "Bearer " + accessToken);
    }
    }


    but now I do not know how to configure this class.

    I am trying to create a new property below the "clientFactoryClass" property (see Example: REST client configuration, https://documentation.magnolia-cms.com/display/DOCS/REST+client+module#RESTclientmodule-Configuration) with
    Node name: components (since I am using version 1.1)
    value: ch.ff.AccessTokenClientRequestFilter (also tried [ch.ff.AccessTokenClientRequestFilter] and ["ch.ff.AccessTokenClientRequestFilter"])

    but I see that the Header is not included in my HTTP request.

    What value do I need to set?

    Thank you in advance.

  • cmeier
    cmeier
    Full name: Christoph Meier
    Posts: 193
    Last post: Mar 22, 2017 3:53:09 AM
    Re: Add headers using the REST client module
    #4 by cmeier on Jan 4, 2017 12:01:12 PM

    Kyriakos

    I have updated the configuration section on the docu page.
    This way the filter gets registered and is executed with each request.

    I hope it works ;-)

  • kyriakos-schwarz
    kyriakos-schwarz
    Full name: Kyriakos Schwarz
    Posts: 7
    Last post: Jan 6, 2017 4:32:10 PM
    Registered on: Feb 1, 2016
    Re: Add headers using the REST client module
    #5 by kyriakos-schwarz on Jan 4, 2017 1:43:58 PM

    Thank you very much, it works now!

    But I had to replace "components" with "clientFilters" in the configuration, even though I am using this dependency:
    <dependency>
    <groupId>info.magnolia.restclient</groupId>
    <artifactId>magnolia-rest-client-app</artifactId>
    <version>1.1</version>
    </dependency>

    "components" is supposed to work since version 1.0.8+ instead of "clientFilters" (which is deprecated), unless the 1.0.8+ is referring to some other dependency/library/etc...

  • cmeier
    cmeier
    Full name: Christoph Meier
    Posts: 193
    Last post: Mar 22, 2017 3:53:09 AM
    Re: Add headers using the REST client module
    #6 by cmeier on Jan 4, 2017 5:04:52 PM

    Kyriakos

    I'm glad to hear that it works now.

    I had to replace "components" with "clientFilters" in the configuration

    That's astonishing, i would expect both should work. However, thanks for reporting it, i will check it.

    cheers,
    chm

  • cmeier
    cmeier
    Full name: Christoph Meier
    Posts: 193
    Last post: Mar 22, 2017 3:53:09 AM
    Re: Add headers using the REST client module
    #7 by cmeier on Jan 5, 2017 4:06:30 AM

    Hi Kyriakos

    I was also trying out quickly some (dummy) ClientRequestFilter(s).
    I have registered one via "components" and one via "clientFilters" (which is deprecated).
    The result was (luckily) as expected: Both work fine.

    There is a little documentation project which now contains the 2 dummy filters.
    =>" target="_blank">https://git.magnolia-cms.com/projects/DOCUMENTATION/repos/rest-client-examples/browse]=> GIT, rest-client-examples
    It relies on rest-client-app 1.1

    I was adding the project to magnolia-community-webapp 5.5.

    So ... i would expect your filter should work with via "components" too.

    Happy filtering!
    cheers,
    Christoph

  • cmeier
    cmeier
    Full name: Christoph Meier
    Posts: 193
    Last post: Mar 22, 2017 3:53:09 AM
    Re: Add headers using the REST client module
    #8 by cmeier on Jan 5, 2017 4:07:40 AM

    grrr ... bad link above ... sorry :-)
    Next try:
    https://git.magnolia-cms.com/projects/DOCUMENTATION/repos/rest-client-examples/browse

  • kyriakos-schwarz
    kyriakos-schwarz
    Full name: Kyriakos Schwarz
    Posts: 7
    Last post: Jan 6, 2017 4:32:10 PM
    Registered on: Feb 1, 2016
    Re: Add headers using the REST client module
    #9 by kyriakos-schwarz on Jan 5, 2017 10:12:53 AM

    I forgot to mention that I am using:

    Edition: Enterprise Edition - Professional
    Version: 5.4.6

    Maybe that is only fixed in 5.5?

You don't have the permission to post on this thread

Sign in

To login on this forum, you can use your Magnolia Forge, Support or Partner account, or, below, your Google, Yahoo! or OpenID account. If you have trouble logging in, or any other sort of issue, please let us know in the Meta forum, on the user-list, or simply by email at forum-admin at magnolia-cms dot com.

* Required

... or sign in with:

  • icon http://{your-openid-url}
  • icon
  • icon https://me.yahoo.com/