Send and receiving binary data web api
PeopleSoft supports the MTOM protocol for sending and receiving binary data using service operations. While you can send and receive binary data using SOAP, 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 send and receiving binary data web api the Message object is used to send and receiving binary data web api 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 binary 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 send and receiving binary data web api 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 send and receiving binary data web api 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 send and receiving binary data web api of MTOM, the first segment used to add binary data is considered to be 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:. You 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 sent 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 system 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 send and receiving binary data web api 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 send and receiving binary data web api, 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 send and receiving binary data web api 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.
The responseType property of the XMLHttpRequest object can be set to change the expected response type from the server. Possible values are the empty string default"arraybuffer""blob""document""json"and "text". This is null if the request is not complete or was not successful. This example reads an image as a binary file and creates an 8-bit unsigned integer array from the raw bytes.
Note that this will not decode the image and read the pixels. You will need a png decoding library for that. An alternative to the above method utilizes the Blob interface to directly construct a Blob with the arraybuffer data. Also you can read a binary file as send and receiving binary data web api Blob by setting the string "blob" to the responseType property. The magic happens in line 5, which overrides the MIME type, forcing the browser to treat it as plain text, using a user-defined character set.
This tells the browser not to parse it, and to let the bytes pass through unprocessed. The example above send and receiving binary data web api the byte at offset x within the loaded binary data. The valid range for x is from 0 to filestream. See also downloading files. The following example sends creates a text file on-the-fly and uses the POST method to send the "file" to the server. This example uses plain text, but you can imagine the data being a binary file instead.
This is building a byte array of 8-bit integers and sending it; you can use any binary data you'd like, of course. Please, read this paragraph. Line 4 sets the Content-Length send and receiving binary data web api toindicating that the data is bytes long.
Obviously you need to change this value based on the actual size of the data being sent. You can also send binary content by passing an instance of the nsIFileInputStream to send. In that case, you don't have to set the Content-Length header yourself, as the information is fetched from the stream automatically:.