Using XEP-0363, I want to upload a file . The process is as follow:
- the client discover the upload featur
- the server respond with the upload feature's domain
- the client request a slot to xmpp server
- the xmpp server respond with the slot with the following xml :
<iq from='upload.montague.tld'
id='step_03'
to='[email protected]/garden'
type='result'>
<slot xmlns='urn:xmpp:http:upload:0'>
<put url='https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/tr%C3%A8s%20cool.jpg'>
<header name='Authorization'>Basic Base64String==</header>
<header name='Cookie'>foo=bar; user=romeo</header>
</put>
<get url='https://download.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/tr%C3%A8s%20cool.jpg' />
</slot>
</iq>
where the utls in the put and get are the urls for uploading and downloading respectively. After that:
- the client upload the file
- when the upload is successfull, the get url will download the file .
now my problem is inn the uploading stage where an error is thrown .The relevant code is :
private void apacheUpload(File file,URI url) throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPut put = new HttpPut(url);
FileEntity reqEntity = new FileEntity(file, ContentType.APPLICATION_OCTET_STREAM);
put.setEntity(reqEntity);
HttpResponse response = null;
try {
response = httpclient.execute(put);
} catch (IOException e) {
throw new Exception(e.getMessage());
}
if(response == null) {
return ;
}
int responseCode = response.getStatusLine().getStatusCode();
if (responseCode - 200 >= 100)
throw new Exception("bad status code: " + responseCode);
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity);
System.out.println("response");
System.out.println(responseString);
}
the client error is :
Exception in thread "main" java.lang.Exception: Connection reset
at main.java.com.tecfrac.external.HttpFileUploadManagerUser.apacheUpload(HttpFileUploadManagerUser.java:292)
at main.java.com.tecfrac.external.HttpFileUploadManagerUser.uploadFile(HttpFileUploadManagerUser.java:275)
at main.java.com.tecfrac.smack.Client.uploadFile(Client.java:244)
at main.java.com.tecfrac.smack.Client.main(Client.java:274)
the server error is :
2021.10.06 03:34:15 WARN [socket_c2s-thread-2]: org.jivesoftware.openfire.nio.ConnectionHandler - Closing connection due to exception in session: (0x0000003D: nio socket, server, null => 0.0.0.0/0.0. 0.0:5222)
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method) ~[?:1.8.0_202]
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39) ~[?:1.8.0_202]
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) ~[?:1.8.0_202]
at sun.nio.ch.IOUtil.read(IOUtil.java:197) ~[?:1.8.0_202]
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380) ~[?:1.8.0_202]
at org.apache.mina.transport.socket.nio.NioProcessor.read(NioProcessor.java:378) ~[mina-core-2.1.3.jar:?]
at org.apache.mina.transport.socket.nio.NioProcessor.read(NioProcessor.java:47) ~[mina-core-2.1.3.jar:?]
at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:519) ~[mina-core-2.1.3.jar:?]
at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$1200(AbstractPollingIoProcessor.java:68) ~[mina-core-2.1.3.jar:?]
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.process(AbstractPollingIoProcessor.java:1222) ~[mina-core-2.1.3.jar:?]
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.process(AbstractPollingIoProcessor.java:1211) ~[mina-core-2.1.3.jar:?]
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:683) ~[mina-core-2.1.3.jar:?]
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64) ~[mina-core-2.1.3.jar:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_202]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_202]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_202]
the following statement caused the error :
response = httpclient.execute(put);
thank you in advance
the openfire fire was on another pc, so I needed to use the ip address of that pc (not localhost)