use of org.jivesoftware.smackx.filetransfer.FileTransferException.NoAcceptableTransferMechanisms 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
* @throws NoAcceptableTransferMechanisms
* @throws InterruptedException
*/
public StreamNegotiator selectStreamNegotiator(FileTransferRequest request) throws NotConnectedException, NoStreamMethodsOfferedException, NoAcceptableTransferMechanisms, InterruptedException {
StreamInitiation si = request.getStreamInitiation();
FormField streamMethodField = getStreamMethodField(si.getFeatureNegotiationForm());
if (streamMethodField == null) {
String errorMessage = "No stream methods contained in stanza.";
XMPPError.Builder error = XMPPError.from(XMPPError.Condition.bad_request, errorMessage);
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, XMPPError.from(XMPPError.Condition.bad_request, "No acceptable transfer mechanism"));
connection().sendStanza(iqPacket);
throw e;
}
return selectedStreamNegotiator;
}
Aggregations