0

I've got a basic Spring Boot app with a REST endpoint that is configured to receive POSTs with Content-Type = application/json.

My external partner is posting me HTTP requests, but apparently with a different Content-Type, because my app rejects those requests with HTTP 415 Unsupported Media Type.

Unfortunately, Spring's logs do not reveal what exactly the Content-Type is, and the external partner is currently unavailable for questions.

Is there a way to crank up Spring's log level so the log also includes the received Content-Type that's being rejected?

Olimpiu POP
  • 5,001
  • 4
  • 34
  • 49
Florian
  • 4,821
  • 2
  • 19
  • 44
  • Can't you write a custom interceptor? Something like done [here](https://www.baeldung.com/spring-http-logging) – Olimpiu POP Jan 10 '20 at 08:51
  • True, that can be done. Turn it into an answer and I'll upvote it? I was hoping for a configuration-based solution though, that would enable me to see more log details without code, maybe even without redeploying. – Florian Jan 10 '20 at 08:55
  • That's why I listed it as a comment only, as I was looking into what you mentioned as well :). That would be desirable. Don't you have a http server in front of it? Or can't you use an external application like [wireshark](https://www.wireshark.org)? Or how about [actuators](https://www.baeldung.com/spring-boot-actuator-http), that should be just a config change? – Olimpiu POP Jan 10 '20 at 08:59
  • Turn it into an answer anyway, I'd say. Doesn't mean it has to be/remain the best answer, right? Looked into the other options but it's not so easy. [Corporate stuff... :-(] There is an HTTP server but it's not under my control and I can't get access to it quickly, which makes it hard to inspect their logs or add extra tools like wireshark. Actuators are switched off because of security concerns... – Florian Jan 10 '20 at 09:23

1 Answers1

1

I see the following options as stated in the comments above:

  1. Use an external packet analyser like wireshark
  2. Use the httptrace actuator you can see an example here
  3. Write an interceptor as you can see here

Use the httpTrace actuator

The httptrace provides information about the HTTP request/response exchange. It can be called by doing a get to /actuator/httptrace. One can use curl:

$ curl 'http://localhost:8080/actuator/httptrace' -i -X GET

or directly from your browser, on your local machine that would be http://localhost:8080/actuator/httptrace.

The information is provided as JSON:

HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v3+json
Content-Length: 503

{
  "traces" : [ {
    "timestamp" : "2019-12-06T06:13:02.341Z",
    "principal" : {
      "name" : "alice"
    },
    "session" : {
      "id" : "41a5c57b-112a-4b15-8ea9-05c5942e7e88"
    },
    "request" : {
      "method" : "GET",
      "uri" : "https://api.example.com",
      "headers" : {
        "Accept" : [ "application/json" ]
      }
    },
    "response" : {
      "status" : 200,
      "headers" : {
        "Content-Type" : [ "application/json" ]
      }
    },
    "timeTaken" : 1
  } ]
}
Olimpiu POP
  • 5,001
  • 4
  • 34
  • 49