Now am working with Xmpp file Transfer in Android.While am sending files it give a 503 service unavailable error.
> 07-29 15:33:12.183: D/SMACK(22151): 03:33:12 PM SENT (1095973320):
> <iq id="s9DTB-10" to="jithu4@jabber.org/Smack"
> from="jithu1@jabber.org/Smack" type="set"><si
> xmlns="http://jabber.org/protocol/si" id="jsi_6388535575928662640"
> mime-type="image/jpeg"
> profile="http://jabber.org/protocol/si/profile/file-transfer"><file
> xmlns="http://jabber.org/protocol/si/profile/file-transfer"
> name="IMG_20130715_115622_1445552069.jpg" size="2105955"
> ><desc>test_file</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>
After that it gives a response like that
> 07-29 15:33:12.708: D/SMACK(22151): 03:33:12 PM RCV (1095973320): <iq
> from='jithu4@jabber.org/Smack' to='jithu1@jabber.org/Smack'
> type='error' id='s9DTB-10'><error code='503'
> type='cancel'><service-unavailable
> xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>
Am using the asmack-android-6-0.8.1.1.jar libs
Please help me ,why this 503 error happens.
Add service discovery to your code. You can use below code for file transfer.
ServiceDiscoveryManager sdm = ServiceDiscoveryManager
.getInstanceFor(kXmppConnection);
if (sdm == null)
sdm = new ServiceDiscoveryManager(XmppConnection);
sdm.addFeature("http://jabber.org/protocol/disco#info");
sdm.addFeature("jabber:iq:privacy");
FileTransferNegotiator.setServiceEnabled(kXmppConnection,
true);
FileTransferManager manager = new FileTransferManager(
kXmppConnection);
final OutgoingFileTransfer transfer = manager
.createOutgoingFileTransfer(jid + "/Smack");
File file = new File(file_path);
try {
transfer.sendFile(file, "test_file");
} catch (XMPPException e) {
e.printStackTrace();
}
new AsyncTask<Void, Void, Void>() {
protected void onPreExecute() {
}
@Override
protected Void doInBackground(Void... params) {
while (!transfer.isDone()) {
if (transfer.getStatus().equals("Error")) {
Log.d("file transfer",
"ERROR!!! " + transfer.getError());
} else if (transfer.getStatus().equals("Cancelled")
|| transfer.getStatus().equals("Refused")) {
Log.d("file transfer",
"Cancelled!!! " + transfer.getError());
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return null;
};
protected void onPostExecute(Void result) {
if (transfer.getStatus().equals("Refused")
|| transfer.getStatus().equals("Error")
|| transfer.getStatus().equals("Cancelled")) {
Log.i("file transfer", "refused cancelled error "
+ transfer.getError());
} else {
Log.i("file transfer", "Success: " + transfer.getFileName());
}
};
}.execute();
I had same problem, I investigated the stanza and solved it this way.
Many people use "/Smack" or "/Resource" as resource part in jid, but that can be done another way.
Resource path is changing with every presence changed of user. Lets say we want to send image to this user: "user1@mydomain"
You must add "/Resource" or "/Smack" part to this jid and it become this: user1@mydomain/Resource
But resource path is changing with presence so you must follow every presence change to update resource path. Best way is to get user presence is in roster listener and in presencheChanged() method you get last user resource part like this:
Roster roster=getRoster();
roster.addRosterListener(new RosterListener() {
@Override
public void entriesAdded(Collection<Jid> addresses) {
Log.d("entriesAdded", "ug");
context.sendBroadcast(new Intent("ENTRIES_ADDED"));
}
@Override
public void entriesUpdated(Collection<Jid> addresses) {
Log.d("entriesUpdated", "ug");
}
@Override
public void entriesDeleted(Collection<Jid> addresses) {
Log.d("entriesDeleted", "ug");
}
@Override
public void presenceChanged(Presence presence) {
Log.d("presenceChanged", "ug");
//Resource from presence
String resource = presence.getFrom().getResourceOrEmpty().toString();
//Update resource part for user in DB or preferences
//...
}
});
}
Resource string will be some generated string like "6u1613j3kv" and jid will become: user1@mydomain/6u1613j3kv
That means that you must create your outgoing transfer like this:
EntityFullJid jid = JidCreate.entityFullFrom("user1@mydomain/6u1613j3kv");
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer(jid)
And that is how i have solved my problem with file transfer on smack and Openfire.
Also to mention you must add following properties in your Openfire server:
xmpp.proxy.enabled - true
xmpp.proxy.externalip - MY_IP_ADDRESS
xmpp.proxy.port -7777
Just to mention, I am using Openfire 4.0.2 and Smack 4.2.2.
Also this can be configured the easy way, just set the resource on
XMPPTCPConnectionConfiguration.Builder .
like
XMPPTCPConnectionConfiguration.Builder configurationBuilder =
XMPPTCPConnectionConfiguration.builder();
configurationBuilder.setResource("yourResourceName");
来源:https://stackoverflow.com/questions/17921288/xmpp-filetransnfer-in-android-giving-503-service-unavailable-error