Skip to main content
Solved

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


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?

Best answer by neilhellas

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.

 

 

View original
Did this help you find an answer to your question?

5 replies

gazza
Contributor
Forum|alt.badge.img+6
  • Contributor
  • July 30, 2021

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.


  • Author
  • August 3, 2021
gazza wrote:

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?


  • Author
  • Best Answer
  • August 5, 2021

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.

 

 


gazza
Contributor
Forum|alt.badge.img+6
  • Contributor
  • August 5, 2021
neilhellas wrote:

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.


malek
  • January 15, 2024

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.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings