[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Looking for best option
YEA! Thanks so much Scott!
Turns out my problem was I specified a CCSID of 819 for my tiff file rather
than 37. Makes sense to me now.
Now I can code everything up using the code you sent me and we can move to
the new box next week.
Thanks again,
Bruce
-----Original Message-----
From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
[mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Wednesday, January 07, 2009 6:01 PM
To: HTTPAPI and FTPAPI Projects
Subject: Re: Looking for best option
Hi Bruce,
>
> I've attached the response from the soap call and the debug log.
>
I took the output from http_url_post() that you sent me off list, and
wrote a program using http_parse_xml_stmf() to read your file and
extract the TIFF file inside. Obviously, you'll have to change the
code to use http_url_post_xml() to contact the web service, but the
logic I used to interpret your XML data worked fine for me (I could view
the TIF file) so it should illustrate what you need to do.
My suggestion is that you try my code (below) as I've included the whole
program, it should be easy to download it to your system, change the IFS
pathnames, compile it, and try it out. If it works to your
satisfaction, you can use it to help you understand how to get your own
code working.
H DFTACTGRP(*NO) BNDDIR('HTTPAPI':'BASE64')
/copy httpapi_h
/copy base64_h
/copy ifsio_h
D DIR C '/home/klemscot/reynolds'
D Element_Val_t ds qualified
D based(Template)
D buf *
D len 10i 0
D GetInnerDoc PR
D filename 50a varying
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value likeds(Element_Val_t)
D Attrs * dim(32767)
D const options(*varsize)
D GetTiffImage PR
D info likeds(ParseInfo)
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value likeds(Element_Val_t)
D Attrs * dim(32767)
D const options(*varsize)
D ParseInfo ds qualified
D count 10i 0 inz(0)
D id 50a varying inz('UNKNOWN')
D size 10i 0 inz(0)
D Filename s 50a varying
D rc s 10i 0
/free
http_debug(*ON: DIR + '/reynolds_log.txt');
http_xmlReturnPtr(*ON);
filename = http_tempfile() + '.xml';
// --------------------------------------------------------
// This gets the SOAP message and extracts the XML
// document from it.
//
// NOTE: Bruce should change this to use HTTP_URL_POST_XML.
// I'm parsing a stream file from Bruce. But, Bruce
// should change this to use HTTP_URL_POST_XML to get
// the SOAP message from the web service.
//
// (The same callback/userdata should be retained.)
// --------------------------------------------------------
rc = http_parse_xml_stmf( DIR + '/http_url_post_response.txt'
: HTTP_XML_CALC
: *NULL
: %paddr(GetInnerDoc)
: %addr(filename) );
if (rc < 0);
unlink(filename);
http_crash();
endif;
// --------------------------------------------------------
// Now the "inner" XML document is in the temporary file,
// parse it to get the base64 encoded data.
// --------------------------------------------------------
rc = http_parse_xml_stmf( filename
: HTTP_XML_CALC
: *NULL
: %paddr(GetTiffImage)
: %addr(ParseInfo));
unlink(filename);
if (rc < 0);
http_crash();
endif;
http_comp('No errors. ' + %char(ParseInfo.count)
+ ' images decoded.');
*inlr = *on;
/end-free
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* GetInnerDoc(): End-element handler for HTTPAPI's XML parser.
* to be called by http_url_post_xml()
*
* The response from the web service contains
* an "inner" XML document. This retrieves
* that document and writes it to a temporary
* file in th IFS.
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P GetInnerDoc B export
D GetInnerDoc PI
D filename 50a varying
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value likeds(Element_Val_t)
D Attrs * dim(32767)
D const options(*varsize)
D fd s 10i 0
/free
if name = 'GetImageDataResult';
fd = open( filename
: O_CREAT + O_TRUNC + O_WRONLY + O_CCSID
+ O_TEXTDATA + O_TEXT_CREAT
: S_IRUSR + S_IWUSR
: 819
: 0 );
// FIXME: Add error handling.
callp write(fd: value.buf: value.len);
callp close(fd);
endif;
/end-free
P E
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* GetTiffImage(): The payload of the SOAP message is an XML
* document like this:
*
* <IMAGEQUERYRESPONSE>
* <IMAGES>
* <IMAGE>
* <ID>12345</ID>
* <IMAGESIZE>12345</IMAGESIZE>
* <BASE64DATA>xxxxx</BASE64DATA>
* </IMAGE>
* </IMAGES>
* </IMAGEQUERYRESPONSE>
*
* This routine saves every image to an IFS file using the
* ID number as the filename.
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P GetTiffImage B export
D GetTiffImage PI
D info likeds(ParseInfo)
D depth 10I 0 value
D name 1024A varying const
D path 24576A varying const
D value likeds(Element_Val_t)
D Attrs * dim(32767)
D const options(*varsize)
D fd s 10i 0
D data s 65535a based(p_data)
D len s 10i 0
D outbuf s *
/free
select;
when value.len <= 0;
// skip any elements that have no value...
when name = 'ID';
p_data = value.buf;
info.ID = %subst(data:1:value.len);
when name = 'IMAGESIZE';
p_data = value.buf;
info.size = %int(%subst(data:1:value.len));
// FIXME: probably want to MONITOR the %INT, above.
when name = 'BASE64DATA';
outbuf = %alloc( value.len );
len = base64_decode( value.buf
: value.len
: outbuf
: value.len );
if (info.size <> len);
// image decoded to a different size...
// might want to halt?
endif;
fd = open( DIR + '/' + info.id + '.tif'
: O_WRONLY + O_CREAT + O_EXCL
: S_IRUSR + S_IWUSR + S_IRGRP + S_IROTH );
// FIXME: Add error handling.
callp write( fd: outbuf: len);
callp close(fd);
dealloc outbuf;
info.count = info.count + 1;
info.size = 0;
info.id = 'UNKNOWN';
endsl;
/end-free
P E
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------