1

Using Domino Designer 9.0.1FP3 how can I use Gmail API?

Tried sample Java code from this link https://developers.google.com/gmail/api/quickstart/java without any luck as follows:

  1. Imported necessary gmail api .jar latest version.
  2. Installed jre is 8 and setup build path for jre 8 path
  3. Complier JRE version is still same which 1.5 by default.

Any help will be appreciated.

This is java agent to interact with gmail api:

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

import lotus.domino.*;

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
//import com.google.api.*;
/***/The following lines has error "import can not be resolved". I've imported jar and their sources from gmail .jar file zip***
import com.google.api.services.gmail.*;
import com.google.api.services.gmail.GmailScopes;
import com.google.api.services.gmail.model.*;
import com.google.api.services.gmail.Gmail;





public class JavaAgent extends AgentBase {


    public void NotesMain() {
         /** Application name. */
        final String APPLICATION_NAME =
            "Gmail API Java Quickstart";
        /** Directory to store user credentials for this application. */
        final java.io.File DATA_STORE_DIR = new java.io.File(
            System.getProperty("user.home"), ".credentials/gmail-java-quickstart");

        FileDataStoreFactory DATA_STORE_FACTORY;

        /** Global instance of the JSON factory. */
        final JsonFactory JSON_FACTORY =
            JacksonFactory.getDefaultInstance();

        HttpTransport HTTP_TRANSPORT;

        /* Global instance of the scopes required by this quickstart. */
        final List<String> SCOPES =
         //   Arrays.asList(com.google.api.services.gmail.GmailScopes.)//.GMAIL_LABELS);
Arrays.asList(com.google.api.)

        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();

          // (Your code goes here)

      } catch(Exception e) {
          e.printStackTrace();
       }
   }
Mohan Gangan
  • 127
  • 11

2 Answers2

2

Ok, you need to make sure that the API can actually run on a Java 1.6 as Per mentions.

You can add the jar(s) to your Domino in several ways:

1. In the JVM ext/lib directory

This works fine - it is just a pain to maintain as everthing needs to be done in the file system (also in your Domino Designer). This works for XPages as well as agents.

2. Attach the jar to your agent/script library

This only applies to code running in agents (or webservices). However, there is a memory leak which occurs every time the code is called (and the jar is detached internally). So don't use this one!

3. Add the jar as a jar design element

This should also work - though I haven't got much experience with it. I fear the same issues as with the element above - but has no evidence on that. So you are probably fine using this - will only work for XPages.

4. Add the jar as a plugin

You can wrap the jar into an OSGi plugin and deploy it server wide (2 and 3 above only makes the jar available to the NSF the jar is inside). This is by far my preferred way. I have written an article about the details that can help you on the way.

/John

John Dalsgaard
  • 2,797
  • 1
  • 14
  • 26
  • Also, if installing the jar in the NSF, if you get a NoClassDefFoundError, try changing security settings to allow all permissions in java.policy. If that solves the problem, option 4 is the way to go. Domino's Java security is copied from Websphere and does not delegate as much to the Domino server as it should. Java 8 will be coming to Domino in the next release, probably early next year. The Mac install released recently already includes some Java 8 files, which proves that's where IBM are looking. – Paul Stephen Withers Oct 07 '15 at 08:08
  • Exactly, you will have the permissions issue. You can work around this if you use option 4 - see: http://www.dalsgaard-data.eu/blog/elevating-permissions-for-your-third-party-jar/ :-) – John Dalsgaard Oct 07 '15 at 13:48
  • I don't have any permission errors. Most errors are related to classes and methods in .gmail api such as "CalendarSample cannot be resolved to a type" – Mohan Gangan Oct 07 '15 at 15:46
  • ... and how did you add the jars to be used by your application? – John Dalsgaard Oct 08 '15 at 09:04
  • Added .jars using agent's archive feature means imported .jar file as archive in agent it self – Mohan Gangan Oct 08 '15 at 19:15
  • Hmmmm.... that means that you use what I call option 2. There seems to be a problem with your class path... - but due to the reasons I mentioned above I would go for option 1 - or option 4 - and recode as an XAgent... – John Dalsgaard Oct 09 '15 at 12:46
  • Just saw the comments about JVM version under your original question. You should have read and carried out the first line in my response... :-) – John Dalsgaard Oct 09 '15 at 12:47
0
  1. Installed jdk1.7.079
  2. In project properties->Java Build Path set it up as JRE System Library(jdk1.7.079)

No more compilation error.

Mohan Gangan
  • 127
  • 11