Consultor Eletrônico



Kbase P136944: How do I properly retrieve and process a multipart message in the ABL using the Sonic JMS Adapter?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   05/11/2008
Status: Unverified

GOAL:

How do I properly retrieve and process a multipart message in the ABL using the Sonic JMS Adapter?

FACT(s) (Environment):

All Supported Operating Systems
OpenEdge 10.x

FIX:

The following code fragment shows how to properly handle the reading in and process of a multipart message:

procedure MessageHandler:
define input parameter hMessage as handle no-undo.
define input parameter hConsumer as handle no-undo.
define output parameter hReply as handle no-undo.
run value('Process' + dynamic-function('getMessageType' in hMessage)) in this-procedure (hMessage, hConsumer, output hReply) no-error.
/*--------------------------------------------------------------*/
/* testing should be done here to ensure that your call to the */
/* internal procedure to process the message worked as you */
/* would expect. */
/*--------------------------------------------------------------*/

run deleteMessage in hMessage.
end procedure.

procedure ProcessMultiPartMessage:
define input parameter hMessage as handle no-undo.
define input parameter hConsumer as handle no-undo.
define output parameter hReply as handle no-undo.

define variable iParts as integer no-undo.
define variable iCounter as integer no-undo.
define variable iSeg as integer no-undo.
define variable iLength as integer no-undo.
define variable hPart as handle no-undo.
define variable cSeg as character no-undo.
define variable cContentType as character no-undo.
define variable mpBytes as memptr no-undo.

/*--------------------------------------------------------------*/
/* this code makes no attempt to deal with replying to the */
/* incoming message. this code focuses only on how to properly */
/* read in a multi part message. */
/*--------------------------------------------------------------*/
assign iParts = dynamic-function('getPartCount' in hMessage).
do iCounter = 1 to iParts:
if dynamic-function('isMessagePart' in hMessage, input iCounter) then
do:
dynamic-function('getMessagePartByIndex' in hMessage, input iCounter, output hPart).

assign iSeg = 1
. iLength = 0.
do while dynamic-function('endOfStream' in hPart) = false:
assign cSeg = dynamic-function('getTextSegment' in hPart)
iSeg = iSeg + 1
iLength = iLength + LENGTH (cSeg).
end.
message substitute('Part &1 returned &2 chars of data', iCounter, iLength) view-as alert-box.
end.
else
do:
/*--------------------------------------------------------------*/
/* message is not a part but instead is data. fetch data using */
/* either getBytesPartByIndex or getTextPartByIndex functions. */
/* both functions return the data as an output parameter to the */
/* function and the oontent type (i.e. text/xml, etc) as the */
/* return value from the function. you should test the return */
/* value to determine what kind of content you received and */
/* then deal with it as appropriate. the following URL gives */
/* a list of the current "standardized" content types that you */
/* may need to handle (depending on the messages you receive: */
/* */
/* http://www.iana.org/assignments/media-types/ */
/* &.nbsp; */
/* the code below is very simplistic in that it ignores the */
/* content type and simply fetches the data as a set of bytes */
/* then assumes the memptr contains a string and puts that */
/* string into a character variable. real world processing */
/* would most likely be more complex. */
/*--------------------------------------------------------------*/
set-size(mpBytes) = 0.
assign cContentType = dynamic-function('getBytesPartByIndex' in hMessage, input iCounter, output mpBytes)
cSeg = get-string(mpBytes,1).
end.
end.
end procedure.

.