code: private static ServiceAccount getInstanceByVcapServices(String serviceName, String serviceInstanceName) {
          Map<String, String> env = System.getenv();
          String vcapServices = env.get("VCAP_SERVICES");
          if (vcapServices == null) {
              return null;
          }
  
          try {
              JsonObject obj = new JsonParser().parse(vcapServices).getAsJsonObject();
  
              // When service name is specified,
              // this method returns only a matching entry
              if (serviceName != null) {
                  JsonElement elem = obj.get(serviceName);
                  if (elem != null && elem.isJsonArray()) {
                      return parseToServiceAccount(elem.getAsJsonArray(), serviceInstanceName);
                  }
              }
  
              // Otherwise, lookup a valid entry with a name matching
              // the default pattern GP_SERVICE_NAME_PATTERN.
              for (Entry<String, JsonElement> entry : obj.entrySet()) {
                  String name = entry.getKey();
                  JsonElement elem = entry.getValue();
                  if (elem.isJsonArray() && GP_SERVICE_NAME_PATTERN.matcher(name).matches()) {
                      ServiceAccount account = parseToServiceAccount(elem.getAsJsonArray(), serviceInstanceName);
                      if (account != null) {
                          return account;
                      }
                  }
              }
          } catch (JsonParseException e) {
              // Fall through - will return null
          }
  
          return null;
      }
docs: Returns an instance of ServiceAccount from the VCAP_SERVICES environment
  variable.
  <p>
  When <code>serviceInstanceName</code> is null, this method returns
  a ServiceAccount for the first valid IBM Globlization Pipeline service instance.
  If <code>serviceInstanceName</code> is not null, this method look up a
  matching service entry, and returns a ServiceAccount for the matching entry.
  If <code>serviceInstanceName</code> is not null and there is no match,
  this method returns null.
  
  @param serviceName
  The name of IBM Globalization Pipeline service. If null,
  the first service with a name matching GP_SERVICE_NAME_PATTERN
  will be used.
  @param serviceInstanceName
  The name of IBM Globalization Pipeline service instance, or null
  designating the first available service instance.
  @return  An instance of ServiceAccount for the specified service instance
  name, or null.