Skip to main content

Binding with JAX-WS

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
nicolasst22
Offline
Joined: 2011-02-02

I have been having a problem with incompatible types between my web services' response and my POJO.

I have been develop a simple Login Application, where my service recieves username and password and it must return a POJO (the User Object) but it returns a class (User) within LoginResponse, incompatible with my POJO.

here my code

SERVER CODE

@WebService(name = "login",targetNamespace="http://prueba.com/",
serviceName = "MyAdminService"
)
public class AdmWebService {

Usuario user;

@WebMethod(operationName = "login")
@WebResult(name = "Usuario")

public Usuario login(@WebParam(name = "username") String username, @WebParam(name = "passwd") String passwd) {
Helper helper = new Helper("Usuario");

user = new Usuario();
user.setClave(passwd);
user.setNombre(username);
List<Usuario> matchingUsers = helper.searchEntitiesBySample(
user, "nombre");
if (matchingUsers.size() != 1) {
user = null;
} else {
user = matchingUsers.get(0);
}

return user;
}

}

SOAP MESSAGES
SOAP Request

<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">

<S:Header/>
<S:Body>
<ns2:login xmlns:ns2="http://prueba.com/">
<username1>prueba</username1>

<passwd>prueba</passwd>

</ns2:login>
</S:Body>
</S:Envelope>
SOAP Response

<?xml version="1.0" encoding="UTF-8"?>

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">

<S:Body>
<ns2:loginResponse xmlns:ns2="http://prueba.com/">

<Usuario>
<id>1</id>
<rol>

<id>1</id>
<nombre>Sin definir</nombre>

<descripcion>Rol que debe asignarse a los usuarios que todavia no tienen un rol asignado</descripcion>

<objetoXRols>
<id>2</id>

<objeto>
<id>2</id>
<nombre>Objeto2</nombre>

<descripcion>Prueba</descripcion>

</objeto>
<nuevo>false</nuevo>
<ver>true</ver>

<editar>false</editar>

<eliminar>false</eliminar>
</objetoXRols>
</rol>
<nombre>prueba</nombre>

<clave>prueba</clave>

<theme>black-tie</theme>
</Usuario>
</ns2:loginResponse>
</S:Body>
</S:Envelope>

CLIENT CODE

public static void main(String[] args) {
try {

service = new MyAdminService();
Login port = service.getLoginPort();
LoginResponse.Usuario user = port.login("prueba", "prueba");

if (user!=null){
System.out.println(user.
getNombre());
System.out.println(user.getRol().getNombre());
System.out.println(user.getRol().getDescripcion());
}
else{
System.out.println("es nulo");
}

} catch(Exception e) {
e.printStackTrace();
}
}

I'm forgetting something?

What I did wrong?

Any suggestion?

What can I read to learn this?

Thanks in advance.

Regards.

Nicolas