MrNiamh
01/04/2022, 1:05 PMfun downloadDocument(documentService: DocumentService): ContractRoute =
"document" / Path.uuid().of("documentId") meta {
summary = "Download document"
returning(OK, formBody to formExample)
} bindContract Method.GET to
{ documentId ->
{
val doc = documentService.getDocument(documentId))
Response(OK)
.with(
formBody of MultipartForm()
.with(outputFile of MultipartFormFile(filename = doc.filename, contentType = ContentType(doc.mimeType), content = doc.data.inputStream()))
)
}
}
private val outputFile = MultipartFormFile.required("outputFile")
private val formBody = Body.multipartForm(Validator.Strict, outputFile).toLens()
private val formExample = MultipartForm()
.with(outputFile of MultipartFormFile(filename = "test_file.txt", contentType = ContentType.TEXT_PLAIN, content = createTempFileWithName("byteBufferExample", suffix = ".txt")
.also { it.writeText("example") }
.inputStream()))
java.lang.IllegalArgumentException: No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.http4k.lens.MultipartForm[\“files\“]->java.util.Collections$SingletonMap[\“outputFile\“]->java.util.ArrayList[0]->org.http4k.lens.MultipartFormFile[\“content\“]->java.io.FileInputStream[\“fd\“])Once I disable that, I get:
org.http4k.contract.openapi.v3.NoFieldFound: Could not find open in sun.nio.ch.FileChannelImpl@12707084\n\tat org.http4k.contract.openapi.v3.FieldRetrieval$Companion.compose$lambda-0(FieldRetrieval.kt:17)\n\tat org.http4k.contract.openapi.v3.AutoJsonToJsonSchema.toObjectSchema(AutoJsonToJsonSchema.kt:99)
MultipartForm()
.
Next issue is that nothing actually returns from the service, just stays stuck loading until I stop the service, then swagger/postman displays the results…. very odd behaviour.dave
01/04/2022, 4:03 PMMrNiamh
01/04/2022, 4:33 PM