openfaas / templates

OpenFaaS Classic templates
https://www.openfaas.com
MIT License
276 stars 228 forks source link

response is corrupted by app.java when converting byte[] to and from string in specific use case #182

Open przemeqq opened 4 years ago

przemeqq commented 4 years ago

Expected Behaviour

Ability to provide byte[] as response body in handler

Current Behaviour

In java12 template, you can't provide byte[] as response. You need to convert it to string in handler and in app.java it is again converted to byte[]. In result it gets corrupted. In our use case (generating pdf using JasperReports) we received blank PDFs

Possible Solution

Another template "Java12Byte" or changes to Java12 As workaround (1) did custom template (2 alternative ) encoded byte[] with base64 and decoded in client (unnecessary step)

Context

Some software eg JasperReports provides byte[] or outputstreams and they cannot be converted to String because they are getting corrupted (lost 2 workdays trying to understand cause). I tried to use different encoding but it is not working. According to response in: https://community.jaspersoft.com/questions/976061/pdf-byte-array-encoding it will not work.

Your Environment