0
votes

enter code hereI try to acess a java class by his interface I make a class in Ls2J instead the java interface because i don't know how i do and i have the error :

error : LS2J Error: Java constructor failed to execute

An idea ? ^^

thanks !

my class 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 

End Class

my java interface:

package com.pasquier.IDAO.WS;

import com.pasquier.MesExceptions.ExceptionWS;

public interface ILogWebService {

void notesMain() throws ExceptionWS;    

}

my java class :

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);
    }
}

my lotuscript :

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     

End Class

thanks for your help !!

i come back because it didn't work i try this to call my class as if the interface doesn't exist but it says error : "LS2J Error : Java constructor failed to execute"

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

could you help me ?

3
show your lotusscript code, that causes the problem, and show java constructor codeuser784540
first point: you need to specify fully qualified class name, instead of fully qualified interface path. second point: make sure there is no typo in the fully qualified name of your class. There is mixture with . and / symbols in the fully qualified class name. Third point: invoke the class constructor with the necessary parameter and specify the signature of your class constructor method.user784540
thanks a lot for your answer. But if i understand what you say, i do as if the interface not exist ? yes ? i try and i come backsissi49
Create the instance of your class, do not java interface upon class instantce creation. And call the class constructor properly, via specifying all necessary parameters with signatures.user784540
i try to do that in a "hello button" but it crash, see my second answer, please ^^. I think in my signature of the constructor but i don't know what i have to do ...sissi49

3 Answers

2
votes

Let us assume we have a package com.pasquier.IDAO.WS and the following classes/interface in it:

  • LogWebService
  • LogWSDTO
  • ILogWebService

LS2J is a strange thing and does not work as it should be in some cases. And a developer reacts like this when LS2J reports an error which should not be occured.

We assume that LogWSDTO has default constructor, so we create its instance:

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

Then we create object, that uses this log in it's constructor.

We get the class:

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

And calling:

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

TA-DAA!, that's does not work. We get a famous "Java constructor failed to execute". Why? Because the constructor has one parameter with a correct type and this error should not occur. But it is LS2J, and we need to suffer :)

So, we need a workaround to solve this task.

We are modifying our LogWebService class to declare a default constructor, and we're adding a new method:

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

After that we do:

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

It works. Magic.

Below there is listing of all classes/code you will need for this example:


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();

    }
}

And lotusscript code:

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

To view output messages (via System.out.println) open Java Debug Console via menu "Tools - Show Java Debug Console". Sometimes this console does not show up and you need to restart lotus client and designer.

0
votes

I haven't played with LS2J much, but it looks to me like the constructor of your Java class takes a LogWSDTO object as an argument, but you are calling classJava.CreateObject without any arguments. I believe you should be passing a JNI signature string and the argument, as shown in doc here.

0
votes

Um; there is a known issue in this area with Domino 9.0.1FP3; could that be the underlying issue? Are you using that version of Domino or Notes? See IBM technote http://www-01.ibm.com/support/docview.wss?uid=swg21696682