Thanks for pointing this out Andrea. This is a pretty significant error
on my behalf. I'll see if I can fix this soon, or at the very least
update the javadocs. This may also be affecting uDig negatively. I'll
see if I can implement methods in each response to retrieve the data
from the inputstream and close the connection.
Richard
[EMAIL PROTECTED] wrote:
> Hi,
> it seems to me that the followig method in AbstractOpenWebService
> has some leak-like issues (see end of the mail).
>
> Basically, we do have the opening of a new connection, that is not passed
> around to anything, and is never disconnected. I guess it'll be during
> garbage
> collection and finalization, but it seems to be it should be
> disconnected asap,
> maybe linking somehow the disconnection to the end of the input stream.
>
> One more thing that scares me is that the typical code to read an image
> from a GetMap request is more or less along the lines of:
>
> GetMapRequest request = wms.createGetMapRequest();
> request.addLayer(layer);
> ...
> GetMapResponse response = wms.issueRequest(request);
> BufferedImage image = ImageIO.read(response.getInputStream());
>
> and there's not clear cut way to "close" the response... I noticed
> that in a stress test against geoserver I'm writing, adding:
>
> response.getInputStream().close();
>
> after the above allows geoserver to handle much more requests before
> bombing with an OOM.
> So my proposal would be to have the connection and streams handled
> in the requests objects and have an explicit close() method that allows
> to clean up both the stream and the connection.
>
> Let me know what you think
> Cheers
> Andrea Aime
>
> -------------------------------------------------------------------------------------------
>
>
> protected Response internalIssueRequest( Request request ) throws
> IOException, ServiceException {
> URL finalURL = request.getFinalURL();
>
> HttpURLConnection connection = (HttpURLConnection)
> finalURL.openConnection();
>
> connection.addRequestProperty("Accept-Encoding", "gzip");
>
> if (request.requiresPost()) {
> connection.setRequestMethod("POST");
> connection.setDoOutput(true);
> connection.setRequestProperty("Content-type",
> request.getPostContentType());
>
> OutputStream outputStream = connection.getOutputStream();
>
> if (LOGGER.isLoggable(Level.FINE)) {
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> request.performPostOutput(out);
>
> InputStream in = new
> ByteArrayInputStream(out.toByteArray());
> BufferedReader reader = new BufferedReader(new
> InputStreamReader(in));
>
> PrintStream stream = new PrintStream(outputStream);
>
> String postText = "";
>
> while (reader.ready()) {
> String input = reader.readLine();
> postText = postText + input;
> stream.println(input);
> }
> LOGGER.fine(postText);
> System.out.println(postText);
>
> out.close();
> in.close();
> } else {
> request.performPostOutput(outputStream);
> }
>
> outputStream.flush();
> outputStream.close();
> } else {
> connection.setRequestMethod("GET");
> }
>
>
> InputStream inputStream = connection.getInputStream();
>
> if (connection.getContentEncoding() != null &&
> connection.getContentEncoding().indexOf("gzip") != -1) { //$NON-NLS-1$
> inputStream = new GZIPInputStream(inputStream);
> }
>
> String contentType = connection.getContentType();
>
> return request.createResponse(contentType, inputStream);
> }
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Geotools-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-devel
>
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel