Spring integration 在网关中设置标头值
下面是我目前为我们的web服务所做的配置。对于每个服务,我创建一个单独的网关和报头enricher,这样我就可以添加一个报头,告诉路由器要路由到哪个服务。为了简洁起见,我省略了一些配置。我也明白,这可以通过另一个流来完成-但是还有一些其他工作部分(如版本控制、弃用等),所以我需要以这种方式进行设置,并在流中稍后使用自定义路由器Spring integration 在网关中设置标头值,spring-integration,Spring Integration,下面是我目前为我们的web服务所做的配置。对于每个服务,我创建一个单独的网关和报头enricher,这样我就可以添加一个报头,告诉路由器要路由到哪个服务。为了简洁起见,我省略了一些配置。我也明白,这可以通过另一个流来完成-但是还有一些其他工作部分(如版本控制、弃用等),所以我需要以这种方式进行设置,并在流中稍后使用自定义路由器 <bean class="org.springframework.ws.server.endpoint.mapping.UriEndpointMap
<bean
class="org.springframework.ws.server.endpoint.mapping.UriEndpointMapping">
<property name="mappings">
<props>
<!-- TODO use config property for host -->
<prop key="${service.endpoint.url}/SNTWS/service/CompanyService">SOAPCompanyGateway</prop>
<prop key="${service.endpoint.url}/SNTWS/service/ContactService">SOAPContactGateway</prop>
</props>
</property>
</bean>
<!-- define gateways for each service endpoint -->
<int-ws:inbound-gateway id="SOAPCompanyGateway"
request-channel="SOAPCompanyRequestChannel" marshaller="SOAPMarshaller"
unmarshaller="SOAPMarshaller" />
<int-ws:inbound-gateway id="SOAPContactGateway"
request-channel="SOAPContactRequestChannel" marshaller="SOAPMarshaller"
unmarshaller="SOAPMarshaller" />
<bean id="SOAPMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPaths">
<list>
<!-- list all schema versions that we wish to accept -->
<value>com.predictivesolutions.schema.v1_1</value>
<value>com.predictivesolutions.schema.v2_0</value>
</list>
</property>
</bean>
<!-- these header enrichers add the service header and send all the messages
to the same output channel, add specific service headers in this section
before all messages are placed on a common channel. THe values of the header
must match the service-activator input-channel -->
<int:header-enricher input-channel="SOAPContactRequestChannel"
output-channel="SOAPRequestChannel">
<int:header name="service" value="ContactService" />
</int:header-enricher>
<int:header-enricher input-channel="SOAPCompanyRequestChannel"
output-channel="SOAPRequestChannel">
<int:header name="service" value="CompanyService" />
</int:header-enricher>
<!-- set another header with the package name, which is used to determine
version. THis is necessary (along with service header) to route messages
to the appropriate versioned service. This code is the same regardless of
service type. -->
<int:header-enricher input-channel="SOAPRequestChannel"
output-channel="SOAPRequestChannelWithHeaders">
<int:header name="version"
expression="payload.getClass().getPackage().getName().substring(payload.getClass().getPackage().getName().lastIndexOf('.')+1)" />
</int:header-enricher>
索普公司大道
SOAPContactGateway
com.predictivesolutions.schema.v1_1
com.predictivesolutions.schema.v2\u 0
我需要一个单独的网关和头enricher的原因是,我可以在消息上设置适当的服务头。所有消息都将放在SOAPRequestChannel上,在那里我可以获得版本
理想情况下,为了减少配置,我希望所有端点映射都有一个网关。我可以从URL设置标题,因为我知道最后一部分是服务名称
我正在寻找这样做的想法。我可以使用Spel访问URL路径吗 是的,您可以使用
URI
:
<int:header-enricher>
<int:header name="uri"
expression="T(org.springframework.ws.transport.context.TransportContextHolder).transportContext.connection.uri" />
</int:header-enricher>
这样,您就可以基于该uri
值进行路由,甚至可以分别摆脱这两个
和
值