Java 运行Intellij时查看JSON响应/请求

Java 运行Intellij时查看JSON响应/请求,java,spring,intellij-idea,spring-boot,Java,Spring,Intellij Idea,Spring Boot,我从IntelliJ 2017.1.2的两个实例中调试了两个服务。服务A向服务B提交json请求。这两个服务都是使用REST调用的Spring引导 服务A提供一个职位: ResponseEntity<InvoiceResponse> response = restTemplate.postForEntity(invoiceUrl, request, InvoiceResponse.class); 但是我得到了一个截获请求的JW

我从IntelliJ 2017.1.2的两个实例中调试了两个服务。服务A向服务B提交json请求。这两个服务都是使用REST调用的Spring引导

服务A提供一个职位:

ResponseEntity<InvoiceResponse> response =
                            restTemplate.postForEntity(invoiceUrl, request, InvoiceResponse.class);
但是我得到了一个截获请求的JWT过滤器,并成功地处理了它(我已经通过断点确认):

这似乎正常退出,因为我在日志中没有看到任何错误。但是,IntelliJ中的服务A显示以下消息:

无法读取文档:无法识别的标记“丢失”:应为 [来源]处的('true'、'false'或'null'): java.io。PushbackInputStream@7d005eb;第1行第9列] com.fasterxml.jackson.core.JsonParseException:无法识别的令牌 “缺少”:在[源代码: java.io。PushbackInputStream@7d005eb;第1行第9列]

我没有任何堆栈跟踪,单步执行代码不会显示问题。我正试图找到一种方法来检查JSON即将/即将离开的服务B,这样我就可以看到正在使用什么,因为这似乎导致了jackson的问题。在IntelliJ中是否仍可以查看此内容?如果我可以从服务A获得发送的JSON,我可以重新创建来自Postman的调用,但我似乎也无法跟踪离开服务A的实际JSON

如果有必要的话,我正在OSX上使用SpringBoot1.3.5和Java8

更新:

我根据Patrick Bay的建议添加了以下服务:

@Bean
public CommonsRequestLoggingFilter requestLoggingFilter() {
    CommonsRequestLoggingFilter loggingFilter = new CommonsRequestLoggingFilter();
    loggingFilter.setIncludeClientInfo(true);
    loggingFilter.setIncludeQueryString(true);
    loggingFilter.setIncludePayload(true);
    return loggingFilter;
}
但我仍然没有看到任何json来帮助我发现我的请求有什么问题:

调试74188---[nio-8081-exec-3]o.s.web.client.RestTemplate
:正在写入[com.common.invoice]。InvoiceRequest@44471e8e]作为 使用“application/json;charset=UTF-8” [org.springframework.http.converter.json。MappingJackson2HttpMessageConverter@610fefeb] 调试74188---[nio-8081-exec-3]o.s.web.client.RestTemplate
:已生成对“”的POST请求 在200(空)调试74188中--[nio-8081-exec-3] o、 s.web.client.RestTemplate:正在读取[class] com..common.invoice.InvoiceResponse]作为“应用程序/json”,使用 [org.springframework.http.converter.json。MappingJackson2HttpMessageConverter@610fefeb] 错误74188---[nio-8081-exec-3]c.finance.Connector:无法执行 读取文档:无法识别的标记“丢失”:应为('true', “false”或“null”)


我还尝试在我的服务B JwtAuthenticationTokenFilter中检查HttpRequest。我试着通过它导航,但我没有看到我发送的实际身体。我确实在请求中看到了正确的url,但一旦筛选器成功处理它,就永远不会到达实际的端点(“/office/1/invoice”),因为我认为服务B会启动来记录传入的请求,您可以使用CommonRequestLoggingFilter查看此处以了解更多详细信息

将此添加到Spring配置中:

@Bean
public CommonsRequestLoggingFilter requestLoggingFilter() {
    CommonsRequestLoggingFilter loggingFilter = new CommonsRequestLoggingFilter();
    loggingFilter.setIncludeClientInfo(true);
    loggingFilter.setIncludeQueryString(true);
    loggingFilter.setIncludePayload(true);
    return loggingFilter;
}
并将其添加到应用程序属性文件:

logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG  

在调试JwtAuthenticationTokenFilter时,您还应该能够通过检查httpRequest来检查请求正文。同样值得检查的是,这个问题实际上没有显示json请求或响应。我需要看到这一点,这样我才能看到我的Jackson映射是如何不正确的。只要有效负载长度小于50个字符,它就应该显示有效负载。您可以通过设置来修改此最大值:
loggingFilter.setMaxPayloadLength(1000)如下所示
2017-05-25 17:42:00.581调试86141---[nio-8080-exec-4]o.s.w.f.CommonRequestLoggingFilter:After request[uri=/greet post;client=0:0:0:0:0:0:1;有效负载={“In”}]
对于混淆,CommonRequestLoggingFilter过滤器应该应用于服务器端。您的示例中的服务B。您是否签出了链接问题?您是否尝试添加ClientHttpRequestInterceptor以在客户端服务a中记录来自RestTemplate的请求和响应?
@Bean
public CommonsRequestLoggingFilter requestLoggingFilter() {
    CommonsRequestLoggingFilter loggingFilter = new CommonsRequestLoggingFilter();
    loggingFilter.setIncludeClientInfo(true);
    loggingFilter.setIncludeQueryString(true);
    loggingFilter.setIncludePayload(true);
    return loggingFilter;
}
logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=DEBUG