WARN: Event forwarding failed (SOLVED)

Sandor2 years ago

If you read this post, you probably have enabled event forwarding to an external service and have seen this line in your server.log ;-)

2022-12-15 19:22:06 WARN: Event forwarding failed - MessageBodyReader not found for media type=text/html;charset=UTF-8, type=class java.lang.Object, genericType=class java.lang.Object. - MessageBodyProviderNotFoundException (...)

I could not find a walkthrough on how to solve it so here is how I did that.

As described in the forum this WARN means your service is RETURNING something Traccar is not expecting.
You can test this easily. In my case:

curl -v -X POST http://REDACTED_IP:REDACTED_PORT/ -H 'Content-Type: application/json'
Resulted in:

* Expire in 0 ms for 6 (transfer 0x1298950)
*   Trying xxx.xxx.x.xx...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x1298950)
* Connected to xxx.xxx.x.xx (xxx.xxx.x.xx) port REDACTED_PORT (#0)
> POST /index.php HTTP/1.1
> Host: xxx.xxx.x.xx:REDACTED_PORT
> User-Agent: curl/7.64.0
> Accept: /
* Content-Type: application/json*
>
< HTTP/1.1 200 OK
< Server: nginx
< Date: Thu, 15 Dec 2022 20:10:31 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Keep-Alive: timeout=20

As you can see the nginx server returns Content-Type: text/html; charset=UTF-8; hence the WARN message in your Traccar log.
To solve this you will only need to add 1 line to the config file of the webserver.

add_header Content-Type application/json; # 15-12-2022 Force specific content type, help traccar! ;-)

This can by done
cd /etc/nginx/conf.d/
Open your service config file and add 1 line in the location block

  location ~ [^/]\.php(/|$) {
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                if (!-f $document_root$fastcgi_script_name) {
                return 404;
                }
                add_header  Content-Type    application/json;
                .......LEAVE REST OF CONFIG UNTOUCHED ....

Save your config.
Issue the following to see if you have a valid config.
sudo nginx -t
If there are no errors reload your config
sudo nginx -s reload

Now we can test if your changes worked out:
curl -v -X POST http://REDACTED_IP:REDACTED_PORT/ -H 'Content-Type: application/json'

Expected Result:

 * Expire in 0 ms for 6 (transfer 0xa52950)
*   Trying REDACTED_IP...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0xa52950)
* Connected to REDACTED_IP (REDACTED_IP) port REDACTED_PORT (#0)
> POST /index.php HTTP/1.1
> Host: REDACTED_IP:REDACTED_PORT
> User-Agent: curl/7.64.0
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 200 OK
< Server: nginx/1.14.2
< Date: Sat, 24 Dec 2022 10:09:40 GMT
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Content-Type: application/json
<
* Connection #0 to host REDACTED_IP left intact

The response should now have Content-Type application/json and your warnings in the Traccar logs should be gone.