Closed rmcdouga closed 4 years ago
The reason this issue is happening is that the AEM API is returning an empty document to the fluentforms
library and fluentforms
is returning the empty document to the rest-services.server
code. The rest-services.server
code writes nothing into the response to the rest-services.client
code, so no entity is created. The rest-services.client code
detects that no entity was returned, which is not what was expected, so it throws an exception.
There's a couple of problems here:
1) By convention, a REST service that is not returning any output should return an HTTP status of 204 'No Content' to indicate the lack of content was intentional. The rest-services.server
code should follow this convention.
2) The rest-services.client
code should handle this and return something to the user indicating that there was nothing to export. One approach to this would be to return an empty Document (this is what the Adobe API does) however I don't believe this is the best approach. Using the empty Document
approach means that the user of the API has to know that an empty Document
is possible and check for that. This is easy to miss if they haven't read the documentation (assuming this behaviour is documented). A better approach would be to have the exportData
API return an Optional<Document>
instead of a Document
. This makes it clear as part of the API that they are not guaranteed to get a result back.
I would propose that we make a change to the current fluentforms exportData API to return an Optional<Document>
. This involves the following changes:
fluentforms.core
to have the exportData API return Optional<Document>
Optional.empty()
return value.If anyone has additional thoughts or concerns, please leave them in the comments.
Hi Rob,
The suggestion looks good to me. Currently, we are using export data API to export data from rendered pdf and saving the result in the document variable. From the xml document, we are extracting htmloutput through xpath.
According to you, in the plugin we need to convert optional
Thanks, Ritika.
According to you, in the plugin we need to convert optional into document. I didn't get it clearly. My understanding is if we are not getting any document from API, it should just handle the error message , may be by putting the code into try catch or adding some logger.
There are actually three cases:
1) PDF Form with Data in it - This returns a Document object with XML in it.
2) PDF without Form (or other server errors) - This throws an Exception from exportData()
3) PDF Form without Data in it - This returns an empty Document (note: this is not valid XML).
It's the last case that I am concerned about. I would rather we return an empty Optional
than an empty Document as this follows the "principal of least surprise". Developers will see the API and realize that they have to allow for the case where no document is returned. Without that, they may not check for data in the Document before trying to do something with it.
Associated PR was merged (I forgot to link the PR to this issue so it wasn't closed automatically). I'm closing this issue now.
I am executing a unit test using the other PDF available the sample forms directory (SampleForm.pdf) using the following code:
When I invoke the code, I get the following error message and stack trace.
The message
Call to server succeeded but server failed to return document. This should never happen.
does not give me any indication of what the problem is or how to correct it. There are no error messages in the AEM log, so that is not helpful either.This would be problematic if a library user encounters this issue.