CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-google-api-client--google-api-client

The Google APIs Client Library for Java is a flexible, efficient, and powerful Java client library for accessing any HTTP-based API on the web, not just Google APIs.

Pending
Overview
Eval results
Files

utilities.mddocs/

Utilities

Core utility classes providing version information, certificate management, and common functionality used throughout the library.

Core Imports

import com.google.api.client.googleapis.GoogleUtils;
import com.google.api.client.googleapis.util.Utils;
import com.google.api.client.googleapis.notifications.NotificationUtils;

Version and Library Information

GoogleUtils

Central utility class providing version information and certificate management.

public final class GoogleUtils {
    public static final String VERSION;
    public static final Integer MAJOR_VERSION;
    public static final Integer MINOR_VERSION;
    public static final Integer BUGFIX_VERSION;
    
    public static synchronized KeyStore getCertificateTrustStore()
        throws IOException, GeneralSecurityException;
}

Usage Example:

import com.google.api.client.googleapis.GoogleUtils;
import java.security.KeyStore;

// Get library version information
System.out.println("Google API Client Version: " + GoogleUtils.VERSION);
System.out.println("Major Version: " + GoogleUtils.MAJOR_VERSION);
System.out.println("Minor Version: " + GoogleUtils.MINOR_VERSION);
System.out.println("Bugfix Version: " + GoogleUtils.BUGFIX_VERSION);

// Get Google's certificate trust store
try {
    KeyStore trustStore = GoogleUtils.getCertificateTrustStore();
    System.out.println("Trust store loaded with " + trustStore.size() + " certificates");
} catch (Exception e) {
    System.err.println("Failed to load trust store: " + e.getMessage());
}

Version Pattern Matching

// The library uses a specific version pattern for parsing
// Pattern: (\\d+)\\.(\\d+)\\.(\\d+)(-SNAPSHOT)?
// Examples: "2.8.0", "2.8.0-SNAPSHOT"

public class VersionInfo {
    public static void printVersionDetails() {
        String version = GoogleUtils.VERSION;
        System.out.println("Full Version String: " + version);
        
        // Check if it's a snapshot build
        boolean isSnapshot = version.contains("-SNAPSHOT");
        System.out.println("Is Snapshot Build: " + isSnapshot);
        
        // Version components are available as separate constants
        System.out.println("Version Components: " + 
            GoogleUtils.MAJOR_VERSION + "." + 
            GoogleUtils.MINOR_VERSION + "." + 
            GoogleUtils.BUGFIX_VERSION);
    }
}

General Utilities

Utils

General utility methods for common operations.

public final class Utils {
    public static final String USER_AGENT_SUFFIX = "google-api-java-client/" + GoogleUtils.VERSION;
    
    public static String getDefaultUserAgent();
    public static String getUserAgent(String applicationName);
}

Usage Example:

import com.google.api.client.googleapis.util.Utils;

// Get default user agent string
String defaultUserAgent = Utils.getDefaultUserAgent();
System.out.println("Default User Agent: " + defaultUserAgent);

// Get user agent with custom application name
String customUserAgent = Utils.getUserAgent("MyApplication/1.0");
System.out.println("Custom User Agent: " + customUserAgent);

// Example output:
// "MyApplication/1.0 google-api-java-client/2.8.0"

Notification Utilities

NotificationUtils

Utility methods for generating notification channel identifiers.

public final class NotificationUtils {
    public static String randomUuidString();
}

Usage Example:

import com.google.api.client.googleapis.notifications.NotificationUtils;

// Generate a random UUID string for notification channel ID
String channelId = NotificationUtils.randomUuidString();
System.out.println("Generated channel ID: " + channelId);

// Example usage in creating a notification channel
public void createNotificationChannel(String resourceUri, long expiration) {
    String channelId = NotificationUtils.randomUuidString();
    
    // Use the generated ID to create a notification channel
    // (implementation depends on specific Google API being used)
    System.out.println("Creating notification channel with ID: " + channelId);
    System.out.println("Resource URI: " + resourceUri);
    System.out.println("Expiration: " + new Date(expiration));
}

Certificate Management

Trust Store Operations

import java.security.KeyStore;
import java.security.cert.Certificate;
import java.util.Enumeration;

public class CertificateInspector {
    public static void inspectGoogleTrustStore() throws Exception {
        KeyStore trustStore = GoogleUtils.getCertificateTrustStore();
        
        System.out.println("Google Trust Store Information:");
        System.out.println("Type: " + trustStore.getType());
        System.out.println("Provider: " + trustStore.getProvider().getName());
        System.out.println("Number of certificates: " + trustStore.size());
        
        // List all certificate aliases
        Enumeration<String> aliases = trustStore.aliases();
        while (aliases.hasMoreElements()) {
            String alias = aliases.nextElement();
            Certificate cert = trustStore.getCertificate(alias);
            
            System.out.println("Certificate alias: " + alias);
            System.out.println("Certificate type: " + cert.getType());
            // Additional certificate details can be extracted here
        }
    }
}

User Agent Management

Application Identification

public class UserAgentManager {
    private final String applicationName;
    private final String applicationVersion;
    
    public UserAgentManager(String applicationName, String applicationVersion) {
        this.applicationName = applicationName;
        this.applicationVersion = applicationVersion;
    }
    
    public String buildUserAgent() {
        String appIdentifier = applicationName;
        if (applicationVersion != null && !applicationVersion.isEmpty()) {
            appIdentifier += "/" + applicationVersion;
        }
        
        return Utils.getUserAgent(appIdentifier);
    }
    
    public HttpRequestInitializer createRequestInitializer(HttpRequestInitializer baseInitializer) {
        return new HttpRequestInitializer() {
            @Override
            public void initialize(HttpRequest request) throws IOException {
                if (baseInitializer != null) {
                    baseInitializer.initialize(request);
                }
                
                // Set custom user agent
                HttpHeaders headers = request.getHeaders();
                if (headers.getUserAgent() == null) {
                    headers.setUserAgent(buildUserAgent());
                }
            }
        };
    }
}

// Usage
UserAgentManager userAgentManager = new UserAgentManager("MyApp", "2.1.0");
String userAgent = userAgentManager.buildUserAgent();
// Result: "MyApp/2.1.0 google-api-java-client/2.8.0"

Library Compatibility

Version Compatibility Checks

public class CompatibilityChecker {
    private static final int MIN_SUPPORTED_MAJOR = 2;
    private static final int MIN_SUPPORTED_MINOR = 0;
    
    public static boolean isCompatibleVersion() {
        return GoogleUtils.MAJOR_VERSION >= MIN_SUPPORTED_MAJOR && 
               (GoogleUtils.MAJOR_VERSION > MIN_SUPPORTED_MAJOR || 
                GoogleUtils.MINOR_VERSION >= MIN_SUPPORTED_MINOR);
    }
    
    public static void checkCompatibility() {
        if (!isCompatibleVersion()) {
            System.err.println("Warning: Google API Client version " + GoogleUtils.VERSION + 
                             " may not be compatible with this application. " +
                             "Minimum required version: " + MIN_SUPPORTED_MAJOR + "." + 
                             MIN_SUPPORTED_MINOR + ".0");
        }
    }
    
    public static String getVersionInfo() {
        return String.format(
            "Google API Client for Java v%s (Build: %d.%d.%d)",
            GoogleUtils.VERSION,
            GoogleUtils.MAJOR_VERSION,
            GoogleUtils.MINOR_VERSION, 
            GoogleUtils.BUGFIX_VERSION
        );
    }
}

Configuration Helpers

Library Configuration

public class LibraryConfiguration {
    public static void printSystemInformation() {
        System.out.println("=== Google API Client Configuration ===");
        System.out.println("Library Version: " + GoogleUtils.VERSION);
        System.out.println("Java Version: " + System.getProperty("java.version"));
        System.out.println("Java Vendor: " + System.getProperty("java.vendor"));
        System.out.println("OS Name: " + System.getProperty("os.name"));
        System.out.println("OS Version: " + System.getProperty("os.version"));
        System.out.println("OS Architecture: " + System.getProperty("os.arch"));
        
        // Check for important system properties that affect the library
        String httpAgent = System.getProperty("http.agent");
        if (httpAgent != null) {
            System.out.println("System HTTP Agent: " + httpAgent);
        }
        
        String proxyHost = System.getProperty("http.proxyHost");
        String proxyPort = System.getProperty("http.proxyPort");
        if (proxyHost != null) {
            System.out.println("HTTP Proxy: " + proxyHost + 
                             (proxyPort != null ? ":" + proxyPort : ""));
        }
        
        String httpsProxyHost = System.getProperty("https.proxyHost");
        String httpsProxyPort = System.getProperty("https.proxyPort");
        if (httpsProxyHost != null) {
            System.out.println("HTTPS Proxy: " + httpsProxyHost + 
                             (httpsProxyPort != null ? ":" + httpsProxyPort : ""));
        }
    }
}

Types

KeyStore

Java security KeyStore for certificate and key management.

IOException

Exception for I/O operations.

GeneralSecurityException

Exception for general security-related operations.

HttpRequestInitializer

Interface for initializing HTTP requests.

HttpRequest

HTTP request representation.

HttpHeaders

HTTP headers container.

String

Java string class.

Integer

Java integer wrapper class.

Certificate

Java security certificate representation.

Date

Java date class for timestamp representation.

Install with Tessl CLI

npx tessl i tessl/maven-com-google-api-client--google-api-client

docs

batch-operations.md

client-services.md

http-transport.md

index.md

json-error-handling.md

media-operations.md

oauth2-auth.md

utilities.md

tile.json