Solved

How can I generate a JSON response and custom HTTP status code when using FME Server Data Streaming service?

  • 30 July 2021
  • 5 replies
  • 57 views

I am sending JSON data to a Text File Writer. The Text File Writer has its MIME type set to "application/json", yet the response Content-Type remains "text/plain". Is there a way to force this to "application/json"? (Note: Using a JSON writer does set the content type to application/json, but it formats the response as a JSON array, which is not suitable for my calling application.)

 

Second, the application that will be using this Data Streaming service sometimes requires specific HTTP status codes to be returned. Is there a way to force the HTTP status code e.g. to 400?

icon

Best answer by neilhellas 5 August 2021, 21:12

View original

5 replies

Badge +5

Do you have multiple writers in the workspace? From memory it's the mime type of the top writer that is used. This may not help you but having a text file writer that does nothing but has the mime type of application/json allows you to have a json writer that gets that mime type.

 

Can't help with status codes sorry.

Do you have multiple writers in the workspace? From memory it's the mime type of the top writer that is used. This may not help you but having a text file writer that does nothing but has the mime type of application/json allows you to have a json writer that gets that mime type.

 

Can't help with status codes sorry.

Unfortunately that is not the case. I have tried with:

  • Text writer only, mime type set to application/json. Result: response content type is text/plain
  • Json writer preceding text writer (with mime type application/json), output stream set to the text writer. Result: response content type is text/plain
  • text writer (with mime type application/json) preceding Json writer, output stream set to the text writer. Result: response content type is text/plain

 

Has anyone got this to work?

Worked with Richard at Safe to determine that you need to set the MIME type on the Text Writer at the time when you add the Writer to the Workspace. If you try to change the MIME type later, it is ignored. Presumably this will be fixed in a future version of FME.

 

 

Badge +5

Worked with Richard at Safe to determine that you need to set the MIME type on the Text Writer at the time when you add the Writer to the Workspace. If you try to change the MIME type later, it is ignored. Presumably this will be fixed in a future version of FME.

 

 

Thanks for figuring that out and posting the result.

Hi there,

Is there any body able to sendto set a status_code depending of the recieved body ?

For exemple, if the body contain "error", I want to send back a satus_code = 400.

Which transformer, or which param do I have to configure?

Thank you.

Reply