Bonjour à tous,
J'ai eu recours à la classe HttpURLConnection pour créer une requête HTTP PUT :Ma requête fait appel un WS pour créer un nouveau utilisateur dans mon annuaire LDAP.
Le WS prends en entrée un objet json et retourne true ou false comme réponse.
Voilà un aperçu du code de la requête :
L'exécution de cette requête me retourne une erreur 500 :
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 // Construction de l'url. StringBuilder urlStrCreerCompte = new StringBuilder(urlWebService); urlStrCreerCompte.append("/"); urlStrCreerCompte.append(contextRootCreerCompte); // Création de la connexion. URL urlCreerCompte; HttpURLConnection cnxCreerCompte; try{ //Construction de l'url. urlCreerCompte = new URL(urlStrCreerCompte.toString()); //Ouverture de connexion. cnxCreerCompte = (HttpURLConnection) urlCreerCompte.openConnection(); cnxCreerCompte.setRequestMethod("PUT"); // Définir les timeout de connexion et de lecture de données. cnxCreerCompte.setConnectTimeout(timeout); cnxCreerCompte.setReadTimeout(timeout); // Ajout de l'entête. cnxCreerCompte.setRequestProperty(HTTP.CONTENT_TYPE, "application/json"); cnxCreerCompte.setDoInput(true); cnxCreerCompte.setDoOutput(true); // Construction de l'objet json à envoyer. JSONObject userJson = new JSONObject(); userJson.put("courriel", daoBean.getMail()); userJson.put("identifiant", daoBean.getIdUtilisateur()); userJson.put("motDePasse", daoBean.getMotDePasse()); userJson.put("nom", daoBean.getNom()); userJson.put("prenom", daoBean.getPrenom()); logger.info("userJson : " + userJson); //Envoi de la requête logger.info("cnxCreerCompte.getOutputStream() : " + cnxCreerCompte.getOutputStream()); OutputStreamWriter outCreerCompte = new OutputStreamWriter(cnxCreerCompte.getOutputStream()); outCreerCompte.write(userJson.toString()); outCreerCompte.flush(); outCreerCompte.close(); // Analyse et lecture de la réponse. Integer statusCreerCompte = cnxCreerCompte.getResponseCode(); String lineCreerCompte; StringBuffer response = new StringBuffer(); BufferedReader readerCreerCompte = null; if(statusCreerCompte.equals(200)){ readerCreerCompte = new BufferedReader(new InputStreamReader(cnxCreerCompte.getInputStream())); }else { readerCreerCompte = new BufferedReader(new InputStreamReader(cnxCreerCompte.getErrorStream())); } while ((lineCreerCompte = readerCreerCompte.readLine()) != null){ response.append(lineCreerCompte); response.append("\r"); } readerCreerCompte.close(); // Fermeture de la connexion. cnxCreerCompte.disconnect(); if(statusCreerCompte.equals(200)){ if("true".equals(response.toString())){ System.out.println("true"); }else{ System.out.println("false"); } }else { throw new TechnicalException("TechnicalException !!! lors de l'appel du WS de création d'un nouveau compte : " + urlStrCreerCompte + " ; " + response.toString()); } } catch (JSONException | IOException e) { e.printStackTrace(); throw new TechnicalException("ERREUR (JSONException | IOException) !!! lors de l'appel du WS de création d'un nouveau compte : " + urlStrCreerCompte); }
J'ai fait quelques recherches sur le net mais je n'ai pas trouvé une réponse qui peut résoudre mon problème.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 <!doctype html><html lang="fr"><head><title>État HTTP 500 – Internal Server Error</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>État HTTP 500 – Internal Server Error</h1><hr class="line" /><p><b>Type</b> Rapport d''exception</p><p><b>message</b> Circular view path [error]: would dispatch back to the current handler URL [/ws/error] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)</p><p><b>description</b> Le serveur a rencontré une erreur interne qui l''a empêché de satisfaire la requête.</p><p><b>exception</b></p><pre>javax.servlet.ServletException: Circular view path [error]: would dispatch back to the current handler URL [/ws/error] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
Des pistes ?
Partager