使用LS2J访问lotusscript中的java接口?

时间:2014-06-24 11:36:57

标签: java lotus-domino ls2j

enter code here我试图通过他的界面访问一个java类 我在Ls2J中创建了一个类而不是java接口,因为我不知道我是怎么做的 我有错误:

error : LS2J Error: Java constructor failed to execute

一个想法? ^^

谢谢!

我的班级java in lotus

Class ILogWebService
sessionJava As JAVASESSION      
classJava As JAVACLASS
objectJava As JAVAOBJECT        
methodJava As JAVAMETHOD

Public Sub New(logDTO As LogWSDTO)
    Set sessionJava = New JAVASESSION
    Set classJava = sessionJava.GetClass("com.pasquier.DAO.WS/ILogWebService")
    Set objectJava = classJava.CreateObject     
End Sub

Public Sub notesMain()
    Set methodJava = classJava.GetMethod("notesMain","()V")     
    objectJava.notesMain        
End Sub 

结束班

我的java界面:

包com.pasquier.IDAO.WS;

import com.pasquier.MesExceptions.ExceptionWS;

public interface ILogWebService {

void notesMain() throws ExceptionWS;    

}

我的java课程:

public class LogWebService implements ILogWebService {
private Session session;
private LogWSDTO logDTO = null;

public LogWebService(LogWSDTO log) {
    this.logDTO = log;
}


public void notesMain() throws ExceptionWS  {
    try 
    {
        try 
        {           
            session =  WebServiceBase.getCurrentSession();              
                        ILogWSDAO ilog = FactoryWS.getInstance().createLogWSDAO(session, logDTO);

            ilog.ajouterLog();  
        } finally
        {
            UtilMemoire.purgeMemoire(); 
        }
    } catch (NullPointerException e1)
    {   
        System.out.println("ERREUR NullPointer sur NotesMain sur LogWebService");
        throw new ExceptionWS("ERREUR NullPointer sur NotesMain sur LogWebService", e1, logDTO);
    } catch (ExceptionWS e) 
    {
        System.out.println( e.getMessage());        
    } catch (Exception e2) 
    {           
        System.out.println("ERREUR sur NotesMain sur LogWebService " + e2.getMessage());    
        throw new ExceptionWS("ERREUR sur NotesMain sur LogWebService " + e2.getMessage(), e2, logDTO);
    }
}

我的莲花:

Class LogGetAllDocumentsDAO

Private ilog As ILogWebService 
Private logDTO As LogWSDTO
Private docDTO As LogGetAllDocumentsDTO
Private utilDt As UtilDate

Public Sub New(logWSparam As LogWSDTO, docDTOparam As LogGetAllDocumentsDTO)
    Set Me.logDTO = logWSparam
    Set Me.docDTO = docDTOparam

End Sub 

Public Sub appelLog()       
    Call ajouterParam()         
    Set ilog = New ILogWebService(logDTO)       
    'Call ilog.notesMain()
End Sub 

Public Sub ajouterParam()

    Dim retourWS As String 
    Dim paramWS As String

    'paramètres d'envoi de web services
    paramWS = "dbserver=" + docDTO.getDbServer
    paramWS = paramWS + "dbpath="  + docDTO.getDbPath
    paramWS = paramWS + "nomVue="  + docDTO.getNomVue
    paramWS = paramWS + "key="  + docDTO.getKey
    paramWS = paramWS + "sep="  + docDTO.getSep

    logDTO.setParamWS(paramWS)

    'paramètres de retour de web services
    retourWS = "Nombre d'Identifiants : ...." 
    logDTO.setRetourWS(retourWS)

    'logDTO.setDateHeureDebutWS(utilDt.dateTimeDuJour(session, logDTO))     

End Sub     

结束班

感谢您的帮助!!

我回来因为它不起作用 我试着这个调用我的类,好像接口不存在,但它说错误:“LS2J错误:Java构造函数无法执行”

Sub Click(Source As Button)
Dim mySession As JAVASESSION    
Dim myClass As JAVACLASS
Dim myObjet As JAVAOBJECT
Dim toto As String
Dim toto2 As String
Dim myCollection As JavaMethodCollection
Dim myMethod As JavaMethod
Dim myMethod2 As JavaMethod
toto2 = "test"

Set mySession = New  JAVASESSION        
Set myClass = mySession.GetClass("com.pasquier.launcher/LogWebService") 
Set myObjet = myClass.CreateObject("(Lcom/pasquier/DTO/WS/LogWSDTO;)V")


Messagebox (toto2)

Set myCollection = myClass.getClassMethods()

Set myMethod = myCollection.getFirst()
Do
    If myCollection.count <> 0 Then 
        toto2 =  myMethod.MethodName & " " & myMethod.signature
        Messagebox (toto2)          

    End If
    Set myMethod = myCollection.getNext()       
Loop While myCollection.current <> 1    

End Sub

你可以帮助我吗?

3 个答案:

答案 0 :(得分:2)

我们假设我们有一个包com.pasquier.IDAO.WS,其中包含以下类/接口:

  • LogWebService
  • LogWSDTO
  • ILogWebService

LS2J是一件奇怪的事情,并且在某些情况下不起作用。当LS2J报告不应发生的错误时,开发人员会like this作出反应。

我们假设LogWSDTO具有默认构造函数,因此我们创建其实例:

Set logWSDTOClass = javaSession.getClass("com/pasquier/IDAO/WS/LogWSDTO")
Set logWSDTOObject = logWSDTOClass.CreateObject()

然后我们创建对象,在其中使用此日志的构造函数。

我们上课了:

Set logWebServiceClass = javaSession.getClass("com/pasquier/IDAO/WS/LogWebService")

并致电:

Set logWebServiceObject = logWebServiceClass.CreateObject("(Lcom/pasquier/IDAO/WS/LogWSDTO;)V", logWSDTOObject)

TA-DAA!,这不起作用。我们得到了一个着名的#34; Java构造函数未能执行&#34;。为什么?因为构造函数具有一个具有正确类型的参数,所以不应发生此错误。但它是LS2J,我们需要忍受:))

因此,我们需要一种解决方法来解决此任务。

我们正在修改我们的LogWebService类以声明默认构造函数,并且我们正在添加一个新方法:

public void setLog(LogWSDTO log) {
   this.logDTO = log;       
}

之后我们做:

Set logWebServiceObject = logWebServiceClass.CreateObject()
Call logWebServiceObject.setLog(logWSDTOObject)
Call logWebServiceObject.notesMain()

有效。魔法。

下面列出了此示例所需的所有类/代码:


package com.pasquier.IDAO.WS;

public class LogWSDTO {

    public LogWSDTO() {
        System.out.println("@@@ LogWSDTO constructor called!");
    }

    public void log() {
        System.out.println("@@@ LogWSDTO DO called!");
    }

}

package com.pasquier.IDAO.WS;

public interface ILogWebService {
    void notesMain();
}

package com.pasquier.IDAO.WS;

import lotus.domino.Session;

public class LogWebService implements ILogWebService {

    private Session session;
    private LogWSDTO logDTO = null; 

    public LogWebService() {
        System.out.println("LogWebService: Default Constructor called!");
    }

    public void setLog(LogWSDTO log) {
        this.logDTO = log;      
    }

    public LogWebService(LogWSDTO log) {
        this.logDTO = log;
        System.out.println("~~~ LogWebService.constructor!!!");
    }

    public void notesMain() {
        // TODO Auto-generated method stub
        System.out.println("~~~ LogWebService.notesmain called!!!");
        this.logDTO.log();

    }
}

和lotusscript代码:

Sub Click(Source As Button)
    Dim javaSession As New JAVASESSION
    Dim javaError As JAVAERROR

    On Error Goto ErrorHandling

    Dim logWSDTOClass As JAVACLASS
    Dim logWSDTOObject As JavaObject

    Dim logWebServiceClass As JAVACLASS
    Dim logWebServiceObject As JavaObject

    Set logWSDTOClass = javaSession.getClass("com/pasquier/IDAO/WS/LogWSDTO")
    Set logWSDTOObject = logWSDTOClass.CreateObject()

    Set logWebServiceClass = javaSession.getClass("com/pasquier/IDAO/WS/LogWebService")

    'Does not work, but should 
    'Set logWebServiceObject = logWebServiceClass.CreateObject("(Lcom/pasquier/IDAO/WS/LogWSDTO;)V", logWSDTOObject)

    'workaround
    Set logWebServiceObject = logWebServiceClass.CreateObject()
    Call logWebServiceObject.setLog(logWSDTOObject)
    Call logWebServiceObject.notesMain()

    Msgbox "done"

    Exit Sub
ErrorHandling:
    Msgbox Error '
    Set javaError = javaSession.getLastJavaError
    Msgbox "Java error: " + javaError.ErrorMsg 
End Sub

要查看输出消息(通过System.out.println),请通过菜单&#34;工具 - 显示Java调试控制台&#34;打开Java调试控制台。有时这个控制台没有出现,你需要重启Lotus客户端和设计器。

答案 1 :(得分:0)

我还没有玩过LS2J,但它看起来像你的Java类的构造函数将LogWSDTO对象作为参数,但是你在没有任何参数的情况下调用classJava.CreateObject。我相信你应该传递一个JNI签名字符串和参数,如doc here所示。

答案 2 :(得分:0)

庵; Domino 9.0.1FP3在这个领域存在一个已知问题;这可能是潜在的问题吗?您使用的是该版本的Domino还是Notes?请参阅IBM技术说明http://www-01.ibm.com/support/docview.wss?uid=swg21696682