Search in sources :

Example 1 with ListSingleFormField

use of org.jivesoftware.smackx.xdata.ListSingleFormField in project Smack by igniterealtime.

the class FileTransferNegotiator method selectStreamNegotiator.

/**
 * Selects an appropriate stream negotiator after examining the incoming file transfer request.
 *
 * @param request The related file transfer request.
 * @return The file transfer object that handles the transfer
 * @throws NoStreamMethodsOfferedException If there are either no stream methods contained in the packet, or
 *                       there is not an appropriate stream method.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws NoAcceptableTransferMechanisms if no acceptable transfer mechanisms are available
 * @throws InterruptedException if the calling thread was interrupted.
 */
public StreamNegotiator selectStreamNegotiator(FileTransferRequest request) throws NotConnectedException, NoStreamMethodsOfferedException, NoAcceptableTransferMechanisms, InterruptedException {
    StreamInitiation si = request.getStreamInitiation();
    ListSingleFormField streamMethodField = getStreamMethodField(si.getFeatureNegotiationForm());
    if (streamMethodField == null) {
        String errorMessage = "No stream methods contained in stanza.";
        StanzaError error = StanzaError.from(StanzaError.Condition.bad_request, errorMessage).build();
        IQ iqPacket = IQ.createErrorResponse(si, error);
        connection().sendStanza(iqPacket);
        throw new FileTransferException.NoStreamMethodsOfferedException();
    }
    // select the appropriate protocol
    StreamNegotiator selectedStreamNegotiator;
    try {
        selectedStreamNegotiator = getNegotiator(streamMethodField);
    } catch (NoAcceptableTransferMechanisms e) {
        IQ iqPacket = IQ.createErrorResponse(si, StanzaError.from(StanzaError.Condition.bad_request, "No acceptable transfer mechanism").build());
        connection().sendStanza(iqPacket);
        throw e;
    }
    return selectedStreamNegotiator;
}
Also used : StreamInitiation(org.jivesoftware.smackx.si.packet.StreamInitiation) NoStreamMethodsOfferedException(org.jivesoftware.smackx.filetransfer.FileTransferException.NoStreamMethodsOfferedException) ListSingleFormField(org.jivesoftware.smackx.xdata.ListSingleFormField) IQ(org.jivesoftware.smack.packet.IQ) NoAcceptableTransferMechanisms(org.jivesoftware.smackx.filetransfer.FileTransferException.NoAcceptableTransferMechanisms) StanzaError(org.jivesoftware.smack.packet.StanzaError)

Aggregations

IQ (org.jivesoftware.smack.packet.IQ)1 StanzaError (org.jivesoftware.smack.packet.StanzaError)1 NoAcceptableTransferMechanisms (org.jivesoftware.smackx.filetransfer.FileTransferException.NoAcceptableTransferMechanisms)1 NoStreamMethodsOfferedException (org.jivesoftware.smackx.filetransfer.FileTransferException.NoStreamMethodsOfferedException)1 StreamInitiation (org.jivesoftware.smackx.si.packet.StreamInitiation)1 ListSingleFormField (org.jivesoftware.smackx.xdata.ListSingleFormField)1