I am calling a a java getHTML( urlToRead ) class from LotusScript (thank you, Matt Holthe), which uses a CONST to pass the URL. The java code sits in a java "script-library". When I change the constant urlToRead to a variable, the java class does not read the variable and I get an empty response. Do I need to use in-memory documents, or is there an easier way? I need to get a return json value so a "call" does not work unless I'm using in-memory documents, which I am trying to avoid. I am starting to think that I have to convert the entire code to java, but am more comfortable in LotusScript. This is running in Notes Client.
import java.io.*;
import java.net.*;
public class GetHTML {
public String getHTML( String urlToRead) {
URL url;
HttpURLConnection conn;
BufferedReader rd;
String line;
String result = "";
try {
url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("PUT");
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
result += line;
}
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
Uselsx "*javacon"
Use "GetHTML"
Function getWebData( myURLvar As String) As String
Const myURL = "http://mywebsite.com/testdb.nsf/testagent1"
Dim js As JAVASESSION
Dim getHTMLClass As JAVACLASS
Dim getHTMLObject As JavaObject
Dim html As String
Set js = New JAVASESSION
Set getHTMLClass = js.GetClass("GetHTML")
Set getHTMLObject = getHTMLClass.CreateObject
' next line works because it uses CONSTANT
html = getHTMLObject.getHTML( myURL )
Msgbox "html: " + html
' next line does not work, uses variable
html = getHTMLObject.getHTML( myURLvar )
Msgbox "html: " + html
getWebData = html
End Function
I tried using byVal for myURLvar but that didn't make a difference. How do I get the java code to see the variable string?
It is not about using a constant or variable string as parameter for getHtml(). Both work fine in your example.
I had to change one line in Java though to get it to run ("GET" instead of "PUT"):
conn.setRequestMethod("GET");
This is my working version of your LotusScript agent:
UseLSX "*javacon"
Use "GetHTML"
Sub Initialize
getWebData("http://www.spiegel.de/")
End Sub
Function getWebData( myURLvar As String) As String
Const myURL = "http://www.spiegel.de/"
Dim js As JAVASESSION
Dim getHTMLClass As JAVACLASS
Dim getHTMLObject As JavaObject
Dim html As String
Set js = New JAVASESSION
Set getHTMLClass = js.GetClass("GetHTML")
Set getHTMLObject = getHTMLClass.CreateObject
' next line works because it uses CONSTANT
html = getHTMLObject.getHTML( myURL )
MsgBox "html: " + html
' next line does not work, uses variable
html = getHTMLObject.getHTML( myURLvar )
MsgBox "html: " + html
getWebData = html
End Function