我正在使用SimpleWebServiceInboundGateway,目前我有网关将请求放入一个通道然后从通道消耗流量 . 一切似乎都很好 .
我的问题是,如果你有多个不同的soap endpoints 服务,每个服务的运行方式略有不同,我如何将这些 endpoints 映射到不同的流程,这样做的正确方法是什么?是否期望每个soap Web服务 endpoints 都有一个新的SimpleWebServiceInboundGateway,并使用EndpointMapper映射到每个 endpoints ?或者有更好的做法吗?我不太确定是否预计会有多个Soap Gateways .
此外,任何简单的方法来访问用于在流中调用ws的URI / URL?我注意到它似乎没有出现在 Headers 中 .
这是我的示例配置:
/**
* URL mappings used by WS endpoints
*/
public static final String[] WS_URL_MAPPINGS = {"/services/*", "*.wsdl", "*.xsd"};
public static final String GATEWAY_INBOUND_CHANNEL_NAME = "wsGatewayInboundChannel";
public static final String GATEWAY_OUTBOUND_CHANNEL_NAME = "wsGatewayOutboundChannel";
/**
* Register the servlet mapper, note that it uses MessageDispatcher
*/
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
servlet.setTransformSchemaLocations(true);
servlet.setPublishEvents(true);
ServletRegistrationBean servletDef = new ServletRegistrationBean(servlet, WS_URL_MAPPINGS);
servletDef.setLoadOnStartup(1);
return servletDef;
}
/**
* Create a new Direct channels to handle the messages
*/
@Bean
public MessageChannel wsGatewayInboundChannel() {
return MessageChannels.direct(GATEWAY_INBOUND_CHANNEL_NAME).get();
}
@Bean
public MessageChannel wsGatewayOutboundChannel() {
return MessageChannels.direct(GATEWAY_OUTBOUND_CHANNEL_NAME).get();
}
/**
* Startup the WebServiceInboundGateway Endpoint, this will handle the incoming SOAP requests
* and place them onto the request channel
*/
@Bean
public SimpleWebServiceInboundGateway webServiceInboundGateway(
@Value("${spring.ws.should.track:true}") boolean shouldTrack
) {
SimpleWebServiceInboundGateway wsg = new SimpleWebServiceInboundGateway();
wsg.setRequestChannel(wsGatewayInboundChannel());
wsg.setReplyChannel(wsGatewayOutboundChannel());
wsg.setExtractPayload(false); // Send the full RAW SOAPMessage and not just payload
wsg.setLoggingEnabled(true);
wsg.setShouldTrack(shouldTrack);
wsg.setCountsEnabled(true);
return wsg;
}
/**
* Map the allowable service Uri's.
*
* although this isn't needed (can map everything using the mapping.setDefaultEndpoint)
* using this approach ensures that people don't use unexpected uris, probably can
* find a better way to deal with this in the future
*/
@Bean
public EndpointMapping uriEndpointMapping(@Qualifier("serviceUris") List<String> serviceUris
, PayloadValidatingInterceptor payloadValidatingInterceptor
, SimpleWebServiceInboundGateway webServiceInboundGateway) {
UriEndpointMapping mapping = new UriEndpointMapping();
mapping.setUsePath(true);
Map<String, Object> endpointMap = new HashMap<>();
endpointMap.put("/services/myservice1", webServiceInboundGateway);
mapping.setEndpointMap(endpointMap);
//mapping.setDefaultEndpoint(webServiceInboundGateway());
return mapping;
}
@Bean
public IntegrationFlow itemLookupFlow(ItemLookupRequestToItemDetailsRequestTransformer requestTransformer
, ItemDetailsResponseToItemLookupResponseTransformer responseTransformer) {
return IntegrationFlows.from("wsGatewayInboundChannel")
.transform(new MyTransformer())
.log(LoggingHandler.Level.INFO)
.handle(myBean, "execute")
.get();
}
1 回答
为什么每个人都将Spring Integration视为不良做法?想象您在应用程序中不使用Spring Integration而只使用Spring WS . 所以,现在你需要编写几个 endpoints . 你做什么?是的,用
@Endpoint
和/或适当的url映射开发几个类 . 在某种程度上,你不会说这是不好的做法,只是遵循框架要求 .所以,为什么你的意见明显不好的方式去?
我认为不同的 endpoints 实际上意味着完全不相关的逻辑,不同的转换,路由,最后是SOAP解组 .
因此,将新的
SimpleWebServiceInboundGateway
及其下游流程视为单独的Spring WS@Endpoint
类 .要获取URL,您应该注入自定义
SoapHeaderMapper
. 我认为SoapMessage
有一些钩子来提取这些信息 .