WARN: Event forwarding failed

JD2 years ago

I have tried to forward my all events to another server database but I got error in the console

2022-07-25 20:49: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 (...)

traccar.xml

        <entry key='event.forward.enable'>true</entry>
        <entry key='event.forward.url'>https://mywebsite.com/input.php</entry>

input.php


<?php

$request_body = file_get_contents('php://input');
$data = json_decode($request_body);

$type = $data->{'event'}->{'type'};
$serverTime = $data->{'event'}->{'serverTime'};
$deviceName = $data->{'device'}->{'name'};
$alarmType = $data->{'event'}->{'attributes'};
$alarmTypeReturn = $alarmType->{'alarm'};
$deviceId = $data->{'event'}->{'deviceId'};
$geofenceId = $data->{'event'}->{'geofenceId'};


$servername = "localhost";
$username = "user";
$password = "password";
$dbname = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}


$sql = "INSERT INTO notifications (type, serverTime, deviceName, alarmType, alarmTypeReturn, deviceId, geofenceId)
VALUES ('$type', '$serverTime', '$deviceName', '$alarmType-', '$alarmTypeReturn', '$deviceId', '$geofenceId')";

if ($conn->query($sql) === TRUE) {
  echo "New record created successfully";
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>
Anton Tananaev2 years ago

You shouldn't send anything back. Or if you're sending, it should be JSON.

JD2 years ago

This error after updating the PHP code


2022-07-25 21:25:26  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 (...)

input.php (new Code)


<?php

$request_body = file_get_contents('php://input');
$data = json_decode($request_body);

$type = $data->{'event'}->{'type'};
$serverTime = $data->{'event'}->{'serverTime'};
$deviceName = $data->{'device'}->{'name'};
$alarmType = $data->{'event'}->{'attributes'};
$alarmTypeReturn = $alarmType->{'alarm'};
$deviceId = $data->{'event'}->{'deviceId'};
$geofenceId = $data->{'event'}->{'geofenceId'};


$servername = "localhost";
$username = "abc";
$password = "abc";
$dbname = "crm";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);


$sql = "INSERT INTO notifications (type, serverTime, deviceName, alarmType, alarmTypeReturn, deviceId, geofenceId)
VALUES ('$type', '$serverTime', '$deviceName', '$alarmType-', '$alarmTypeReturn', '$deviceId', '$geofenceId')";

$conn->query($sql);

$conn->close();
?>
JD2 years ago

it's giving an error in the console but the data still receive means working fine Thanks dear great support...!