Search in sources :

Example 31 with XMPPError

use of org.jivesoftware.smack.packet.XMPPError in project ecf by eclipse.

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 XMPPException If there are either no stream methods contained in the packet, or
 *                       there is not an appropriate stream method.
 */
public StreamNegotiator selectStreamNegotiator(FileTransferRequest request) throws XMPPException {
    StreamInitiation si = request.getStreamInitiation();
    FormField streamMethodField = getStreamMethodField(si.getFeatureNegotiationForm());
    if (streamMethodField == null) {
        String errorMessage = "No stream methods contained in packet.";
        XMPPError error = new XMPPError(XMPPError.Condition.bad_request, errorMessage);
        IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(), IQ.Type.ERROR);
        iqPacket.setError(error);
        connection.sendPacket(iqPacket);
        throw new XMPPException(errorMessage, error);
    }
    // select the appropriate protocol
    StreamNegotiator selectedStreamNegotiator;
    try {
        selectedStreamNegotiator = getNegotiator(streamMethodField);
    } catch (XMPPException e) {
        IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(), IQ.Type.ERROR);
        iqPacket.setError(e.getXMPPError());
        connection.sendPacket(iqPacket);
        throw e;
    }
    return selectedStreamNegotiator;
}
Also used : StreamInitiation(org.jivesoftware.smackx.packet.StreamInitiation) IQ(org.jivesoftware.smack.packet.IQ) XMPPError(org.jivesoftware.smack.packet.XMPPError) XMPPException(org.jivesoftware.smack.XMPPException) FormField(org.jivesoftware.smackx.FormField)

Example 32 with XMPPError

use of org.jivesoftware.smack.packet.XMPPError in project ecf by eclipse.

the class FileTransferNegotiator method getOutgoingNegotiator.

private StreamNegotiator getOutgoingNegotiator(final FormField field) throws XMPPException {
    String variable;
    boolean isByteStream = false;
    boolean isIBB = false;
    for (Iterator<String> it = field.getValues(); it.hasNext(); ) {
        variable = it.next();
        if (variable.equals(Socks5BytestreamManager.NAMESPACE) && !IBB_ONLY) {
            isByteStream = true;
        } else if (variable.equals(InBandBytestreamManager.NAMESPACE)) {
            isIBB = true;
        }
    }
    if (!isByteStream && !isIBB) {
        XMPPError error = new XMPPError(XMPPError.Condition.bad_request, "No acceptable transfer mechanism");
        throw new XMPPException(error.getMessage(), error);
    }
    if (isByteStream && isIBB) {
        return new FaultTolerantNegotiator(connection, byteStreamTransferManager, inbandTransferManager);
    } else if (isByteStream) {
        return byteStreamTransferManager;
    } else {
        return inbandTransferManager;
    }
}
Also used : XMPPError(org.jivesoftware.smack.packet.XMPPError) XMPPException(org.jivesoftware.smack.XMPPException)

Example 33 with XMPPError

use of org.jivesoftware.smack.packet.XMPPError in project ecf by eclipse.

the class InBandBytestreamManager method replyResourceConstraintPacket.

/**
 * Responses to the given IQ packet's sender with an XMPP error that an In-Band Bytestream open
 * request is rejected because its block size is greater than the maximum allowed block size.
 *
 * @param request IQ packet that should be answered with a resource-constraint error
 */
protected void replyResourceConstraintPacket(IQ request) {
    XMPPError xmppError = new XMPPError(XMPPError.Condition.resource_constraint);
    IQ error = IQ.createErrorResponse(request, xmppError);
    this.connection.sendPacket(error);
}
Also used : IQ(org.jivesoftware.smack.packet.IQ) XMPPError(org.jivesoftware.smack.packet.XMPPError)

Example 34 with XMPPError

use of org.jivesoftware.smack.packet.XMPPError in project ecf by eclipse.

the class VCard method doLoad.

private void doLoad(Connection connection, String user) throws XMPPException {
    setType(Type.GET);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(getPacketID()));
    connection.sendPacket(this);
    VCard result = null;
    try {
        result = (VCard) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
        if (result == null) {
            String errorMessage = "Timeout getting VCard information";
            throw new XMPPException(errorMessage, new XMPPError(XMPPError.Condition.request_timeout, errorMessage));
        }
        if (result.getError() != null) {
            throw new XMPPException(result.getError());
        }
    } catch (ClassCastException e) {
        System.out.println("No VCard for " + user);
    }
    copyFieldsFrom(result);
}
Also used : PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPError(org.jivesoftware.smack.packet.XMPPError) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 35 with XMPPError

use of org.jivesoftware.smack.packet.XMPPError in project ecf by eclipse.

the class XMPPConnection method initReaderAndWriter.

private void initReaderAndWriter() throws XMPPException {
    try {
        if (compressionHandler == null) {
            reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
            writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
        } else {
            try {
                OutputStream os = compressionHandler.getOutputStream(socket.getOutputStream());
                writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
                InputStream is = compressionHandler.getInputStream(socket.getInputStream());
                reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            } catch (Exception e) {
                e.printStackTrace();
                compressionHandler = null;
                reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
                writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
            }
        }
    } catch (IOException ioe) {
        throw new XMPPException("XMPPError establishing connection with server.", new XMPPError(XMPPError.Condition.remote_server_error, "XMPPError establishing connection with server."), ioe);
    }
    // If debugging is enabled, we open a window and write out all network traffic.
    initDebugger();
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XMPPInputOutputStream(org.jivesoftware.smack.compression.XMPPInputOutputStream) OutputStream(java.io.OutputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) XMPPError(org.jivesoftware.smack.packet.XMPPError) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) BufferedWriter(java.io.BufferedWriter)

Aggregations

XMPPError (org.jivesoftware.smack.packet.XMPPError)36 XMPPException (org.jivesoftware.smack.XMPPException)11 IQ (org.jivesoftware.smack.packet.IQ)10 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)6 SmackException (org.jivesoftware.smack.SmackException)5 XmlPullParser (org.xmlpull.v1.XmlPullParser)5 AdHocCommandData (org.jivesoftware.smackx.packet.AdHocCommandData)3 NetworkException (com.xabber.android.data.NetworkException)2 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 Form (org.jivesoftware.smackx.Form)2 Action (org.jivesoftware.smackx.commands.AdHocCommand.Action)2 MultiUserChat (org.jivesoftware.smackx.muc.MultiUserChat)2 StreamInitiation (org.jivesoftware.smackx.packet.StreamInitiation)2 AccountItem (com.xabber.android.data.account.AccountItem)1 ConnectionThread (com.xabber.android.data.connection.ConnectionThread)1 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)1 UserJid (com.xabber.android.data.entity.UserJid)1 Realm (io.realm.Realm)1 BufferedImage (java.awt.image.BufferedImage)1