android - 在Android中使用asmack在接收文件时获取ExecutionException

标签 android xmpp asmack

我正在尝试使用 asmack-2010.05.07.jar 共享文件,我发送成功但收到 0kb 文件并出现 ExecutionException

我的发送和接收代码是:

正在发送文件:

private void sendFile(XMPPConnection connection) {
        configureProviderManager(connection);

        // Create the file transfer manager
        FileTransferNegotiator.setServiceEnabled(connection, true);
        //FileTransferNegotiator.IBB_ONLY = true;
        FileTransferManager manager = new FileTransferManager(connection);

        // Create the outgoing file transfer
        String toName = to + "@" + getResources().getString(R.string.service)
                + "/Smack";
        transfer = manager.createOutgoingFileTransfer(toName);
        Log.i(TAG, "send-TO:  " + toName);

        // Send the file
        try {
            File myFile = new File(PICKUP_LOC);

            if (myFile.exists()) {
                Toast.makeText(MyChat.this, "File Exist---", 1).show();
                transfer.sendFile(myFile, "You won't believe this!");
            } else {
                Toast.makeText(MyChat.this, "NOt Exist---", 1).show();
            }
        } catch (XMPPException e) {
            e.printStackTrace();
        }
new AsyncTask<Void, Void, Void>() {
            ProgressDialog pd;
            protected void onPreExecute() {
                pd = ProgressDialog.show(MyChat.this, "",
                        "Please wait..");
            }
            @Override
            protected Void doInBackground(Void... params) {
                while (!transfer.isDone()) {
                    if (transfer.getStatus().equals("Error")) {
                        System.out.println("ERROR!!! " + transfer.getError());
                    } else if (transfer.getStatus().equals("Cancelled")
                            || transfer.getStatus().equals("Refused")) {
                        System.out.println("Cancelled!!! " + transfer.getError());
                    }
                    try {
                        Thread.sleep(1000L);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                return null;
            };

            protected void onPostExecute(Void result) {
                pd.dismiss();
                if (transfer.getStatus().equals("Refused")
                        || transfer.getStatus().equals("Error")
                        || transfer.getStatus().equals("Cancelled")) {
                    Log.i(TAG, "refused cancelled error " + transfer.getError());

                } else {                                    
                    setMessageToList(new ChatDTO(PICKUP_LOC,
                            utilityDAO.getCurrentTime(), "1", "Me")); 
                    Log.i(TAG, "Success: "+ transfer.getFileName());
                }
            };
        }.execute();

    }

接收文件:

public void enableFileTransferListener(XMPPConnection _connection) {
if (_connection != null) {
            configureProviderManager(_connection);
            FileTransferNegotiator.setServiceEnabled(_connection, true);
           //FileTransferNegotiator.IBB_ONLY = true;                            

            FileTransferManager manager = new FileTransferManager(_connection);
            manager.addFileTransferListener(new FileTransferListener() {
                public void fileTransferRequest(
                        final FileTransferRequest request) {
                    Log.i(TAG, "in fileTransferRequest");
                    new Thread() {
                        @Override
                        public void run() {
                            IncomingFileTransfer transfer = request.accept();
                            File mf = Environment.getExternalStorageDirectory();
                            DROP_LOC = mf.getAbsoluteFile()+ "/DCIM/" + transfer.getFileName();
                            File file = new File(DROP_LOC);                         
                            try {
                                transfer.recieveFile(file);
                                while (!transfer.isDone()) {
                                    Log.i(TAG, "in While");
                                    try {
                                        Thread.sleep(1000L);
                                    } catch (Exception e) {
                                        Log.e("", e.getMessage());
                                    }
                                    if (transfer.getStatus().equals(
                                            Status.error)) {
                                        Log.e("ERROR!!! ", transfer.getError()
                                                + "");
                                    }
                                    if (transfer.getException() != null) {
                                        transfer.getException()
                                                .printStackTrace();
                                    }                                                                       
                                    } 

                                if ( !transfer.getStatus().equals("Refused")
                                        || !transfer.getStatus().equals("Error")
                                        || !transfer.getStatus().equals("Cancelled")) {

                                     runOnUiThread(new Runnable() {
                                          public void run() {
                                              setMessageToList(new ChatDTO(DROP_LOC,
                                                        utilityDAO.getCurrentTime(), "2", to
                                                                .toLowerCase()));
                                                System.out.println("Success");
                                          }
                                        });                                                                                                                                                         
                                }
                            } catch (Exception e) {
                                Log.e(TAG, e.getMessage());
                            }

                        };
                    }.start();


                }
            });
        }
    }

发送时的 XMPP XML 响应:

05-08 12:42:32.013: I/MyChat(3644): send-TO:  Social_66@hitchup.co.in/Smack
05-08 12:42:32.017: D/dalvikvm(3644): threadid=19: interp stack at 0x4d301000
05-08 12:42:32.025: D/dalvikvm(3644): threadid=19: calling run()
05-08 12:42:32.028: D/SMACK(3644): 12:42:32 PM SENT (1098434792): <iq id="zxsxs-29" to="Social_66@hitchup.co.in/Smack" from="social_53@hitchup.co.in/Smack" type="set"><si xmlns="http://jabber.org/protocol/si" id="jsi_6138153213036298122" mime-type="image/jpeg" profile="http://jabber.org/protocol/si/profile/file-transfer"><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="FOODS.jpg" size="65293" ><desc>You won&apos;t believe this!</desc></file><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="form"><field var="stream-method" type="list-single"><option><value>http://jabber.org/protocol/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature></si></iq>
05-08 12:42:32.047: D/ActivityThread(3644): SEND_RESULT handled : 0 / ResultData{token=android.os.BinderProxy@418468e0 results[ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://media/external/images/media/24150 }}]}
05-08 12:42:32.052: D/ActivityThread(3644): ACT-AM_ON_RESUME_CALLED ActivityRecord{41847120 token=android.os.BinderProxy@418468e0 {com.it.socialapp/com.it.socialapp.MyChat}}
05-08 12:42:33.740: D/SMACK(3644): 12:42:33 PM RCV  (1098434792): <iq id="zxsxs-29" to="social_53@hitchup.co.in/Smack" from="social_66@hitchup.co.in/Smack" type="result"><si xmlns="http://jabber.org/protocol/si"><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="submit"><field var="stream-method"><value>http://jabber.org/protocol/bytestreams</value><value>http://jabber.org/protocol/ibb</value></field></x></feature></si></iq>
05-08 12:42:33.744: D/SMACK(3644): 12:42:33 PM SENT (1098434792): <iq id="zxsxs-30" to="Social_66@hitchup.co.in/Smack" type="get"><query xmlns="http://jabber.org/protocol/disco#info"></query></iq>
05-08 12:42:34.660: D/SMACK(3644): 12:42:34 PM RCV  (1098434792): <iq id="zxsxs-30" to="social_53@hitchup.co.in/Smack" type="result" from="social_66@hitchup.co.in/Smack"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="client" name="Smack" type="pc"/><feature var="jabber:iq:privacy"/><feature var="http://jabber.org/protocol/si/profile/file-transfer"/><feature var="http://jabber.org/protocol/disco#items"/><feature var="http://jabber.org/protocol/ibb"/><feature var="http://jabber.org/protocol/si"/><feature var="http://jabber.org/protocol/bytestreams"/><feature var="http://jabber.org/protocol/disco#info"/></query></iq>
05-08 12:42:34.663: D/SMACK(3644): 12:42:34 PM SENT (1098434792): <iq id="zxsxs-31" to="hitchup.co.in" type="get"><query xmlns="http://jabber.org/protocol/disco#items"></query></iq>
05-08 12:42:35.070: D/SMACK(3644): 12:42:35 PM RCV  (1098434792): <iq type="result" id="zxsxs-31" from="hitchup.co.in" to="social_53@hitchup.co.in/Smack"><query xmlns="http://jabber.org/protocol/disco#items"><item jid="search.hitchup.co.in" name="User Search"/><item jid="pubsub.hitchup.co.in" name="Publish-Subscribe service"/><item jid="sipark.hitchup.co.in" name="SIP Controller"/><item jid="broadcast.hitchup.co.in" name="Broadcast service"/><item jid="proxy.hitchup.co.in" name="Socks 5 Bytestreams Proxy"/><item jid="logger.hitchup.co.in" name="Remote Logger"/><item jid="conference.hitchup.co.in" name="Public Chatrooms"/></query></iq>
05-08 12:42:35.073: D/SMACK(3644): 12:42:35 PM SENT (1098434792): <iq id="zxsxs-32" to="proxy.hitchup.co.in" type="get"><query xmlns="http://jabber.org/protocol/disco#info"></query></iq>
05-08 12:42:35.480: D/SMACK(3644): 12:42:35 PM RCV  (1098434792): <iq type="result" id="zxsxs-32" from="proxy.hitchup.co.in" to="social_53@hitchup.co.in/Smack"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="proxy" name="SOCKS5 Bytestreams Service" type="bytestreams"/><feature var="http://jabber.org/protocol/bytestreams"/><feature var="http://jabber.org/protocol/disco#info"/></query></iq>
05-08 12:42:35.483: D/SMACK(3644): 12:42:35 PM SENT (1098434792): <iq id="zxsxs-33" to="proxy.hitchup.co.in" type="get"><query xmlns="http://jabber.org/protocol/bytestreams"/></iq>
05-08 12:42:35.890: D/SMACK(3644): 12:42:35 PM RCV  (1098434792): <iq type="result" id="zxsxs-33" from="proxy.hitchup.co.in" to="social_53@hitchup.co.in/Smack"><query xmlns="http://jabber.org/protocol/bytestreams"><streamhost jid="proxy.hitchup.co.in" host="198.57.204.44" port="7777"/></query></iq>
05-08 12:42:35.896: D/SMACK(3644): 12:42:35 PM SENT (1098434792): <iq id="zxsxs-34" to="Social_66@hitchup.co.in/Smack" type="set"><query xmlns="http://jabber.org/protocol/bytestreams" sid="jsi_6138153213036298122" mode = "tcp"><streamhost jid="social_53@hitchup.co.in/Smack" host="127.0.0.1" port="7777"/><streamhost jid="proxy.hitchup.co.in" host="198.57.204.44" port="7777"/></query></iq>
05-08 12:42:37.840: D/SMACK(3644): 12:42:37 PM RCV  (1098434792): <iq id="zxsxs-34" to="social_53@hitchup.co.in/Smack" type="result" from="social_66@hitchup.co.in/Smack"><query xmlns="http://jabber.org/protocol/bytestreams"><streamhost-used jid="proxy.hitchup.co.in"/></query></iq>
05-08 12:42:39.072: D/SMACK(3644): 12:42:39 PM SENT (1098434792): <iq id="zxsxs-35" to="Social_66@hitchup.co.in/Smack" type="set"><open xmlns="http://jabber.org/protocol/ibb" block-size="4096" sid="jsi_6138153213036298122" stanza="iq"/></iq>
05-08 12:42:39.880: D/SMACK(3644): 12:42:39 PM RCV  (1098434792): <iq id="zxsxs-35" to="social_53@hitchup.co.in/Smack" from="social_66@hitchup.co.in/Smack" type="error"><error code="501" type="CANCEL"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
05-08 12:42:39.881: D/NativeCrypto(3644): Entering sslRead, caller requests to read 11 bytes timeout=0...
05-08 12:42:39.881: D/NativeCrypto(3644): Doing SSL_Read() ssl=0x13a6a38, appData=0x140bdd0
05-08 12:42:39.881: D/NativeCrypto(3644): Returned from SSL_Read() with result -1, error code 2 ssl=0x13a6a38, appData=0x140bdd0
05-08 12:42:39.881: D/NativeCrypto(3644): sslSelect type=READ fd=54 appData=0x140bdd0 timeout=0
05-08 12:42:39.881: D/dalvikvm(3644): threadid=19: exiting
05-08 12:42:39.882: D/dalvikvm(3644): threadid=19: bye!
05-08 12:42:39.882: D/dalvikvm(3644): threadid=0: freeing
05-08 12:42:40.069: I/MyChat(3644): Success: FOODS.jpg

接收时的 XMPP XML 响应:

05-08 12:42:31.340: D/SMACK(13479): 12:42:31 PM RCV  (1093450272): <iq id="zxsxs-29" to="social_66@hitchup.co.in/Smack" from="social_53@hitchup.co.in/Smack" type="set"><si xmlns="http://jabber.org/protocol/si" id="jsi_6138153213036298122" mime-type="image/jpeg" profile="http://jabber.org/protocol/si/profile/file-transfer"><file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="FOODS.jpg" size="65293"><desc>You won't believe this!</desc></file><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="form"><field var="stream-method" type="list-single"><option><value>http://jabber.org/protocol/bytestreams</value></option><option><value>http://jabber.org/protocol/ibb</value></option></field></x></feature></si></iq>
05-08 12:42:31.360: I/MyChat(13479): in fileTransferRequest
05-08 12:42:31.360: I/MyChat(13479): in While
05-08 12:42:31.370: D/SMACK(13479): 12:42:31 PM SENT (1093450272): <iq id="zxsxs-29" to="social_53@hitchup.co.in/Smack" from="social_66@hitchup.co.in/Smack" type="result"><si xmlns="http://jabber.org/protocol/si"><feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="submit"><field var="stream-method"><value>http://jabber.org/protocol/bytestreams</value><value>http://jabber.org/protocol/ibb</value></field></x></feature></si></iq>
05-08 12:42:32.260: D/SMACK(13479): 12:42:32 PM RCV  (1093450272): <iq id="zxsxs-30" to="social_66@hitchup.co.in/Smack" type="get" from="social_53@hitchup.co.in/Smack"><query xmlns="http://jabber.org/protocol/disco#info"/></iq>
05-08 12:42:32.270: D/SMACK(13479): 12:42:32 PM SENT (1093450272): <iq id="zxsxs-30" to="social_53@hitchup.co.in/Smack" type="result"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="client" name="Smack" type="pc"/><feature var="jabber:iq:privacy"/><feature var="http://jabber.org/protocol/si/profile/file-transfer"/><feature var="http://jabber.org/protocol/disco#items"/><feature var="http://jabber.org/protocol/ibb"/><feature var="http://jabber.org/protocol/si"/><feature var="http://jabber.org/protocol/bytestreams"/><feature var="http://jabber.org/protocol/disco#info"/></query></iq>
05-08 12:42:32.370: I/MyChat(13479): in While
05-08 12:42:33.370: I/MyChat(13479): in While
05-08 12:42:34.300: D/SMACK(13479): 12:42:34 PM RCV  (1093450272): <iq id="zxsxs-34" to="social_66@hitchup.co.in/Smack" type="set" from="social_53@hitchup.co.in/Smack"><query xmlns="http://jabber.org/protocol/bytestreams" sid="jsi_6138153213036298122" mode="tcp"><streamhost jid="social_53@hitchup.co.in/Smack" host="127.0.0.1" port="7777"/><streamhost jid="proxy.hitchup.co.in" host="198.57.204.44" port="7777"/></query></iq>
05-08 12:42:34.370: I/MyChat(13479): in While
05-08 12:42:35.370: I/MyChat(13479): in While
05-08 12:42:35.440: D/SMACK(13479): 12:42:35 PM SENT (1093450272): <iq id="zxsxs-34" to="social_53@hitchup.co.in/Smack" type="result"><query xmlns="http://jabber.org/protocol/bytestreams"><streamhost-used jid="proxy.hitchup.co.in" /></query></iq>
05-08 12:42:36.370: I/MyChat(13479): in While
05-08 12:42:37.370: I/MyChat(13479): in While
05-08 12:42:37.480: D/SMACK(13479): 12:42:37 PM RCV  (1093450272): <iq id="zxsxs-35" to="social_66@hitchup.co.in/Smack" type="set" from="social_53@hitchup.co.in/Smack"><open xmlns="http://jabber.org/protocol/ibb" block-size="4096" sid="jsi_6138153213036298122" stanza="iq"/></iq>
05-08 12:42:37.480: D/SMACK(13479): 12:42:37 PM SENT (1093450272): <iq id="zxsxs-35" to="social_53@hitchup.co.in/Smack" from="social_66@hitchup.co.in/Smack" type="error"><error code="501" type="CANCEL"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
05-08 12:42:38.370: I/MyChat(13479): in While
05-08 12:42:39.370: I/MyChat(13479): in While
05-08 12:42:40.370: I/MyChat(13479): in While
05-08 12:42:41.370: I/MyChat(13479): in While
05-08 12:42:42.370: E/ERROR!!!(13479): null
05-08 12:42:42.370: W/System.err(13479): Error in execution: 
05-08 12:42:42.370: W/System.err(13479):   -- caused by: java.util.concurrent.ExecutionException: 
05-08 12:42:42.370: W/System.err(13479):   -- caused by: No response from remote client: 
05-08 12:42:42.370: W/System.err(13479):    at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer.negotiateStream(IncomingFileTransfer.java:199)
05-08 12:42:42.370: W/System.err(13479):    at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer.access$100(IncomingFileTransfer.java:47)
05-08 12:42:42.370: W/System.err(13479):    at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer$1.run(IncomingFileTransfer.java:124)
05-08 12:42:42.370: W/System.err(13479):    at java.lang.Thread.run(Thread.java:856)
05-08 12:42:42.370: W/System.err(13479): Nested Exception: 
05-08 12:42:42.370: W/System.err(13479): java.util.concurrent.ExecutionException: 
05-08 12:42:42.370: W/System.err(13479):   -- caused by: No response from remote client: 
05-08 12:42:42.370: W/System.err(13479):    at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:233)
05-08 12:42:42.370: W/System.err(13479):    at java.util.concurrent.FutureTask.get(FutureTask.java:90)
05-08 12:42:42.370: W/System.err(13479):    at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer.negotiateStream(IncomingFileTransfer.java:193)
05-08 12:42:42.370: W/System.err(13479):    at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer.access$100(IncomingFileTransfer.java:47)
05-08 12:42:42.370: W/System.err(13479):    at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer$1.run(IncomingFileTransfer.java:124)
05-08 12:42:42.370: W/System.err(13479):    at java.lang.Thread.run(Thread.java:856)
05-08 12:42:42.370: W/System.err(13479): Caused by: 
05-08 12:42:42.380: W/System.err(13479):   -- caused by: No response from remote client: 
05-08 12:42:42.380: W/System.err(13479):    at org.jivesoftware.smackx.filetransfer.FaultTolerantNegotiator.createIncomingStream(FaultTolerantNegotiator.java:114)
05-08 12:42:42.380: W/System.err(13479):    at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer$2.call(IncomingFileTransfer.java:186)
05-08 12:42:42.380: W/System.err(13479):    at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer$2.call(IncomingFileTransfer.java:183)
05-08 12:42:42.380: W/System.err(13479):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-08 12:42:42.380: W/System.err(13479):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-08 12:42:42.380: W/System.err(13479):    at org.jivesoftware.smackx.filetransfer.IncomingFileTransfer.negotiateStream(IncomingFileTransfer.java:190)
05-08 12:42:42.380: W/System.err(13479):    ... 3 more
05-08 12:42:42.390: I/System.out(13479): Success
05-08 12:42:42.510: D/dalvikvm(13479): GC_FOR_ALLOC freed 333K, 24% free 8541K/11207K, paused 34ms, total 36ms
05-08 12:42:42.520: I/image arrived on----->(13479): /mnt/sdcard/DCIM/FOODS.jpg

最佳答案

正如我们讨论的那样 here - Smack 在文件传输实现中有一些错误:在你的情况下,发起者提供了 bytestreamsibb 方法,响应者接受这两种(这是错误的)方法,在下一次旅行发起者提供bytestreams 流主机,响应者选择一个,文件传输应该从选定的流主机开始。但是发起者错误地启动了 ibb 方法(原文如此!)。您可以尝试在代码中调用 FileTransferNegotiator.IBB_ONLY = true;,但强烈建议向 Smack 开发人员提交错误报告。

关于android - 在Android中使用asmack在接收文件时获取ExecutionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23475448/

相关文章:

android - 我如何知道服务器是否收到聊天消息?

android - 使用导航架构时如何设置 `setReorderingAllowed`?

android - 当父 Activity 作为参数传递给非 Activity 类中的 Intent 时, onActivityResult 不会被 finish() 调用

php - 使用 php 接收 XMPP 消息

python 无法连接到本地 XMPP 服务器

android - 在 Android 中将 Facebook 聊天与 Asmack API 集成

java - 解决使用 SAX 解析器解析 xml 的安全问题

Android - 使用现有数据库进行全文搜索

Android listview空指针异常?

调用 vcard.load(conn) 时 Android asmack vcard classcastException