I have tried to implement this many ways, but this is the way that makes the most sense to me, and I am still unable to return anything from my resource. I added the resource with the GlassFish admin GUI (essentially, i am trying to save username and passwords on the local server).
While I am getting a null pointer exception (NPE), please do not point me here, it doesn't help me at all. What is a NullPointerException, and how do I fix it?
Here are my supporting classes...
Creating the bean
@LocalBean
@Stateless
public class JndiProperties {
@Resource(name="jndiCreds")
private Properties properties;
public String getUser() {
return properties.getProperty("UserName");
}
public String getPass() {
return properties.getProperty("UserPass");
}
}
This is my bean manager:
@ManagedBean
@ViewScoped
public class GetCreds {
@Inject
private JndiProperties property;
public String getUserName(){
return property.getUser();
}
public String getPassword(){
return property.getPass();
}
}
And this is how I call them
GetCreds creds = new GetCreds();
String username = creds.getUserName();
String pass = creds.getPassword();
I named the resource jndiCreds and have the names UserName and UserPass with the values containing respective data.
Here is the view from the GlassFish GUI:
Have any idea WHY it won't return my requested information? I AM receiving an NPE when I try to call the resource when I call either function from getCreds.
Help would be appreciated; I am very stuck.
I decided to step away from trying to use a bean and just accessing it directly (although I am giving up some security here). I am trying to access the data in a contextual manner. BUT! I still can not do it! Here is my NEW supporting class:
public class JndiProperties {
public Properties getProperties(String jndiName) {
Properties properties = null;
try {
InitialContext context = new InitialContext();
properties = (Properties) context.lookup(jndiName);
context.close();
}
catch (NamingException e) {
return null;
}
return properties;
}
And this is how I grab the information:
JndiProperties creds = new JndiProperties();
String username = creds.getProperties("jndiCreds").getProperty("UserName");
String pass = creds.getProperties("jndiCreds").getProperty("UserPass");
String credentials = String.join(System.getProperty("line.separator"),
"user=" + username,
"password=" + pass);
System.out.print(credentials);
I am using the same resource shown above. I am STILL ending up with null pointer... ANY help would be greatly appreciated.Feel free to answer what was wrong with my bean implementation also.