Как демаршалировать xml с помощью Spring интеграции dsl

Я работаю над весенней интеграцией dsl. Требование - прочитать XML-сообщение из очереди на основе значения заголовка сообщения, мне нужно вызвать другую службу. Мне удалось получить сообщение из очереди, но не смог написать код в dsl для демаршалинга XML-сообщения в объект. Может ли кто-нибудь помочь и у меня есть демаршаллер, но я не могу подключить его к dsl

 IntegrationFlows
            .from(Jms.inboundGateway(connectionFactory)
                    .destination(someQueue)
                    .configureListenerContainer(spec -> spec.get().setSessionTransacted(true)))
            .transform(??)

person nagendra    schedule 09.04.2018    source источник


Ответы (1)


Прежде всего, вы можете настроить Jms.inboundGateway() с помощью MarshallingMessageConverter:

/**
 * @param messageConverter the messageConverter.
 * @return the spec.
 * @see ChannelPublishingJmsMessageListener#setMessageConverter(MessageConverter)
 */
public S jmsMessageConverter(MessageConverter messageConverter) {
    this.target.getListener().setMessageConverter(messageConverter);
    return _this();
}

Но если вы по-прежнему настаиваете на .transform(), подумайте об использовании UnmarshallingTransformer:

/**
 * An implementation of {@link Transformer} that delegates to an OXM
 * {@link Unmarshaller}. Expects the payload to be of type {@link Document},
 * {@link String}, {@link File}, {@link Source} or to have an instance of
 * {@link SourceFactory} that can convert to a {@link Source}. If
 * {@link #alwaysUseSourceFactory} is set to true, then the {@link SourceFactory}
 * will be used to create the {@link Source} regardless of payload type.
 * <p>
 * The {@link #alwaysUseSourceFactory} is ignored if payload is
 * {@link org.springframework.ws.mime.MimeMessage}.
 * <p>
 * The Unmarshaller may return a Message, but if the return value is not
 * already a Message instance, a new Message will be created with that
 * return value as its payload.
 *
 * @author Jonas Partner
 * @author Artem Bilan
 */
public class UnmarshallingTransformer extends AbstractPayloadTransformer<Object, Object> {

https://docs.spring.io/spring-integration/docs/5.0.4.RELEASE/reference/html/xml.html#xml-unmarshalling-transformer

person Artem Bilan    schedule 09.04.2018
comment
Спасибо. Я внес следующие изменения, чтобы он заработал. Это правильный путь .from(Jms.inboundGateway(connectionFactory) .destination(sourceQueue) .jmsMessageConverter(new MarshallingMessageConverter(jaxbMarshaller())) .configureListenerContainer(spec -> spec.get().setSessionTransacted(true))) @Bean public org.springframework.oxm.Marshaller jaxbMarshaller() { Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller(); .... return jaxb2Marshaller; } - person nagendra; 10.04.2018