Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Problem of private key file(.p12) not found while Google Analytics API authenticating in WebLogic

I encountered with a problem in WebLogic about to find full path of .p12(private key file) that needs to be specified for Google Analytics API authentication.

My private key file (google_analytics_private_key.p12) was in path '<PROJECT_PATH>/src/main/resources/keys/google_analytics_private_key.p12' in project source. Key loader method was such below and it worked in Tomcat flawlessly but not in WebLogic.

public String getGoogleAccountPrivateKeyFile() {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    URL resource = loader.getResource("/keys/google_analytics_private_key.p12");
    return resource.getFile();
}

The private key could not be found in WebLogic and threw exception. Key file was being searched in 'classpath.jar' that a WebLogic related jar file. After investigation with my team lead through bunch of SO questions, then I changed my method as below.

public String getGoogleAccountPrivateKeyFile() throws MalformedURLException {
    URL resource = servletContext.getResource("/WEB-INF/keys/google_analytics_private_key.p12");
    return resource.getFile();
}

and worked flawlessly for both Tomcat and WebLogic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.