Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baybatu/62d239493d1602c67109 to your computer and use it in GitHub Desktop.
Save baybatu/62d239493d1602c67109 to your computer and use it in GitHub Desktop.
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