0

We are using the new gcp cloud functions using Java / Kotlin.

As in the current reference implementations, we are returning org.springframework.messaging.support.GenericMessage objects.

So our code looks like this (Kotlin):

   fun generatePdfInBase64(message: Message<Map<String, Any>>): Message<*> {
        val document = process(message)
        val encoded = Base64.getEncoder().encodeToString(document.document)
        return GenericMessage(encoded)
    }

We were not able to find any way to include a custom http response code to our message, e.g. 201 or something. The function only responds 200 in case of no exception or 500.

Does someone know of a way to do this?

Best wishes

Andy

DAndy
  • 117
  • 11

1 Answers1

0

As it is mentioned at the official documentation, the HttpResponse class has a method called setStatusCode where you are able to set the number of the status as your convenience

For example:

 switch (request.getMethod()) {
      case "GET":
        response.setStatusCode(HttpURLConnection.HTTP_OK);
        writer.write("Hello world!");
        break;
    

On the other hand the constructor of the GenericMessage receives as parameter a payload, therefore I think you can create a string with a json format and use the constructor for create your GenericMessage instance with the status response you need.

If you want to know more about the statuds codes take a look at this document.

Harif Velarde
  • 733
  • 5
  • 10
  • Thank you for your answer. We did not find any way to insert a status code into the constructur / the headers of GenericMessage though. – DAndy Oct 05 '20 at 09:25