尝试使用spock获取简单的问候语控制器时遇到404错误。
我尝试将RxHttpClient修改为RxStreamingHttpClient
My Greetings Controller endpoint:
@Get("/greetings/{name}")
String greetings(String name){
return "hello "+name;
}
Spock测试:
class TacRulesControllerSpec extends Specification {
@Shared
@AutoCleanup
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer)
@Shared
@AutoCleanup
RxStreamingHttpClient client = embeddedServer.applicationContext.createBean(RxStreamingHttpClient, embeddedServer.getURL())
def "greetings controller check" () {
when:
HttpRequest httpRequest = HttpRequest.GET("/greetings/bon")
HttpResponse<String> httpResponse = client.toBlocking().exchange(httpRequest)
then:
httpResponse.status == HttpStatus.OK
}
}
/greetings/bon
)抛出错误,为什么它没有传播并打印在日志中?我已经看到了实际的API引发400错误的情况,但是micronaut提供的声明性httpclient引发404错误。 22:27:42.889 [nioEventLoopGroup-1-3] DEBUG i.m.http.client.DefaultHttpClient - Sending HTTP Request: GET /greetings/bon
22:27:42.889 [nioEventLoopGroup-1-3] DEBUG i.m.http.client.DefaultHttpClient - Chosen Server: localhost(19174)
22:27:42.891 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - X-B3-TraceId: 4b31b84f1f36b856
22:27:42.891 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - X-B3-SpanId: 4b31b84f1f36b856
22:27:42.891 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - X-B3-Sampled: 0
22:27:42.891 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - host: localhost:19174
22:27:42.891 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - connection: close
22:27:43.009 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - HTTP Client Response Received for Request: GET http://localhost:19174/greetings/bon
22:27:43.009 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - Status Code: 404 Not Found
22:27:43.009 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - Date: Sat, 29 Jun 2019 03:27:42 GMT
22:27:43.009 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - content-type: application/json
22:27:43.009 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - content-length: 90
22:27:43.009 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - connection: close
22:27:43.009 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - Response Body
22:27:43.009 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - ----
22:27:43.010 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - {"_links":{"self":{"href":"/greetings/bon","templated":false}},"message":"Page Not Found"}
22:27:43.010 [nioEventLoopGroup-1-3] TRACE i.m.http.client.DefaultHttpClient - ----
io.micronaut.http.client.exceptions.HttpClientResponseException: Page Not Found
at io.micronaut.http.client.DefaultHttpClient$10.channelRead0(DefaultHttpClient.java:1783)
at io.micronaut.http.client.DefaultHttpClient$10.channelRead0(DefaultHttpClient.java:1723)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at i