SOAP Client for Downloading Attachments - Streaming
We have seen uploading of larger data files using SOAP with attachments in the previous post(Upload attachments using SOAP). We will see how to download/stream larger files from SOAP web service.
Java Mail API Problem
The SOAP web service client for downloading attachments we will be discussing uses the MimeMessage structure but we will avoid using the JAVA MAIL package as it is not efficient while downloading the contents. If you use MimeMessage java api to get the MimeBodyPart then you'll be in trouble as MimeMessage loads the entire content as byte array into memory for calculating the size and number of MimeBodyParts. So we will avoid using it for larger files if you have small JVM memory.
How to stream larger files
The memory intensive operation can be avoided using our own custom code to parse the response from the SOAP web service.
The following example shows the SOAP message response with the attachments. This example is for Oracle UCM's GetFileByName operation.
The SOAP response message package is constructed using the
Java Mail API Problem
The SOAP web service client for downloading attachments we will be discussing uses the MimeMessage structure but we will avoid using the JAVA MAIL package as it is not efficient while downloading the contents. If you use MimeMessage java api to get the MimeBodyPart then you'll be in trouble as MimeMessage loads the entire content as byte array into memory for calculating the size and number of MimeBodyParts. So we will avoid using it for larger files if you have small JVM memory.
How to stream larger files
The memory intensive operation can be avoided using our own custom code to parse the response from the SOAP web service.
The following example shows the SOAP message response with the attachments. This example is for Oracle UCM's GetFileByName operation.
The SOAP response message package is constructed using the
Multipart/Related
media type. The structure of the response stream is as follows:- The primary SOAP message must be carried in the root body part of the Multipart/Related structure. Consequently the type parameter of the
Multipart/Related
media header will always equal theContent-Type
header for the primary SOAP 1.1 message, i.e.,text/xml.
- Referenced MIME parts must contain either a
Content-ID
MIME header.
Content-Type: multipart/related;
type="text/xml"; start="rootContent";
boundary="----=_Part_12_21424854.1424891476173"
SOAPAction:
"http://www.stellent.com/CheckIn/"
Content-Length: 1818
------=_Part_12_21424854.1424891476173
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: rootContent
<soapenv:Envelope
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:get=\"http://www.stellent.com/GetFile/\">
<soapenv:Header/>
<soapenv:Body>
<get:GetFileByName>
<get:dDocName>Test.txt</get:dDocName> <get:revisionSelectionMethod>LatestReleased</get:revisionSelectionMethod>
<get:rendition>primary</get:rendition>
<get:extraProps>
<get:property>
<get:name>soapResponseType</get:name>
<get:value>Multipart/Related</get:value>
</get:property>
</get:extraProps>
</get:GetFileByName>
</soapenv:Body>
</soapenv:Envelope>
------=_Part_12_21424854.1424891476173
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Content-ID: test.log
Hello
------=_Part_12_21424854.1424891476173--
As you can see above the response stream starts with boundary (------=_Part_12_21424854.1424891476173). Each MimeBodyParts are separated by boundary. The content of each MimeBodyPart starts after blank line. The blank line is used to seperate the headers and content of each MimeBodyPart. Using apache LineInputStream we read each line until we encounter the blank line for the attachment content. Once the blank line preceeding the attachment body is read we will switch back to BufferInputStream for efficiency. Don't forget to ignore the boundary line which indicates the end of response and exclude it from writing into the file.
|
The example was tested with 10 concurrent thread each downloaded 160MB of file from web service and the JVM memory utilization was mere 20MB.
Interesting Article
ReplyDeleteJava Web Services Training Online Java Web Services Training Online Online Java Training Java Online Training Java EE Online Training Java EE Online Training
| Java Web Services Training in Chennai Java Web Services Training in Chennai Java Online Training from India
The prevalent availability of high speed internet access has accelerated the adoption of streaming media services, further reducing the lag time in content delivery and thus improving the user's overall experience. moviebox download
ReplyDeleteWhen your website or blog goes live for the first time, it is exciting. That is until you realize no one but you and your. Touchless soap dispenser
ReplyDeletePTV is defined as Internet Protocol television which is a system, where services for digital television are delivered through broadband IP link with the use of data communications. There are established organizations offering IPTV consulting to assist vendors and operators to safely enter the complex world of smart iptv
ReplyDeleteWhich assault organizations to legitimize their own reality. Strangely enough these administration organizations catch fire half of all monies gathered in organization.soap box printing
ReplyDeleteI wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts. Voir film
ReplyDeleteThis is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. Protocol
ReplyDeleteThank you for sharing the latest update about the new release.
ReplyDeleteonline internship
online internships
watch internship online
online internship for students
the internship online
online internship with certificate
online internship certificate
python online internship
data science online internship
i'm grateful to you for sharing this plethora of beneficial trace. i found this aid utmost beneficial for me. thanks loads for difficult do some thing. https://totalsportek.news/f1-streaming
ReplyDeleteAmazing Article, Really useful information to all So, I hope you will share more information to be check and share here.
ReplyDeleteflask in python
how to install flask in python
what is flask in python
flask in python tutorial
how to create a web page using flask in python
rest api using flask in python
how to install flask in python without pip
flask in python is used for
what is flask in python used for
learn flask in python
Im no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that. ICAR Webmail
ReplyDeleteWow, excellent post. I'd like to draft like this too - taking time and real hard work to make a great article. There are wonderful hashtag on tiktok, please go to site tiktok downloader to know more
ReplyDeleteWow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks The useless web
ReplyDeleteThe rapid growth in this field of science has resulted in the development of universities that have introduced different graduate programs related to data science. In this article, data science course syllabus
ReplyDelete
ReplyDeleteEverything is going to be alright. Are we really being honest
frasesparaenamorarz.com
fras-es.com
At the point when the iPad was first delivered, just Apple apps offered help for an outside screen hookup yet soon after dispatch, the Netflix app added this usefulness enabling supporters of utilization the iPod Dock Connector to VGA Adapter to watch Netflix on a TV, screen, projector or LCD show that can utilize a VGA link. https://twitchviral.com/
ReplyDeleteHey thanks for the blog post. Thanks Again. Cool.
ReplyDeletedownload instagram photos
ทีมงาน pokerN8 พร้อมดูแลคุณ 24 ชม Poker เงิน พร้อมเล่นเกมส์ เติมเครดิตฝากถอน พร้อมรวมกลุ่มนักเล่นโป๊กเกอร์ทั่วประเทศไทย มาไว้ที่นี่โป๊กเกอร์ออนไลน์ Poker is the #1 poker game in the world. Play with friends and see who's got the best poker face or come and meet some new buddies. Help out in a poker
ReplyDeleteWow awesome blog article. Really thank you! Awesome.
ReplyDeletehow to upload carousel to instagram from pc