Posted By:
Mark_Wrynn
Posted On:
Friday, July 22, 2005 01:54 PM
The verdict: It seems there is a problem with either URLDataSource or JavaMail.
One of these classes wants to "GET" request the URL three times for every call to Transport.send. I verified this through my application server logs. For this particular non-threadsafe JSP, the logs show that while Transport.send is hanging, only the first JSP request ever runs. If the URL points to any other (threadsafe) JSP, the logs show that it gets requested three times.
So, after replacing URLDataSource with another class which implements DataSource, my problem is solved.
Below is the retrieveData method of the implementing class. Note that at the very beginning, if data is not null the method just returns out. This means that if called multiple times, only the data retrieved from the first request will be used. The data is effectively cached. Why three requests are made I do not understand, so for my purposes, forbidding more than one request to the JSP solves the problem.
private void retrieveData() throws IOException {
if (data != null)
return;
URLConnection connection = url.openConnection();
connection.setAllowUserInteraction(false);
connection.setDoInput(true);
connection.setDoOutput(false);
//connection.setIfModifiedSince(false);
connection.setUseCaches(false);
connection.connect();
contentType = connection.getContentType();
int contentLength = connection.getContentLength();
if(contentLength == -1) contentLength = 2048;
InputStream in = connection.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream(contentLength);
byte buff[] = new byte[BUFF_SIZE];
int count;
while((count=in.read(buff)) >= 0)
out.write(buff, 0, count);
data = out.toByteArray();
}
If anyone has any insight as to why three requests are made, I'd love to hear it.
Thanks,
Mark