axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thorsten Schöning <tschoen...@am-soft.de>
Subject Re: [AXIS2] Throttle upload bandwidth during sending SOAP messages
Date Fri, 05 Oct 2018 08:59:56 GMT
Guten Tag Thorsten Schöning,
am Montag, 11. Juni 2018 um 13:44 schrieben Sie:

> Not sure if there's an easier way, better ideas welcome. :-)

Time to share my experiences: I'm stuck on some old Axis2 1.6.2
currently, which seems to use MultiThreadedHttpConnectionManager,
for which I didn't find how to provide it with a connection factory to
be able to create limiting OutputStreams at all. Maybe I missed
something somewhere...

Nevertheless, at least for my use case I think I have an easier
approach: I need to upload only one file currently and am using SOAP
with attachments to not need to encode Base64 and such. If I
understood correctly, Axis2 demands a DataHandler in those cases and
those can be created based on some DataSource, which itself wraps some
InputStream and that actually wraps the data to upload.

So what I simply did was creating a limiting InputStream around my
data to upload, wrapped that into a DataSource, wrapped that into a
DataHandler and provided that to Axis2. To let Axis2 not consume too
much memory during creation of the request, it needs to be set to use
chunked transfers.[1] In the end, Axis2 is reading somewhat small
packages from my InputStream and writing those directly to the server
and because it can only send what it read, I'm limiting upload
bandwidth that way.

Care needs to be taken regarding the limiter used, I started with
Guava RateLimiter and ran into problems[1] when using it in
Inputstream.read with only reading one byte. Apaches TimedSemaphore
worked better even in those situations. Limiting one byte only instead
of individual packets might be unnecessary, though.

Attaching some PoC in case anyone is interested. Of course it's not
strictly limiting the output, but good enough for what I need
currently. :-)

[1]: http://mail-archives.apache.org/mod_mbox/axis-java-user/201809.mbox/<1486821759.20180923202008%40am-soft.de>
[2]: https://stackoverflow.com/a/52626754/2055163

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail: Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow
Mime
View raw message