[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Posting MultPart Mime
Is the OP question...I have two (or more) XML formatted SOAP documents in the IFS and I need to make a multi part mime message out of them. Does HTTPAPI have any tools for that?
No.
Mime is a specific format and encoding. There are lots of considerations for a full implementation but one can probably "get away with" something a little less complicated.
But based on Scott's hints you can see it goes like this (pseudo/real code :-) ).
File(1) = '/path/fileforheader';
File(2) = '/path/fileforpart1';
File(3) = '/path/fileforpart2';
numberOfFiles = 3;
fd = open(IFS file to contain mime);
mimeBoundary = CreateMimeBoundary();
mimeNumber = 1;
for mimeNumber = 1 to numberoffiles;
mimeName = CreateContentID();
if mimeNumber = 1;
mimeName += 'header';
startMime = mimeName;
else;
mimeName += 'payload.1'; // or maybe %char(mimeNumber - 1)?
endif;
WriteLine(fd: %addr(mimeBoundary): %len(mimeBoundary)); // there might be some line feeds required in here, just insert them in the appropriate WriteLine
WriteLine(fd: 'content-ID: ' + mimeName + 'header' : 19+%len(mimeName) );
WriteLine(fd: 'Content-Type: text/xml': 21);
Copy( file(mimeNumber): fd );
Endfor;
Write(fd: mimeBoundary);
// now you have a single file in *almost* mime format that can be used with HTTPAPI
// it is unclear from OP but appears that this document does not need encoding.
// If not, you are probably done.
// If so, you will have to run the file through an appropriate encoding.
// we saved the startMime and mimeBoundary so you create the content-type on the GET or POST
CreateContentID...
// There are specific rules for the contentID.
// It is suppose to be globally and permanently unique. But, frankly, probably doesn't have to be.
Return ('globally unique id' + random(characters));
CreatMimeBoundary...
// you will have to write some random character generator. And since you are only doing this once - unless it is complicated - you could skip the subprocedure and just set mimeBoundary to some value in-line.
rtnField = '-----ZMODEDI??' + random(characters) + '--';
return rtnField;
The Copy procedure is pretty straight forward. Read the file passed in and write the data to fd (your new mime file). Pretty much like this (from IFS_ebook):
c eval fd2 = open(filepassedin:
c O_RDONLY)
c if fd2 < 0
c callp die('open(): ' + %str(strerror(errno)))
c endif
c dow readline(fd2: %addr(line): %size(line))>=0
c callp writeline(fd3: %addr(line): %len(line)); // fd3 is really fd - it was passed in so avoid global variable confusion
c enddo
c callp close(fd2)
-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Henrik Rützou
Sent: Tuesday, December 06, 2011 12:20 PM
To: HTTPAPI and FTPAPI Projects
Subject: Re: Posting MultPart Mime
Richard,
if your xml-files looks like the following you can't do a raw concatination
because
only one root element is allowed in XML:
<?xml version="1.0" encoding="UTF-8"?>
<orders>
<order refnum="1234567" tax="0.0" total="50.0">
<date>2011-03-20</date>
<address>
<name>Patricia DiMascio</name>
<street1>6 Jamie Drive</street1>
<street2 />
<street3 />
<city>Johnston</city>
<state>RI</state>
<zip>02919</zip>
<country>United States of America (U.S.A)</country>
<email />
<phone>(401)-942-2604</phone>
</address>
</order>
</orders>
or
<order refnum="1234567" tax="0.0" total="50.0">
<date>2011-03-20</date>
<address>
<name>Patricia DiMascio</name>
<street1>6 Jamie Drive</street1>
<street2 />
<street3 />
<city>Johnston</city>
<state>RI</state>
<zip>02919</zip>
<country>United States of America (U.S.A)</country>
<email />
<phone>(401)-942-2604</phone>
</address>
</order>
So you have to extract data from the two xml-files and create a
new XML file.
I don't know if Scott has some tool for that, but otherwise I have
subprocedures in powerEXT Core that can do the job quite easily.
On Tue, Dec 6, 2011 at 3:50 PM, Richard Medders <richard@xxxxxxxxxxxx>wrote:
> Thanks for the insight!
>
> So, with that in mind, I have 2 separate xml documents that I need to
> combine into 1 before I send it.... does httpapi have any tool that will
> accomplish that?
>
> Richard Medders
>
> Cleveland, MS
> 662-846-5653 direct
> 662-588-4521 Cell
>
> -----Original Message-----
> From: Scott Klement [mailto:sk@xxxxxxxxxxxxxxxx]
> Sent: Monday, December 05, 2011 3:47 PM
> To: HTTPAPI and FTPAPI Projects
> Subject: Re: Posting MultPart Mime
>
> hi Richard,
>
> > Can anyone give me advice on how to post a multipart mime document (aka
> > ebxml or soap with attachment)?
>
> HTTPAPI does not have tools for building/formatting a MIME document.
> You will have to create/format that document yourself. Once created,
> HTTPAPI can send it.
>
>
> > So, I need to insert the http headers, including total bytes as Content
> > Length, then insert the soap doc, then insert a mime break, then insert
> > the payload doc, then insert final mime break. Here is a sample of
> > what it should look like.
>
> HTTPAPI is going to take care of the HTTP keywords for you -- but it
> won't take care of the MIME keywords or MIME formatting.
>
> In your example, these are the HTTP keywords:
>
> POST /rich HTTP/1.1
> Connection: close
> Cache-control: no-cache
> SOAPAction: "ebXML"
> Host: 172.16.16.10
> Content-Type: multipart/related; type="text/xml"
> start="20111205094816.header"; boundary="---ZMODEDI??gc0p4Jq0M2Yt50001"
> Content-Length: 8740
>
> HTTPAPI will automatically take care of all of those for you. It will
> calculate the content-length from the length of the data you pass to it.
>
> The values for the Content-Type and SoapAction fields are provided in
> parameters that you pass to HTTPAPI.
>
> Note that in older versions of HTTPAPI, the Content-Type and SoapAction
> keywords were limited to shorter (64 char) variables. In the current
> BETA of HTTPAPI, they allow up to 16k. So if the size of the parameters
> isn't long enough in the copy you're using, please update to the one here:
> http://www.scottklement.com/httpapi/beta
>
> With those tips in mind, you should be able to call http_url_post_stmf()
> to send the document (provided that it's formatted properly.)
>
> Good luck
>
>
>
>
> -----------------------------------------------------------------------
> This is the FTPAPI mailing list. To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> -----------------------------------------------------------------------
>
--
Regards,
Henrik Rützou
http://powerEXT.com <http://powerext.com/>
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------