[英]access to a java interface in lotuscript with LS2J?
enter code here
I 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 : enter code here
我尝试通过他的接口访问Java类,而在Ls2J中创建一个类,而不是Java接口,因为我不知道我该怎么做,并且出现错误:
error : LS2J Error: Java constructor failed to execute
An idea ? 一个主意 ? ^^
^^
thanks ! 谢谢 !
my class java in lotus 我的莲花类Java
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: 我的Java介面:
package com.pasquier.IDAO.WS; 包com.pasquier.IDAO.WS;
import com.pasquier.MesExceptions.ExceptionWS; 导入com.pasquier.MesExceptions.ExceptionWS;
public interface ILogWebService { 公用接口ILogWebService {
void notesMain() throws ExceptionWS;
} }
my java class : 我的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);
}
}
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" 我回来了,因为它不起作用,我尝试使用它来调用我的类,好像该接口不存在,但是它显示错误:“ 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 结束子
could you help me ? 你可以帮帮我吗 ?
Let us assume we have a package com.pasquier.IDAO.WS
and the following classes/interface in it: 让我们假设我们有一个包
com.pasquier.IDAO.WS
及其下面的类/接口:
LS2J is a strange thing and does not work as it should be in some cases. LS2J是一件奇怪的事情,在某些情况下不能正常工作。 And a developer reacts like this when LS2J reports an error which should not be occured.
当LS2J报告不应发生的错误时,开发人员会做出这样的反应。
We assume that LogWSDTO has default constructor, so we create its instance: 我们假设LogWSDTO具有默认构造函数,因此我们创建其实例:
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. TA-DAA !,那是行不通的。 We get a famous "Java constructor failed to execute".
我们得到了著名的“ Java构造函数执行失败”。 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 :)
但这是LS2J,我们需要忍受:)
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: 我们正在修改
LogWebService
类以声明默认构造函数,并添加了一个新方法:
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: 和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
To view output messages (via System.out.println) open Java Debug Console via menu "Tools - Show Java Debug Console". 要查看输出消息(通过System.out.println),可通过菜单“工具-显示Java调试控制台”打开Java调试控制台。 Sometimes this console does not show up and you need to restart lotus client and designer.
有时此控制台不会显示,您需要重新启动Lotus Client和Designer。
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. 我没怎么玩LS2J,但是在我看来,您的Java类的构造函数将LogWSDTO对象作为参数,但是您在调用
classJava.CreateObject
没有任何参数。 I believe you should be passing a JNI signature string and the argument, as shown in doc here . 我相信您应该传递JNI签名字符串和参数,如doc here所示。
Um; 嗯 there is a known issue in this area with Domino 9.0.1FP3;
Domino 9.0.1FP3在此领域存在一个已知问题; could that be the underlying issue?
这可能是潜在的问题吗? Are you using that version of Domino or Notes?
您是否正在使用该版本的Domino或Notes? See IBM technote http://www-01.ibm.com/support/docview.wss?uid=swg21696682
请参阅IBM技术说明http://www-01.ibm.com/support/docview.wss?uid=swg21696682
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.