Skip to Content
Technical Articles
Author's profile photo Aman Sharma

Passing Dynamic Configuration Value from Request mapping to Response mapping In a Synchronous Scenario

I was working in a Synchronous scenario, where to push Invoice data on a server. To fulfill this requirement I faced two challenges.

1.) When I call the PushInvoice API it needs one AuthToken which I need to generate using 2nd  Token API.

2.) The response from PushInvoice API is encrypted, to decrypt the response I have one session key which I received during the Token API call.

 

To decrypt the response I need to pass this sessing key from RQ to RS and during the RQ mapping, I need to call 2nd Token API. Generally, dynamic configuration exists only till the message sent to the receiver and to call the 2nd API we can use JAVA URI classes.

To overcome this I have created one communication channel in ID for Token API and called this channel in message mapping using SystemAccessor and Lookup Services. Further, I have passed the token and session key using dynamic configuration and in response mapping, I have captured the session key by using Dynamic Configuration Bean.

 

NOTE: While using this you can only call the receiver channel which generates some response. we can not call the FTP channel which this class.

 

ESR Part:

Java UDF to call Communication Channel

You can write this UDF in the init method of Message mapping, as this function execute before the message mapping operation.

/* 	message: String which contains the request payload for Auth API
*/
	String lv_payloadContent = "";	
	Channel restChannel;
		try {
restChannel = LookupService.getChannel("BC_Component", "CC_RestToken_rcv");
			SystemAccessor restAccessor = LookupService.getSystemAccessor(restChannel);
			InputStream inputStream = new ByteArrayInputStream(message.getBytes());
			Payload payload = LookupService.getXmlPayload(inputStream);
			Payload response = restAccessor.call(payload);

			ByteArrayOutputStream resultbyte = new ByteArrayOutputStream();
			Byte[] buffer = new byte[1024];
			int length;
while ((length = response.getContent().read(buffer)) != -1) {
				resultbyte.write(buffer, 0, length);
			}
		lv_payloadContent = resultbyte.toString("UTF-8");
		} catch (LookupException e) {
			// TODO Auto-generated catch block
			trace.addDebugMessage("{Error}"+e.getMessage());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			trace.addDebugMessage("{Error}"+e.getMessage());
		}

 

After parsing the response, I have captured the Token and decryption key in two variables and passed them dynamic configuration.

here I stored token and decryption key in two variables which I have passed in this UDF.

 

Java UDF to pass values in Dynamic Configuration

Map<String, Object> all = container.getInputHeader().getAll();
		try {
			DynamicConfiguration config = (DynamicConfiguration) all
					.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
			DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/REST",
					"Authtoken");
			DynamicConfigurationKey Sek = DynamicConfigurationKey.create("http://sap.com/Custom", "SessionKey");
config.p	ut(key1, lv_AuthToken);
	config.put(Sek, lv_decSek);
} catch (Exception e) {
		trace.addDebugMessage("[ERROR] Unable to set dynamic configuration "+e.getMessage());
		}

DynamicConfigurationKey.create(“http://sap.com/Custom”, “SessionKey”);

please note the namespace as and key name as this needs to be used in the module configuration in the REST receiver channel.

 

ID Part

In the receiver channel, we need to maintain certain DynamicConfigurationBean parameter which is used to pass the values between different messages.

I am using a REST receive channel which is used to generate Invoice. (in my scenario)

 

Processing sequence

number Module Name Type Module Key
1 AF_Modules/DynamicConfigurationBean Local Enterprise Bean Sender
2 sap.com/com.sap.aii.adapter.rest.app/RESTAdapterBean Local Enterprise Bean rest
3 AF_Modules/DynamicConfigurationBean Local Enterprise Bean Receiver

Module Configuration

Module Key Parameter Name Parameter Value
Sender key.1 write http://sap.com/Custom SessionKey
Sender value.1 module.http://sap.com/Custom
Receiver key.1 read http://sap.com/Custom SessionKey
Receiver value.1 module.http://sap.com/Custom

 

 

Here I am getting only session key in RS mapping as I have passed only the session key in module configuration in the REST channel.

 

Assigned Tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo kratika varshney
      kratika varshney

      Excellent blog …!! explained nicely..!! Keep up d good work..

      Author's profile photo Aman Sharma
      Aman Sharma
      Blog Post Author

      Thanx a lot!!.

      Author's profile photo Michelle Crapo
      Michelle Crapo

      I really like this blog.  Code with explanation really helps!

      Keep them coming.

      Author's profile photo Aman Sharma
      Aman Sharma
      Blog Post Author

      Thanx a lot!!.

      Author's profile photo Venu Ravipati
      Venu Ravipati

      Nice Read. Thanks for sharing..

      Author's profile photo Megha Aggarwal
      Megha Aggarwal

      Nicely explained, Great work.