Attemt to use SBT from Domino Java Agent fails with NoSuchMethodError: org/apache/http/protocol/BasicHttpContext.<init>()V

StackOverflow https://stackoverflow.com/questions/19652994

  •  01-07-2022
  •  | 
  •  

Question

UPDATE OCT 30th, see at bottom of question.

I have created a working sample of a standalone java application in Eclipse (based on the SBT's sbt.sample.app GetAllCommunitiesApp.java. My only change is that I manually create my BasicEndpoint to skip the use of the managed beans for endpoint configuration (and thus the reading of managed-beans.xml). As said, this all works beautifully in Eclipse.

Moving the code to a local Notes Java agent (agent being placed in local database), I have first and foremost copied the SBT jar files to my C:\Program Files (x86)\IBM\Lotus\Notes\jvm\lib\ext catalog. See below for a list of these files. When I run the java agent, I get the following stack trace;

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)

Searching StackOverflow and other sites shows that others has seen similar problems with mixed versions of Apache's HttpClient (typically people has been using httpclient 4.0.1, and the problem went away replacing it with httpclient 4.1). The SBT includes httpclient-4.2.1.jar is that file is what I have copied to Lotus Notes's C:\Program Files (x86)\IBM\Lotus\Notes\jvm\lib\ext.

To me it seems like Lotus Notes somehow is using some other httpclient from somewhere, which perhaps is outdated.

So the question is - can I force Notes to use the SBT jars in some way? Any ideas?

For reference, the SBT jar files I copied to my C:\Program Files (x86)\IBM\Lotus\Notes\jvm\lib\ext are;

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

UPDATE OCT 30th, 2013 - Found a sample which perhaps goes along the same lines. The following code is a complete Notes Java Agent, with core code directly from Apache.org HttpClient 4.2 example code. This too generates NoSuchMethodError, and is perhaps easier to debug than 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();
       }
   }
}
Was it helpful?

Solution

First, where is your agent running from? Notes ? then that's a great location or On the Server? If on the server, you should make sure the libraries are there too.

One great test is to put the libraries in the Agent's code.

Open your Database in Designer

Expand the Database > Code > Agents

Open your Agent

Click on Archive

Click Import > Archive

Click Browse (Find the folder with the referenced jars)

Select the Jars you want

Click Finish

Click Save (let it compile)

Close and test

If that works, it's down to path issues

---- Updated ----

I added com.ibm.sbt.core / com.ibm.commons.xml com.ibm.commons.runtime com.ibm.commons httpcore httpclient commons-logging jars to the agent as an archive

I used your code, and changed the workspace compatibility to Java1.5

I then changed the Security to Level 3. ... you should try the same, and if it fails, you should look into conflicting java classes.

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

import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;



public class JavaAgent extends AgentBase {

    public void NotesMain() {

        try {
            Session session = getSession();
            AgentContext agentContext = session.getAgentContext();
            lotus.domino.Log log = session.createLog("SampleAgentSBT");
            log.openAgentLog();

            HttpClient httpclient = new DefaultHttpClient();
            try {
                HttpGet httpget = new HttpGet("http://www.google.com/");

                log.logAction("executing request " + httpget.getURI());

                // Create a response handler
                ResponseHandler<String> responseHandler = new BasicResponseHandler();
                String responseBody = httpclient.execute(httpget,
                        responseHandler);
                log.logAction("----------------------------------------");
                log.logAction(responseBody);
                log.logAction("----------------------------------------");

            } finally {
                // When HttpClient instance is no longer needed,
                // shut down the connection manager to ensure
                // immediate deallocation of all system resources
                httpclient.getConnectionManager().shutdown();
            }
            log.close();

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

        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top