Getting ExecutionException on receiving file using

2019-06-08 05:15发布

I'm trying for sharing files using asmack-2010.05.07.jar, I'm sending successfully but receiving 0kb file with ExecutionException.

My sending and receiving code is:

SENDING FILE:

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();

    }

RECEIVING FILE:

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 response on Send:

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 response on Receive:

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

2条回答
淡お忘
2楼-- · 2019-06-08 05:53

I think you got your solution already.

Since I suffered of this problem badly and found the solution from this site ,I decided to share it here.

The problem is you need to modify asmack library to increase the timeout value in createIncomingStream() method in FaultTolerantNegotiator class which is in package org.jivesoftware.smackx.filetransfer package.

I downloaded the source code of asmack-android-6-source-0.8.1.1 and modified the source according to the link I provided. It works like a charm!

查看更多
放荡不羁爱自由
3楼-- · 2019-06-08 05:54

As we discussed here - Smack have some bugs in file transfer implementation: in you case initiator offered bytestreams and ibb methods, responder accept both (which is wrong) methods, on the next trip initiator offer bytestreams streamhosts, responder selects one, and there file transfer should start with selected streamhost. But initiator wrongly starts ibb method(sic!). You can try call FileTransferNegotiator.IBB_ONLY = true; in your code, but strongly recommended to submit bug report to Smack developers.

查看更多
登录 后发表回答