J'explore SOAP WS en ce moment et j'ai créé une classe très simple que j'expose en tant que service Web.Schéma de réponse SOAP
@WebService
public class StudentWS {
@WebMethod
public Student getStudent(){
Student stud = new Student();
stud.setId(99);
stud.setFirstName("John");
stud.setLastName("Doe");
stud.setGpa(2.1);
return stud;
}
}
Quand j'appelle ce service Web, la réponse SOAP retourné suit ce format.
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getStudentResponse xmlns:ns2="http://annotation/">
<return>
<firstName>John</firstName>
<gpa>2.1</gpa>
<id>99</id>
<lastName>Doe</lastName>
</return>
</ns2:getStudentResponse>
</S:Body>
</S:Envelope>
Ma question est, est-il possible que je puisse influencer la réponse SOAP à suivre une sorte de schéma comme ci-dessous.
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getStudentResponse xmlns:ns2="http://annotation/">
<student gpa="2.1">
<id>99</id>
<name>
<firstName></firstName>
<lastName></lastName>
</name>
</student>
</ns2:getStudentResponse>
</S:Body>
</S:Envelope>
Mes données proviennent d'une classe POJO comme celle-ci.
@XmlRootElement
public class Student {
private int id;
private String firstName;
private String lastName;
private double gpa;
//getters and setters
}
Merci.