Java Code Examples for org.jivesoftware.smack.XMPPConnection#registerIQRequestHandler()

The following examples show how to use org.jivesoftware.smack.XMPPConnection#registerIQRequestHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityTimeManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
private EntityTimeManager(XMPPConnection connection) {
    super(connection);
    if (autoEnable)
        enable();

    connection.registerIQRequestHandler(new AbstractIqRequestHandler(Time.ELEMENT, Time.NAMESPACE, Type.get,
                    Mode.async) {
        @Override
        public IQ handleIQRequest(IQ iqRequest) {
            if (enabled) {
                return Time.createResponse(iqRequest);
            }
            else {
                return IQ.createErrorResponse(iqRequest, Condition.not_acceptable);
            }
        }
    });
}
 
Example 2
Source File: InBandBytestreamManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor.
 *
 * @param connection the XMPP connection
 */
private InBandBytestreamManager(XMPPConnection connection) {
    super(connection);

    // register bytestream open packet listener
    this.initiationListener = new InitiationListener(this);
    connection.registerIQRequestHandler(initiationListener);

    // register bytestream data packet listener
    this.dataListener = new DataListener(this);
    connection.registerIQRequestHandler(dataListener);

    // register bytestream close packet listener
    this.closeListener = new CloseListener(this);
    connection.registerIQRequestHandler(closeListener);
}
 
Example 3
Source File: FileTransferManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a file transfer manager to initiate and receive file transfers.
 *
 * @param connection TODO javadoc me please
 *            The XMPPConnection that the file transfers will use.
 */
private FileTransferManager(XMPPConnection connection) {
    super(connection);
    this.fileTransferNegotiator = FileTransferNegotiator
            .getInstanceFor(connection);
    connection.registerIQRequestHandler(new AbstractIqRequestHandler(StreamInitiation.ELEMENT,
                    StreamInitiation.NAMESPACE, IQ.Type.set, Mode.async) {
        @Override
        public IQ handleIQRequest(IQ packet) {
            StreamInitiation si = (StreamInitiation) packet;
            final FileTransferRequest request = new FileTransferRequest(FileTransferManager.this, si);
            for (final FileTransferListener listener : listeners) {
                        listener.fileTransferRequest(request);
            }
            return null;
        }
    });
}
 
Example 4
Source File: VersionManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
private VersionManager(final XMPPConnection connection) {
    super(connection);

    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
    sdm.addFeature(Version.NAMESPACE);

    connection.registerIQRequestHandler(new AbstractIqRequestHandler(Version.ELEMENT, Version.NAMESPACE, IQ.Type.get,
                    Mode.async) {
        @Override
        public IQ handleIQRequest(IQ iqRequest) {
            if (ourVersion == null) {
                return IQ.createErrorResponse(iqRequest, Condition.not_acceptable);
            }

            return Version.createResultFor(iqRequest, ourVersion);
        }
    });
}
 
Example 5
Source File: BoBManager.java    From Smack with Apache License 2.0 6 votes vote down vote up
private BoBManager(XMPPConnection connection) {
    super(connection);
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    serviceDiscoveryManager.addFeature(NAMESPACE);

    connection.registerIQRequestHandler(
            new AbstractIqRequestHandler(BoBIQ.ELEMENT, BoBIQ.NAMESPACE, Type.get, Mode.async) {
                @Override
                public IQ handleIQRequest(IQ iqRequest) {
                    BoBIQ bobIQRequest = (BoBIQ) iqRequest;

                    BoBInfo bobInfo = bobs.get(bobIQRequest.getBoBHash());
                    if (bobInfo == null) {
                        // TODO return item-not-found
                        return null;
                    }

                    BoBData bobData = bobInfo.getData();
                    BoBIQ responseBoBIQ = new BoBIQ(bobIQRequest.getBoBHash(), bobData);
                    responseBoBIQ.setType(Type.result);
                    responseBoBIQ.setTo(bobIQRequest.getFrom());
                    return responseBoBIQ;
                }
            });
}
 
Example 6
Source File: DnsOverXmppManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
public synchronized void enable() {
    if (enabled) return;

    if (resolver == null) {
        throw new IllegalStateException("No DnsOverXmppResolver configured");
    }

    XMPPConnection connection = connection();
    if (connection == null) return;

    connection.registerIQRequestHandler(dnsIqRequestHandler);
    serviceDiscoveryManager.addFeature(NAMESPACE);
}
 
Example 7
Source File: IoTControlManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
private IoTControlManager(XMPPConnection connection) {
    super(connection);

    connection.registerIQRequestHandler(new IoTIqRequestHandler(IoTSetRequest.ELEMENT, IoTSetRequest.NAMESPACE, IQ.Type.set, Mode.async) {
        @Override
        public IQ handleIoTIqRequest(IQ iqRequest) {
            // TODO Lookup thing and provide data.
            IoTSetRequest iotSetRequest = (IoTSetRequest) iqRequest;

            // TODO Add support for multiple things(/NodeInfos).
            final Thing thing = things.get(NodeInfo.EMPTY);
            if (thing == null) {
                // TODO return error if not at least one thing registered.
                return null;
            }

            ThingControlRequest controlRequest = thing.getControlRequestHandler();
            if (controlRequest == null) {
                // TODO return error if no request handler for things.
                return null;
            }

            try {
                controlRequest.processRequest(iotSetRequest.getFrom(), iotSetRequest.getSetData());
            } catch (XMPPErrorException e) {
                return IQ.createErrorResponse(iotSetRequest, e.getStanzaError());
            }

            return new IoTSetResponse(iotSetRequest);
        }
    });
}
 
Example 8
Source File: AdHocCommandManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
private AdHocCommandManager(XMPPConnection connection) {
    super(connection);
    this.serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);

    // Add the feature to the service discovery manage to show that this
    // connection supports the AdHoc-Commands protocol.
    // This information will be used when another client tries to
    // discover whether this client supports AdHoc-Commands or not.
    ServiceDiscoveryManager.getInstanceFor(connection).addFeature(
            NAMESPACE);

    // Set the NodeInformationProvider that will provide information about
    // which AdHoc-Commands are registered, whenever a disco request is
    // received
    ServiceDiscoveryManager.getInstanceFor(connection)
            .setNodeInformationProvider(NAMESPACE,
                    new AbstractNodeInformationProvider() {
                        @Override
                        public List<DiscoverItems.Item> getNodeItems() {

                            List<DiscoverItems.Item> answer = new ArrayList<>();
                            Collection<AdHocCommandInfo> commandsList = getRegisteredCommands();

                            for (AdHocCommandInfo info : commandsList) {
                                DiscoverItems.Item item = new DiscoverItems.Item(
                                        info.getOwnerJID());
                                item.setName(info.getName());
                                item.setNode(info.getNode());
                                answer.add(item);
                            }

                            return answer;
                        }
                    });

    // The packet listener and the filter for processing some AdHoc Commands
    // Packets
    connection.registerIQRequestHandler(new AbstractIqRequestHandler(AdHocCommandData.ELEMENT,
                    AdHocCommandData.NAMESPACE, IQ.Type.set, Mode.async) {
        @Override
        public IQ handleIQRequest(IQ iqRequest) {
            AdHocCommandData requestData = (AdHocCommandData) iqRequest;
            try {
                return processAdHocCommand(requestData);
            }
            catch (InterruptedException | NoResponseException | NotConnectedException e) {
                LOGGER.log(Level.INFO, "processAdHocCommand threw exception", e);
                return null;
            }
        }
    });
}
 
Example 9
Source File: JingleManager.java    From Smack with Apache License 2.0 4 votes vote down vote up
private JingleManager(XMPPConnection connection) {
    super(connection);

    jutil = new JingleUtil(connection);

    connection.registerIQRequestHandler(
            new AbstractIqRequestHandler(Jingle.ELEMENT, Jingle.NAMESPACE, Type.set, Mode.async) {
                @Override
                public IQ handleIQRequest(IQ iqRequest) {
                    final Jingle jingle = (Jingle) iqRequest;

                    FullJid fullFrom = jingle.getFrom().asFullJidOrThrow();
                    String sid = jingle.getSid();
                    FullJidAndSessionId fullJidAndSessionId = new FullJidAndSessionId(fullFrom, sid);

                    JingleSessionHandler sessionHandler = jingleSessionHandlers.get(fullJidAndSessionId);
                    if (sessionHandler != null) {
                        // Handle existing session
                        return sessionHandler.handleJingleSessionRequest(jingle);
                    }

                    if (jingle.getAction() == JingleAction.session_initiate) {

                        JingleContent content = jingle.getContents().get(0);
                        JingleContentDescription description = content.getDescription();
                        JingleHandler jingleDescriptionHandler = descriptionHandlers.get(
                                description.getNamespace());

                        if (jingleDescriptionHandler == null) {
                            // Unsupported Application
                            LOGGER.log(Level.WARNING, "Unsupported Jingle application.");
                            return jutil.createSessionTerminateUnsupportedApplications(fullFrom, sid);
                        }
                        return jingleDescriptionHandler.handleJingleRequest(jingle);
                    }

                    // Unknown session
                    LOGGER.log(Level.WARNING, "Unknown session.");
                    return jutil.createErrorUnknownSession(jingle);
                }
            });
    // Register transports.
    JingleTransportMethodManager transportMethodManager = JingleTransportMethodManager.getInstanceFor(connection);
    transportMethodManager.registerTransportManager(JingleIBBTransportManager.getInstanceFor(connection));
    transportMethodManager.registerTransportManager(JingleS5BTransportManager.getInstanceFor(connection));
}