I am trying to solve an issue where by I have to .p12 files that correspond to production and development. I am looking for a way for java to know whether it is running in prod or dev so that I can choose the appropriate p12 to use.
Currently I am using the following logic
private static final String PATH_TO_P12_DEV = "/JavaPNSDEV.p12";
private static final String PATH_TO_P12_PROD = "/JavaPNSPROD.p12";
private InputStream keystoreInputStream = null;
private final Logger logger = Logger.getLogger(ApplePushNotificationSystem.class);
private PushManager<SimpleApnsPushNotification> pushManager = null;
private void connect() throws NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException, KeyManagementException, KeyStoreException {
try {
if(InetAddress.getLocalHost().getHostName().toLowerCase().equals("hostname")){
keystoreInputStream = this.getClass().getResourceAsStream(PATH_TO_P12_PROD);
}else{
keystoreInputStream = this.getClass().getResourceAsStream(PATH_TO_P12_DEV);
}
However this worries me because as soon as the hostname changes / someone changes the hostname this will fail.
What is the correct approach for solving as issue like this?
Thanks