简体   繁体   English

升级后,使用内部主机名而不是转发主机生成的Hateoas链接

[英]Hateoas links generated with internal hostname instead of forwarded host after upgrade

We recently upgraded to Spring 5.1.3 and Hateoas 0.25 and started facing problems with the generated links. 我们最近升级到了Spring 5.1.3和Hateoas 0.25,并开始面对所生成链接的问题。
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. 假设我们的域是xyz.com,并且所有通过负载平衡器到达任何子系统的请求都将转发到主系统,在该主系统中生成的hateoas链接具有与xyz.com域的链接。
However, after the upgrade, the hateoas links generated for such requests now have the internal hostname eg. 但是,升级后,为此类请求生成的仇恨链接现在具有内部主机名,例如。 host5678.internaldomain.com. 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 我在https://github.com/spring-projects/spring-hateoas/issues/753上遇到了为此问题记录的问题,该问题通过https://stackoverflow.com/a/53269319提供了一个临时解决方案,建议使用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. 看来FilterRegistrationBean是Spring Boot的一部分,我们不使用它,因此解决方案就不成问题了。
So I tried adding a new filter ForwardedHeaderFilter directly in the application web.xml. 因此,我尝试直接在应用程序web.xml中添加新的过滤器ForwardedHeaderFilter。 However, this creates problems with redirect URLs with HTTPS getting converted to HTTP. 但是,这会导致重定向URL和HTTPS转换为HTTP时出现问题。
The other solution mentioned was to upgrade to 0.25.1 and use Spring property server.use-forward-headers=true. 提到的另一个解决方案是升级到0.25.1并使用Spring属性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. 升级已经完成,但是由于我们使用Spring XML进行配置,所以找不到与此属性等效的XML。
Any help with this regards would be sincerely appreciated. 在这方面的任何帮助将由衷的感谢。

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. 问题中提到的问题已在Hateoas 0.25.1版中修复,因此解决方案的一部分是将Hateoas升级到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. 另一部分是从问题中给出的SO链接启发而来的,但是它并没有按原样工作,因为在我的情况下,这仅适用于Spring Boot。 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: 由于我们不使用Spring Boot,而是使用J2EE容器运行传统的Web应用程序,因此解决方案是将ForwardedHeaderFilter包含在Web应用程序的web.xml中,如下所示:

    <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM