JayC
JayC

Reputation: 2292

How to access CUPS variables from java?

I am trying to access the variables in CUPS in cloud foundry. Currently I have my values set as environment variables.

In java I use the following code to retrieve environment variables.

String variableName = System.getenv("variableName");

I am following this link and it talks about creating a user provided service and retrieve data from there.

Example

cfenv = require("cfenv")

var localVCAP = require("./local-vcap.json")

var appEnv = cfenv.getAppEnv({vcap: localVCAP})
var creds  = appEnv.getServiceCreds(/session-secret/) || {}

console.log("session secret is:", creds.secret)

How can I do simliar thing but in java? "How to retrieve cloud foundry CUPS varibles into java?"

Upvotes: 0

Views: 1670

Answers (1)

Praneeth Ramesh
Praneeth Ramesh

Reputation: 3564

Once created, user-provided service instances behave like service instances created through the marketplace only. By Default all the services binded to the application is available in environment variable VAP_SERVICES.

Bind the CUPS service to your application, then read the VCAP_SERVICES System property in your java code.

String vcapServices = System.getenv("VCAP_SERVICES");

This value is a JSON that has a all the binded services related information. You can parse this JSON to read your CUPS service properties. Sample variable would look like

{
    "VCAP_SERVICES": {
        "user-provided": [
            {
                "sec": {
                    "key": "1234567890"
                },
                "label": "user-provided",
                "name": "sample-cups-secret",
                "syslog_drain_url": "",
                "tags": []
            }
        ]
    }

Upvotes: 2

Related Questions