I have two services being debugged from two instances of IntelliJ 2017.1.2. Service A submits a json request to Service B. Both services are Spring-Boot using REST calls.
Service A makes a post:
ResponseEntity<InvoiceResponse> response =
restTemplate.postForEntity(invoiceUrl, request, InvoiceResponse.class);
Service B had an endpoint:
@RequestMapping(value = "/office/{officeId}/invoice", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity createInvoice(@RequestBody InvoiceRequest invoiceRequest, @PathVariable("officeId") long officeId) {
...}
But I get a JWT filter that intercepts the request, and processed it successfully (I have confirmed via breakpoint):
public class JwtAuthenticationTokenFilter extends GenericFilterBean {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String authToken = httpRequest.getHeader(this.tokenHeader);
String username = jwtTokenUtil.getUsernameFromToken(authToken);
if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
if (jwtTokenUtil.validateToken(authToken, userDetails)) {
UsernamePasswordAuthenticationToken
authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpRequest));
SecurityContextHolder.getContext().setAuthentication(authentication);
}
}
chain.doFilter(request, response);
}
This seems to exit normally, as I don't see any errors in the logs. However, Service A in IntelliJ shows the message:
Could not read document: Unrecognized token 'Missing': was expecting ('true', 'false' or 'null') at [Source: java.io.PushbackInputStream@7d005eb; line: 1, column: 9] com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Missing': was expecting ('true', 'false' or 'null') at [Source: java.io.PushbackInputStream@7d005eb; line: 1, column: 9]
I don't have any stack traces and stepping thru the code doesn't show me the problem. I am trying to find a way to examine the JSON coming/leaving Service B so I can see what is being used since that appears to be causing issues with jackson. Is there anyway to view this in IntelliJ? If I could get the JSON being sent from Service A, I could recreate the call from Postman, but I can't seem to track the actual json leaving Service A either.
If it matters, I am using Spring-Boot 1.3.5 and Java 8 on OS X
UPDATE:
I added the following to Service A per Patrick Bay suggestions:
@Bean
public CommonsRequestLoggingFilter requestLoggingFilter() {
CommonsRequestLoggingFilter loggingFilter = new CommonsRequestLoggingFilter();
loggingFilter.setIncludeClientInfo(true);
loggingFilter.setIncludeQueryString(true);
loggingFilter.setIncludePayload(true);
return loggingFilter;
}
But I still don't see any json to help me see what is wrong with my request:
DEBUG 74188 --- [nio-8081-exec-3] o.s.web.client.RestTemplate
: Writing [com.common.invoice.InvoiceRequest@44471e8e] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@610fefeb] DEBUG 74188 --- [nio-8081-exec-3] o.s.web.client.RestTemplate
: POST request for "http://localhost:8998/office/1/invoice" resulted in 200 (null) DEBUG 74188 --- [nio-8081-exec-3] o.s.web.client.RestTemplate : Reading [class com..common.invoice.InvoiceResponse] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@610fefeb] ERROR 74188 --- [nio-8081-exec-3] c.finance.Connector : Could not read document: Unrecognized token 'Missing': was expecting ('true', 'false' or 'null')
I also tried inspecting the HttpRequest in my Service B JwtAuthenticationTokenFilter. I have tried navigating thru it, but I don't see the actual body that I am sending. I do see the correct url in the request, but once the filter successfull processes it, the actual endpoint ("/office/1/invoice") is never reached because I think Service B blows up