Implemented encoding response bytes with Base64

This commit is contained in:
dankito 2023-04-10 20:13:30 +02:00
parent 7a6d6055f1
commit 7d69fc9d2d
1 changed files with 4 additions and 1 deletions

View File

@ -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.responses.APIResponse
import org.eclipse.microprofile.openapi.annotations.tags.Tag import org.eclipse.microprofile.openapi.annotations.tags.Tag
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.util.*
import javax.ws.rs.* import javax.ws.rs.*
import javax.ws.rs.core.MediaType import javax.ws.rs.core.MediaType
import javax.ws.rs.core.Response import javax.ws.rs.core.Response
@ -23,6 +24,8 @@ class EpcQrCodeResource {
protected val epcQrCodeGenerator = EpcQrCodeGenerator() protected val epcQrCodeGenerator = EpcQrCodeGenerator()
private val base64Encoder = Base64.getEncoder()
private val log = LoggerFactory.getLogger(EpcQrCodeResource::class.java) private val log = LoggerFactory.getLogger(EpcQrCodeResource::class.java)
@ -51,7 +54,7 @@ class EpcQrCodeResource {
private fun handleJsonRequest(request: GenerateEpcQrCodeRequest): Response { private fun handleJsonRequest(request: GenerateEpcQrCodeRequest): Response {
try { try {
val epcQrCode = epcQrCodeGenerator.generateEpcQrCode(mapToEpcQrCodeConfig(request), request.imageHeightAndWidth) 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)) return Response.ok(GenerateEpcQrCodeResponse(qrCodeBytes))
.header("Access-Control-Allow-Origin", "*") .header("Access-Control-Allow-Origin", "*")