Как получить пользовательские значения заголовков в Spring Integration Gateway?

Это мой первый вопрос.

Мое веб-приложение использует весеннюю интеграцию для получения ответа сторонних API.

В ответе значения настраиваемого заголовка начинаются с «X-». X-значений два. (X-AccessToken-Quota-Allotted, X-AccessToken-Quota-Current)

Итак, я добавил inboundHeaderNames в header-mapper в config xml, как показано ниже.

    <int-http:outbound-gateway id="dms.put.outbound.gateway.cert"
        header-mapper="dmsHeaderMapper"
       ...
</int-http:outbound-gateway>

<bean id="dmsHeaderMapper" class="org.springframework.integration.http.support.DefaultHttpHeaderMapper" factory-method="outboundMapper" >
    <property name="outboundHeaderNames" value="X-Request-Id...blabla"/>
    <property name="inboundHeaderNames" value="X-AccessToken-Quota-Allotted, X-AccessToken-Quota-Current"/>
    <property name="userDefinedHeaderPrefix" value=""/>
</bean>

Ниже ответ. Я вижу атрибуты заголовков X-AccessToken-Quota-Allotted и X-AccessToken-Quota-Current.

[интеграция] GenericMessage [payload = {type: commonResponse, serverName: uslxacd20022use1c.intranet.local, errorMessage: null}, headers={errorChannel=org.springframework.messaging.core.GenericMessagingTemplateTemplateTemternalReply208-RequestTemplateTemternalReply208-Request_$8. 0ce88cd6-d04b-47dc-b3db-224656fe9090, uri = https: //api-server.com/blabla, http_statusCode = 200, X-AccessToken-Quota-Allotted = 5000, jsonObjectName = DmsCommonResponseDto, Авторизация = Bearer qqdtbhtp5vk2ss69wjpbdfvh, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@41208186, json__TypeId __ = class com.blablad6.DecTypeId __ = class com.blablad6.DecTypeId __ = class com.blablad6.doc Current = 3, id = 12072f4b-8403-a328-6a77-aaba935beba2, contentType = application / json, Content-Type = application / json; charset = UTF-8, timestamp = 1592791409206}]

Почти каждое значение поля сопоставляется с полями responseDto, но я не знаю, как сопоставить значения заголовка X-custom с полем responseDto.

Ниже приведены текущие настройки.

<int:gateway id="dmsHttpPUTGateway" service-interface="blabla.gateway.DmsHttpPUTGateway" 
        default-request-channel="dms.put.ch.request.header.router"><int:method name="call" /></int:gateway>

<int:header-value-router input-channel="dms.put.ch.reply.header.router" header-name="jsonObjectName">
    <int:mapping value="DmsCommonResponseDto" channel="dms.put.ch.reply.transformer.DmsCommonResponseDto"/>
</int:header-value-router>

<int:channel id="dms.put.ch.reply.transformer.DmsCommonResponseDto"></int:channel>

<int:json-to-object-transformer input-channel="dms.put.ch.reply.transformer.DmsCommonResponseDto" output-channel="dms.put.ch.reply" type="blabla.DmsCommonResponseDto"></int:json-to-object-transformer>

    DmsCommonResponseDto.java 
private static final long serialVersionUID = 1L;

private String serverName;
private DmsErrorMessageDto errorMessage;
private Date responseDate;

...setter, getter method.

Любая даже небольшая подсказка тоже будет полезна. Заранее спасибо.


person fat-takumi    schedule 22.06.2020    source источник


Ответы (1)


Похоже, вам нужен специальный трансформатор после трансформатора json.

class MyTransformer extends AbstractTransformer {

    protected abstract Object doTransform(Message<?> message) {
        DmsCommonResponseDto dto = (DmsCommonResponseDto) message.getPayload();
        dto.setRequestId(message.getHeaders.get("X-request-id"));
        ...
        return dto.
    }    

}
person Gary Russell    schedule 22.06.2020