10 月 30 日更新,见问题底部。
我在 Eclipse 中创建了一个独立 java 应用程序的工作示例(基于 SBT 的 sbt.sample.app GetAllCommunitiesApp.java。我唯一的变化是我手动创建了我的 BasicEndpoint 以跳过使用托管 bean 进行端点配置(和因此读取 managed-beans.xml)。如前所述,这一切都在 Eclipse 中运行良好。
将代码移动到本地 Notes Java 代理(代理被放置在本地数据库中),我首先将 SBT jar 文件复制到我的 C:\Program Files (x86)\IBM\Lotus\Notes\jvm\lib\ext目录。有关这些文件的列表,请参见下文。当我运行 java 代理时,我得到以下堆栈跟踪;
Exception in thread "AgentThread: JavaAgent" java.lang.NoSuchMethodError: org/apache/http/protocol/BasicHttpContext.<init>()V
at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:285)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:851)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
at com.ibm.sbt.services.client.ClientService.executeRequest(ClientService.java:1043)
at com.ibm.sbt.services.client.ClientService._xhr(ClientService.java:1006)
at com.ibm.sbt.services.client.ClientService.execRequest(ClientService.java:972)
at com.ibm.sbt.services.client.ClientService.xhr(ClientService.java:932)
at com.ibm.sbt.services.client.ClientService.get(ClientService.java:808)
at com.ibm.sbt.services.client.ClientService.get(ClientService.java:804)
at com.ibm.sbt.services.client.base.BaseService.retrieveData(BaseService.java:350)
at com.ibm.sbt.services.client.base.BaseService.retrieveData(BaseService.java:372)
at com.ibm.sbt.services.client.base.BaseService.retrieveData(BaseService.java:325)
at com.ibm.sbt.services.client.base.BaseService.getEntities(BaseService.java:185)
at com.ibm.sbt.services.client.connections.communities.CommunityService.getMyCommunities(CommunityService.java:265)
at com.ibm.sbt.services.client.connections.communities.CommunityService.getMyCommunities(CommunityService.java:249)
at no.tine.sbt.SBTCommunityHelper.getMyCommunities(SBTCommunityHelper.java:36)
at JavaAgent.NotesMain(JavaAgent.java:27)
at lotus.domino.AgentBase.runNotes(Unknown Source)
at lotus.domino.NotesThread.run(Unknown Source)
搜索 StackOverflow 和其他站点表明,其他人已经看到了混合版本的 Apache HttpClient 的类似问题(通常人们一直在使用 httpclient 4.0.1,并且问题消失了,将其替换为 httpclient 4.1)。SBT 包含 httpclient-4.2.1.jar 是我复制到 Lotus Notes 的 C:\Program Files (x86)\IBM\Lotus\Notes\jvm\lib\ext 的文件。
对我来说,Lotus Notes 似乎以某种方式使用了某个地方的其他 httpclient,这可能已经过时了。
所以问题是 - 我可以强制 Notes 以某种方式使用 SBT jar 吗?有任何想法吗?
作为参考,我复制到我的 C:\Program Files (x86)\IBM\Lotus\Notes\jvm\lib\ext 的 SBT jar 文件是;
com.ibm.commons-1.0.0.20131024-1349.jar
com.ibm.commons.runtime-1.0.0.20131024-1349.jar
com.ibm.commons.xml-1.0.0.20131024-1349.jar
com.ibm.sbt.core-1.0.0.20131024-1349.jar
com.ibm.sbt.playground-1.0.0.20131024-1349.jar
apache-mime4j-0.6.jar
com.ibm.sbt.javamail-1.4.5.jar
commons-codec-1.3.jar
commons-fileupload-1.2.2.jar
commons-io-2.4.jar
commons-logging-1.1.1.jar
httpclient-4.2.1.jar
httpcore-4.2.1.jar
httpmime-4.2.1.jar
2013 年 10 月 30 日更新 - 找到了一个可能遵循相同路线的样本。以下代码是一个完整的 Notes Java 代理,其核心代码直接来自 Apache.org HttpClient 4.2 示例代码。这也会产生 NoSuchMethodError,并且可能比 SBT 更容易调试。
/*
* Sample retrieved from
* http://hc.apache.org/httpcomponents-client-4.2.x/httpclient/examples/org/apache/http/examples/client/ClientWithResponseHandler.java
*/
import java.io.IOException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet("http://www.google.com/");
System.out.println("executing request " + httpget.getURI());
// Create a response handler
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httpget, responseHandler);
System.out.println("----------------------------------------");
System.out.println(responseBody);
System.out.println("----------------------------------------");
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
// Notes Exception catcher
} catch(Exception e) {
e.printStackTrace();
}
}
}