I have a service methhod like this:
def generateProcessDriverProjectTemplate
(process_uuid: UUID)
: ServiceCall[NotUsed, ByteStream]
In the descriptor, I just added this like other methods:
restCall(Method.GET, "/api/processes/:process_uuid/generateProcessDriverProjectTemplate", generateProcessDriverProjectTemplate _),
I can write a simple unit test like this:
"generate driver process" in {
client
.generateProcessDriverProjectTemplate(createdProcess.uuid)
.invokeAccess(publicToken, NotUsed)
.map {
source: Source[ByteString, NotUsed] =>
val zipArchive: ByteString = source.runWith(Sink.fold(ByteString.empty)(_ ++ _)).futureValue
val unzipResultMap: Map[String, ByteString] = ProcessDriverTemplateGenerator.unzip(zipArchive)
unzipResultMap should have size 2
val driver = unzipResultMap.get(ProcessDriverTemplateGenerator.DRIVER_FILE)
driver should not be None
println(s"Driver:\n------\n${driver.get.utf8String}\n------\n")
val docker = unzipResultMap.get(ProcessDriverTemplateGenerator.DOCKER_FILE)
docker should not be None
println(s"Dockerfile:\n------\n${docker.get.utf8String}\n------\n")
Succeeded
}
}
However, this particular endpoint is very awkward to use.
At least, it’s not obvious how to call it with curl.
I get a status 429 with a message “Upgrade: websocket”
That makes sense according to the Lagom doc:
https://www.lagomframework.com/documentation/1.6.x/scala/ServiceDescriptors.html#Streamed-messages
Unfortunately, this is not very practical because one can use simple tools like curl
or wget
to download such a file via a web socket.
Is there an a simple alternative?
I’m aware of the archived download file example:
The caveat with that receipe is that it’s for a CSV file.
Do I need to define my own serializer for a Zip archive somehow?
Surely someone must have done that somewhere.
Suggestions?
- Nicolas.