1

We recently upgraded to Spring 5.1.3 and Hateoas 0.25 and started facing problems with the generated links.
Say our domain is xyz.com and all requests that come to any subsystem via the load-balancer are forwarded to the main system where the hateoas links generated had links with xyz.com domain.
However, after the upgrade, the hateoas links generated for such requests now have the internal hostname eg. host5678.internaldomain.com.
I came across an issue logged for this at: https://github.com/spring-projects/spring-hateoas/issues/753 where it provided an interim solution via https://stackoverflow.com/a/53269319 which recommends using FilterRegistrationBean
It appears that FilterRegistrationBean is available as part of Spring Boot which we don't use so that solution is out of the question.
So I tried adding a new filter ForwardedHeaderFilter directly in the application web.xml. However, this creates problems with redirect URLs with HTTPS getting converted to HTTP.
The other solution mentioned was to upgrade to 0.25.1 and use Spring property server.use-forward-headers=true. Upgrade is done but I couldn't find XML equivalent of this property as we are using Spring XML for configuration.
Any help with this regards would be sincerely appreciated.

Dhrupadh
  • 261
  • 3
  • 9

1 Answers1

1

Found the answer after going through the source and trying some different combinations.

The issues mentioned in the question have been fixed in the Hateoas release 0.25.1 so one part of the solution was to upgrade Hateoas to 0.25.1.

The other part is inspired from the SO link given in the question but it didn't work as is, in my case since that is applicable for Spring Boot only. Since we don't use Spring Boot but we have a traditional web application running with a J2EE container, the solution is to include the ForwardedHeaderFilter as part of the web application's web.xml as follows:

    <filter>
    <filter-name>forwardedHeaderFilter</filter-name>
    <filter-class>org.springframework.web.filter.ForwardedHeaderFilter</filter-class>
    <init-param>
        <param-name>relativeRedirects</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>forwardedHeaderFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
Dhrupadh
  • 261
  • 3
  • 9