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 REST Webservice : using Json in post/get methods

More
20 Jul 2016 15:34 - 20 Jul 2016 15:35 #1 by letancel
Hi,

I'm trying to create two Rest webservice methods, one "post" method using json in input, one "get" method getting a json in output.
I did follow the webservice tutorial with XML in output and it works perfectly but I couldn't do the same with Json.

I have a very simple json format :
{
	"personne" :
	{
		"id" : 1,
		"firstname" : "jean",
		"lastname" : "durand",
		"company" : "ysance"
	}
}
(attachment : json_metadata.PNG)

1. post Method : load the json entry into a temporary table (attachment : json_post.PNG)
-> Nothing happened -> Error message in XML
2. get Method: get data from the temporary table and retun them in json format (attachment : json_get.PNG)
-> I get the following error :
javax.xml.ws.WebServiceException: java.lang.RuntimeException: [was class com.ctc.wstx.exc.WstxUnexpectedCharException] Unexpected character '{' (code 123) in prolog; expected '<'

Am I missing something?
Attachments:
Last edit: 20 Jul 2016 15:35 by letancel.
More
20 Jul 2016 17:03 - 20 Jul 2016 17:04 #2 by Cyril Dussud
Replied by Cyril Dussud on topic REST Webservice : using Json in post/get methods
Hi,

For Stambia JSON Web Services you have to use the http endpoint version 2.
For this you just have to use a different url to execute the deliveries:
http://<hostname>:42200/rest/StambiaDeliveryService/2/<deliveryName>

This new endpoint is available for Runtime version S17.2.15 or higher

Do you have the correct behavior when using this url ?
Last edit: 20 Jul 2016 17:04 by Cyril Dussud.
More
21 Jul 2016 10:21 - 21 Jul 2016 10:22 #3 by letancel
Hi,

Is there a documentation on the different endpoints?

When I'm using the endpoint 2, here's what I got :
1. Post Method :
I'm using Postman (chrome extension to test webservices).
To the URL : http://servbdd3:42200/rest/StambiaDeliveryService/2/postPersonneInfos, I join the JSON file :
{"json_personne" : 
    {
	    "personne" :
    	{
    		"id" : 1,
    		"firstname" : "jean",
    		"lastname" : "durand",
    		"company" : "ysance"
    	}
    }
}

But it only inserts NULL value in all columns of my target table...

2. Get method : I don't have errors anymore, but a blank page instead..
Last edit: 21 Jul 2016 10:22 by letancel.
More
21 Jul 2016 14:56 #4 by Cyril Dussud
Replied by Cyril Dussud on topic REST Webservice : using Json in post/get methods
Hi,

Unfortunately there is no documentation yet for the different endpoint.

1. For the post method how do you join the JSON file ? You have to put it in the body of the POST request

2. Did you checked if the file loaded by your mapping exists and is not empty after the execution ?
Moreover, make sure it is the same file that you defined as output of your webservice
E.g. If you changed the 'Output File Name' of the Template in your Mapping, the json file will not be stored at the same place at where it is defined on the Metadata.
So the file will not be found for sending the output response.
More
21 Jul 2016 17:44 - 21 Jul 2016 17:59 #5 by letancel
1. Post method :
Yes I put the json file in the body (please see the attachment).

2. Get method :
I'm not sure if the JSON metadata is well set, could you please have a look in the json_metadata.PNG?
When I execute the URL : http://servbdd3:42200/rest/StambiaDeliveryService/2/getPersonneInfos?id=1
The ws is called but nothing happened : I still have the blank page and json is not modified.. still in the same folder as it's configured in the metadata.
Attachments:
Last edit: 21 Jul 2016 17:59 by letancel.
More
22 Jul 2016 17:09 - 28 Sep 2016 16:10 #6 by Cyril Dussud
Replied by Cyril Dussud on topic REST Webservice : using Json in post/get methods
Hi,

Can you please send a request to the support team ?
We'll treat this in a ticket and update this topic when we have the solution.

Thanks
Last edit: 28 Sep 2016 16:10 by Thomas BLETON.
More
28 Jul 2016 14:03 #7 by Cyril Dussud
Replied by Cyril Dussud on topic REST Webservice : using Json in post/get methods
Hi,

After investigating through the support, we found the following solutions:

POST method:
The JSON object that was sent in the body did not have the same structure has the JSON Metadata set as input.
This was the reason why null values where inserted.

GET method
The web service returned a blank page because the Mapping used to create the JSON Response file was not set correctly.
The repetition keys were not mapped so no file was generated.
As a consequence the response was empty.

As a complement, we remind that for calling Stambia JSON Web Services, the endpoint version 2 or higher is required.
If you are waiting for JSON data and getting an XML response, make sure you are using the correct URL.
More
28 Jul 2016 15:35 #8 by letancel
Thanks!
I understand better how to implement Webservices through Stambia, however I'm not sure to get well how endpoint works.

I did the same POST method as I did with Json but this time using XML in input.
It's only working when I use the endpoint 2.. So I'm a bit confused.
More
01 Aug 2016 11:19 #9 by Thomas BLETON
Replied by Thomas BLETON on topic REST Webservice : using Json in post/get methods
The Runtime provides several endpoints. They are listed in the Runtime's startup log sequence:
01/08/2016 11:14:49,392 - SOAP Endpoint: http://pc-tbleton:42200/wsi/DeliverableService?WSDL
01/08/2016 11:14:49,396 - SOAP Legacy "Non WSI-Compliant" Endpoint: http://pc-tbleton:42200/StambiaDeliveryService?WSDL
01/08/2016 11:14:49,402 - HTTP Rest Endpoint v2: http://pc-tbleton:42200/rest/StambiaDeliveryService/2/<deliveryName>
01/08/2016 11:14:49,407 - HTTP Rest Endpoint v1: http://pc-tbleton:42200/rest/StambiaDeliveryService/1/<deliveryName>

Each Endpoint provides its own way to expose deliveries (Soap, Rest, Xml, Json...).
Working with Json responses requires "HTTP Rest Endpoint v2" (the one with "/2/" in the URL).
I hope it clarifies a little - we will prepare more doc / articles on this subject.
More
16 May 2018 14:11 #10 by nada
Hello ,

What are The repetition keys ?