passing LotusScript parameter to Java

瘦欲@ 提交于 2019-12-24 01:43:32

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/36725023/passing-lotusscript-parameter-to-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!