GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Check if JNDI is available before using · einsnull/java-sdk@163dade

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/main/java/com/ibm/watson/developer_cloud/util
    • CredentialUtils.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/com/ibm/watson/developer_cloud/util/CredentialUtils.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/ibm/watson/developer_cloud/util/CredentialUtils.java
+19-12Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,27 @@ public class CredentialUtils {
7474
* @return The encoded API Key
7575
*/
7676
private static String getKeyUsingJNDI(String serviceName) {
77-
try {
78-
Class.forName("javax.naming.Context");
79-
try {
80-
Context context = new InitialContext();
81-
String lookupName = "watson-developer-cloud/" + serviceName + "/credentials";
82-
String apiKey = (String) context.lookup(lookupName);
83-
return apiKey;
84-
} catch (NamingException e) {
85-
return null;
86-
}
87-
} catch (ClassNotFoundException exception) {
77+
if (!isClassAvailable("javax.naming.Context")) {
8878
log.info("JNDI string lookups is not available.");
79+
return null;
80+
}
81+
try {
82+
Context context = new InitialContext();
83+
String lookupName = "watson-developer-cloud/" + serviceName + "/credentials";
84+
String apiKey = (String) context.lookup(lookupName);
85+
return apiKey;
86+
} catch (NamingException e) {
87+
return null;
88+
}
89+
}
90+
91+
private static boolean isClassAvailable(String className) {
92+
try {
93+
Class.forName(className);
94+
return true;
95+
} catch (Throwable e) {
96+
return false;
8997
}
90-
return null;
9198
}
9299

93100
/**

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.