2

将 Spring-Boot 从 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$0(SassRestSimulatorApplication.java:96)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at java.util.stream.SliceOps$1$1.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 - Access denied and no logging found:

在此处输入图像描述

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

在 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下,我在调用其余服务时得到以下调试信息:

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]

弹簧启动器:

        <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 Works 下,1.4.0 错误如所述。Dropboxlink:链接

4

1 回答 1

1

好吧,既然你在那里有一个 Spring Boot,它看起来真的像spring-security在类路径中导致一个安全自动配置(SecurityAutoConfiguration)。

尝试在--debug启动应用程序时打开选项并查看“安全”一词的自动配置。

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 上进行了尝试,结果同样好。

也许您的机器上有一些防火墙,规则不允许带有某些标头或其他内容的请求?..

于 2016-08-10T13:08:54.467 回答