Bonjour,
M'entraînant sur les web services SOAP, je me suis fait un projet (gestion banale de produits) mais je me demande s'il fonctionne vraiment. Je vous présente le projet qui se compose d'une partie client et d'une partie serveur :
Dans ma partie client, dans la classe GProduitImpl, j'ai inclu des System.out afin d'écrire dans la console aux moments où "je passe" dans les fonctions. Donc, voici la classe GProduitImpl :
je vous donne aussi le code de GProduitPublisher :
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 package com.francky.webservices.impl; import javax.jws.WebService; import com.francky.beans.Produit; import com.francky.webservices.interfaces.GProduit; @WebService(endpointInterface="com.francky.webservices.interfaces.GProduit") public class GProduitImpl implements GProduit { @Override public Produit nouveauProduit(String designationProd) { System.out.println("nouveauProduit - server"); Produit produit = new Produit(designationProd); return produit; } @Override public void modifierDesignationProduit(Produit produit, String designationProduit) { System.out.println("modifierDesignationProduit - server"); produit.setDesignation(designationProduit); } }
Au niveau client, j'ai généré toutes les classes (sauf FranckyClient) grâce à wsimport, et ma première QUESTION concerne les warnings que j'ai obtenus pendant le wsimport (que signifient ces warnings et comment les résoudre ?) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 package com.francky.webservices.publishers; import javax.xml.ws.Endpoint; import com.francky.webservices.impl.GProduitImpl; public class GProduitPublisher { public static void main(String[] args) { Endpoint.publish("http://localhost:8080/francky/gproduit", new GProduitImpl()); } }
Après le wsimport, j'ai créé la classe FranckyClient pour tester mon web service, et j'aurais d'autres questions sur ce sujet :
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 analyse du WSDL... [WARNING] unknown extensibility element or attribute "ns1" (in namespace "http:/ /www.w3.org/2000/xmlns/") ligne 21 sur http://localhost:8080/francky/gproduit?wsdl=1 [WARNING] unknown extensibility element or attribute "ns2" (in namespace "http:/ /www.w3.org/2000/xmlns/") ligne 22 sur http://localhost:8080/francky/gproduit?wsdl=1 [WARNING] unknown extensibility element or attribute "ns3" (in namespace "http:/ /www.w3.org/2000/xmlns/") ligne 25 sur http://localhost:8080/francky/gproduit?wsdl=1 [WARNING] unknown extensibility element or attribute "ns4" (in namespace "http:/ /www.w3.org/2000/xmlns/") ligne 26 sur http://localhost:8080/francky/gproduit?wsdl=1 Génération du code... Compilation du code...
voici la classe FranckyClient :
QUESTION : lorsque je fait un "run" de la classe FranckyClient, comment cela se fait-il que je n'obtienne pas les sorties en console concernant les méthodes de la classe GProduitImpl côté serveur ? je me doute bien que je ne "passe pas" dans ces méthodes puisque le system.out n'a pas été lu. Mais pourquoi la partie serveur n'est pas lue ? ca sert à quoi d'avoir une partie serveur si le client ne se sert que de ses propres classes sans aller visiter le server ?? c'est pour cela que, même si je n'obtiens pas d'erreurs ici, je ne suis pas certain que mon code fonctionne ...
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 package com.francky.webservices.client; import java.util.Scanner; import com.francky.webservices.impl.GProduit; import com.francky.webservices.impl.GProduitImplService; import com.francky.webservices.interfaces.Produit; public class FranckyClient { public static void main(String[] args){ GProduitImplService gpImplService = new GProduitImplService(); GProduit gProduit = gpImplService.getGProduitImplPort(); Produit produit = gProduit.nouveauProduit("Nem au porc"); System.out.println("nom du nouveau produit créé : " + produit.getDesignation()); Scanner scan = new Scanner(System.in); System.out.println("Saisissez une nouvelle designation du produit " + produit.getDesignation()); String nouvelleDesignation = scan.next(); produit.setDesignation(nouvelleDesignation); System.out.println("nouvelle désignation du produit : " + produit.getDesignation()); } }
Ensuite, j'ai modifié la classe FranckyClient afin d'essayer de l'obliger à attaquer le serveur. Voici la classe FranckyClient modifiée :
Mais voilà que j'obtiens l'erreur suivante en console d'Eclipse côté client :
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 public class FranckyClient { public static void main(String[] args){ GProduitImplService gpImplService = new GProduitImplService(); GProduit gProduit = gpImplService.getGProduitImplPort(); Produit produit = gProduit.nouveauProduit("Nem au porc"); System.out.println("nom du nouveau produit créé : " + produit.getDesignation()); Scanner scan = new Scanner(System.in); System.out.println("Saisissez une nouvelle designation du produit " + produit.getDesignation()); String nouvelleDesignation = scan.next(); // produit.setDesignation(nouvelleDesignation); gProduit.modifierDesignationProduit(produit, nouvelleDesignation); System.out.println("nouvelle désignation du produit : " + produit.getDesignation()); } }
et donc cette erreur génère une autre QUESTION :
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 nom du nouveau produit créé : Nem au porc Saisissez une nouvelle designation du produit Nem au porc samoussas Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: Le serveur a envoyé le code de statut HTTP 500 : Internal Server Error at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.checkStatusCode(Unknown Source) at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(Unknown Source) at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(Unknown Source) at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(Unknown Source) at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source) at com.sun.xml.internal.ws.client.Stub.process(Unknown Source) at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(Unknown Source) at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source) at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source) at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source) at com.sun.proxy.$Proxy32.modifierDesignationProduit(Unknown Source) at com.francky.webservices.client.FranckyClient.main(FranckyClient.java:21)
Pourquoi cette erreur ? j'ai beau regarder la nouvelle ligne que j'ai codée (ligne 13 de la classe FranckyClient), il me semble qu'il n'y a pas d'erreurs mais .... il y en a quand même une ....
et voici l'affichage console côté serveur :
Donc on voit bien que le System.out a fonctionné pour la méthode "nouveauProduit" mais pas pour la méthode "modifierDesignationProduit".
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
86 nouveauProduit - server oct. 07, 2015 3:10:25 PM com.sun.xml.internal.bind.v2.ClassFactory create0 INFOS: No default constructor found on class com.francky.beans.Produit java.lang.NoSuchMethodException: com.francky.beans.Produit.<init>() at java.lang.Class.getConstructor0(Unknown Source) at java.lang.Class.getDeclaredConstructor(Unknown Source) at com.sun.xml.internal.bind.v2.ClassFactory.create0(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.createInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.createInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StructureLoader.startElement(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.BridgeImpl.unmarshal(Unknown Source) at com.sun.xml.internal.bind.api.Bridge.unmarshal(Unknown Source) at com.sun.xml.internal.ws.db.glassfish.BridgeWrapper.unmarshal(Unknown Source) at com.sun.xml.internal.ws.server.sei.EndpointArgumentsBuilder$DocLit.readRequest(Unknown Source) at com.sun.xml.internal.ws.server.sei.TieHandler.readRequest(Unknown Source) at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeRequest(Unknown Source) at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeRequest(Unknown Source) at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source) at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(Unknown Source) at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(Unknown Source) at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(Unknown Source) at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(Unknown Source) at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(Unknown Source) at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source) at sun.net.httpserver.AuthFilter.doFilter(Unknown Source) at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source) at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(Unknown Source) at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source) at sun.net.httpserver.ServerImpl$Exchange.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) oct. 07, 2015 3:10:25 PM com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit handle GRAVE: com.francky.beans.Produit.<init>() java.lang.NoSuchMethodError: com.francky.beans.Produit.<init>() at com.sun.xml.internal.bind.v2.ClassFactory.create0(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.createInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.createInstance(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StructureLoader.startElement(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.BridgeImpl.unmarshal(Unknown Source) at com.sun.xml.internal.bind.api.Bridge.unmarshal(Unknown Source) at com.sun.xml.internal.ws.db.glassfish.BridgeWrapper.unmarshal(Unknown Source) at com.sun.xml.internal.ws.server.sei.EndpointArgumentsBuilder$DocLit.readRequest(Unknown Source) at com.sun.xml.internal.ws.server.sei.TieHandler.readRequest(Unknown Source) at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeRequest(Unknown Source) at com.sun.xml.internal.ws.db.DatabindingImpl.deserializeRequest(Unknown Source) at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source) at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source) at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(Unknown Source) at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(Unknown Source) at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(Unknown Source) at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(Unknown Source) at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(Unknown Source) at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source) at sun.net.httpserver.AuthFilter.doFilter(Unknown Source) at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source) at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(Unknown Source) at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source) at sun.net.httpserver.ServerImpl$Exchange.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NoSuchMethodException: com.francky.beans.Produit.<init>() at java.lang.Class.getConstructor0(Unknown Source) at java.lang.Class.getDeclaredConstructor(Unknown Source) ... 36 more
voici aussi le wsdl généré à partir cette adresse : http://localhost:8080/francky/gproduit?wsdl
Je vous remercie par avance de bien vouloir m'aider à comprendre mes problèmes !
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 <!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --> <!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --> <definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://impl.webservices.francky.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://impl.webservices.francky.com/" name="GProduitImplService"> <import namespace="http://interfaces.webservices.francky.com/" location="http://localhost:8080/francky/gproduit?wsdl=1"/> <binding xmlns:ns1="http://interfaces.webservices.francky.com/" name="GProduitImplPortBinding" type="ns1:GProduit"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> <operation name="modifierDesignationProduit"> <soap:operation soapAction=""/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> <operation name="nouveauProduit"> <soap:operation soapAction=""/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> <service name="GProduitImplService"> <port name="GProduitImplPort" binding="tns:GProduitImplPortBinding"> <soap:address location="http://localhost:8080/francky/gproduit"/> </port> </service> </definitions>
Partager