RESPONSE BODY TRANSFORM is not Working

I am trying to create a api that is trying to hit a SOAP End Point. But I am facing a issue. Below are steps I have followed to

1. I have used TYK on Cloud for this api. I have created the api entered all the required details in core settings mentioned below and saved.
API Name*: Test IP API
API Slug: test-ip-api
Target URL: http://www.webservicex.net/geoipservice.asmx
Authentication mode: Open(Keyless)

2. In the EndPoint Designer added the below setting:
Method Added - Get without any path
Plugins Added - MODIFY HEADERS , BODY TRANSFORMATION

3. In MODIFY HEADERS for request and response below are the details entered.
--------
REQUEST:
--------
Content-Type: application/xml
SOAPAction: http://www.webservicex.net/GetGeoIP
--------
RESPONSE:
--------
content-type: application/json

4. In BODY TRANSFORMATION below are the details added.
--------
REQUEST:
--------
No Transformation added

---------
RESPONSE:
--------
Input Type:  XML

CASE 1:
No Body Transformation

CASE 2:
Template : {{.}}

CASE 3:
Hello

5. Updated the API an invoked the URL using insomnia using the below url
apiurl/GetGeoIP?IPAddress=234.33.45.3

6. Below is the result which I got in the Preview tab. And My Header - Content-Type is changed to "application/json" as per the Modify headers.

CASE 1:
<GeoIP
    <ReturnCode>1</ReturnCode>
    <IP>234.33.45.3</IP>
    <ReturnCodeDetails>Success</ReturnCodeDetails>
    <CountryName>Reserved</CountryName>
    <CountryCode>ZZZ</CountryCode>
</GeoIP>

CASE 2:
map[]

CASE 3:
Hello

I would like to know why the returned response is blank in CASE 3. When we are trying to apply a transformation {{.}}. But when there is no transformation as in CASE 1, I am able to see the XML response.
Also let me know where can I check the logs for typ cloud.

I have also included a youtube recording for your reference.

**http://youtu.be/vUGhBMU8rfQ?hd=1**

Thank you in advance.

Regards,
Madhavi

Hi there, based on your YouTube video, you have not specified a path for the gateway to apply the transformations to.

The path can be a regular expression if you wish it to match multiple paths.

Hello ahmet,

Thank you for the quick response.

I have tried keeping GetGeoIP{.} and {.} and {.} in the PATH for GET Method, but for all of them the output is same as in CASE 2 i.e., map[].

Could you please let me know what could be the best possible way to define this path ?

Many Thanks,
Madhavi

Hi Madhavi

Try the below template in your transform, it should turn the XML into a formatted JSON:

    "return_code": "{{ .GeoIP.ReturnCode}}",
    "ip": "{{ .GeoIP.IP }}",
    "return_code_details": "{{ .GeoIP.ReturnCodeDetails }}",
    "country_name": "{{ .GeoIP.CountryName}}",
    "country_code": "{{ .GeoIP.CountryCode}}"
}

Let me know how that goes and if you need further help.

Josh @ Tyk.io

Hello Josh,

Thank you for the response.

Below is the output after applying this transformation. 
{
"return_code": "<no value>",
"ip": "<no value>",
"return_code_details": "<no value>",
"country_name": "<no value>",
"country_code": "<no value>"
}
     
I doubt, the problem here is that the XML output from the SOAP is not redirected to the TYK.IO when Transformations are being applied. That is the reason why <no value> is being printed for all the xml values.
     
Could you please suggest a solution for this?
     
Also let me know how to enable debug logging for the api in the tyk cloud, so that I can debug and verify the logs for the response returned.

Thanks,
Madhavi

Logs are unavailable on cloud unfortunately including debug logging. If you wish to do some debugging on your own environment I would recommend running your own free on premises installation.

Are you getting a response from the upstream at all? It looks like the template can see no values in the returned XML if there are any.

Ok i ran a quick test and there is a problem with the Go XML library not being able to decode the returned XML from the site when transforming it. There are likely some non-standard xml entities in the response.

I’m not sure where to go from here, I’ll test with httpbin XML endpoint to see if this is a common bug or not.

Thanks
Josh @ Tyk.io

Thanks Josh for your response. I will wait for you reply on this issue.

Regards,
Madhavi

Hi

I tested with another site returning XML and the transform works fine. The problem is that the response body from the geo ip service contains some characters that our XML parser can’t handle.

I would try another site to test body transforms if you can.

Hello Josh,

Thank you for your help. I tried using another SOAP based Webservice and I am able to get back the get XML response which then has been transformed to Json by the body transformation rules. It worked for me.

I have another question, if you had to use a POST method for the SOAP service, is it necessary to add SOAP ACTION as a request header? And are the request transformation rules going to be applied on the Json input and passed as input XML to SOAP service?

Thank you
Madhavi