2013-12-20 69 views
2

我们被要求构建一个与远程非Domino服务器交换数据的基于Domino服务器的数据库。远程服务器可以通过使用webservices连接到。在基于服务器的代理中使用REST服务

使用R8.5.3在Domino中创建RESTful服务看起来很简单:在Internet上有关于Domino数据服务的一些非常有趣的文章。学习this page一定会帮助我创建连接的一端。

现在用于代理中的消费部分。我们之前做过一次,之前有一次,然后我们使用普通的HTTP URL和一个简单的GetDocumentByURL。这不是完美的,但它的工作原理。

但是,这是在Domino代理中使用Web服务的最佳方式吗?这是一个Linux环境,所以我不能使用MS对象等等。是否有一些标准库可以调用,最好是在LotusScript中?或者有没有办法在代理中使用某些XPage控件?

感谢您的建议!

回答

4

[编辑]从breakingpar

Java代码的示例被放置在一个Java库称为GetHTML:

import java.io.*; 
import java.net.*; 

public class GetHTML { 

    public String getHTML(String urlToRead) { 
     URL url; // The URL to read 
     HttpURLConnection conn; // The actual connection to the web page 
     BufferedReader rd; // Used to read results from the web page 
     String line; // An individual line of the web page HTML 
     String result = ""; // A long string containing all the HTML 
     try { 
     url = new URL(urlToRead); 
     conn = (HttpURLConnection) url.openConnection(); 
     conn.setRequestMethod("GET"); 
     rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
     while ((line = rd.readLine()) != null) { 
      result += line; 
     } 
     rd.close(); 
     } catch (Exception e) { 
     e.printStackTrace(); 
     } 
     return result; 
    } 
} 

并用LotusScript使用它:

Uselsx "*javacon" 
Use "GetHTML" ' Java library 
Const myURL = "http://www.breakingpar.com" 
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 
html = getHTMLObject.getHTML(myURL) 

我通过这项服务使用这个来填充一个国家的莲花:http://ws.geonames.org/countryInfo

您可以使用Java代理消费REST服务: Is there an alternative to using the LotusScript GetDocumentByURL method

下面的代码是从技术说明复制。如果请求的是一个更大的脚本柔的部分可以在LS2J

import lotus.domino.*; 
import java.net.*; 
import java.io.*; 
import java.text.*; 
import java.util.*; 
import java.math.*; 

public class JavaAgent extends AgentBase { 
    public void NotesMain() { 
     try { 
      Session session = getSession(); 
      AgentContext agentContext = session.getAgentContext(); 

      Database db = agentContext.getCurrentDatabase(); 
      URL ibmURL = new URL(" http://finance.yahoo.com/q?s=IBM&d=t"); 
      BufferedReader bin = new BufferedReader(new InputStreamReader(ibmURL.openStream())); 
      String line; 
      StringBuffer sb = new StringBuffer(); 

      while ((line = bin.readLine()) != null) { 
       sb.append(line); 
      } 
      String ibmString = sb.toString(); 

      Document newNotesDoc = db.createDocument(); 
      newNotesDoc.replaceItemValue("Form", "IBMForm"); 
      newNotesDoc.replaceItemValue("WebPageUS", ibmString); 
      newNotesDoc.computeWithForm(true, false); 
      newNotesDoc.save(true, true); 

      String ibms = newNotesDoc.getItemValueString("QuoteUS"); 
      System.out.println("IBM Raw String is " + ibms); 
      newNotesDoc.recycle(); 

      NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US); 
      BigDecimal d = new BigDecimal(ibms); 
      double ibmd = d.doubleValue(); 
      String ibm = n.format(ibmd); 
      System.out.println("IBM Currency is " + ibm); 

      SimpleDateFormat formatter = new SimpleDateFormat("EEEE, MMMM dd, yyyy hh:mm:ss a"); 
      Date currentTime_1 = new Date(); 
      String dateString = formatter.format(currentTime_1); 
      System.out.println("Formatted date is " + dateString); 
      String displayText = "IBM stock price as of " + dateString + " NYSE US " + ibm; 
      System.out.println("Display text is " + displayText); 
      db.recycle(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 
+0

嗯包裹HTTP请求,是的,这听起来是正确的,我认为。我会看看是否可以使用相同的方式同时发送一些数据(POST)。谢谢! –