bonjour comment invoquer et traiter un service web qui me retourne une reponse json
alors j ai un genre de http://fddd/fddddd/aspect.aspx?aspec...sbn=2253127183 que lorqu on tape dessus on obtient { "result" : true }.
et moi test
et
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
38
39
40
41
42
43 @Test public void testImportationResponseResource() throws Exception { byte[] ba = IOUtils.toByteArray( this.getClass().getResourceAsStream("/tes/catt_xml/notic/imag.xml")); URL postUrl = new URL("http://localhost:8080/G.../seam/resource/restv1/urlWebServiceDispo/retournerUrlImagette2"); HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection(); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/xml;charset=UTF-8"); OutputStream os = connection.getOutputStream(); os.write(ba); os.flush(); BufferedReader reader = new BufferedReader(new InputStreamReader( connection.getInputStream())); String line = reader.readLine(); while (line != null) { System.out.println(line); line = reader.readLine(); } System.out .println("Location: " + connection.getHeaderField("Location")); System.out.println("RESPONSE: " + connection.getResponseCode()); connection.disconnect(); } }
et mon fameux service
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 @POST @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) @Path("/retournerUrlImagette2") public String receiveResults(NoticesEnrichieDefinition notiveEnrichieList) { ImagetteService imagetteService = new ImagetteServiceImpl(); String numIsbn =notiveEnrichieList.getNoticeEnrichie().get(0).getNumeroNormalise(); String fsdfsd = imagetteService.haveCover(numIsbn); return imagetteService.haveCover(numIsbn); }
que qu en je l appelle
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 public String haveCover(String isbn) { String reponse = null; isbn = "2253127018"; // recupere l'imagette avec le premier isbn if(valideIsbn(isbn)) { reponse = "http://dggggg/Ele/aspect.aspx?aspect=havecover&isbn=" + isbn; } return reponse; }
il me retoure "http://dggggg/Ele/aspect.aspx?aspect=havecover&isbn=" + isbn.
J imagine de le retour dois etre un JSON mais comment l invoquer et surtout
quelle libraire faire appel merci
Partager