spring-integration DSL - 这种行为似乎不对吗?

时间:2016-05-25 18:24:56

标签: java spring spring-integration dsl

当我运行下面的Spring集成DSL代码时,我看到意外的行为,其中'flow2'显示两个IntegrationFlow路径。容易复制。运行下面的代码,只需使用一个简单的curl命令来演示两个入口点。

$ curl localhost:8080 / foo

路径:httpGate() - > requestChannel() - >流()

意外'flow2'打印到stdout

$ curl localhost:8080 / bar

路径:httpGate2() - > requestChannel2() - >流2()

如预期的那样,'flow2'将打印到stdout。

通过查看下面的preSend和postSend的SI调试输出来确认。

Looking up handler method for path /foo
preSend on channel 'requestChannel'
preSend on channel 'flow.channel#0
preSend on channel 'flow2.channel#1       !!!! 'flow2' unexpected  !!!

Looking up handler method for path /bar 
preSend on channel'requestChannel2'
preSend on channel 'flow2.channel#0'
preSend on channel 'flow2.channel#1

我缺少什么或不理解?      :: Spring Boot ::(v1.3.5.RELEASE)

2016-05-25 10:52:58.840  INFO 2478 --- [           main] com.example.SpringIntegrationIssue       : Starting SpringIntegrationIssue on dfwloxmm64dfd57.local with PID 2478 (/Users/grk/dev/git/si-dsl-issue/build/classes/main started by grk in /Users/grk/dev/git/si-dsl-issue)
2016-05-25 10:52:58.842  INFO 2478 --- [           main] com.example.SpringIntegrationIssue       : No active profile set, falling back to default profiles: default
2016-05-25 10:52:58.995  INFO 2478 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@525b461a: startup date [Wed May 25 10:52:58 PDT 2016]; root of context hierarchy
2016-05-25 10:52:59.694  INFO 2478 --- [           main] o.s.b.f.config.PropertiesFactoryBean     : Loading properties file from URL [jar:file:/Users/grk/.gradle/caches/modules-2/files-2.1/org.springframework.integration/spring-integration-core/4.2.5.RELEASE/2e9624d73abb5a8acee3e71b3bb637bc913b37b8/spring-integration-core-4.2.5.RELEASE.jar!/META-INF/spring.integration.default.properties]
2016-05-25 10:52:59.696  INFO 2478 --- [           main] o.s.i.config.IntegrationRegistrar        : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2016-05-25 10:52:59.697 DEBUG 2478 --- [           main] o.s.i.config.IntegrationRegistrar        : The '#jsonPath' SpEL function cannot be registered: there is no jayway json-path.jar on the classpath.
2016-05-25 10:52:59.697 DEBUG 2478 --- [           main] o.s.i.config.IntegrationRegistrar        : SpEL function '#xpath' isn't registered: there is no spring-integration-xml.jar on the classpath.
2016-05-25 10:52:59.836  INFO 2478 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2016-05-25 10:52:59.838  INFO 2478 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
2016-05-25 10:53:00.236  INFO 2478 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-05-25 10:53:00.246  INFO 2478 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-05-25 10:53:00.247  INFO 2478 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.0.33
2016-05-25 10:53:00.321  INFO 2478 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2016-05-25 10:53:00.321  INFO 2478 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1334 ms
2016-05-25 10:53:00.510  INFO 2478 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2016-05-25 10:53:00.513  INFO 2478 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-05-25 10:53:00.514  INFO 2478 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-05-25 10:53:00.514  INFO 2478 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-05-25 10:53:00.514  INFO 2478 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'requestContextFilter' to: [/*]
2016-05-25 10:53:00.573 DEBUG 2478 --- [           main] .h.i.HttpRequestHandlingMessagingGateway : 'Jaxb2RootElementHttpMessageConverter' was added to the 'defaultMessageConverters'.
2016-05-25 10:53:00.575 DEBUG 2478 --- [           main] .h.i.HttpRequestHandlingMessagingGateway : 'MappingJackson2HttpMessageConverter' was added to the 'defaultMessageConverters'.
2016-05-25 10:53:00.589  INFO 2478 --- [           main] o.s.b.f.config.PropertiesFactoryBean     : Loading properties file from URL [jar:file:/Users/grk/.gradle/caches/modules-2/files-2.1/org.springframework.integration/spring-integration-core/4.2.5.RELEASE/2e9624d73abb5a8acee3e71b3bb637bc913b37b8/spring-integration-core-4.2.5.RELEASE.jar!/META-INF/spring.integration.default.properties]
2016-05-25 10:53:00.606 DEBUG 2478 --- [           main] .h.i.HttpRequestHandlingMessagingGateway : Using MultipartResolver [org.springframework.web.multipart.support.StandardServletMultipartResolver@48f5bde6]
2016-05-25 10:53:00.606  WARN 2478 --- [           main] .h.i.HttpRequestHandlingMessagingGateway : The 'requestPayloadType' attribute will have no relevance for one of the specified HTTP methods '[GET, HEAD, OPTIONS]'
2016-05-25 10:53:00.609 DEBUG 2478 --- [           main] .h.i.HttpRequestHandlingMessagingGateway : 'Jaxb2RootElementHttpMessageConverter' was added to the 'defaultMessageConverters'.
2016-05-25 10:53:00.610 DEBUG 2478 --- [           main] .h.i.HttpRequestHandlingMessagingGateway : 'MappingJackson2HttpMessageConverter' was added to the 'defaultMessageConverters'.
2016-05-25 10:53:00.611 DEBUG 2478 --- [           main] .h.i.HttpRequestHandlingMessagingGateway : Using MultipartResolver [org.springframework.web.multipart.support.StandardServletMultipartResolver@48f5bde6]
2016-05-25 10:53:00.612  WARN 2478 --- [           main] .h.i.HttpRequestHandlingMessagingGateway : The 'requestPayloadType' attribute will have no relevance for one of the specified HTTP methods '[GET, HEAD, OPTIONS]'
2016-05-25 10:53:01.037  INFO 2478 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@525b461a: startup date [Wed May 25 10:52:58 PDT 2016]; root of context hierarchy
2016-05-25 10:53:01.084  INFO 2478 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-05-25 10:53:01.085  INFO 2478 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-05-25 10:53:01.103  INFO 2478 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-05-25 10:53:01.103  INFO 2478 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-05-25 10:53:01.127  INFO 2478 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-05-25 10:53:01.196  INFO 2478 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService  'taskScheduler'
2016-05-25 10:53:01.262  INFO 2478 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-05-25 10:53:01.266 DEBUG 2478 --- [           main] .s.i.c.GlobalChannelInterceptorProcessor : No global channel interceptors.
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2016-05-25 10:53:01.269  INFO 2478 --- [           main] .h.i.HttpRequestHandlingMessagingGateway : started httpGate2
2016-05-25 10:53:01.269  INFO 2478 --- [           main] .h.i.HttpRequestHandlingMessagingGateway : started httpGate
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.i.channel.PublishSubscribeChannel    : Channel 'application.errorChannel' has 1 subscriber(s).
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started _org.springframework.integration.errorLogger
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {object-to-string-transformer} as a subscriber to the 'requestChannel' channel
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.integration.channel.DirectChannel    : Channel 'application.requestChannel' has 1 subscriber(s).
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started org.springframework.integration.config.ConsumerEndpointFactoryBean#0
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {http:outbound-gateway} as a subscriber to the 'flow.channel#0' channel
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.integration.channel.DirectChannel    : Channel 'application.flow.channel#0' has 1 subscriber(s).
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started org.springframework.integration.config.ConsumerEndpointFactoryBean#1
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.integration.channel.DirectChannel    : Channel 'application.flow.channel#1' has 1 subscriber(s).
2016-05-25 10:53:01.269  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started org.springframework.integration.config.ConsumerEndpointFactoryBean#2
2016-05-25 10:53:01.270  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {object-to-string-transformer} as a subscriber to the 'requestChannel2' channel
2016-05-25 10:53:01.270  INFO 2478 --- [           main] o.s.integration.channel.DirectChannel    : Channel 'application.requestChannel2' has 1 subscriber(s).
2016-05-25 10:53:01.270  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started org.springframework.integration.config.ConsumerEndpointFactoryBean#3
2016-05-25 10:53:01.270  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {http:outbound-gateway} as a subscriber to the 'flow2.channel#0' channel
2016-05-25 10:53:01.270  INFO 2478 --- [           main] o.s.integration.channel.DirectChannel    : Channel 'application.flow2.channel#0' has 1 subscriber(s).
2016-05-25 10:53:01.270  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started org.springframework.integration.config.ConsumerEndpointFactoryBean#4
2016-05-25 10:53:01.270  INFO 2478 --- [           main] o.s.integration.channel.DirectChannel    : Channel 'application.flow2.channel#1' has 1 subscriber(s).
2016-05-25 10:53:01.270  INFO 2478 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started org.springframework.integration.config.ConsumerEndpointFactoryBean#5
2016-05-25 10:53:01.271 DEBUG 2478 --- [           main] .IntegrationRequestMappingHandlerMapping : Looking for request mappings in application context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@525b461a: startup date [Wed May 25 10:52:58 PDT 2016]; root of context hierarchy
2016-05-25 10:53:01.272  INFO 2478 --- [           main] .IntegrationRequestMappingHandlerMapping : Mapped "{[/bar],methods=[GET]}" onto public abstract void org.springframework.web.HttpRequestHandler.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException
2016-05-25 10:53:01.272  INFO 2478 --- [           main] .IntegrationRequestMappingHandlerMapping : Mapped "{[/foo],methods=[GET]}" onto public abstract void org.springframework.web.HttpRequestHandler.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException
2016-05-25 10:53:01.333  INFO 2478 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-05-25 10:53:01.336  INFO 2478 --- [           main] com.example.SpringIntegrationIssue       : Started SpringIntegrationIssue in 2.791 seconds (JVM running for 3.168)
2016-05-25 10:53:04.322  INFO 2478 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-05-25 10:53:04.322  INFO 2478 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2016-05-25 10:53:04.332  INFO 2478 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 10 ms
2016-05-25 10:53:04.346 DEBUG 2478 --- [nio-8080-exec-1] .IntegrationRequestMappingHandlerMapping : Looking up handler method for path /bar
2016-05-25 10:53:04.347 DEBUG 2478 --- [nio-8080-exec-1] .IntegrationRequestMappingHandlerMapping : Returning handler method [public abstract void org.springframework.web.HttpRequestHandler.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException]
2016-05-25 10:53:04.356 DEBUG 2478 --- [nio-8080-exec-1] o.s.integration.channel.DirectChannel    : preSend on channel 'requestChannel2', message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, host=localhost:8080, http_requestUrl=http://localhost:8080/bar, id=ce44ad18-4202-a6a6-0870-fc38b87dc8af, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198784356}]
2016-05-25 10:53:04.356 DEBUG 2478 --- [nio-8080-exec-1] o.s.i.t.MessageTransformingHandler       : org.springframework.integration.transformer.MessageTransformingHandler#1 received message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, host=localhost:8080, http_requestUrl=http://localhost:8080/bar, id=ce44ad18-4202-a6a6-0870-fc38b87dc8af, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198784356}]
2016-05-25 10:53:04.356 DEBUG 2478 --- [nio-8080-exec-1] o.s.integration.channel.DirectChannel    : preSend on channel 'flow2.channel#0', message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, host=localhost:8080, http_requestUrl=http://localhost:8080/bar, id=e6fc73c1-7872-0c79-bf04-8b8f9c06350d, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198784356}]
2016-05-25 10:53:04.357 DEBUG 2478 --- [nio-8080-exec-1] i.h.o.HttpRequestExecutingMessageHandler : consumerPostbackGate received message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, host=localhost:8080, http_requestUrl=http://localhost:8080/bar, id=e6fc73c1-7872-0c79-bf04-8b8f9c06350d, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198784356}]
2016-05-25 10:53:04.461 DEBUG 2478 --- [nio-8080-exec-1] o.s.integration.channel.DirectChannel    : preSend on channel 'flow2.channel#1', message: GenericMessage [payload=<200 OK,{Date=[Wed, 25 May 2016 17:53:04 GMT], Expires=[-1], Cache-Control=[private, max-age=0], Content-Type=[text/html; charset=ISO-8859-1], P3P=[CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."], Content-Encoding=[gzip], Server=[gws], Content-Length=[4452], X-XSS-Protection=[1; mode=block], X-Frame-Options=[SAMEORIGIN], Set-Cookie=[NID=79=TunItaDTDDyn5gEJxdcCFjC_KmtrIT-VlJ_woRkWuVYNpuKC49nbBQhjE_mwzDfiQvPttiUYTuOg2qBtlAc0PtSu_Qjg8-91ETGwUzoFxq34Bs1e7A7KcXz7WLnl_9GjY1xBl8gJDcdrJQ; expires=Thu, 24-Nov-2016 17:53:04 GMT; path=/; domain=.google.com; HttpOnly]}>, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, host=localhost:8080, http_requestUrl=http://localhost:8080/bar, id=e980cc2c-4617-6231-fd69-c0f798483312, http_statusCode=200, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198784461}]
flow2
2016-05-25 10:53:04.461 DEBUG 2478 --- [nio-8080-exec-1] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'flow2.channel#1', message: GenericMessage [payload=<200 OK,{Date=[Wed, 25 May 2016 17:53:04 GMT], Expires=[-1], Cache-Control=[private, max-age=0], Content-Type=[text/html; charset=ISO-8859-1], P3P=[CP="This is not a P3P policy! See https://www.google.com/support/accounts/answer/151657?hl=en for more info."], Content-Encoding=[gzip], Server=[gws], Content-Length=[4452], X-XSS-Protection=[1; mode=block], X-Frame-Options=[SAMEORIGIN], Set-Cookie=[NID=79=TunItaDTDDyn5gEJxdcCFjC_KmtrIT-VlJ_woRkWuVYNpuKC49nbBQhjE_mwzDfiQvPttiUYTuOg2qBtlAc0PtSu_Qjg8-91ETGwUzoFxq34Bs1e7A7KcXz7WLnl_9GjY1xBl8gJDcdrJQ; expires=Thu, 24-Nov-2016 17:53:04 GMT; path=/; domain=.google.com; HttpOnly]}>, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, host=localhost:8080, http_requestUrl=http://localhost:8080/bar, id=e980cc2c-4617-6231-fd69-c0f798483312, http_statusCode=200, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198784461}]
2016-05-25 10:53:04.461 DEBUG 2478 --- [nio-8080-exec-1] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'flow2.channel#0', message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, host=localhost:8080, http_requestUrl=http://localhost:8080/bar, id=e6fc73c1-7872-0c79-bf04-8b8f9c06350d, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198784356}]
2016-05-25 10:53:04.461 DEBUG 2478 --- [nio-8080-exec-1] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'requestChannel2', message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@786f1d94, host=localhost:8080, http_requestUrl=http://localhost:8080/bar, id=ce44ad18-4202-a6a6-0870-fc38b87dc8af, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198784356}]
2016-05-25 10:53:07.508 DEBUG 2478 --- [nio-8080-exec-2] .IntegrationRequestMappingHandlerMapping : Looking up handler method for path /foo
2016-05-25 10:53:07.508 DEBUG 2478 --- [nio-8080-exec-2] .IntegrationRequestMappingHandlerMapping : Returning handler method [public abstract void org.springframework.web.HttpRequestHandler.handleRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws javax.servlet.ServletException,java.io.IOException]
2016-05-25 10:53:07.509 DEBUG 2478 --- [nio-8080-exec-2] o.s.integration.channel.DirectChannel    : preSend on channel 'requestChannel', message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, host=localhost:8080, http_requestUrl=http://localhost:8080/foo, id=dd3e590d-6a8e-3ac5-035b-e67838708002, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198787509}]
2016-05-25 10:53:07.509 DEBUG 2478 --- [nio-8080-exec-2] o.s.i.t.MessageTransformingHandler       : org.springframework.integration.transformer.MessageTransformingHandler#0 received message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, host=localhost:8080, http_requestUrl=http://localhost:8080/foo, id=dd3e590d-6a8e-3ac5-035b-e67838708002, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198787509}]
2016-05-25 10:53:07.509 DEBUG 2478 --- [nio-8080-exec-2] o.s.integration.channel.DirectChannel    : preSend on channel 'flow.channel#0', message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, host=localhost:8080, http_requestUrl=http://localhost:8080/foo, id=eef228c6-cc3a-eec9-fe52-d340db69815a, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198787509}]
2016-05-25 10:53:07.509 DEBUG 2478 --- [nio-8080-exec-2] i.h.o.HttpRequestExecutingMessageHandler : consumerPostbackGate received message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, host=localhost:8080, http_requestUrl=http://localhost:8080/foo, id=eef228c6-cc3a-eec9-fe52-d340db69815a, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198787509}]
2016-05-25 10:53:07.578 DEBUG 2478 --- [nio-8080-exec-2] o.s.integration.channel.DirectChannel    : preSend on channel 'flow2.channel#1', message: GenericMessage [payload=<200 OK,{Date=[Wed, 25 May 2016 17:53:07 GMT], Expires=[-1], Cache-Control=[private, max-age=0], Content-Type=[text/html; charset=ISO-8859-1], Content-Encoding=[gzip], Server=[gws], Content-Length=[4452], X-XSS-Protection=[1; mode=block], X-Frame-Options=[SAMEORIGIN]}>, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, host=localhost:8080, http_requestUrl=http://localhost:8080/foo, id=8cda5a13-1d7c-983b-ee47-847ae520be3a, http_statusCode=200, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198787578}]
flow2
2016-05-25 10:53:07.579 DEBUG 2478 --- [nio-8080-exec-2] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'flow2.channel#1', message: GenericMessage [payload=<200 OK,{Date=[Wed, 25 May 2016 17:53:07 GMT], Expires=[-1], Cache-Control=[private, max-age=0], Content-Type=[text/html; charset=ISO-8859-1], Content-Encoding=[gzip], Server=[gws], Content-Length=[4452], X-XSS-Protection=[1; mode=block], X-Frame-Options=[SAMEORIGIN]}>, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, host=localhost:8080, http_requestUrl=http://localhost:8080/foo, id=8cda5a13-1d7c-983b-ee47-847ae520be3a, http_statusCode=200, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198787578}]
2016-05-25 10:53:07.579 DEBUG 2478 --- [nio-8080-exec-2] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'flow.channel#0', message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, host=localhost:8080, http_requestUrl=http://localhost:8080/foo, id=eef228c6-cc3a-eec9-fe52-d340db69815a, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198787509}]
2016-05-25 10:53:07.579 DEBUG 2478 --- [nio-8080-exec-2] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'requestChannel', message: GenericMessage [payload={}, headers={http_requestMethod=GET, replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@ecef3f, host=localhost:8080, http_requestUrl=http://localhost:8080/foo, id=dd3e590d-6a8e-3ac5-035b-e67838708002, user-agent=curl/7.43.0, accept=*/*, timestamp=1464198787509}]

违规代码是:

@SpringBootApplication
@EnableAutoConfiguration
@Configuration
@ComponentScan
public class SpringIntegrationIssue {

    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext ctx = SpringApplication.run(SpringIntegrationIssue.class, args);
    }

    @Autowired
    private Environment env;

    @Bean
    public HttpRequestHandlingMessagingGateway httpGate() {
        HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
        RequestMapping mapping = new RequestMapping();
        mapping.setMethods(HttpMethod.GET);
        mapping.setPathPatterns("/foo");
        gateway.setRequestMapping(mapping);
        gateway.setRequestChannel(requestChannel());
        gateway.setRequestPayloadType(byte[].class);
        return gateway;
    }

    @Bean
    public HttpRequestHandlingMessagingGateway httpGate2() {
        HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
        RequestMapping mapping = new RequestMapping();
        mapping.setMethods(HttpMethod.GET);
        mapping.setPathPatterns("/bar");
        gateway.setRequestMapping(mapping);
        gateway.setRequestChannel(requestChannel2());
        gateway.setRequestPayloadType(byte[].class);
        return gateway;
    }

    @Bean
    public MessageChannel requestChannel() {
        return new DirectChannel();
    }

    @Bean
    public MessageChannel requestChannel2() {
        return new DirectChannel();
    }


    @Bean
    public IntegrationFlow flow() {
        return IntegrationFlows.from("requestChannel")
                .transform(new ObjectToStringTransformer())
                .handle(consumerPostbackGate())
                .handle(m -> System.out.println("flow"))
                .get();
    }

    @Bean
    public IntegrationFlow flow2() {
        return IntegrationFlows.from("requestChannel2")
                .transform(new ObjectToStringTransformer())
                .handle(consumerPostbackGate())
                .handle(m -> System.out.println("flow2"))
                .get();
    }

    @Bean
    HeaderMapper headerMapper() {
        DefaultHttpHeaderMapper headerMapper = new DefaultHttpHeaderMapper();
        headerMapper.setExcludedOutboundStandardRequestHeaderNames(new String[]{"host"});
        return headerMapper;
    }

    @Bean
    HttpRequestExecutingMessageHandler consumerPostbackGate() {
        HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("http://www.google.com/");
        handler.setHeaderMapper(headerMapper());
        handler.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
        handler.setHttpMethod(HttpMethod.HEAD);
        return handler;
    }

}

1 个答案:

答案 0 :(得分:0)

您无法在两种不同的@Bean方法中使用相同的MessageHandler .handle()

原因是当流程组成时,DSL会将一个输出通道注入处理程序,因此,在这种情况下,第二个流程会获胜。

如果您将@Bean @Scope更改为原型,它应该可以正常工作,因为每个流都将获得自己的处理程序实例。

@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)

我们应该在DSL中检测到这一点并拒绝配置;我opened an issue

当您使用XML硬连接MessageHandler bean时,我们有类似的逻辑。