Transfering documents over web service endpoints

Probably anyone who ever dealt with integration of distributed systems, no matter what the programming language is, came upon a use case where a document, such as .pdf, would need to be sent over a java web service. Usual use case involves feeding data to an isolated module for report generation, and obtaining a generated file as a result. Such transfer is not possible with out-of-the-box technologies. There exists no such "return-type" as File in Java Web Services, nor anywhere else. The only way to perform such transfer is to convert the contents of such file into a byte array which can further be packed within the XML response. This means that our report generation endpoint is going to deserialize the java object, turn it into a byte array, send it back to the client, who afterwards needs to serialize it once again into a corresponding java object, that can now be written into a specific file, and offered as a download within a favourite browser. However, beware of the fact that different browsers sometimes require specific settings of your UI framework used for downloading.

Comments

The simplest things in life are sometimes the hardest ones. Sending files is one of them, whether to the browser with correct response types in content headers, multipart uploads for bigger files or directly to a printer (e.g. with printer command language - PCL). The amount of code needed for such a simple thing always amazes me.
Artur Marcin Sz... - Sun, 12/09/2018 - 19:07 :::
No answers yet.