Bug 69016 - HttpURLConnection getOutputStream createCapacityException
Summary: HttpURLConnection getOutputStream createCapacityException
Status: RESOLVED WORKSFORME
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Util (show other bugs)
Version: 9.0.89
Hardware: All All
: P2 normal (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-16 15:20 UTC by Raffaele Tripodo
Modified: 2024-06-12 08:14 UTC (History)
0 users



Attachments
exception screenshot (812.00 KB, image/jpeg)
2024-05-16 15:26 UTC, Raffaele Tripodo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Raffaele Tripodo 2024-05-16 15:20:34 UTC
Hello,
a simple code to download pdf file (generated by a servlet) is working fine in Apache Tomcat 9.0.87, but the same exact code throws an excpetion in Apache Tomcat 9.0.89.

This is the code

			URL url = URI.create(address).toURL();
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();

			if (!params.isEmpty())
			{
				byte[] postData = String.join("&", params).getBytes(Charset.forName("UTF-8"));
				int postDataLength = postData.length;

				conn.setDoInput(true);
				conn.setDoOutput(true);
				conn.setRequestMethod("POST");
				conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
				conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
				conn.setRequestProperty("Charset", "utf-8");
				conn.setConnectTimeout(1000 * 15);
				conn.setReadTimeout(1000 * 30);

				// here is the error!
				try (DataOutputStream dos = new DataOutputStream(conn.getOutputStream()))
				{
					dos.write(postData);
					dos.flush();
					dos.close();
				}
			}

			try (InputStream in = conn.getInputStream())
			{
				if (tempFile)
				{
					file = File.createTempFile("getUrlFile", ".tmp");

					try (FileOutputStream out = new FileOutputStream(file))
					{
						copyBinaryStream(in, out);
					}
				}

				content = getTextStream(in);
			}

The same code works fine in previous version.
Comment 1 Raffaele Tripodo 2024-05-16 15:26:00 UTC
Created attachment 39719 [details]
exception screenshot

this is the exception thrown running this line:

DataOutputStream out = new DataOutputStream(conn.getOutputStream())
Comment 2 Mark Thomas 2024-05-16 16:07:41 UTC
And the sample code used to generate the response that triggers this behaviour?

Looks like the Servlet isn't writing a response body so we need to see that code.
Comment 3 Christopher Schultz 2024-05-17 14:48:04 UTC
Also, an example of the full HTTP request including headers and body would be very helpful, here.
Comment 4 Mark Thomas 2024-05-23 08:46:04 UTC
Dropping priority to normal. It really was a blocker, I'd expect a faster response to our questions.

I'll note at this point that without the requested information, this issue will eventually get resolved as WORKSFORME given that the issue appears to be that the Servlet isn't writing a response body.
Comment 5 Mark Thomas 2024-06-12 08:14:52 UTC
Resolving based on previous comment.