从 http 入站网关提取 XML 有效负载并提供给 xslt 转换器 spring 集成

Extract XML payload from http inbound gateway and supply to xslt transformer spring integration

我有一个要求,其中我需要使用 XML 负载公开 restful 服务。之后,我需要掌握 xml 有效负载并使用 xslt 转换器将其转换为不同的 xml。

我正在努力如何获得可以作为 xslt 转换器输入的 xml 有效载荷。

我想避免编组和解组开销。

有人可以帮我解决这个问题吗?

问候 拉利特

在问这样的问题时,最好展示一下你尝试过的和没有成功的。

在这种情况下,您只需要 HTTP Inbound Gateway

如果传入content-type包含文本;默认情况下,有效负载将为 String。如果不是(例如 application/xml),那么您需要使用您想要的类型配置网关...

request-payload-type="java.lang.String"

否则,有效载荷将是 byte[]

根据 Gary 的建议...使用了以下代码并且有效...

<int:channel id="inputChannel"></int:channel>

<int-http:inbound-gateway request-channel="inputChannel" path="/test" supported-methods="POST">
    <int-http:request-mapping consumes="application/xml" produces="application/xml" />
</int-http:inbound-gateway>

<int:chain input-channel="inputChannel">
    <int:service-activator ref="sa1"></int:service-activator>
    <int-xml:xslt-transformer
        xsl-resource="classpath:/testTransformer.xsl"/>
    <int:service-activator ref="sa2"></int:service-activator>   
</int:chain>

<!-- input type is byte[] -->
<bean id="sa1" class="com.fidintl.integration.ServiceActivator1">
</bean>

<!-- input type is String -->
<bean id="sa2" class="com.fidintl.integration.ServiceActivator2"></bean>

看起来 post(正如 Gary 提到的)输出是 byte[],我在 ServiceActivator1

中将其转换为字符串

此致, 拉利特·库马尔