我需要在 Spring Integration 应用程序中通过 HTTP 请求请求 JWT 令牌。
我已经配置了一个普通的 http 出站网关,但服务器回复了 301 Moved Permanently;
它要求客户端遵循重定向(显然它以这种方式使用 SOAP-UI 进行一些测试);
我怎样才能使 http-outbound-gateway 跟随重定向?
尝试了我能找到的一切,但到目前为止没有任何效果。
谢谢!
我需要在 Spring Integration 应用程序中通过 HTTP 请求请求 JWT 令牌。
我已经配置了一个普通的 http 出站网关,但服务器回复了 301 Moved Permanently;
它要求客户端遵循重定向(显然它以这种方式使用 SOAP-UI 进行一些测试);
我怎样才能使 http-outbound-gateway 跟随重定向?
尝试了我能找到的一切,但到目前为止没有任何效果。
谢谢!
您需要考虑使用HttpComponentsClientHttpRequestFactory
. 这个是基于 Apache HTTP Client 4.x 的,它的默认行为是对方法和when或status进行DefaultRedirectStrategy
重定向。GET
HEAD
302
301
307
如果您需要重定向POST
,请考虑HttpClient
使用LaxRedirectStrategy
.
在此处查看更多信息:处理 HttpClient 重定向
更新
LaxRedirectStrategy
要为HttpClient
使用的配置一个HttpComponentsClientHttpRequestFactory
你需要这样的东西:
<beans:bean id="httpClientBuilder" class="org.apache.http.impl.client.HttpClients" factory-method="custom">
<beans:property name="redirectStrategy" value="#{new org.apache.http.impl.client.LaxRedirectStrategy()}"/>
</beans:bean>
<beans:bean id="clientHttpRequestFactory"
class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
<beans:constructor-arg>
<beans:bean factory-bean="httpClientBuilder" factory-method="build"/>
</beans:constructor-arg>
</beans:bean>
在 XML 中做所有这些事情有点麻烦,所以考虑将您的项目移动到 Java 和注释配置。