diff --git a/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/CrnEmitter.kt b/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/CrnEmitter.kt index bef0646824..0d51ebe9cf 100644 --- a/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/CrnEmitter.kt +++ b/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/CrnEmitter.kt @@ -1,11 +1,12 @@ package uk.gov.justice.digital.hmpps.controller import org.springframework.beans.factory.annotation.Value +import org.springframework.http.MediaType import org.springframework.stereotype.Controller import org.springframework.transaction.PlatformTransactionManager import org.springframework.transaction.support.TransactionTemplate import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.servlet.mvc.method.annotation.SseEmitter +import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter import uk.gov.justice.digital.hmpps.service.CrnStreamingService import java.util.concurrent.Executors @@ -18,11 +19,11 @@ class CrnEmitter( private val executorService = Executors.newSingleThreadExecutor() @GetMapping("/probation-cases") - fun handleSse(): SseEmitter = SseEmitter(timeout).also { emitter -> + fun handleSse(): ResponseBodyEmitter = ResponseBodyEmitter(timeout).also { emitter -> executorService.execute { TransactionTemplate(transactionManager).execute { crnStreamingService.getActiveCrns().use { stream -> - stream.forEach { emitter.send(it) } + stream.forEach { emitter.send(it + System.lineSeparator(), MediaType.TEXT_PLAIN) } emitter.complete() } }