Resource resolver returning null...
Hello all,
I have two classes. Class A, is where I am calling a method to Class B (Which contains code that's trying to get the resource resolver).
Code for class B where I am getting the null error:
@8220494
@ServiceMode
public class NotifyAdminImpl implements NotifyAdminService
{
private static final Logger LOGGER = LoggerFactory.getLogger(NotifyAdminImpl.class);
@3214626
ResourceResolverFactory resolverFactory;
public void notifyAdmin(String location,String exception)
{
LOGGER.debug("We are inside the notifyAdmin method.");
try
{
LOGGER.debug("Begin.");
String timeStamp = DateTimeFormatter.ofPattern("MM_dd_yyyy_HH_mm_ss").format(LocalDateTime.now());
HashMap<String, Object> authInfo = new HashMap<String, Object>();
authInfo.put("user.name","serviceadmin");
authInfo.put("user.password",new java.lang.String("randomPassword!LOL").toCharArray());
ResourceResolver resourceResolver = resolverFactory.getResourceResolver(authInfo); // line where it nulls out.
Session session = resourceResolver.adaptTo(Session.class);
Resource res = resourceResolver.getResource("/apps/errorHandle/error");
Node node = res.adaptTo(Node.class);
Calendar c = Calendar.getInstance();
c.setTimeInMillis(c.getTimeInMillis());
String nodeName = location + timeStamp;
String path = node.getPath();
LOGGER.debug("PATH OF INCOMING NODE IS: " + path);
Node errorNode = node.addNode(nodeName,"nt:unstructured");
errorNode.setProperty("jcr:created", c);
errorNode.setProperty("exception", exception);
errorNode.setProperty("isEmailSent", false);
session.save();
session.logout();
LOGGER.debug("End.");
}
catch (Exception e)
{
e.printStackTrace();
LOGGER.info("An exception in notifyAdmin method occurred due to: " + e.getMessage(),e);
}
}
}
Class A code snippet of calling this method from Class B that's within my OSGi bundle:
NotifyAdminImpl notify = new NotifyAdminImpl();
notify.notifyAdmin("this_is_an_error",printExceptionString);


