powered by Jive Software

Getting Error on Custom query

I have made a custom query plugin to handle IQ.

public class MyCustomQueryPlugin implements Plugin, SessionEventListener, ClusterEventListener, PluginListener {

    private static final Logger Log = LoggerFactory.getLogger(MyCustomQueryPlugin.class);
    public File pluginDirectory;
    private MyCustomHandler customHandler;
    private IQRouter iqRouter;
    private IQHandler filter;
    
    @Override
    public void initializePlugin(PluginManager manager, File pluginDirectory) {

        manager.addPluginListener(this);

        this.pluginDirectory = pluginDirectory;
       
        filter = new CustomIQHandler();
        iqRouter = XMPPServer.getInstance().getIQRouter();
        iqRouter.addHandler(filter);
        SessionEventDispatcher.addListener(this);
        ClusterManager.addListener(this);

        Log.info("customquery Plugin - Initialize email listener");

    }

    @Override
    public void destroyPlugin() {
        try {
            SessionEventDispatcher.removeListener(this);
        } catch (Exception ex) {
            Log.error("An exception occurred while trying to destroy the customiqhandler IQ Handler.", ex);
        }
        if (customHandler != null) {
            InterceptorManager.getInstance().removeInterceptor(customHandler);
            customHandler = null;
        }
        iqRouter.removeHandler(filter);
        ClusterManager.removeListener(this);
        XMPPServer.getInstance().getPluginManager().removePluginListener(this);

    }

    @Override
    public void anonymousSessionCreated(Session session) {
        Log.debug("customquery Plugin -  anonymousSessionCreated " + session.getAddress().toString() + "\n" + ((ClientSession) session).getPresence().toXML());
    }

    @Override
    public void anonymousSessionDestroyed(Session session) {
        Log.debug("customquery Plugin -  anonymousSessionDestroyed " + session.getAddress().toString() + "\n" + ((ClientSession) session).getPresence().toXML());
    }

    @Override
    public void resourceBound(Session session) {
        Log.debug("customquery Plugin -  resourceBound " + session.getAddress().toString() + "\n" + ((ClientSession) session).getPresence().toXML());
    }

    @Override
    public void sessionCreated(Session session) {
        Log.debug("customquery Plugin -  sessionCreated " + session.getAddress().toString() + "\n" + ((ClientSession) session).getPresence().toXML());
    }

    @Override
    public void sessionDestroyed(Session session) {
        Log.debug("customquery Plugin -  sessionDestroyed " + session.getAddress().toString() + "\n" + ((ClientSession) session).getPresence().toXML());
    }

    @Override
    public void pluginCreated(final String pluginName, final Plugin plugin) {
        System.out.println("pluginName " + pluginName);
    }

    @Override
    public void leftCluster(byte[] arg0) {
    }

    @Override
    public void markedAsSeniorClusterMember() {
        Log.info("This instance was marked as senior member of an Openfire cluster. Loading all OFMeet functionality.");
        try {

        } catch (Exception ex) {
            Log.error("An exception occurred while trying to initialize the Jitsi Plugin.", ex);
        }
    }

    @Override
    public void pluginDestroyed(final String pluginName, final Plugin plugin) {
    }

    @Override
    public void joinedCluster() {
        Log.info("An Openfire cluster was joined. Unloading customquery functionality (as only the senior cluster node will provide this.");
    }

    @Override
    public void joinedCluster(byte[] bytes) {
    }

    @Override
    public void leftCluster() {
    }

}

IQ Handler

public class CustomIQHandler extends IQHandler {

    private final String childElementName = "query";
    private final String childElementNameSpace = "com:via:call#request";
    private IQHandlerInfo info;
    private final PacketRouter router;

    public CustomIQHandler() {
        super("my custom handler");
        info = new IQHandlerInfo(childElementName, childElementNameSpace);
        this.router = XMPPServer.getInstance().getPacketRouter();
        System.out.println("CustomIQHandler invoked ");
    }

    @Override
    public IQ handleIQ(IQ iq) throws UnauthorizedException {
        System.out.println("handleIQ invoked");
        IQ result = IQ.createResultIQ(iq);

        IQ.Type type = iq.getType();

        switch (type) {
            case get:
                System.out.println("1");
                result.setChildElement(childElementName, childElementNameSpace);
                break;
            case set:
                System.out.println("2");
                result.setChildElement(childElementName, childElementNameSpace);
                break;
            default:
                System.out.println("3");
                result.setChildElement(iq.getChildElement().createCopy());
                result.setError(PacketError.Condition.not_acceptable);
                break;
        }

        return result;
    }

    @Override
    public IQHandlerInfo getInfo() {
        return info;
    }
}

when am running XML in miranda IM

<iq xmlns='jabber:client' to='test2@example.com/Android_User4207' id='LGmcR-64' type='set'><query xmlns='com:via:call#request'><call type='set' calltype='video'>https://meet.jit.si/testroom123</call></query></iq>

I want destination user get the xml and send response xml that user accepted call. But am getting error:

<iq type="error" to="test2@example.com/Android_User328" id="OA14U-113">
<query xmlns="com:via:call#request">
<call type="set" calltype="video">https://meet.jit.si/testroom123</call>
</query>
<error type="cancel">
<service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
</error>
</iq>

how to handle this error what am doing wrong?