exist icon indicating copy to clipboard operation
exist copied to clipboard

[feature] rest-API reports validation errors

Open line-o opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe.

When an invalid XML (including HTML) resource is uploaded to exist utilising the rest-API with a PUT-request the database responds with HTTP status code 400, Bad Request. The response body is empty in that case giving the client no indication what the actual error is nor detailed information where the validation failed.

invalid.xml contents:

<?xml version="1.0" encoding="UTF-8"?>
<collection>
    <item property />
</collection>
; curl -I -X PUT http://admin@localhost:8080/exist/rest/db/temp/invalid.xml \
  -H 'content-type: application/xml' \ 
  -T invalid.xml
HTTP/1.1 100 Continue

HTTP/1.1 400 Bad Request
Content-Length: 0
Server: Jetty(9.4.48.v20220622)

In contrast uploading and parsing an invalid XML resource using XML-RPC will fail with a detailed validation error report.

Failed to invoke method parseLocal in class org.exist.xmlrpc.RpcConnection: org.xml.sax.SAXException: The XML parser reported a problem: fatal error at (3,20) : Attribute name "property" associated with an element type "item" must be followed by the ' = ' character.
org.xml.sax.SAXException: fatal error at (3,20) : Attribute name "property" associated with an element type "item" must be followed by the ' = ' character.
org.xml.sax.SAXParseException; systemId: file:///var/folders/5m/tgkp8r_90z1_j4sg82r3lz200000gn/T/exist-db-temp-file-manager-8254596085445948201/exist-db-temp-6443132455132372568.tmp; lineNumber: 3; columnNumber: 20; Attribute name "property" associated with an element type "item" must be followed by the ' = ' character.

Describe the solution you'd like

The response body of to the above PUT request to contain a detailed error message containing the validation error similar to the report as provided by the XML-RPC request.

Describe alternatives you've considered

  • not using the REST-API
  • using a custom endpoint

Additional context

This test was done with the current HEAD of the develop branch (6.1.0-SNAPSHOT)

line-o avatar Jul 13 '22 13:07 line-o