2

I have a json response using the Http Client Adapter which has the below format

{
  "?xml": {
    "@version":"1.0",
    "@encoding":"utf-8"
  },
  ArrayOfBusinessTypeAPI {
    "@xmlns:xsd":"http://www.w3.org/2001/XMLSchema",
    "@xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance",
     ...
  }
}

I need some information on how the below elements can be defined in the event definition.

1.?xml

2.@version

3.@xmlns:xsd

As per the documentation "@" is used for substitution and : for coassignment. Can someone please provide any insight as to how this can be done.

Snel23
  • 1,381
  • 1
  • 9
  • 19

1 Answers1

1

I assume you mean in the yaml mapper codec, in which case you can simply quote the keys and this should work:

mapFrom:
  - payload.xml: "payload.?xml"
  - payload.version: "payload.@version.myField2"
  - payload.xmlns_xsd: "payload.@xmlns:xsd"

If you were asking how to declare an event in EPL to handle this response, you don't need to use the exact naming scheme in your event definition. You could have:

event Response {
    string xml;
    string version;
    string xmlns_xsd;
}

And then using the mapper codec map between the two fields like so:

mapFrom:
  - payload.xml: "payload.?xml"
  - payload.version: "payload.@version.myField2"
  - payload.xmlns_xsd: "payload.@xmlns:xsd"

EDIT

So the first thing stopping your event parsing is that your response isn't valid JSON. The line "ArrayOfBusinessTypeAPI {" would need to be ""ArrayOfBusinessTypeAPI": {". You can only use the mapper codec to parse JSON.

The second reason this isn't working is because the content type is set to text/html. Does the JSON codec have filterOnContentType set to true? If so, it won't transform this message.

However, if the JSON is valid and gets processed by the JSON codec, you can correctly map the event like so:

mapFrom:
 - payload.id: metadata.requestId
 - payload.xml: "payload.?xml"
 - payload.version: "payload.xml.@version"
 - payload.xsd: "payload.ArrayOfBusinessTypeAPI.@xmlns:xsd"
 - payload.xsi: "payload.ArrayOfBusinessTypeAPI.@xmlns:xsi"
 - payload.encoding: "payload.xml.@encoding"

Which maps to an event:

event Resp {
    dictionary<string, string> xml;
    string version;
    string xsd;
}
  • Hi Antony, i tried your suggested way but it did not help.I am getting the below error:- Error while transforming message: Could not find payload.?xml in message; Message< ...> will be dropped. – Eshaan Bengani May 21 '19 at 13:46
  • Could I see the dropped message? It might help debug what's happening – Antony Marsden May 21 '19 at 13:50
  • 1
    I am unable to post the entire message, it says too long by 252 characters.Pasting the payload part if it helps ----> payload={id:2,contentType:text/html,body:{"?xml":{"@version":"1.0","@encoding":"utf-8"},"ArrayOfWebBusinessTypeAPI":{"@xmlns:xsd":"http://www.w3.org/2001/XMLSchema","@xmlns:xsi":"http://www.w3.org/2001/XM ...> – Eshaan Bengani May 22 '19 at 05:23
  • Ah, there's the problem. You would need " - payload.xml: "payload.body.?xml"" – Antony Marsden May 22 '19 at 08:14
  • Its says payload.body.?xml not found now....the yaml is given below `mapFrom: - payload.body: payload - payload.id: metadata.requestId - payload.contentType: metadata.contentType - payload.xml: "payload.body.?xml" - payload.version: "payload.body.@version" - payload.xsd: "payload.body.@xmlns:xsd" - payload.xsi: "payload.body.@xmlns:xsi" - payload.encoding: "payload.body.@encoding" defaultValue: - metadata.contentType: text/html` – Eshaan Bengani May 22 '19 at 09:29
  • I've figured out the issue and updated my answer accordingly. Hope that helps :) – Antony Marsden May 22 '19 at 10:30