How to process JSON/XML string in SAP Cloud Applications Studio? – Part 3


Written by: Kristián Kačinetz, SAP Developer & Ondrej Rimovský, SAP Developer



In the first part of this series of articles, we presented how to implement a simple SOAP service in Java. In the second part, we extended this simple SOAP service with data processing of the REST service and their sending in the SOAP format.


In this final part of the series, we will go through the implementation of the SOAP web service in the SAP Cloud Application Studio. In the SAP Cloud Application Studio, we will gradually go through the implementation of the Business Object, ABSL scripts, and screen generation.

 

 

Implementation

 

The first step of implementation is to create a new project in SAP Cloud Application Studio. In the new project, we will create a new Business Object, which we will name, for example, Corona.


The content of the Business Object will be as follows:

 

import AP.Common.GDT as apCommonGDT;

businessobject Corona {
		[Label("Country")][AlternativeKey] element Country: MEDIUM_Name;
		[Label("Confirmed")] element Confirmed:INTEGER_Quantity;
		[Label("Dead")] element Dead:INTEGER_Quantity;
		[Label("Recovered")] element Recovered:INTEGER_Quantity;
		[Label("Updated Date")] element UpdatedDate:Date;
		[Label("Updated Time")] element UpdatedTime:Time;

		action LoadDataFromWS;
}

 

Subsequently, we activate the Business Object and after the activation, we have script files created for it. After generating files for scripts, we can generate screens for the Business Object. For simplicity, we will use object-based navigation, and fill in the Short ID field in the form:


 

In the Cloud for Customer web interface, we log in as an administrator, navigate to the Administrator tab and then Business Users, we search for our account and click Edit -> Access Rights, sort ascending by Work Center / View Name, and find by the name we entered in the previous form:



We assign the right “to view” to our users and save. In the SAP Cloud Application Studio, we add a new item and choose External Web Service Integration from the list. For example, we name the new item CoronaService:


 

On the next screen, we select Web Service Type to SOAP. In the next step, we need to upload the WSDL of our service. The WSDL file can be obtained from the interface of our service, which we created in the previous sections of the manual, in a browser at:

 

https://{your_url}/soap_guide/guideService?wsdl

 

After loading the WSDL file in the browser, we save the file as {file} .wsdl. By changing the parameter in the url address of our SOAP service, we also get an XSD scheme for our web service. The parameter needs to be changed from wsdl to xsd = 1:

 

https://{your_url}/soap_guide/guideService?xsd=1

 

We save the file as {file} .xml. After downloading these files, it is necessary to edit the wsdl file and change the XSD schema address in it. In our case, we named these files guideService.wsdl and guideService.xml. So we are editing the file guideService.wsdl, a line referring to the XSD schema online:

<xsd:import namespace="http://soap/" schemaLocation="https:// {your_url}/soap_guide/guideService?xsd=1" />

 

We change the line to point to a local file:

<xsd:import namespace="http://soap/" schemaLocation="guideService.xml" />

 

We return to creating a new item in SAP Cloud Application Studio. We insert both files on the current screen:


 

In the next step, we will check the Create Communication Scenario and fill in the necessary data, we can also enable unsecured URLs:


 

After creating the files, we open the Communication Scenario and adjust the Communication Type to A2X, in the services tab. We will make sure that we have the following checked:


 

If the services in Communication Scenario are not available, we will log out of the Cloud Application Studio and log in again. We then activate both new items and right-click on Communication Scenario. We will create a new communication system:

 

 

At the bottom of System Instances, we add a new line and copy the system ID, then we select Web Service as the preferred application protocol:


 

Then we save the communication system and click on the Actions button where we activate it. In SAP Cloud Application Studio, we right-click on the Communication Scenario again and create a new Communication Arrangement. From the list of available scenarios, we choose CoronaServiceCommScena. In the next step, we select the system we created as the System Instance ID. We press the next button and select Edit Advanced Settings on the next screen. We will change the Use Basic Settings switch to No. We will make other settings according to the following picture:

 

 

We save and activate the Communication Arrangement. After this step, we should be able to test our web service in SAP Cloud Application Studio. To test, we right-click on the web service integration and select Test Service Operations. On the screen that appears, we will select the service and, if necessary, fill in the required data. We will then send the request and wait for a response:



 

We will add the following code to our action:

 

import ABSL;

var data : elementsof Corona;
var Response = Library::CoronaService.getCountryDataList(" ", "CoronaServiceCommScena");

var CommFault = Response.CommunicationFault;
var CommFaultItems = CommFault.Item;

if(CommFaultItems.Count() == 0)
{
	foreach(var CountryData in Response.return.countryDataList)
	{
		var query = Corona.QueryByElements;
		var selparam = query.CreateSelectionParams();
		selparam.Add(query.Country.content, "I", "EQ", CountryData.country);
		var result = query.Execute(selparam);
		if(result.Count() > 0)
		{
			var inst = result.GetFirst();
			inst.Confirmed.content = CountryData.confirmed;
			inst.Dead.content = CountryData.dead;
			inst.Recovered.content = CountryData.recovered;
			inst.UpdatedDate = CountryData.updated.GetDate();
			inst.UpdatedTime = CountryData.updated.GetTime();
		}
		else
		{
			data.Confirmed.content = CountryData.confirmed;
			data.Country.content = CountryData.country;
			data.Dead.content = CountryData.dead;
			data.Recovered.content = CountryData.recovered;
			data.UpdatedDate = CountryData.updated.GetDate();
			data.UpdatedTime = CountryData.updated.GetTime();
			Corona.Create(data);
		}
	}
}

 

We will open our object in the web interface, add a new item, and run our script:


 

After running the script and saving the item, we have all the data received from the web service based on our object:


Conclusion

As a final step, we completed this series of articles, during which we created a SOAP web service that enables easy data processing from the REST web service in the SAP Cloud Application Studio. To create the service, we used Java, which allows you to easily create a SOAP web service.

This series of articles was created due to the requirement for easy processing of responses from REST web services, as SAP Cloud Application Studio does not currently provide the ability to native processing of such responses in JSON / XML format. In the manual, we described the way in which it is possible to process responses in JSON format, but it is easy to modify the implementation in Java so that it can also process responses in XML format.


Part 1
Part 2

Stay tuned to #AND!

Sign-up for newsletter