powered by Jive Software

aSmack File Transfer Negotiation Returns Null

Hello guys, i have problem with my aSmack file transfer, my Sending Works Brilliantly , but interesting part is my Receiving part, works Ocassionly ! some times it feels sorry for me and transfers file and then its ok untill i restart the emulator and tada , bye hopes. it seems after receiving the requests the Negotiator Seems lost his cookie and no time to answer it,and returns NullPointer at Negotiating, here is my my providers shiits i have added:

ProviderManager.addIQProvider(“vCard”, “vcard-temp”, new VCardProvider());

ProviderManager.addIQProvider(“query”, “jabber:iq:private”,new PrivateDataManager.PrivateDataIQProvider());

ProviderManager.addExtensionProvider(“x”, “jabber:x:event”,new MessageEventProvider());

// Group Chat Invitations

ProviderManager.addExtensionProvider(“x”, “jabber:x:conference”,new GroupChatInvitation.Provider());

// Service Discovery # Items

            ProviderManager.addIQProvider("query","[http://jabber.org/protocol/disco#items](http://jabber.org/protocol/disco#items)", new DiscoverItemsProvider());

// Service Discovery # Info

            ProviderManager.addIQProvider("query","[http://jabber.org/protocol/disco#info](http://jabber.org/protocol/disco#info)", new DiscoverInfoProvider());

// Data Forms

ProviderManager.addExtensionProvider(“x”, “jabber:x:data”, new DataFormProvider());

// Delayed Delivery

ProviderManager.addExtensionProvider(“x”, “jabber:x:delay”, new DelayInformationProvider());

// Version

try {

ProviderManager.addIQProvider(“query”, “jabber:iq:version”,Class.forName(“org.jivesoftware.smackx.packet.Version”));

} catch (ClassNotFoundException e) { }

// Offline Message Requests

            ProviderManager.addIQProvider("offline", "[http://jabber.org/protocol/offline](http://jabber.org/protocol/offline)",new OfflineMessageRequest.Provider());

// Offline Message Indicator

            ProviderManager.addExtensionProvider("offline","[http://jabber.org/protocol/offline](http://jabber.org/protocol/offline)",new OfflineMessageInfo.Provider());

// Last Activity

ProviderManager.addIQProvider(“query”, “jabber:iq:last”, new LastActivity.Provider());

// User Search

ProviderManager.addIQProvider(“query”, “jabber:iq:search”, new UserSearch.Provider());

// SharedGroupsInfo

            ProviderManager.addIQProvider("sharedgroup","[http://www.jivesoftware.org/protocol/sharedgroup](http://www.jivesoftware.org/protocol/sharedgroup)", new SharedGroupsInfo.Provider());

// JEP-33: Extended Stanza Addressing

            ProviderManager.addExtensionProvider("addresses","[http://jabber.org/protocol/address](http://jabber.org/protocol/address)",new MultipleAddressesProvider());

// FileTransfer

            ProviderManager.addIQProvider("si","[http://jabber.org/protocol/si](http://jabber.org/protocol/si)", new StreamInitiationProvider());

            ProviderManager.addIQProvider("query","[http://jabber.org/protocol/bytestreams](http://jabber.org/protocol/bytestreams)", new BytestreamsProvider());

            ProviderManager.addIQProvider("open","[http://jabber.org/protocol/ibb](http://jabber.org/protocol/ibb)", new OpenIQProvider());

            ProviderManager.addIQProvider("close","[http://jabber.org/protocol/ibb](http://jabber.org/protocol/ibb)", new CloseIQProvider());

            ProviderManager.addExtensionProvider("data","[http://jabber.org/protocol/ibb](http://jabber.org/protocol/ibb)", new DataPacketProvider());

// Privacy

ProviderManager.addIQProvider(“query”, “jabber:iq:privacy”, new PrivacyProvider());

            ProviderManager.addIQProvider("command", "[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",new AdHocCommandDataProvider());

            ProviderManager.addExtensionProvider("malformed-action","[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",new AdHocCommandDataProvider.MalformedActionError());

            ProviderManager.addExtensionProvider("bad-locale","[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",new AdHocCommandDataProvider.BadLocaleError());

            ProviderManager.addExtensionProvider("bad-payload","[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",new AdHocCommandDataProvider.BadPayloadError());

            ProviderManager.addExtensionProvider("bad-sessionid","[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",new AdHocCommandDataProvider.BadSessionIDError());

            ProviderManager.addExtensionProvider("session-expired","[http://jabber.org/protocol/commands](http://jabber.org/protocol/commands)",new AdHocCommandDataProvider.SessionExpiredError());

// Attention

ProviderManager.addExtensionProvider(“attention”, “urn:xmpp:attention:0”,

new AttentionExtension.Provider());

// XEP-184 Message Delivery Receipts

ProviderManager.addExtensionProvider(“received”, “urn:xmpp:receipts”,

new DeliveryReceipt.Provider());

ProviderManager.addExtensionProvider(“request”, “urn:xmpp:receipts”,

new DeliveryReceipt.Provider());

            ProviderManager.addIQProvider("query", "[http://jabber.org/protocol/bytestreams](http://jabber.org/protocol/bytestreams)",

new BytestreamsProvider());

            ProviderManager.addIQProvider("query", "[http://jabber.org/protocol/disco#items](http://jabber.org/protocol/disco#items)",

new DiscoverItemsProvider());

            ProviderManager.addIQProvider("query", "[http://jabber.org/protocol/disco#info](http://jabber.org/protocol/disco#info)",

new DiscoverInfoProvider());

System.out.println(“Providers Set”);

            ServiceDiscoveryManager.getInstanceFor(connection).addFeature("[http://jabber.org/protocol/disco#info](http://jabber.org/protocol/disco#info)");

ServiceDiscoveryManager.getInstanceFor(connection).addFeature(“jabber:iq:privac y”);

            ServiceDiscoveryManager.getInstanceFor(connection).addFeature("[http://jabber.org/protocol/si](http://jabber.org/protocol/si)");

and here is my code:

public void listenforFiles(){

connection.addPacketListener(new PacketListener() {

@Override

public void processPacket(Packet packet) throws NotConnectedException {

System.out.println(“new packet”);

System.out.println(packet.getPacketID());

// if( packet.getXmlns()!=null){

    //    if( packet.getXmlns().equals("[http://jabber.org/protocol/disco#info](http://jabber.org/protocol/disco#info)")){

   //         System.out.println("its a"+"[http://jabber.org/protocol/disco#info](http://jabber.org/protocol/disco#info)");

// }

// }

MyService.packetid=packet.getPacketID();

}

}, null);

SmackAndroid.init(this);

final FileTransferManager manager = new FileTransferManager(connection);

manager.addFileTransferListener(new FileTransferListener() {

public void fileTransferRequest(final FileTransferRequest request) {

new Thread(){

@Override

public void run() {

System.out.println(request.getStreamID());

// IncomingFileTransfer transfer = request.accept();

// System.out.println("New file Arrived: "+request+"status: "+transfer.getStatus()+"type: "+request.getMimeType());

// File file = new File(“storage/sdcard/LifeMatePrivate/”+transfer.getFileName());

FileTransferNegotiator.setServiceEnabled(connection,true);

IncomingFileTransfer transfer = request.accept();

try{

transfer.recieveFile(new File("/storage/sdcard/"+transfer.getFileName()));

System.out.println(“after receive file here”);

while(!transfer.isDone()) {

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

}

}

}catch (Exception e) {

Log.e("", e.getMessage());

}

};

}.start();

}

});

}

and here is the IQ Received:

07-03 13:41:49.622: D/SMACK(1395): RCV (0):

autumn-desktop-wallpaper.jpghttp://jabber.org/protocol/bytestreamshttp://jabber.org /protocol/ibb

its all fine in the packet, Please my Beloved Developers, help me so i can sleep after being awake working on this for 3 days beg you , love u thanks alot

Found the Answer, After Digging inside Smack SO Hard, Found out that for Some reasons , In the IncomingFileTransfer, when this method:

private InputStream negotiateStream() throws SmackException, XMPPErrorException {

reaches to here:

final MyManager.StreamNegotiator streamNegotiator =

negotiator.selectStreamNegotiator(recieveRequest);

so it wants to Select a negotiator, but, It Fails For Some Reason,I Tried it with Almost Every Lib, All same weakness, so i turned these variables in the FileTransferNegotiator to public static :

public static XMPPConnection connection=null;

public static StreamNegotiator byteStreamTransferManager;

public static StreamNegotiator inbandTransferManager;

and added this line instead where above method was:

final MyManager.StreamNegotiator streamNegotiator = new FaultTolerantNegotiator(FaultTolerateNegotiator.connection,FaultTolerateNegotia tor.byteStreamTransferManager,FaultTolerateNegotiator.inbandTransferManager);

this is not an absolute Solution, this is for when you know extacly what type of Negotiator you need( Means Just the App that you Built uses it so you are sure). how ever its easy to make it absolute solution with some if or case conditions.

so this solution is for when you need FaultTolerateNegotiator (Both IBB and ByteStream);

so if you needed only IBB method will be like this:

final MyManager.StreamNegotiator streamNegotiator = inbandTransferManager;

and so the ByteStream:

final MyManager.StreamNegotiator streamNegotiator = byteStreamTransferManager;

GoodLuck, Any Question ill Try to Answer

and returns NullPointer at Negotiating,
Good post, but I fail to find where you mention which method actually returns null.

this method returns null from IncomingFileTransfer.java :

final StreamNegotiator streamNegotiator =

negotiator.selectStreamNegotiator(recieveRequest);

which requests negotiator from this method:

public StreamNegotiator selectStreamNegotiator(MyManager.FileTransferRequest request) throws

XMPPErrorException, NotConnectedException {

StreamInitiation si = request.getStreamInitiation();

FormField streamMethodField = getStreamMethodField(si

.getFeatureNegotiationForm());

Log.i(“FileTransferNegotiator”," Selecting Negotiator with request: "+request);

if (streamMethodField == null) {

Log.i(“FileTransferNegotiator”,“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 XMPPErrorException(errorMessage, error);

}

// select the appropriate protocol

StreamNegotiator selectedStreamNegotiator;

try {

selectedStreamNegotiator = getNegotiator(streamMethodField);

}

catch (XMPPErrorException e) {

IQ iqPacket = createIQ(si.getPacketID(), si.getFrom(), si.getTo(),

IQ.Type.ERROR);

iqPacket.setError(e.getXMPPError());

connection.sendPacket(iqPacket);

throw e;

}

// return the appropriate negotiator

Log.i(“FileTransferNegotiator”,“Best Suited Negotiator is :”+selectedStreamNegotiator);

return selectedStreamNegotiator;

}

ill report this as issue once i have time