Extracting plaintext content

Not applicable

I have a target "service" that lies about what is does. Specifically, it includes headers saying that it is returning json, but the body just contains the string "false" or "true" (not valid json).

It's a nasty old RPC system, to which I want to add a nice RESTful facade.

I haven't managed to find a way to extract the body successfully. Whatever I try the content is just blank.

Does anyone know the right approach?

I have tried Extract Variables and Javascript policies with a standard flow.

I am considering re-engineering as a Service Callout, but will this work?

0 5 473
5 REPLIES 5

@stewartritchie Can you share your sample response & your Extract Variables and JS policies? In general, extracting values based on JSON Path or XPath works well only if the content type header is set appropriately.

Also what do you mean by "re-engineering as a Service Callout"?

Not applicable

@sudheendra1 I understand that the situation I'm facing is not ideal. If the target service was returning JSON, I would not have the problem I think.

Do you know of any way of reading a plain-text payload, given that the content of the payload would be predictable. I was aiming to just wrap the poorly formed response in a valid JSON representation and send it on its way.

I have used the ServiceCallout policies, and noted that their return is an HTTP response. So I thought that I might have better access to the content via this route than using ExtractVariables.

Former Community Member
Not applicable

I'd try with a JavaScript policy. Something like this:

var response = context.getVariable("response.content");

Thank you @Srinandan Sridhar, I thought I had tried this approach (unscuccessfully). But I gave it another go and it worked.

Hi @stewartritchie As @Srinandan Sridhar suggested above, you could use a JS policy to handle the response.

The ServiceCallout policy does not alter the response content. i.e. It does not change the content-type header nor the internal format. So if your service is not returning a JSON, you still can't use ExtractVariable policy on ServiceCallout response.