3
votes

I'm using HATEOAS for my REST API which is behind https, but link stay in http.

"links": [
      {
        "rel": "self",
        "href": "http://..."
      },
      {
        "rel": "object",
        "href": "..."
      }
    ]

Is it possible to config HATEOAS to point on my https ?

2

2 Answers

4
votes

I resolved my problem by specifing the header as part of my virtual host configuration

<VirtualHost *:443>
    RequestHeader set X-Forwarded-Proto "https"
    ProxyPreserveHost On
    ServerName www.example.com

    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/server.crt
    SSLCertificateKeyFile /etc/apache2/ssl/server.key

    <Location/>
        SSLRequireSSL
    </Location>

    ProxyPass / http://127.0.0.1:9000/
    ProxyPassReverse / http://127.0.0.1:9000/
</VirtualHost>
2
votes

Here's one way, via ControllerLinkBuilder:

Link selfLink = new Link(ControllerLinkBuilder.linkTo(methodOn(Mycontroller.class).someMethod()).toUriComponentsBuilder().scheme("https").build().toUriString(), Link.REL_SELF);

That should produce a Link with the self rel and a URI of the following form: https://host:port/contextroot/pathtocontrollermethod