From 7d69fc9d2de86b78e4a1593567b401d46a6220c5 Mon Sep 17 00:00:00 2001 From: dankito Date: Mon, 10 Apr 2023 20:13:30 +0200 Subject: [PATCH] Implemented encoding response bytes with Base64 --- .../net/codinux/banking/epcqrcode/rest/EpcQrCodeResource.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/EpcQrCodeRest/src/main/kotlin/net/codinux/banking/epcqrcode/rest/EpcQrCodeResource.kt b/EpcQrCodeRest/src/main/kotlin/net/codinux/banking/epcqrcode/rest/EpcQrCodeResource.kt index cbca111..9cd343e 100644 --- a/EpcQrCodeRest/src/main/kotlin/net/codinux/banking/epcqrcode/rest/EpcQrCodeResource.kt +++ b/EpcQrCodeRest/src/main/kotlin/net/codinux/banking/epcqrcode/rest/EpcQrCodeResource.kt @@ -11,6 +11,7 @@ import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody import org.eclipse.microprofile.openapi.annotations.responses.APIResponse import org.eclipse.microprofile.openapi.annotations.tags.Tag import org.slf4j.LoggerFactory +import java.util.* import javax.ws.rs.* import javax.ws.rs.core.MediaType import javax.ws.rs.core.Response @@ -23,6 +24,8 @@ class EpcQrCodeResource { protected val epcQrCodeGenerator = EpcQrCodeGenerator() + private val base64Encoder = Base64.getEncoder() + private val log = LoggerFactory.getLogger(EpcQrCodeResource::class.java) @@ -51,7 +54,7 @@ class EpcQrCodeResource { private fun handleJsonRequest(request: GenerateEpcQrCodeRequest): Response { try { val epcQrCode = epcQrCodeGenerator.generateEpcQrCode(mapToEpcQrCodeConfig(request), request.imageHeightAndWidth) - val qrCodeBytes = epcQrCode.bytes // TODO: convert to Base64 + val qrCodeBytes = base64Encoder.encode(epcQrCode.bytes) return Response.ok(GenerateEpcQrCodeResponse(qrCodeBytes)) .header("Access-Control-Allow-Origin", "*")