Spring-集成:int:http:inbound-通道适配器在 spring-引导升级到 1.4 后抛出 403

Spring-Integration: int:http:inbound-channel-adapter throws 403 after spring-boot upgrade to 1.4

升级后 Spring- 从 1.3.7.RELEASE 启动到 1.4.0.RELEASE 我在调用休息服务时遇到了问题通过入站通道适配器,它抛出一个 HttpClientErrorException.

配置inbound-channel-adapter:

<int-http:inbound-channel-adapter
        channel="api_app_integration_request_channel" 
        supported-methods="PUT" 
        path="/process/ticket"
        request-payload-type="*.model.Ticket"
        header-mapper="headerMapper"
        error-channel="internal-client-rest-ticket-error-channel"
    >
        <int-http:request-mapping consumes="application/json" />
    </int-http:inbound-channel-adapter>

Restservice-调用:

private static final String URL = "http://localhost:8080/process/ticket";
public void openTicket(final Profile profile, final Ticket ticket) {
        final HttpHeaders headers = new HttpHeaders();
        headers.set(Profile.PROFILE, profile.toString());
        final HttpEntity<Ticket> entity = new HttpEntity<Ticket>(ticket, headers);
        template.exchange(URL, HttpMethod.PUT, entity, Ticket.class);
    }

异常:

org.springframework.web.client.HttpClientErrorException: 403 null
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:667)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:620)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:580)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:498)
    at *.client.rest.simulator.ProblemReporter.openTicket(ProblemReporter.java:28)
    at *.client.SassRestSimulatorApplication.lambda[=15=](SassRestSimulatorApplication.java:96)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at java.util.stream.SliceOps.accept(SliceOps.java:204)
    at java.util.stream.StreamSpliterators$InfiniteSupplyingSpliterator$OfRef.tryAdvance(StreamSpliterators.java:1356)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
    at *.client.SassRestSimulatorApplication.executeApplication(SassRestSimulatorApplication.java:96)
    at *.client.SassRestSimulatorApplication.main(SassRestSimulatorApplication.java:47)

调试输出

2016-08-07 18:56:24.022 DEBUG 16288 --- [           main] o.s.web.client.RestTemplate              : Created PUT request for "http://localhost:8080/process/ticket"
2016-08-07 18:56:24.180 DEBUG 16288 --- [           main] o.s.web.client.RestTemplate              : Setting request Accept header to [application/json, application/*+json]
2016-08-07 18:56:24.223 DEBUG 16288 --- [           main] o.s.web.client.RestTemplate              : Writing [Ticket# 1: [SIDE1-BS1-SP1] [SIDE1-BS1-SP1] [emergency] [NEW] Urgend problem. Fix immediately or revenue will be lost!] using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@18918d70]
2016-08-07 18:56:24.331 DEBUG 16288 --- [           main] o.s.web.client.RestTemplate              : PUT request for "http://localhost:8080/process/ticket" resulted in 403 (null); invoking error handler

我试过 int-http:inbound-gateway 但结果相同。

当直接通过 Postman 访问服务时,我收到 403 - 访问被拒绝且未找到日志记录:

我对访问被拒绝感到有点惊讶,我没有使用任何安全框架。

在 Spring-Boot 1.3.7.RELEASE 下工作正常:

日志输出:

2016-08-07 20:03:23.098 TRACE 9372 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Bound request context to thread: org.apache.catalina.connector.RequestFacade@32818b2d
2016-08-07 20:03:23.098 DEBUG 9372 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing PUT request for [/process/ticket]
2016-08-07 20:03:23.098 TRACE 9372 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@23764bec] in DispatcherServlet with name 'dispatcherServlet'
2016-08-07 20:03:23.098 TRACE 9372 --- [nio-8080-exec-4] o.s.w.s.handler.SimpleUrlHandlerMapping  : No handler mapping found for [/process/ticket]
2016-08-07 20:03:23.098 TRACE 9372 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@5fa0d972] in DispatcherServlet with name 'dispatcherServlet'
2016-08-07 20:03:23.098 DEBUG 9372 --- [nio-8080-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /process/ticket
2016-08-07 20:03:23.098 DEBUG 9372 --- [nio-8080-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/process/ticket]
2016-08-07 20:03:23.098 TRACE 9372 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping@64dfb31d] in DispatcherServlet with name 'dispatcherServlet'
2016-08-07 20:03:23.098 TRACE 9372 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Testing handler adapter [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter@35467187]
2016-08-07 20:03:23.098 TRACE 9372 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Testing handler adapter [org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter@52466d8b]
2016-08-07 20:03:23.100 DEBUG 9372 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2016-08-07 20:03:23.100 TRACE 9372 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@32818b2d
2016-08-07 20:03:23.100 DEBUG 9372 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Successfully completed request
2016-08-07 20:03:23.119 DEBUG 9372 --- [ sassExecutor-1] o.s.web.client.RestTemplate              : Created PUT request for "http://localhost:8080/process/ticket"
2016-08-07 20:03:23.120 DEBUG 9372 --- [ sassExecutor-1] o.s.web.client.RestTemplate              : Writing [Ticket# 666: [SIDE1-BS1-SP1] ] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@4d3ce1c0]
2016-08-07 20:03:23.126 TRACE 9372 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Bound request context to thread: org.apache.catalina.connector.RequestFacade@32818b2d
2016-08-07 20:03:23.127 DEBUG 9372 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing PUT request for [/process/ticket]
2016-08-07 20:03:23.128 TRACE 9372 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@23764bec] in DispatcherServlet with name 'dispatcherServlet'
2016-08-07 20:03:23.128 TRACE 9372 --- [nio-8080-exec-5] o.s.w.s.handler.SimpleUrlHandlerMapping  : No handler mapping found for [/process/ticket]
2016-08-07 20:03:23.128 TRACE 9372 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@5fa0d972] in DispatcherServlet with name 'dispatcherServlet'
2016-08-07 20:03:23.128 DEBUG 9372 --- [nio-8080-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /process/ticket
2016-08-07 20:03:23.129 DEBUG 9372 --- [nio-8080-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/process/ticket]
2016-08-07 20:03:23.129 TRACE 9372 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Testing handler map [org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping@64dfb31d] in DispatcherServlet with name 'dispatcherServlet'
2016-08-07 20:03:23.129 TRACE 9372 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Testing handler adapter [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter@35467187]
2016-08-07 20:03:23.129 TRACE 9372 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Testing handler adapter [org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter@52466d8b]
2016-08-07 20:03:23.130 DEBUG 9372 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2016-08-07 20:03:23.130 TRACE 9372 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@32818b2d
2016-08-07 20:03:23.130 DEBUG 9372 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Successfully completed request
2016-08-07 20:03:23.134 DEBUG 9372 --- [ sassExecutor-1] o.s.web.client.RestTemplate              : PUT request for "http://localhost:8080/process/ticket" resulted in 200 (OK)
Ticket# 666: [SIDE1-BS1-SP1] [SIDE1-BS1-SP1] [low] [DECRYPTED] Ich bin von Postman gesendet worden

====== 编辑 =======

Spring Boot 1.4.0 下,我在调用 rest 服务时得到以下调试信息:

2016-08-08 19:21:35.382 DEBUG 8268 --- [nio-8080-exec-2] o.a.coyote.http11.Http11InputBuffer      : Received [PUT /process/ticket HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 206
Cache-Control: no-cache
Origin: chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
profile: 192.168.56.102:10000
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip, deflate, sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4

{"ticketId":666,"issueDateTime":"2016-06-27","description":"Ich bin von Postman gesendet worden","sender":"SIDE1-BS1-SP1","receiver":"SIDE1-BS1-SP1","priority":"low","secured":"NEW","mimeType":"text/plain"}]
2016-08-08 19:21:35.383 DEBUG 8268 --- [nio-8080-exec-2] o.a.c.authenticator.AuthenticatorBase    : Security checking request PUT /process/ticket
2016-08-08 19:21:35.383 DEBUG 8268 --- [nio-8080-exec-2] org.apache.catalina.realm.RealmBase      :   No applicable constraints defined
2016-08-08 19:21:35.383 DEBUG 8268 --- [nio-8080-exec-2] o.a.c.authenticator.AuthenticatorBase    :  Not subject to any constraint
2016-08-08 19:21:35.383 DEBUG 8268 --- [nio-8080-exec-2] o.apache.catalina.core.StandardWrapper   :   Returning non-STM instance
2016-08-08 19:21:35.384 DEBUG 8268 --- [nio-8080-exec-2] o.apache.coyote.http11.Http11Processor   : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@16ab5cb1:org.apache.tomcat.util.net.NioChannel@5a719bf2:java.nio.channels.SocketChannel[connected local=/0:0:0:0:0:0:0:1:8080 remote=/0:0:0:0:0:0:0:1:57863]], Status in: [OPEN_READ], State out: [OPEN]

Spring-引导程序:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-http</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-stream</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

====

示例应用程序:

在 Spring-Boot 1.3.7 下运行,1.4.0 错误如所述。 投递箱链接:link

好吧,既然你有一个 Spring 引导,它看起来确实像类路径中的 spring-security 导致安全 auto-configuration (SecurityAutoConfiguration).

在启动应用程序时尝试打开 --debug 选项并查看 auto-configuration 中的 "security" 字词。

OTOH 你显示了 Tomcat 的第一个日志,但他们没有提到 DispatcherServlet 的进一步过程。

我们能看到那些日志吗?

更新

感谢您提供示例应用程序。不幸的是,这对我有用:

:: Spring Boot ::        (v1.4.0.RELEASE)

2016-08-11 11:35:36.762  INFO 8636 --- [           main] com.example.RestSimulatorApplication     : Starting RestSimulatorApplication on HOME with PID 8636 (D:\SpringIO\Spring140IntegrationTest\target\classes started by abilan in D:\SpringIO\Spring140IntegrationTest)
...
'dispatcherServlet': initialization started
2016-08-11 11:35:39.694  INFO 8636 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 11 ms
Ticket# 1: [emergency] [NEW] Urgend problem. Fix immediately or revenue will be lost!
Ticket# 2: [medium] [NEW] There is an issue; take a look whenever you have time.
Ticket# 3: [emergency] [NEW] Urgend problem. Fix immediately or revenue will be lost!
Ticket# 4: [medium] [NEW] There is an issue; take a look whenever you have time.

我在 Windows 和 Mac 上试过,效果一样好。

也许你的机器上有一些防火墙,规则不允许某些 header 或其他的请求?..