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.