private void init() throws IOException { try { Class<?> factoryClass = forName(APP_IDENTITY_SERVICE_FACTORY_CLASS); Method method = factoryClass.getMethod(GET_APP_IDENTITY_SERVICE_METHOD); this.appIdentityService = method.invoke(null); Class<?> serviceClass = forName(APP_IDENTITY_SERVICE_CLASS); Class<?> tokenResultClass = forName(GET_ACCESS_TOKEN_RESULT_CLASS); this.getAccessTokenResult = serviceClass.getMethod(GET_ACCESS_TOKEN_RESULT_METHOD, Iterable.class); this.getAccessToken = tokenResultClass.getMethod(GET_ACCESS_TOKEN_METHOD); this.getExpirationTime = tokenResultClass.getMethod(GET_EXPIRATION_TIME_METHOD); this.account = (String) serviceClass.getMethod(GET_SERVICE_ACCOUNT_NAME_METHOD) .invoke(appIdentityService); this.signForApp = serviceClass.getMethod(SIGN_FOR_APP_METHOD, byte[].class); Class<?> signingResultClass = forName(SIGNING_RESULT_CLASS); this.getSignature = signingResultClass.getMethod(GET_SIGNATURE_METHOD); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { throw new IOException( "Application Default Credentials failed to create the Google App Engine service account" + " credentials. Check that the App Engine SDK is deployed.", ex); } }
private void init() throws IOException { try { Class<?> factoryClass = forName(APP_IDENTITY_SERVICE_FACTORY_CLASS); Method method = factoryClass.getMethod(GET_APP_IDENTITY_SERVICE_METHOD); this.appIdentityService = method.invoke(null); Class<?> serviceClass = forName(APP_IDENTITY_SERVICE_CLASS); Class<?> tokenResultClass = forName(GET_ACCESS_TOKEN_RESULT_CLASS); this.getAccessTokenResult = serviceClass.getMethod(GET_ACCESS_TOKEN_RESULT_METHOD, Iterable.class); this.getAccessToken = tokenResultClass.getMethod(GET_ACCESS_TOKEN_METHOD); this.getExpirationTime = tokenResultClass.getMethod(GET_EXPIRATION_TIME_METHOD); this.account = (String) serviceClass.getMethod(GET_SERVICE_ACCOUNT_NAME_METHOD) .invoke(appIdentityService); this.signForApp = serviceClass.getMethod(SIGN_FOR_APP_METHOD, byte[].class); Class<?> signingResultClass = forName(SIGNING_RESULT_CLASS); this.getSignature = signingResultClass.getMethod(GET_SIGNATURE_METHOD); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { throw new IOException( "Application Default Credentials failed to create the Google App Engine service account" + " credentials. Check that the App Engine SDK is deployed.", ex); } }