Recommendations for a service that generates a Zip file

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.

@NicolasRouquette

Hi Nicolas maybe there are some points that you have missing on consuming this endpoint with a curl or wget in fact if you define your service call like you did
ServiceCall[NotUsed, ByteStream
Then you should consume him with other protocol and not the HTTP because this call is not an http anymore is an websocket endpoint, so try to use https://www.websocket.org/echo.html and tell me if it works. =D. If you consume with an HTTP request you ill receive the given error “Upgrade: websocket” so use WS or WSS.

If you want to consume it with HTTP my suggestion is use something between you microservice and your request like a controller tyhen you can consume the controller endpoint with HTTP request and internally build your zip file using the same ServiceCall that you mention above.

Thanks @VictorBLS for the feedback.

Indeed, I realize that the endpoint is a websocket; however, consuming that endpoint with a simple CLI tool turns out to be really difficult.

I’ve tried wscat but it gives me a non-helpful message:

wscat -H "Authorization: Bearer ..." ws://my_endpoint_url
error: Error: unexpected server response (302)
>

I tried websocat; however, it
seems that in order to pass an option, I have to use the advanced mode with 2 addresses.

Although it’s nice that Lagom supports WebSockets, it surprises me how difficult it is to consume such an endpoint.

My original problem is to send a Zip file as a response to and endpoint.
Clearly, this is not rocket science and it should be easy to do; unfortunately it is anything but easy.

  • Nicolas.

Hi @NicolasRouquette

Can you share a toy exemple ?

I’ve been using Lagom websockets for a while and I really don’t get this consume problem.