|
@@ -1,8 +1,6 @@
|
1
|
1
|
package app.insa.clav.Reseau;
|
2
|
2
|
import app.insa.clav.Core.Utilisateurs;
|
3
|
|
-import app.insa.clav.Messages.Message;
|
4
|
|
-import app.insa.clav.Messages.MessageInit;
|
5
|
|
-import app.insa.clav.Messages.MessagePseudo;
|
|
3
|
+import app.insa.clav.Messages.*;
|
6
|
4
|
|
7
|
5
|
import java.io.BufferedReader;
|
8
|
6
|
import java.io.IOException;
|
|
@@ -17,7 +15,6 @@ import java.util.ArrayList;
|
17
|
15
|
import java.util.Arrays;
|
18
|
16
|
import java.util.List;
|
19
|
17
|
|
20
|
|
-import app.insa.clav.Messages.MessageSrvTCP;
|
21
|
18
|
import com.google.gson.Gson;
|
22
|
19
|
import com.google.gson.GsonBuilder;
|
23
|
20
|
import com.google.gson.reflect.TypeToken;
|
|
@@ -219,6 +216,56 @@ public class ServletConnection {
|
219
|
216
|
}
|
220
|
217
|
}
|
221
|
218
|
|
|
219
|
+ public void SubmitMessageChatTxt(int userId, int remoteId, MessageChatTxt msg){
|
|
220
|
+ URL url = null;
|
|
221
|
+ HttpURLConnection con = null;
|
|
222
|
+ try {
|
|
223
|
+ url = new URL(baseURL + "SubmitMessageChat");
|
|
224
|
+ } catch (MalformedURLException e) {
|
|
225
|
+ e.printStackTrace();
|
|
226
|
+ }
|
|
227
|
+
|
|
228
|
+ try {
|
|
229
|
+ con = (HttpURLConnection) url.openConnection();
|
|
230
|
+ con.setRequestMethod("POST");
|
|
231
|
+ con.setRequestProperty("Content-Type", "application/json; utf-8");
|
|
232
|
+ con.setDoOutput(true);
|
|
233
|
+ try(OutputStream os = con.getOutputStream()) {
|
|
234
|
+ byte[] input = gson.toJson(new MessageSrvTCP(userId, remoteId, new MessageRetourSrvTCP(msg), null)).getBytes(StandardCharsets.UTF_8);
|
|
235
|
+ os.write(input, 0, input.length);
|
|
236
|
+ }
|
|
237
|
+ int status = con.getResponseCode();
|
|
238
|
+ System.out.println("Error code HTTP request submit msg chat = " + status);
|
|
239
|
+ } catch (IOException e) {
|
|
240
|
+ e.printStackTrace();
|
|
241
|
+ }
|
|
242
|
+ }
|
|
243
|
+
|
|
244
|
+ public void SubmitMessageChatFile(int userId, int remoteId, MessageChatFile msg){
|
|
245
|
+ URL url = null;
|
|
246
|
+ HttpURLConnection con = null;
|
|
247
|
+ try {
|
|
248
|
+ url = new URL(baseURL + "SubmitMessageChat");
|
|
249
|
+ } catch (MalformedURLException e) {
|
|
250
|
+ e.printStackTrace();
|
|
251
|
+ }
|
|
252
|
+
|
|
253
|
+ try {
|
|
254
|
+ con = (HttpURLConnection) url.openConnection();
|
|
255
|
+ con.setRequestMethod("POST");
|
|
256
|
+ con.setRequestProperty("Content-Type", "application/json; utf-8");
|
|
257
|
+ con.setDoOutput(true);
|
|
258
|
+ try(OutputStream os = con.getOutputStream()) {
|
|
259
|
+ byte[] input = gson.toJson(new MessageSrvTCP(userId, remoteId, new MessageRetourSrvTCP(msg), null)).getBytes(StandardCharsets.UTF_8);
|
|
260
|
+ os.write(input, 0, input.length);
|
|
261
|
+ }
|
|
262
|
+ int status = con.getResponseCode();
|
|
263
|
+ System.out.println("Error code HTTP request submit msg chat = " + status);
|
|
264
|
+ } catch (IOException e) {
|
|
265
|
+ e.printStackTrace();
|
|
266
|
+ }
|
|
267
|
+ }
|
|
268
|
+
|
222
|
269
|
public void SubmitMessageChat(int userId, int remoteId, Message msg){
|
223
|
270
|
URL url = null;
|
224
|
271
|
HttpURLConnection con = null;
|
|
@@ -234,7 +281,7 @@ public class ServletConnection {
|
234
|
281
|
con.setRequestProperty("Content-Type", "application/json; utf-8");
|
235
|
282
|
con.setDoOutput(true);
|
236
|
283
|
try(OutputStream os = con.getOutputStream()) {
|
237
|
|
- byte[] input = gson.toJson(new MessageSrvTCP(userId, remoteId, msg)).getBytes(StandardCharsets.UTF_8);
|
|
284
|
+ byte[] input = gson.toJson(new MessageSrvTCP(userId, remoteId, new MessageRetourSrvTCP(msg), null)).getBytes(StandardCharsets.UTF_8);
|
238
|
285
|
os.write(input, 0, input.length);
|
239
|
286
|
}
|
240
|
287
|
int status = con.getResponseCode();
|
|
@@ -244,7 +291,7 @@ public class ServletConnection {
|
244
|
291
|
}
|
245
|
292
|
}
|
246
|
293
|
|
247
|
|
- public void SubmitConnectionChat(int userId, MessageInit msg){
|
|
294
|
+ public void SubmitConnectionChat(int userId, int remoteId, MessageInit msg){
|
248
|
295
|
URL url = null;
|
249
|
296
|
HttpURLConnection con = null;
|
250
|
297
|
try {
|
|
@@ -259,7 +306,7 @@ public class ServletConnection {
|
259
|
306
|
con.setRequestProperty("Content-Type", "application/json; utf-8");
|
260
|
307
|
con.setDoOutput(true);
|
261
|
308
|
try(OutputStream os = con.getOutputStream()) {
|
262
|
|
- byte[] input = gson.toJson(new MessageSrvTCP(userId, 0, msg)).getBytes(StandardCharsets.UTF_8);
|
|
309
|
+ byte[] input = gson.toJson(new MessageSrvTCP(userId, remoteId, null, msg)).getBytes(StandardCharsets.UTF_8);
|
263
|
310
|
os.write(input, 0, input.length);
|
264
|
311
|
}
|
265
|
312
|
int status = con.getResponseCode();
|
|
@@ -269,11 +316,11 @@ public class ServletConnection {
|
269
|
316
|
}
|
270
|
317
|
}
|
271
|
318
|
|
272
|
|
- public Message GetMessageChat(int userId, int remoteId){
|
|
319
|
+ public MessageRetourSrvTCP GetMessageChat(int userId, int remoteId){
|
273
|
320
|
//System.out.println("Demande");
|
274
|
321
|
URL url = null;
|
275
|
322
|
HttpURLConnection con = null;
|
276
|
|
- Message resList = null;
|
|
323
|
+ MessageRetourSrvTCP resList = null;
|
277
|
324
|
try {
|
278
|
325
|
url = new URL(baseURL + "GetMessageChat");
|
279
|
326
|
} catch (MalformedURLException e) {
|
|
@@ -287,7 +334,7 @@ public class ServletConnection {
|
287
|
334
|
con.setDoOutput(true);
|
288
|
335
|
con.setDoInput(true);
|
289
|
336
|
try(OutputStream os = con.getOutputStream()) {
|
290
|
|
- byte[] input = gson.toJson(new MessageSrvTCP(userId, remoteId, null)).getBytes(StandardCharsets.UTF_8);
|
|
337
|
+ byte[] input = gson.toJson(new MessageSrvTCP(userId, remoteId, null, null)).getBytes(StandardCharsets.UTF_8);
|
291
|
338
|
os.write(input, 0, input.length);
|
292
|
339
|
}
|
293
|
340
|
int status = con.getResponseCode();
|
|
@@ -300,7 +347,7 @@ public class ServletConnection {
|
300
|
347
|
}
|
301
|
348
|
in.close();
|
302
|
349
|
System.out.println("Response : " + content);
|
303
|
|
- resList = gson.fromJson(content.toString(),Message.class);
|
|
350
|
+ resList = gson.fromJson(content.toString(),MessageRetourSrvTCP.class);
|
304
|
351
|
//resList = new Utilisateurs[Integer.parseInt(con.getHeaderField("sizeArray"))];
|
305
|
352
|
} catch (IOException e) {
|
306
|
353
|
System.out.println("Erreur recup msg chat 2 avec " + url.toString());
|
|
@@ -326,7 +373,7 @@ public class ServletConnection {
|
326
|
373
|
con.setDoOutput(true);
|
327
|
374
|
con.setDoInput(true);
|
328
|
375
|
try(OutputStream os = con.getOutputStream()) {
|
329
|
|
- byte[] input = gson.toJson(new MessageSrvTCP(userId, 0, null)).getBytes(StandardCharsets.UTF_8);
|
|
376
|
+ byte[] input = gson.toJson(new MessageSrvTCP(userId, 0, null, null)).getBytes(StandardCharsets.UTF_8);
|
330
|
377
|
os.write(input, 0, input.length);
|
331
|
378
|
}
|
332
|
379
|
int status = con.getResponseCode();
|