Salesforce

How to save attachments from SOAP response with HTTP client

« Go Back

Information

 
TitleHow to save attachments from SOAP response with HTTP client
URL NameHow-to-Http-Client-to-save-attachment-from-SOAP-response
Article Number000187200
EnvironmentProduct: OpenEdge
Version: 11.6.1, 11.7, 12.x
OS: All Supported Platforms
Other: ABL Http Client
Question/Problem Description
How to save attachments from SOAP response with HTTP client.
Steps to Reproduce
Clarifying Information
Example code demonstrating the use of the OpenEdge.Net.MultiPartEntity object to save a zip file that is embedded in a multi-part message sent as a SOAP response.
Error Message
Defect Number
Enhancement Number
Cause
Resolution

Below is part pseudo-code, and part solution.  The code demonstrates building a SOAP request, however the actual SOAP envelop, WSDL URL and other URIs need to be filled in in order for it to work.

BLOCK-LEVEL ON ERROR UNDO, THROW.

USING OpenEdge.Core.*.
USING OpenEdge.Net.HTTP.*.
USING OpenEdge.Net.HTTP.Lib.ClientLibraryBuilder.

DEFINE VARIABLE oCredentials             AS Credentials                  NO-UNDO.
DEFINE VARIABLE oRequest                 AS IHttpRequest                 NO-UNDO.
DEFINE VARIABLE oResponse                AS IHttpResponse                NO-UNDO.
DEFINE VARIABLE oRequestBody             AS WidgetHandle                 NO-UNDO.
DEFINE VARIABLE oResponseMemptrEntity    AS OpenEdge.Core.Memptr         NO-UNDO.
DEFINE VARIABLE oResponseMultipartEntity AS OpenEdge.Net.MultipartEntity NO-UNDO.
DEFINE VARIABLE oMessagePart             AS OpenEdge.Net.MessagePart     NO-UNDO.              
DEFINE VARIABLE oByteBucket              AS OpenEdge.Core.ByteBucket     NO-UNDO.
DEFINE VARIABLE oLib                     AS IHttpClientLibrary           NO-UNDO. 

/*
Function:   CreateXMLObject
Returns:    WidgetHandle
Parameters: picSerializedXML    - The XML payload as a string.
Creates an ABL XML document object that can be transmitted through HTTP with
Content ContentType('text/xml;charset=UTF-8'). Wrap this object in a
WidgetHandle for use by the ABL HTTP client.
    
- Load XML payload into an X-Document object

- Create an OpenEdge.Core.WidgetHandle object with the X-document handle as
    input to the constructor.

- Return the WidgetHandle object to the caller.
*/

FUNCTION CreateXMLObject RETURNS WidgetHandle (
    INPUT picSerializedXML AS LONGCHAR
    ):

    DEFINE VARIABLE hXDoc AS HANDLE NO-UNDO.
    DEFINE VARIABLE lcUTF-8 AS LONGCHAR NO-UNDO.

    CREATE X-DOCUMENT hXDoc.
    lcUTF-8 = CODEPAGE-CONVERT(picSerializedXML, 'utf-8').
    hXDoc:LOAD('LONGCHAR', lcUTF-8, FALSE).
    hXDoc:ENCODING = 'UTF-8'.

    RETURN NEW WidgetHandle(hXDoc).

END FUNCTION.

oCredentials = NEW Credentials('<URI>', '<USERID>', '<PASS>').

/* Setup security options */ 
oLib = ClientLibraryBuilder:Build()
                           :sslVerifyHost(NO)
                           :Library.

oRequestBody = CreateXMLObject(
    '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="<URL>" xmlns:ns1="<URI>"><soapenv:Header/><soapenv:Body>...REQUEST_BODY...</soapenv:Body></soapenv:Envelope>'
     ).
oRequest = RequestBuilder:Post("<WSDL_URL>", oRequestBody)
                         :ContentType('text/xml;charset=UTF-8')
                         :UsingBasicAuthentication(oCredentials)
                         :AcceptAll()
                         :AddHeader('SOAPAction', '"<METHOD>"')
                         :Request.

oResponse = ClientBuilder:Build()
                         :UsingLibrary(oLib)
                         :Client:Execute(oRequest).

oResponseMultipartEntity = CAST(oResponse:Entity,OpenEdge.Net.MultipartEntity).  

/* Grab the last part of the multi-part message and put it in a memptr */
​oMessagePart = oResponseMultipartEntity:GetPart(oResponseMultipartEntity:Size).
oByteBucket = CAST(oMessagePart:Body,OpenEdge.Core.ByteBucket).
oResponseMemptrEntity = oByteBucket:GetBytes().

COPY-LOB FROM oResponseMemptrEntity:Value TO FILE "test.zip".

 
Workaround
Notes
References to Other Documentation:
Progress Article(s):
Getting started with HTTP client for OpenEdge
 
Keyword Phrase
Last Modified Date3/9/2023 6:33 PM

Powered by