Skip to main content
Solved

Protocol-independent system flow with binary or text response body


Harm Horstman
Superhero
Forum|alt.badge.img+21

We try to make one single web service that can output json, xml as well as pdf and xlsx.

The system flow works now for a text output (json, xml) or binary (pdf, xlsx) but not for both, because we assigning the 'Response Body’ property can be assigned to only one process flow variable.

So what we need is a possibility to respond with a string or a binary body.

Would that be possible? Or is there a work around?

 

 

Best answer by Vincent Doppenberg

Hello ​@Harm Horstman ,

Have you tried converting your text responses to varbinary and using a varbinary process variable for both? It's hard to be certain if this would give the desired result without trying it, but it's worth a shot. If not, then this is currently impossible and would require some changes in Indicium, for which you can create a ticket or an Idea.

Please note that when converting text to varbinary, you need to take encoding into consideration. Your best bet is to use a UTF-8 encoding, which will probably require you to collate your text to a UTF-8 collation before converting.

I hope this helps.

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

8 replies

Forum|alt.badge.img+4

Hello ​@Harm Horstman ,

Have you tried converting your text responses to varbinary and using a varbinary process variable for both? It's hard to be certain if this would give the desired result without trying it, but it's worth a shot. If not, then this is currently impossible and would require some changes in Indicium, for which you can create a ticket or an Idea.

Please note that when converting text to varbinary, you need to take encoding into consideration. Your best bet is to use a UTF-8 encoding, which will probably require you to collate your text to a UTF-8 collation before converting.

I hope this helps.


Harm Horstman
Superhero
Forum|alt.badge.img+21

Thanks ​@Vincent Doppenberg,

I will give this a try and will let let you know the outcome.

 

 


Harm Horstman
Superhero
Forum|alt.badge.img+21

Hi ​@Vincent Doppenberg ,

I tried this:

SET @response_body = CAST(@response_body_text COLLATE Latin1_General_100_CI_AS_SC_UTF8 AS VARBINARY(MAX));

The result in Postman looks almost good, see below. Do you think the NULL characters can be eliminated with some additional settings in the response header?
 

 




 


Harm Horstman
Superhero
Forum|alt.badge.img+21

Another idea that came to my mind was to assign the Response Body property to 2 different variables.

 

I tried this, but without the desired result.

Could this be a solution under certain conditions?

 


Forum|alt.badge.img+4

Hello ​@Harm Horstman,

I think this problem occurs because @response_body_test is of the type nvarchar which uses two bytes per character, which isn't changed by the collate instruction. When converting to varbinary, the extra byte turns into a null byte (00).

You should be able to avoid this by converting to varchar first:

CONVERT(VARBINARY(MAX), CONVERT(VARCHAR(MAX), @response_body_text COLLATE Latin1_General_100_CI_AS_SC_UTF8))

This seems like a lossy operation, but it shouldn't be due to the COLLATE Latin1_General_100_CI_AS_SC_UTF8 instruction.

As for the idea you mentioned, something like that would work, but it shouldn't even be necessary. Indicium is able to do this right autonomously. It doesn't right now, but it could do without any changes to the model. I have made note of this already as something to pick up soon. If you want to be able to track a ticket for this, then you can report one.

I hope this helps.


Harm Horstman
Superhero
Forum|alt.badge.img+21

Hey ​@Vincent Doppenberg ,

Super! This was it, it works.

In the process flow text outputs (json, xml, csv, etc..) are now prepared and saved in a varchar(max) variable. In the last step the text variable is converted to a varbinary with this:

SET @response_body = CAST(@response_body_text COLLATE Latin1_General_100_CI_AS_SC_UTF8 AS VARBINARY(MAX));

The varbinary variable is linked to the Response Body property. 

So thank you for the tips and if you see possibilities for further optimization in Indicium I would do that. With this we can make very generic API’s for multipurpose use.

 

 


Forum|alt.badge.img+4

Hello ​@Harm Horstman,

I'm glad to hear that it's working.

I wrote that Indicium would be able to handle this properly autonomously but that's not true, I was thinking of something else. I think the best solution to make a use case like yours easier to implement is indeed the idea that you suggested. Can you create an Idea for this here on the Community?


Harm Horstman
Superhero
Forum|alt.badge.img+21

Reply


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