Digital Developer Conference: a FREE half-day online conference focused on AI & Cloud – North America: Nov 2 – India: Nov 9 – Europe: Nov 14 – Asia Nov 23 Register now

Close outline
  • United States
IBM?
  • Site map
IBM?
  • Marketplace

  • Close
    Search
  • Sign in
    • Sign in
    • Register
  • IBM Navigation
IBM Developer Answers
  • Spaces
    • Blockchain
    • IBM Cloud platform
    • Internet of Things
    • Predictive Analytics
    • Watson
    • See all spaces
  • Tags
  • Users
  • Badges
  • FAQ
  • Help
Close

Name

Community

  • Learn
  • Develop
  • Connect

Discover IBM

  • ConnectMarketplace
  • Products
  • Services
  • Industries
  • Careers
  • Partners
  • Support
10.190.13.195

Refine your search by using the following advanced search options.

Criteria Usage
Questions with keyword1 or keyword2 keyword1 keyword2
Questions with a mandatory word, e.g. keyword2 keyword1 +keyword2
Questions excluding a word, e.g. keyword2 keyword1 -keyword2
Questions with keyword(s) and a specific tag keyword1 [tag1]
Questions with keyword(s) and either of two or more specific tags keyword1 [tag1] [tag2]
To search for all posts by a user or all posts with a specific tag, start typing and choose from the suggestion list. Do not use a plus or minus sign with a tag, e.g., +[tag1].
  • Ask a question

What is the Best Method for Accessing the VCAP_*, etc Environment Variables from Within Java for the XPages Runtime?

27000514UM gravatar image
Question by Eric McCormick  (119) | Jul 15, 2015 at 01:58 PM ibmcloudxpagesxpages-runtime

Long story short, I just want to know if someone's already created the handling methods to resolve the effective bluemixContext.isRunningOnBluemix() and dbName, dbServer, dbAppPath calls in Java, or if I should spend a little time with System.getenv().

[Update] Thank you to both David and Tony, who have both provided illustrative responses to my original question; I just wish I'd done a slightly better job at asking it the first time.

Ultimately, I was trying to get at more than just the VCAP_SERVICES var and just wanted access to the bluemixContext object in an app config/utils bean I was writing. I settled on using BluemixContextManager.getInstance(), but as pointed out I could also use a variable resolver to get the bluemixContext object (which is available in Java, it just needs resolving) or parse the environment variables myself (e.g.- System.getenv("VCAP_SERVICES")).

I'm going to leave my accepted answer as is, but I've up-voted both David's and Tony's answers. [/Update]

People who like this

  0
Comment
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster

3 answers

  • Sort: 
27000514UM gravatar image
Accepted answer

Answer by Eric McCormick (119) | Jul 15, 2015 at 02:46 PM

As much David Amid's answer is perfectly valid, what I was ultimately looking for was to use existing code to achieve the same results within the XPages runtime's Java context. That being said, poking through the Extension Library's code in the GitHub repository yielded the class in question. Now I just need to get a handle on the current instance of it and I'm good to go.

Comment

People who like this

  0   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
060001JQXA gravatar image

Answer by Tony McGuckin (486) | Jul 15, 2015 at 02:57 PM

Simple really... bluemixContext is a global var already available in the running context for SSJS and Pojo's...

bluemixContext.getVCAP_SERVICES()

Comment
Eric McCormick
GaryMarjoram

People who like this

  2   Show 3   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
27000514UM gravatar image Eric McCormick (119)   Jul 15, 2015 at 03:55 PM 0
Share

I had settled on resolving the instance via BluemixContextManager.getInstance().

I was setting up a managed bean, DDE told me bluemixContext couldn't be resolved. Am I missing something obvious about how the global var can be resolved (or would a variable resolver on bluemixContext be preferable to the getInstance call I'm using)?

060001JQXA gravatar image Tony McGuckin (486)   Jul 16, 2015 at 02:02 AM 1
Share

No, you're good there Eric with the getInstance approach in Java... the example above is for SSJS just to elaborate var's availability.

27000514UM gravatar image Eric McCormick (119) Tony McGuckin (486)   Jul 16, 2015 at 10:10 AM 0
Share

It's a great and convenient object, unless you're trying to be a Java purist :-P

Thanks for the clarification Tony.

27000041J2 gravatar image

Answer by DavidAmid (644) | Jul 15, 2015 at 02:16 PM

Taken from the Watson Developer Cloud on Git

   /**
          * Gets the <b>VCAP_SERVICES</b> environment variable and return it
          *  as a JSONObject.
          *
          * @return the VCAP_SERVICES as Json
          */
 

 private JSONObject getVcapServices() {
         String envServices = System.getenv("VCAP_SERVICES");
         if (envServices == null) return null;
         JSONObject sysEnv = null;
         try {
             sysEnv = JSONObject.parse(envServices);
         } catch (IOException e) {
             // Do nothing, fall through to defaults
             logger.log(Level.SEVERE, "Error parsing VCAP_SERVICES: "+e.getMessage(), e);
         }
         return sysEnv;
     }


Comment
Eric McCormick

People who like this

  1   Show 1   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
27000514UM gravatar image Eric McCormick (119)   Jul 15, 2015 at 02:35 PM 0
Share

So, I shouldn't treat it appreciably different because it's within an XPages runtime app. I can live with that :-) Thanks.

Follow this question

63 people are following this question.

Answers

Answers & comments

Related questions

How to use other Bluemix Services with XPages 1 Answer

Is it possible to kill a XPage for Bluemix instance if it's none responsive 1 Answer

I want to build an XPages Bluemix app but can't because apparently it's not free and not for production data ? 1 Answer

XPages BoilerPlate throws error 500 1 Answer

Intranet authentication on Xpages 1 Answer

  • Contact
  • Privacy
  • IBM Developer Terms of use
  • Accessibility
  • Report Abuse
  • Cookie Preferences

Powered by AnswerHub

Authentication check. Please ignore.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • API Connect
  • Analytic Hybrid Cloud Core
  • Application Performance Management
  • Appsecdev
  • BPM
  • Blockchain
  • Business Transaction Intelligence
  • CAPI
  • CAPI SNAP
  • CICS
  • Cloud Analytics
  • Cloud Automation
  • Cloud Object Storage
  • Cloud marketplace
  • Collaboration
  • Content Services (ECM)
  • Continuous Testing
  • Courses
  • Customer Experience Analytics
  • DB2 LUW
  • Data and AI
  • DataPower
  • Decision Optimization
  • DevOps Build
  • DevOps Services
  • Developers IBM MX
  • Digital Commerce
  • Digital Experience
  • Finance
  • Global Entrepreneur Program
  • Hadoop
  • Hybrid Cloud Core
  • Hyper Protect
  • IBM Cloud platform
  • IBM Design
  • IBM Forms Experience Builder
  • IBM Maximo Developer
  • IBM StoredIQ
  • IBM StoredIQ-Cartridges
  • IIDR
  • ITOA
  • InformationServer
  • Integration Bus
  • Internet of Things
  • Kenexa
  • Linux on Power
  • LinuxONE
  • MDM
  • Mainframe
  • Messaging
  • Node.js
  • ODM
  • Open
  • PartnerWorld Developer Support
  • PowerAI
  • PowerVC
  • Predictive Analytics
  • Product Insights
  • PureData for Analytics
  • Push
  • QRadar App Development
  • Run Book Automation
  • Search Insights
  • Security Core
  • Storage
  • Storage Core
  • Streamsdev
  • Supply Chain Business Network
  • Supply Chain Insights
  • Swift
  • UBX Capture
  • Universal Behavior Exchange
  • UrbanCode
  • WASdev
  • WSRR
  • Watson
  • Watson Campaign Automation
  • Watson Content Hub
  • Watson Marketing Insights
  • dW Answers Help
  • dW Premium
  • developerWorks Sandbox
  • developerWorks Team
  • Watson Health
  • More
  • Tags
  • Questions
  • Users
  • Badges