"Bad Request" bei RPC-Api-Call mit ID 0

Antworten
dark alex
Beiträge: 326
Registriert: 11 Mär 2015, 10:09

"Bad Request" bei RPC-Api-Call mit ID 0

Beitrag von dark alex »

Hallo! Das hat mich jetzt ne Weile gekostet...

Ich baue eine Integration von OPSI in unser selbstgebautes Ticketsystem. Dafür muss ich RPC-Commands an OPSI senden. So weit, so gut.

Das Ticketsystem basiert auf PHP, da kommt die php-json-rpc-http library recht gelegen - Wenn es denn funktionieren würde.
Ich habe immer wieder einen "Bad Request"-Fehler von OPSI erhalten, bis ich drauf gekommen bin:

Hier zunächst mal die Spezifikation für JSON-RPC 2.0
id
An identifier established by the Client that MUST contain a String, Number, or NULL value if included. If it is not included it is assumed to be a notification. The value SHOULD normally not be Null [1] and Numbers SHOULD NOT contain fractional parts [2]
The Server MUST reply with the same value in the Response object if included. This member is used to correlate the context between the two objects.

[1] The use of Null as a value for the id member in a Request object is discouraged, because this specification uses a value of Null for Responses with an unknown id. Also, because JSON-RPC 1.0 uses an id value of Null for Notifications this could cause confusion in handling.

[2] Fractional parts may be problematic, since many decimal fractions cannot be represented exactly as binary fractions.
Version 1.0 sagt dazu ebenfalls nur
id - The request id. This can be of any type. It is used to match the response with the request that it is replying to.

Meiner Ansicht nach, dürfte dieses Verhalten daher ein Bug sein:
Sende ich einen Request mit der id 0, erhalte ich einen Bad Request Fehler. Mit id 1 klappt das.
Anders gesagt: Ich musste die Library jetzt patchen, damit sie mir OPSI zusammen funktioniert.
Wäre schön, wenn das auf OPSI-Seite korrigiert würde :)

Sorry, falls ich komplett daneben liege...
dark alex
Beiträge: 326
Registriert: 11 Mär 2015, 10:09

Re: "Bad Request" bei RPC-Api-Call mit ID 0

Beitrag von dark alex »

übrigens gibt der call setHostNotes als "result" auch den Wert Null zurück, ich bin mir nciht sicher, ob das so sien darf - die library sieht das jedenfalls als Fehler an.
Dazu hab ich nichts gefunden, nur dass result vorhanden sein MUSS, nicht jeodch ob es Null sein DARF

//Edit:
Jedoch dürfen laut Spezifikation error und result nicht gleichzeitig existieren... Soe sieht die Antwort von OPSI aus:

Code: Alles auswählen

{
"id": 1,
"result": null,
"error": null
}

//Nochmal ein Edit:
Ich habe mir jetzt eine eigene kleine Library gebaut, um das Verhalten nochmal sicher zu bestätigen:

Code: Alles auswählen

Array
(
    [0] => Array
        (
            [direction] => out
            [value] => {"id":1,"method":"setHostNotes","params":["it-opsitest2.<DOMAIN>","test"]}
        )

    [1] => Array
        (
            [direction] => in
            [value] => {"id": 1, "result": null, "error": null}
        )

)
Value ist der von mir(out)/OPSI(in) gesendete String
Antworten