Calling a web service - reponse body transform

Hi,

I’m very new to Tyk, so this is why I post this question under setting up Tyk. This is a very newbie question.

My basic case is the following: call a webservice, transform the request body from json, receive the response and tranform the response body from xml to json.

This is what I have done:

  • I’m running Tyk on premise in docker containers
  • I have chosen a simple test web service: http://www.webservicex.net/geoipservice.asmx
  • Created an API with the dashboard
  • In the core settings: added a name, slug, listen path and set the Authentication mode to “Open”
  • In the endpoint designer: added an endpoint
  • The endpoint: set method to POST, no extra path
  • The endpoint: added Body transform, for the request → result is a XML
  • The endpoint: added Modify request headers, added the required headers for content-type and SOAPAction
  • Tested the API with Postman: worked great!
  • The endpoint: added Modify response headers, removed the unwanted headers and added the content-type application/json
  • The endpoint: added the Body transform for the response body. I started simply by returning a fixed json { “result” : “OK” }
  • Updated and then tested the API with Postman: Postman reports that the API does not reply
  • Checked the docker output:level=error msg=“Error unmarshalling XML: xml.Decoder.Token() - XML syntax error on line 1: invalid character entity & (no semicolon)”
  • The endpoint: removed the response Body transform → API works
  • Checked the validity of the XML returned by the service: XML seems to be valid.

What could I do to fix this / what did I do wrong?

Thanks in advance for your answer.

Ger

Can you give this XML input so we can validate it against our XML parser?

Hi,

Thanks for the quick reply.

The response xml:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <GetGeoIPResponse xmlns="http://www.webservicex.net/">
            <GetGeoIPResult>
                <ReturnCode>1</ReturnCode>
                <IP>192.168.1.1</IP>
                <ReturnCodeDetails>Success</ReturnCodeDetails>
                <CountryName>Reserved</CountryName>
                <CountryCode>ZZZ</CountryCode>
            </GetGeoIPResult>
        </GetGeoIPResponse>
    </soap:Body>
</soap:Envelope>

Ger

Can you also pls put here transformation you trying to apply?

Thank you!

{
“result” : “OK”
}

I set the input type to XML.

Hi

I had a look into this and the problem we have is that the Go XML parser we use can’t handle the response body it has to parse from that endpoint. I tested against httpbin’s XML endpoint and it worked fine so unfortunately is an edge case to do with what the geoipservice is returning.

Hi,

Thanks for your reply. This was only a test for me, so I’m not beholden to this endpoint. I will try to use the real endpoint soon. (I am curious to why this failed: was it the namespaces?)

Thanks for all the help.

Ger

As much as I could gather from diving into the code was there is an entity returned in the response that isn’t in the Go XML packages entity library.

Josh