OSB-12c : Binary Message Type

In the case of both the body and attachments variables, text-, XML- and MFL-based content is placed directly inside of an XML element. For binary data, which can contain byte values that are illegal in XML, Oracle Service Bus does not place the binary content in the XML element. Consequently, the binary content cannot be manipulated, but it is handled efficiently.

When binary content is received, the Oracle Service Bus runtime stores it in an in-memory hash table and a reference to that content is inserted into the XML (body or attachments) element. This reference is represented by the following XML snippet:

<binary-content ref="..."/>
Where the ref attribute contains a URI or URN that uniquely identifies the binary content. This XML can be manipulated in an Oracle Service Bus pipeline, branch, or route node in the same way any other content can be manipulated, but only the reference and not the underlying binary content is affected.


Sample use-case:

1. Send simple text message to TextToBinary conversion proxy.
2. Save binary response obtained from step 1 and provide same as input to BinaryToText conversion proxy.

3. Save text response obtained and write the same into file.


Create new folder inside MessageType_Service

File -> New -> Folder -> Binary_MessageTypeServices along with sub folders.


Create new proxy to convert text message into binary.
Name : TextToBinaryProxyService
Service Type: Messaging service
Request: Text
Response: Binary




Next create one more proxy to convert binary message into text.
Name: BinaryToTextProxyService
Service Type: Messaging service
Request: Binary
Response: Text



Create a business service with file protocol to write response contents into a file.



Name: WriteBinaryBusinessService



Transport Details: Prefix – SampleBinaryContent
                               Suffix - .txt



Create a main proxy called ‘BinaryProxyService’ which invoke text->binary and 
Binary->text proxies.
Service Name: BinaryProxyService
Transport: http


Service Type: WSDL based


Select respective WSDL (For Eg : In this example we have used AttachmentWSDL.wsdl)





Create pipeline from design view







Create new proxy service with ‘http’ transport based protocol.




Add one more stage with ‘Assign’ activity with below expression
Here we are concatenating ‘MessageID’ and ‘Name’ and forming a single string.
This is stored in a variable called ‘TextMessage’.



Add a replace activity to replace body to contents of $TextMessage.



Save changed body into a variable called ‘$ChangedBody’.



Add a service callout to invoke TextToBinaryProxyService. Pass contents of $ChangedBody as input to this proxy and save response in a variable called $BinaryResponse.



In Response action add an Assign activity and save response in a variable called ‘$AddedBinaryResponse.’


Add a Service callout and invoke BinaryToTextProxyService. Pass contents of $AddedBinaryResponse as input to this proxy service and save response in a variable called $MessageTextResponse.



Add a Assign activity in response action of service callout to save response in a variable called ‘$ChangedMessageResponse’.



Add a route node and invoke WriteBinaryMessage business service to write contents of response from Binary->Text proxy into a file.



Add a Replace activity in Request action of route node to change body into below mentioned context.
Concat (‘This is binary to text converted message:::’, $ChangedMessageResponse)





Next add an assign activity to save contents need to be written to file in a variable called $ContentWriteIntoFile.



Add a replace activity in response action to replace contents of body and this will be displayed as final response.




Deploy developed service into local standalone local server and once deployment is successful, we can locate service in sbconsole.



Run ‘Binary_MessageTypeServicePipeLine’




Give request as mentioned below.
<SampleRequest>
<MessageId>”Some valid Id”</MessageId>
<Name>”Some Valid Name”</Name>
</SampleRequest>

Note: Since this is Any XML based service and we initially creating text message by concatenating MessageId and Name, we need to pass element name as ‘MessageId’ and ‘Name’.

In order to ease our job, we can create xsd and wsdl and create template based on this wsdl and use same in creation of pipeline.




Once execution of request is successful, we can in response Binary content and relevant converted text message.




We can see invocation trace and we can see that response text message is written into a file.





Comments

Post a Comment

Popular posts from this blog

Static code analysis of Terraform .tf files using ‘Checkov’ — Secure your infrastructure

OSB-12C : XA Transactional Support feature

OSB12c : Schema Validation - Dynamic Validation