Jens: Wow, that's interesting. As a quick test, I wrote this agent:
Dim fetcher As New UrlFetcher
Dim url As String
Dim i As Integer
For i = 1 To 50
'** I tried with and without this line
Set fetcher = New UrlFetcher
url = "http://localhost?" & i
Call fetcher.getUrlAsString(url)
Print " Attempt #" & i & ": " & _
fetcher.GetReturnStatus & ", url = " & url
Next
I ran it against a Domino 7 server on localhost from a Notes 6.5 and a Notes 7 client, and I even ran it as a web agent ON the Domino server (just for kicks). The server was set up for 40 threads like yours was, and I didn't notice any problems.
But then again, I can see how there could be problems like the one you're describing. I'm not sure how the Java sockets work with regards to releasing connections. I know in my code for this database I try to make sure to explicitly close the connection InputStream, which I think will close the connection too.
Also, with the LS2J stuff, if you're creating a lot of objects I think you can call "Delete" against the JavaSession object to release the resources, and then create a new JavaSession. Not sure how immediately the resources are released, but that may help in some situations too.
- Julian
And also good timing. Two weeks ago we wrote a small LS2J wrapper to get some HTML in a LotusScript agent... ![]()
Now your lib is WAY better and even documented ![]()
PS: Will you post it on OpenNTF, even without Bruce' help? *grin*
I think you are not closing the OutputStreamWriter (method getUrlAsStream) properly?
writer.close() after writer.flush()?
Maybe jakarta.HTTPClient can be used from Domino7. I am going to try that. But your class allready has a lot of the features like basic authentification, ssl, proxy. I can see no support for different encoding shemes like UTF-8 or ISO-8859-1. From my experience you often have to mess with those.
The advantage of jakarta.HTTPClient is, that it allready takes care of low level stuff like closing connections and supporting features like encoding, which can be overlooked easily.
kind regards
Axel
Thats because of: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4615330
I patched URLFetcherJava.createAuthHeader like that to make it work:
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
String str = username + ":" + password;
auth = "Basic " + encoder.encode(str.getBytes());
(the last line is changed).
Thanks (as always) for the help. I'll have to check on closing the OutputStreamWriter. Closing it early might do something bad to the connection, and I need to see if the connection might close it automatically. It certainly does look like something that could leak though, and we don't want that.
Definitely try the Jakarta classes. I've used those in other projects before (not sure about HTTP, but definitely some of the others), and they are very solid. They will definitely be more feature-rich, and I would trust those more than my own code...![]()
Also, thanks very much for the link to the HTTP authentication bug, and your workaround code. Especially the workaround code! It's always the little things that get you. I'll make the change in the download database.
- Julian
I've used the Apache commons codec library with no issues:
I tried to use your code with this agent:
Sub Initialize
Dim fetcher As New UrlFetcher
Dim fileName As String
Call fetcher.AddPostParam("q", "Ronald van Gogh" )
fileName = fetcher.getUrlAsFile("http://www.google.com")
' if we successfully got the URL, say what the file name is
If (fileName "") Then
Print "URL retrieved as file: " + fileName
Else
Print "There was an error: " + fetcher.getLastError()
End If
End Sub
However it results in an error: stream closed.
Without specifying the AddPostParam it seems to work.
Any ideas?
Ronald