1
我想調用POST方法,它需要標題和正文。如何評估網關中的「Header」和「Payload」?
RequestGateway.java
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;
import java.util.Map;
public interface RequestGateway {
// Using this throws error
// This complains saying no more than one Payload parameter
// String process(Map<String, String> request, String x, String s);
String process(@Payload Map<String, String> request, @Header("accountReferenceId") String x, @Header("profileReferenceId") String s);
}
的Java類
public void test(String accountReferenceId, String profileReferenceId) {
.....
.....
RequestGateway paymentRequestGateway = context.getBean("paymentRequestGateway", RequestGateway.class);
String paymentResponse = paymentRequestGateway.process(paymentRequestMap, accountReferenceId, profileReferenceId);
}
SIConfig.xml
<!--HEADER MAPPER-->
<bean id="headerMapper"
class="org.springframework.integration.http.support.DefaultHttpHeaderMapper">
<property name="inboundHeaderNames" value="*" />
<property name="outboundHeaderNames" value="HTTP_REQUEST_HEADERS, Api-Key, Accept, Content-Type" />
<property name="userDefinedHeaderPrefix" value="" />
</bean>
<int:gateway id="paymentRequestGateway"
service-interface="com.abc.api.payments.inboundpayments.api.RequestGateway"
default-request-channel="PaymentRequestChannel"
default-reply-channel="ResponseChannel">
<int:default-header name="Accept" value="application/json; v=5"/>
<int:default-header name="Content-Type" value="application/json; v=5"/>
<int:default-header name="accountReferenceId" expression="#args[1]"/>
<int:default-header name="profileReferenceId" value="test"/>
</int:gateway>
<int-http:outbound-gateway
id="Payment Outbound Gateway"
request-channel="PaymentRequestChannel"
reply-channel="ResponseChannel"
error-handler="errorHandler"
request-factory="sslFactory"
header-mapper="headerMapper"
url="https://localhost:9090/accounts/{accountReferenceId}/payments?profileReferenceId={profileReferenceId}"
http-method="POST"
expected-response-type="java.lang.String"
extract-request-payload="true">
<int-http:uri-variable name="accountReferenceId" expression="headers['accountReferenceId']" />
<int-http:uri-variable name="profileReferenceId" expression="headers['profileReferenceId']" />
</int-http:outbound-gateway>
在默認header expression =「#args [1]」沒有得到正確評估。當我直接把價值,如<int:default-header name="accountReferenceId" value="test"/>
,它工作正常。
我在做什麼這裏的表達錯誤?
它是如何評估呢?我剛剛在本地進行了測試,運行良好。即使使用類似的@Header(「accountReferenceId」)/'mix。請解釋你的目標:應該如何。你期望看到什麼? –
嗨Artem,如果我調用'test(abc,def);'默認頭文件中的url-expression應該被評估爲'https:// localhost:9090/accounts/abc/payments?profileReferenceId = def',doesn'當我給予直接價值時,它似乎正在發生這樣的事情。我不知道這是如何評估當前,也許我應該設置日誌級別進行調試? –
那麼,這看起來像一些混合。你不用'* two args *'顯示方法* ...對於'org.springframework.integration'配置DEBUG來查看'headers'的外觀是很好的。從另一方面來說,直接從你身邊調試SI代碼會更好。或者更好地提出一些簡單的測試案例來重現我們的方面。 –