Welcome Guest! Log in
×

Notice

The forum is in read only mode.
Stambia versions 2.x, 3.x, S17, S18, S19 and S20 are reaching End of Support January, 15th, 2024. Please consider upgrading to the supported Semarchy xDI versions. See Global Policy Support and the Semarchy Documentation.

The Stambia User Community is moving to Semarchy! All the applicable resources have already been moved or are currently being moved to their new location. Read more…

Topic-icon Solved Map HTTP Response Body

More
23 Mar 2017 20:45 - 08 Aug 2018 09:27 #1 by beeplogic
Map HTTP Response Body was created by beeplogic
Hi,

When working with a REST web service I was wondering if it's possible to Map the HTTP Response body in addition to mapping the JSON response. The web service I'm using provides a different JSON response when an error occurs.

Standard Response (HTTP Response code 200):
{
  "id": 123,
  "key": "FOO-456",
  "self:" "http://some-url"
}

When an error occurs (HTTP Response Code 400):
{
	"errorMessages": [],
	"errors": {
		"fieldA": "The feildA specified is not a user.",
                 "fieldB": "fieldB is required"
	}
}

I am using the latest build of Stambia so I'm able to map the HTTP Response Code and Message. I would like to also log the response body for debugging purposes. I know that I could use the the parameter "received messages folder" and possible get the content that way but it seems like the wrong approach. Is there a recommended way for handling this?

My target RDBMS table structure would look something like:

ID varchar,
KEY: varchar,
HTTP_RESPONSE_CODE: int,
HTTP_RESPONSE_MESSAGE: varchar,
HTTP_RESPONSE_BODY: text
Last edit: 08 Aug 2018 09:27 by Thomas BLETON.
More
24 Mar 2017 17:08 #2 by Cyril Dussud
Replied by Cyril Dussud on topic Map HTTP Response Body
Hi,

In your Metadata, you can design the case where you have an error, by adding a 'Fault' node.
As the Input and Output nodes, you can put under a part containing the JSON structure.

For instance:


When an error occurs, like an error 400, you'll be able to retrieve the error response from this node.
Map it then as usual in your Mapping.

Can you look at the Fault node and tell me if it can help you to achieve what you want ?
Attachments:
More
24 Mar 2017 21:31 #3 by beeplogic
Replied by beeplogic on topic Map HTTP Response Body
Hi,

I gave that a try and it didn't work for me :(
Below is some screenshots of my metadata and mappings:


Attachments:
More
28 Mar 2017 17:58 #4 by Cyril Dussud
Replied by Cyril Dussud on topic Map HTTP Response Body
Hi,

The JSON response 'part' cannot be mapped directly like this.
The idea is to map the fields of the JSON Response, like this, for instance:



In the mapping, we handled the two cases that we load in different tables.
  • T_CUSTOMER_OUT table if it is ok
  • T_ERRORS when it is not

For this we are using target filters (the orange filters), that split the result based on the value of the 'id' field.
If we received a customer id, we load the customer table, if not, the error table.

Do you see the idea ?
Attachments:
More
28 Mar 2017 23:33 #5 by beeplogic
Replied by beeplogic on topic Map HTTP Response Body
Hello,

A few things I ran into:

When mapping to a Postgres target table and using the "Action Process INTEGRATION PostgreSql" template and the response is a Fault the mapping fails to insert anything into the target table. Changing the template to "Action Process INTEGRATION RDBMS" resolves this.

I was hoping to map the JSON response "part" (The body of the HTTP Response) and map it into a text field. The reason being is that the returned JSON object will change depending on the error. The keys are dynamic and could be N number:

For one request it could be:
{
	"errorMessages": [],
	"errors": {
		"fieldA": "The feildA specified is not a user."
	}
}

For another it might be:
{
	"errorMessages": [],
	"errors": {
		"fieldB": "fieldB is required"
	}
}

I do not know all the names of the fields in advanced.
More
30 Mar 2017 15:52 #6 by Cyril Dussud
Replied by Cyril Dussud on topic Map HTTP Response Body
Hi,

Ok, I understand what you want to perform.

The ability to retrieve the whole Fault HTTP Body into one field is planned and will be available in the next Runtime version (S17.4.2).
For now, the fault structure should be used as explained before.

About the dynamic return of the web service.
Stambia allows to load JSON / XML structures that contain nodes with changing name
The following articles explain how to do that:
stambia.org/doc/66-technology-articles/x...s-with-varying-names
stambia.org/doc/147-technology-articles/...s-with-varying-names

About your postgreSQL issue
Can you please report this problem to the support ?
They'll investigate on that.
Thanks ;)
More
12 Jul 2018 11:25 #7 by nada
Replied by nada on topic Map HTTP Response Body
Hello Cyril ,

I would like to know how did you define the target filters , i have a similar case, and would like to use them , but i couldn't find any article about them .

Thank you .
More
13 Jul 2018 11:43 #8 by Adrian MATYSIAK
Replied by Adrian MATYSIAK on topic Map HTTP Response Body
Hi Nada,

to define target filters you need to have a source table that is mapped to a target or multiple targets.
Then you create a normal filter on your source table, click right on the filter icon, choose "Activate" and then from the list the target for which you want you filter to be active:


I hope that helps.
Attachments:
More
13 Jul 2018 14:16 #9 by nada
Replied by nada on topic Map HTTP Response Body
It is , thank you Adrian for your response