Extract XL Routes Static credentials from VCAP_SERVICES

    Our documentation assumes that your XL Routes Static credentials are available in the form of a connection string in the xlroutesSTATIC_URL environment variable.

    On CloudFoundry based platforms like IBM Cloud, Pivotal and RedHat Openshift, this is not the case.

    So you need slightly different code to access your XL Routes Static credentials by extracting them from the VCAP_SERVICES environment variable.

    The VCAP_SERVICES entry looks like the following:

    {
      "xlroutes": [
        {
          "name": "xlroutesInstance",
          "label": "xlroutes",
          "tags": [],
          "plan": "starter",
          "credentials": {
            "xlroutesSTATIC_URL": "http://username:password@proxy.xlroutes.com:9293"
          }
        }
      ]
    }
    

    Extract the variable using the snippets below and then continue with our standard documented solutions.

    In Java

    String vcapServices = System.getenv("VCAP_SERVICES");
    JsonRootNode root = new JdomParser().parse(vcapServices);
    JsonNode xlroutesNode = root.getNode("xlroutes");
    JsonNode credentials = xlroutesNode.getNode(0).getNode("credentials");
    String proxyURL = credentials.getStringValue("xlroutesSTATIC_URL");
    

    In Ruby

    vcapServices = JSON.parse(ENV['VCAP_SERVICES'])
    proxyURL = vcapServices['xlroutes'].first.dig('credentials', 'xlroutesSTATIC_URL')
    

    In Python

    service = json.loads(os.environ['VCAP_SERVICES'])['xlroutes'][0]
    credentials = service['credentials']
    proxy_url = credentials['xlroutesSTATIC_URL']
    

    In Node.js/Javascript

    let vcap_services = JSON.parse(process.env.VCAP_SERVICES)
    let proxyUrl = vcap_services.xlroutes[0].credentials.xlroutesSTATIC_URL
    

    In PHP

    $vcap = json_decode(getenv("VCAP_SERVICES"),true);
    $proxy_url = $vcap["xlroutes"][0]["credentials"]["xlroutesSTATIC_URL"];
    

    If you have any questions on these code samples, please write us at Support so we can assist.