Reputation: 65
I have been trying to create a script to use a service acct with Google's Directory API and having no luck. So far I have:
-Downloaded the Admin Directory JAR Files from here and put them all in my WEB-INF/lib dir
-Created a service acct according to their instructions for domain delegation – I generated a P12 file instead of JSON because that's what the instantiation code uses
-I converted the JAVA code on that same instruction page to ColdFusion so it looks like this
p12File = createObject( 'java', 'java.io.File' ).init("{my file path}");
accountId = JavaCast( "string", "[email protected]" );
GoogleCredential = createObject( "java", "com.google.api.client.googleapis.auth.oauth2.GoogleCredential$Builder" );
HttpTransport = createObject( "java", "com.google.api.client.http.HttpTransport" );
NetHttpTransport = createObject( "java", "com.google.api.client.http.javanet.NetHttpTransport" );
JsonFactory = createObject( "java", "com.google.api.client.json.JsonFactory" );
JacksonFactory = createObject( "java", "com.google.api.client.json.jackson2.JacksonFactory" );
Directory = createObject( "java", "com.google.api.services.admin.directory.Directory$Builder" );
DirectoryScopes = createObject( "java", "com.google.api.services.admin.directory.DirectoryScopes" );
Collections = createObject( "java", "java.util.Collections" );
credential = GoogleCredential
.setTransport( NetHttpTransport )
.setJsonFactory( JacksonFactory )
.setServiceAccountId( accountId )
.setServiceAccountScopes( Collections.singleton( DirectoryScopes.ADMIN_DIRECTORY_USER ) )
.setServiceAccountUser("[email protected]")
.setServiceAccountPrivateKeyFromP12File( p12File )
.build();
service = Directory.Init( NetHttpTransport, JacksonFactory, javaCast( "null", "" ) ).setHttpRequestInitializer( credential ).build();
I get a Coldfusion Error at my service=Directory.Init... line that reads "The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code. Null Pointers are another name for undefined values." and I don't understand why. All I've been able to figure out is that this is a rather generic error for what appears to be an unacceptable value for one of the variables.
TIA for any help you could offer
Upvotes: 3
Views: 354
Reputation: 28873
(From the comments ...)
May be unrelated, but .. neither NetHttpTransport
or JacksonFactory
was initialized in the CF Code. Normally CF invokes the no-arg constructor automatically, when you first invoke a method on an un-initialized java object:
If you call a public non-static method on the object without first calling the init method, ColdFusion makes an implicit call to the default constructor.
However, I do not know if that same rule applies when passing an uninitialized object into a constructor. Try invoking init()
on the objects explicitly to see if that resolves the NullPointerException:
NetHttpTransport = createObject( "java", "com.google.api.client.http.javanet.NetHttpTransport" ).init();
JacksonFactory = createObject( "java", "com.google.api.client.json.jackson2.JacksonFactory" ).init();
Upvotes: 1