Rest easy with Json and Binary
5 stars based on
PeopleSoft supports the MTOM protocol for sending and receiving binary data using service operations. While you can send and receive binary data using Send and receiving binary data web api, doing so requires that you Baseencode the data, which can increase message size by 33 percent or more.
The MTOM protocol enables you to send and receive binary data in its original binary form, without any increase in size due to encoding. Whether sending or receiving MTOM-encoded binary data, you use message segments to store the data. The SegmentContentType property of the Message object is used to set or read the content type of each message segment. This section discusses how to send MTOM-encoded binary data and discusses how to:.
Set target connector properties to send MTOM-encoded binary data. Develop messages to send MTOM-encoded send and receiving binary data web api data. Segments are used to add the binary data to the outgoing request. For each chunk of data, use a single segment as follows:.
Set the content transfer encoding to binary. The SetContentString method requires character data, and is not capable of passing binary data. The File object method GetBase64StringFromBinary allows a binary file to be read in and captured as a string; use this string to set the data for the newly created segment.
These references point to the MIME parts that contain the binary data. In order to be able to construct these references, Integration Broker requires that a specific XML element, PsftXopInclude, is present in the outgoing message. Each PsftXopInclude element corresponds directly to an xop: In the following example the first instance of the PsftXopInclude element corresponds to the logical point to include an image and the second PsftXopInclude element corresponds to the logical point to include a binary document:.
The value of the SegmentNumber attribute is used by Integration Broker to link the PsftXopInclude entry to a specific segment used to add the data. For the purposes of MTOM, the first segment used to add binary data is considered to send and receiving binary data web api number 1, the second segment, number 2, and so on. Care should be taken when setting these values as Integration Broker does not check to ensure that they are correct; they are used as-is to build the xop: In the previous example, the message data is not SOAP-wrapped.
An example of XML to use this feature is as follows:. You would include the previous XML in the XmlDoc object and add it to the first segment of the message. The additional segments include the binary data associated with each declaration.
The following code example provides another XML example that demonstrates using this feature:. This section discusses receiving MTOM-encoded binary data requests and discusses how to:. Enable listening connectors to receive MTOM-enoded binary data. If it is not, the message is processed normally. This is effectively a pre-processing step and is done first, before normal processing can occur.
The binary data is Base64 encoded, and is attached to the message in the form of segments. The following listening connectors can receive and process MTOM-encoded messages:.
Send and receiving binary data web api enable these properties in the integration gateway properties file. By default the properties are not enabled and are commented out. To enable a given connector, remove the comment and ensure that the property is set to true.
When these properties are enabled there is a slight performance degradation to all non-MTOM requests send and receiving binary data web api to the connectors. The degradation is a result of system process that takes place to determine if requests are MTOM-encoded messages. MTOM messages are processed in the form of message segments. The send and receiving binary data web api processes inbound MTOM requests in two general steps:.
Process the XML data contained in the first segment. For each subsequent segment, process the binary data. The first segment contains the XML data. You may be able to use the location of the PsftXopInclude elements in the XML to derive information about the binary data segments.
Consider the following inbound MTOM request example:. In this example, the XML has been structured such that the parent element contains a name value for the associated binary content.
A more complete XML might also contain information such as file type, size, or creation date. Again, the structure of this XML is not necessarily determined by Integration Broker, but rather by the design of the application itself.
All segments after the first contain the Base64—encoded binary data. This data is accessible as a string. Processing of this is also application-specific. Some applications may decide to store the encoded string for later use, while others may wish to decode it immediately. To process the string immediately, use the PeopleCode File object method WriteBase64StringToBinary to decode the string and to write it out as a byte array to a file.
Once the method has completed and the file closed, the file can be accessed as any other file on the file system. Skip to Main Content. Sending and Receiving Binary Data This section discusses how to: For each chunk of data, use a single segment as follows: Copy the data to the segment.
In PeopleCode this appears as: In the following example the first instance of the PsftXopInclude element corresponds to the logical point to include an image and the second PsftXopInclude element corresponds to the logical point to include a binary document: An example of XML to use this feature is as follows: PeopleSoft services listening connector.
Related Links Using the integrationGateway. Working With Message Segments.