2016-03-31 25 views
6

試圖通過從預定的Java代理觸發來讓Xagent按計劃運行。如何從Domino Java代理安排Xagent?

以下是我xagentmail.xsp的代碼,只是給我發來電子郵件:

<?xml version="1.0" encoding="UTF-8"?> 
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" rendered="false"> 
<xp:this.beforePageLoad><![CDATA[#{javascript: 
// test send mail 
doc = database.createDocument() ; 
doc.replaceItemValue("Form", "memo"); 
doc.replaceItemValue("Subject", " from xagentmail.xsp"); 
doc.replaceItemValue("SendTo", "PDella-Nebb[email protected]"); 
doc.send(); 

}]]></xp:this.beforePageLoad> 
</xp:view> 

使用德文奧爾森的博客,Scheduled Xagents描述的SSL加密連接的方法,我創建了以下安排的Domino的Java代理:

import java.io.BufferedReader; 
import java.io.BufferedWriter; 
import java.io.InputStreamReader; 
import java.io.OutputStreamWriter; 
import java.net.Socket; 

import javax.net.ssl.SSLSocketFactory; 

import lotus.domino.AgentBase; 

public class JavaAgent extends AgentBase { 
// Change these settings below to your setup as required. 
static final String hostName = "server1.testdomain.com"; 
static final String urlFilepath = "/test/poidemo.nsf/xagentmail.xsp"; 
static final int sslPort = 443; 


public void NotesMain() { 
    try { 
    final SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); 
    final Socket socket = factory.createSocket(JavaAgent.hostName, JavaAgent.sslPort); 

    final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); 
    final BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); 

    final StringBuilder sb = new StringBuilder(); 
    sb.append("GET "); 
    sb.append(JavaAgent.urlFilepath); 
    sb.append(" HTTP/1.1\n"); 
    final String command = sb.toString(); 

    sb.setLength(0); 
    sb.append("Host: "); 
    sb.append(JavaAgent.hostName); 
    sb.append("\n\n"); 
    final String hostinfo = sb.toString(); 

    out.write(command); 
    out.write(hostinfo); 
    out.flush(); 

    in.close(); 
    out.close(); 
    socket.close(); 

    } catch (final Exception e) { 
    // YOUR_EXCEPTION_HANDLING_CODE 
    } 
} 
} 

當我在瀏覽器中輸入URL到我的xagentmail.xsp時,我按預期收到郵件。

但是我的預定Java代理沒有觸發Xagent發送郵件。

我確實爲代理和xagent的應用程序設置了對Reader的匿名訪問。我也有服務器上的限制和非限制特權。

任何想法?

+0

什麼消息做通過服務器控制檯運行代理程序時會得到什麼結果? – xpagesbeast

+0

您使用(1,2,3)運行代理的安全級別是什麼? –

+0

實際上現在在客戶開發服務器上運行盲目。控制檯訪問不是一個選項。需要移動到測試服務器。 –

回答

5

我使用下面的方法,它工作得很好:我使用HttpURLConnection而不是BufferedWriter,並且我使用端口80上的localhost直接與服務器進行本地交談。

這裏是我的代理代碼:

import lotus.domino.AgentBase; 
import lotus.domino.Session; 

public class JavaAgent extends AgentBase { 

    @Override 
    public void NotesMain() { 
     try { 
      final String xpageName = "demo"; 

      Session session = getSession(); 
      dk.fmcgsolutions.XAgent.run(session.getAgentContext(), xpageName); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

而這裏的XAgent類代理使用:

package dk.fmcgsolutions; 

import java.io.BufferedReader; 
import java.io.InputStreamReader; 
import java.net.HttpURLConnection; 
import java.net.URL; 

import lotus.domino.AgentContext; 

public class XAgent { 

    public static void run(AgentContext agentContext, String xpageName) { 

     try { 

      String dbPath = agentContext.getCurrentDatabase().getFilePath(); 
      String url = "http://localhost/" + dbPath + "/" + xpageName + ".xsp"; 

      System.out.println("Starting " + xpageName + " in database " + dbPath); 

      URL xPageURL = new URL(url); 
      HttpURLConnection conn = (HttpURLConnection) xPageURL.openConnection(); 

      conn.connect(); 

      switch (conn.getResponseCode()) { 
      case HttpURLConnection.HTTP_OK: 
       // read from the urlconnection via the bufferedreader 
       BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
       String line; 
       while ((line = bufferedReader.readLine()) != null) { 
        System.out.println("Response: " + line); 
       } 
       bufferedReader.close(); 

       break; 
      case HttpURLConnection.HTTP_INTERNAL_ERROR: 
       System.out.println("Interal server error while running"); 
       break; 
      default: 
       System.out.println("An error occurred: " + conn.getResponseCode()); 
       System.out.println("Error message: " + conn.getResponseMessage()); 
       break; 
      } 

      conn.disconnect(); 

      System.out.println("Finished " + xpageName + " in database " + dbPath); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

代理需要使用運行時的安全級別運行2.

+0

此網站目前通過網頁配置進行設置。使用Web配置時,您還可以設置本地Internet站點嗎?你是怎樣做的? –

+0

當然。只需使用「localhost」作爲域名即可。 –

+0

感謝Per,我會盡力...現在需要與管理員交談! –