Cannot invoke "org.dom4j.Node.getText()" because the return value of "org.dom4j.Document.selectSingleNode(String)" is null

74 Views Asked by At

I am using Openfire and I have a task to create a custom plugin for it, after creating the plugin and trying to upload it I get this error:

org.jivesoftware.openfire.container.PluginManager - An exception occurred while loading plugin 'kartngo-plugin': java.lang.NullPointerException: Cannot invoke "org.dom4j.Node.getText()" because the return value of "org.dom4j.Document.selectSingleNode(String)" is null

I have no clue why it does this, I even read the documentary on how to create the plugin from their website.

My problem is, the condition that the error occurs in, has an if condition to check if the object is null or not, so I don't know how I am getting this error.

This is the full error:

2023.09.05 15:28:54 [1;31mERROR[m [Jetty-QTP-AdminConsole-53]: plugin-admin.jsp - Plugin manager failed to install plugin: kartngo-plugin.jar 2023.09.05 15:28:58 [1;31mERROR[m [PluginMonitorExec-2]: org.jivesoftware.openfire.container.PluginManager - An exception occurred while loading plugin 'kartngo-plugin': java.lang.NullPointerException: Cannot invoke "org.dom4j.Node.getText()" because the return value of "org.dom4j.Document.selectSingleNode(String)" is null at org.jivesoftware.openfire.container.PluginManager.loadPlugin(PluginManager.java:581) [xmppserver-4.7.5.jar:4.7.5] at org.jivesoftware.openfire.container.PluginMonitor$MonitorTask$4.call(PluginMonitor.java:370) [xmppserver-4.7.5.jar:4.7.5] at org.jivesoftware.openfire.container.PluginMonitor$MonitorTask$4.call(PluginMonitor.java:358) [xmppserver-4.7.5.jar:4.7.5] at java.util.concurrent.FutureTask.run(FutureTask.java:317) [?:?] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) [?:?] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) [?:?] at java.lang.Thread.run(Thread.java:1589) [?:?]

(please excuse me if the way of writing the question is bad/wrong, this is my first question to write on stackoverflow, but I wanted to know how to solve this error)

These are my plugin.java, my JSP file, and my plugin.xml that I created to try to upload the plugin into Openfire.

plugin.java:

import java.io.File;

import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.component.Component;


public abstract class KartngoPlugin implements Plugin{
    
    private static final Logger Log = LoggerFactory.getLogger(KartngoPlugin.class);

    @Override
    public void initializePlugin(PluginManager manager, File pluginDirectory) {
                
        Log.info("Kartngo_Plugin Initialized Successfully at " + new java.util.Date());
        
        org.jivesoftware.admin.AuthCheckFilter.addExclude("kartNGoPlugin");
        
    }

    @Override
    public void destroyPlugin() {

    }

}

JSP file:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Kartngo Plugin Page</title>
</head>
<body>
    <h1>Kartngo Plugin Page</h1>
    <p>Current Date: <%= new java.util.Date() %></p>
</body>
</html>

plugin.xml:

<?xml version="1.0" encoding="UTF-8"?>
<plugin>
    <name>Kartngo Plugin</name>
    <class>java.kartNGoPlugin.KartngoPlugin</class>
    <description>A custom plugin for Kartngo</description>
    <author>Ahmed Hatem</author>
    <version>1.0</version>
    <licenseType>gpl</licenseType>

    <!-- Optional: Plugin dependencies -->
    <!-- <dependencies>
        <dependency>
            <plugin-name>OtherPlugin</plugin-name>
            <version>1.0</version>
        </dependency>
    </dependencies> -->

    <!-- Specify the web interface for the plugin -->
    <adminconsole>
        <tab id="mytab" name="Kartngo Plugin">
            <sidebar id="mysidebar" name="Kartngo Plugin">
                <item id="my-plugin" name="Kartngo Page"
                    url="kartngo.jsp"
                    description="kartngo jsp plugin" />
            </sidebar>
        </tab>
    </adminconsole>
</plugin>
1

There are 1 best solutions below

0
Guus On

The error suggests that your plugin.xml file does not have a class element, but from what you copied, it clearly is there, in the right place. Maybe the plugin.xml file is stored in the wrong directory?

As an aside: if you want to define a dependency to another Openfire plugin, you can use something like this:

<?xml version="1.0" encoding="UTF-8"?>
<plugin>
    <name>Kartngo Plugin</name>
    <class>java.kartNGoPlugin.KartngoPlugin</class>
    <description>A custom plugin for Kartngo</description>
    <author>Ahmed Hatem</author>
    <version>1.0</version>
    <licenseType>gpl</licenseType>

    <!-- Optional: Plugin dependencies -->
    <parentPlugin>OtherPlugin</parentPlugin>

    <!-- Specify the web interface for the plugin -->
    <adminconsole>
        <tab id="mytab" name="Kartngo Plugin">
            <sidebar id="mysidebar" name="Kartngo Plugin">
                <item id="my-plugin" name="Kartngo Page"
                    url="kartngo.jsp"
                    description="kartngo jsp plugin" />
            </sidebar>
        </tab>
    </adminconsole>
</plugin>

This does not work to declare dependencies to libraries - you need to do that in the pom.xml file, but if you need your plugin to only load when another plugin is available (and share their classpaths), then the above will do the trick.