AXIS2 : Consommer un WebService (input parameters : complexType)
Bonjour,
J'ai développé 2 WEB Services en Java sous AXIS2 qui me permette de récupérer un client : getClient() et d'en ajouter un addClient().
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public class WS {
public Client getClient(int clientId) throws Exception {
DataSource DS = null;
DataAccess DA = null;
DS = new DataSource("localhost/test", "", "");
DA = new DataAccess(DS);
return DA.getClient(clientId);
}
public void addClient(Client client) throws Exception {
DataSource DS = null;
DataAccess DA = null;
DS = new DataSource("localhost/test", "", "");
DA = new DataAccess(DS);
DA.addClient(client);
}
} |
Du coté du DataAccess :
Code:
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
| public class DataAccess {
private DataSource _DS;
public DataAccess(DataSource DS) {
_DS = DS;
}
private void ExecuteUpdate(String Query) throws SQLException {
_DS.getDbStatement().executeUpdate(Query);
}
private ResultSet ExecuteQuery(String Query) throws SQLException {
return _DS.getDbStatement().executeQuery(Query);
}
public Client getClient(int clientId) throws SQLException {
String q = "SELECT ID,Name,FirstName FROM client WHERE ID=" + clientId;
ResultSet r = ExecuteQuery(q);
r.first();
return new Client(r.getInt("ID"), r.getString("Name"), r.getString("FirstName"));
}
public void addClient(Client client) throws SQLException{
String q = "INSERT INTO client(Name,FirstName) VALUES ('"+client.getClientName()+"','"+client.getClientFirstName()+"')";
ExecuteUpdate(q);
}
} |
getClient fonctionne parfaitement.
Le problème se situe au niveau de addClient(). La requête est bonne.
Ma requête SOAP :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://aitec.net/xsd">
<soap:Header/>
<soap:Body>
<xsd:addClient>
<xsd:client>
<xsd:clientFirstName>Prenom</xsd:clientFirstName>
<xsd:clientId>1</xsd:clientId>
<xsd:clientName>Nom</xsd:clientName>
</xsd:client>
</xsd:addClient>
</soap:Body>
</soap:Envelope> |
La réponse SOAP :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header/>
<soapenv:Body>
<soapenv:Fault>
<soapenv:Code>
<soapenv:Value>soapenv:Sender</soapenv:Value>
</soapenv:Code>
<soapenv:Reason>
<soapenv:Text xml:lang="en-US">Exception occurred while trying to invoke service method addClient</soapenv:Text>
</soapenv:Reason>
<soapenv:Detail/>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope> |
J'ai pas plus d'informations sur l'erreur :(
et pour finir mon WSDL généré par AXIS2 :
Code:
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
| <wsdl:definitions targetNamespace="http://aitec.net">
<wsdl:documentation>WS service</wsdl:documentation>
−
<wsdl:types>
−
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://aitec.net/xsd">
−
<xs:element name="getClientFault">
−
<xs:complexType>
−
<xs:sequence>
<xs:element name="getClientFault" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
−
<xs:element name="getClient">
−
<xs:complexType>
−
<xs:sequence>
<xs:element name="clientId" nillable="true" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
−
<xs:element name="getClientResponse">
−
<xs:complexType>
−
<xs:sequence>
<xs:element name="return" nillable="true" type="ns0:Client"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Client" type="ns0:Client"/>
−
<xs:complexType name="Client">
−
<xs:sequence>
<xs:element name="clientFirstName" nillable="true" type="xs:string"/>
<xs:element name="clientId" type="xs:int"/>
<xs:element name="clientName" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
−
<xs:element name="addClientFault">
−
<xs:complexType>
−
<xs:sequence>
<xs:element name="addClientFault" type="xs:anyType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
−
<xs:element name="addClient">
−
<xs:complexType>
−
<xs:sequence>
<xs:element name="client" nillable="true" type="ns0:Client"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
−
<wsdl:message name="addClientMessage">
<wsdl:part name="part1" element="ns0:addClient"/>
</wsdl:message>
−
<wsdl:message name="addClientFault">
<wsdl:part name="part1" element="ns0:addClientFault"/>
</wsdl:message>
−
<wsdl:message name="getClientMessage">
<wsdl:part name="part1" element="ns0:getClient"/>
</wsdl:message>
−
<wsdl:message name="getClientResponse">
<wsdl:part name="part1" element="ns0:getClientResponse"/>
</wsdl:message>
−
<wsdl:message name="getClientFault">
<wsdl:part name="part1" element="ns0:getClientFault"/>
</wsdl:message>
−
<wsdl:portType name="WSPortType">
−
<wsdl:operation name="addClient">
<wsdl:input message="axis2:addClientMessage" wsaw:Action="urn:addClient"/>
<wsdl:fault message="axis2:addClientFault" name="addClientFault"/>
</wsdl:operation>
−
<wsdl:operation name="getClient">
<wsdl:input message="axis2:getClientMessage" wsaw:Action="urn:getClient"/>
<wsdl:output message="axis2:getClientResponse"/>
<wsdl:fault message="axis2:getClientFault" name="getClientFault"/>
</wsdl:operation>
</wsdl:portType>
−
<wsdl:binding name="WSSOAP11Binding" type="axis2:WSPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
−
<wsdl:operation name="addClient">
<soap:operation soapAction="urn:addClient" style="document"/>
−
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
−
<wsdl:fault name="addClientFault">
<soap:body use="literal"/>
</wsdl:fault>
</wsdl:operation>
−
<wsdl:operation name="getClient">
<soap:operation soapAction="urn:getClient" style="document"/>
−
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
−
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
−
<wsdl:fault name="getClientFault">
<soap:body use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
−
<wsdl:binding name="WSSOAP12Binding" type="axis2:WSPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
−
<wsdl:operation name="addClient">
<soap12:operation soapAction="urn:addClient" style="document"/>
−
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
−
<wsdl:fault name="addClientFault">
<soap12:fault use="literal" name="addClientFault"/>
</wsdl:fault>
</wsdl:operation>
−
<wsdl:operation name="getClient">
<soap12:operation soapAction="urn:getClient" style="document"/>
−
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
−
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
−
<wsdl:fault name="getClientFault">
<soap12:fault use="literal" name="getClientFault"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
−
<wsdl:binding name="WSHttpBinding" type="axis2:WSPortType">
<http:binding verb="POST"/>
−
<wsdl:operation name="addClient">
<http:operation location="addClient"/>
−
<wsdl:input>
<mime:content type="text/xml"/>
</wsdl:input>
</wsdl:operation>
−
<wsdl:operation name="getClient">
<http:operation location="getClient"/>
−
<wsdl:input>
<mime:content type="text/xml"/>
</wsdl:input>
−
<wsdl:output>
<mime:content type="text/xml"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
−
<wsdl:service name="WS">
−
<wsdl:port name="WSSOAP11port_http" binding="axis2:WSSOAP11Binding">
<soap:address location="http://localhost:8080/axis2/services/WS"/>
</wsdl:port>
−
<wsdl:port name="WSSOAP12port_http" binding="axis2:WSSOAP12Binding">
<soap12:address location="http://localhost:8080/axis2/services/WS"/>
</wsdl:port>
−
<wsdl:port name="WSHttpport1" binding="axis2:WSHttpBinding">
<http:address location="http://localhost:8080/axis2/rest/WS"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions> |
Je vous remercie de votre aide.
Class métier (Client) et WSDL
Bonjour Gregb34,
Je sais que çà date un peu mais serait-il possible de voir la class Client ?
En fait je fais un WS java sous AXIS2 mais étant débutant je n'arrive pas à générer le WSDL correctement avec les bons complexType et je pense que cela vient de la mauvaise déclaration de mes "inputs".
Merci