Bonjour, je veux utiliser un client java de web service java
Voici mon web service
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 @GetMapping("/setStatusRemovedForRequestThatAreInApplicationAndNotInAD") @Produces(MediaType.APPLICATION_OCTET_STREAM) public Response setStatusRemovedForRequestThatAreInApplicationAndNotInAD(HttpServletRequest request, HttpServletResponse response) throws RecordNotFoundException, CSCSecurityException_Exception, NotFoundException, IOException { DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss"); String currentDateTime = dateFormatter.format(new Date()); Path javaPath = Paths.get("log-localhost-removeGrouNotInAD-" + currentDateTime + ".txt"); File myObj = null; try { myObj = new File("log-localhost-removeGrouNotInAD-" + currentDateTime + ".txt"); System.out.println("CA PASSE2"); if (myObj.createNewFile()) { System.out.println("File created: " + myObj.getName()); } else { System.out.println("File already exists."); } } catch (IOException e) { System.out.println(e.getMessage()); } scriptService.setStatusREMOVEDForRequestsThatAreNotInAD(javaPath); // fill myObj File through javapath } return Response.ok(myObj, MediaType.APPLICATION_OCTET_STREAM) .header("Content-Disposition", "attachment; filename=\"" + myObj.getName() + "\"" ) //optional .build(); }
Voici mon client java
à la ligne 3 le programme me signale une internal serveur error 500. JE SAIS A COUP SUR que du coté serveur web service, il n'y a pas d'erreur. L'erreur vient du fait que je n'arrive pas à faire le lien entre ce que renvoie le serveur, c'est à dire
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 line 1 Client client = Client.create(); line 2 WebResource objWebResource = client.resource(url); line 3 ClientResponse response = objWebResource.type(javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM).get(ClientResponse.class); line 4 System.out.println("response : " + response);
et la réponse client que voici
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 return Response.ok(myObj, MediaType.APPLICATION_OCTET_STREAM) .header("Content-Disposition", "attachment; filename=\"" + myObj.getName() + "\"" ) //optional .build();
Quand j'envoie la requête sur POSTMAN, la réponse est la suivante
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 ClientResponse response = objWebResource.type(javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM).get(ClientResponse.class);
du coté serveur j'ai les dépendances suivantes
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 { "statusType": "OK", "headers": { "Content-Type": [ { "type": "application", "subtype": "octet-stream", "parameters": {}, "wildcardSubtype": false, "wildcardType": false } ], "Content-Disposition": [ "attachment; filename=\"log-localhost-removeGrouNotInAD-2023-11-21_16_46_15.txt\"" ] }, "entity": "C:\\path\\log-localhost-removeGrouNotInAD-2023-11-21_16_46_15.txt", "entityType": "java.io.File", "metadata": { "Content-Type": [ { "type": "application", "subtype": "octet-stream", "parameters": {}, "wildcardSubtype": false, "wildcardType": false } ], "Content-Disposition": [ "attachment; filename=\"log-localhost-removeGrouNotInAD-2023-11-21_16_46_15.txt\"" ] }, "status": 200 }{ "message": "Handler dispatch failed; nested exception is java.lang.AbstractMethodError: com.sun.jersey.core.spi.factory.ResponseImpl.getLength()I" }
Pouvez vous m'aider ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 <dependency> <groupId>com.sun.jersey.contribs</groupId> <artifactId>jersey-multipart</artifactId> <version>1.19.4</version> </dependency> <!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api --> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>2.0</version> </dependency> <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-bundle --> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-bundle</artifactId> <version>1.9.1</version> </dependency> <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-core --> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> <version>1.13-b01</version> </dependency>
Partager