Re: [Axiom]Send receive an object with an ArrayList

2007-11-20 Thread Michael Bernagou
Hum, just a word to say I know my code is not finished to create the list
received. Anyway the error comes immediately after de sendReceive(method)
call.
I tried to explicitely force having ArrayList instead of List, without
success...

2007/11/20, Michael Bernagou <[EMAIL PROTECTED]>:
>
> Hi,
>
> I'm using Axiom method to sendReceive a list.
> In fact, at the client level I call the server via a web service to get a
> list of user :
>
> Client :
>
> public static List getUserList(String login, char[] password)
> throws PapoException {
>EndpointReference targetEPR =3D new EndpointReference(baseUrl +
> CoreVariables.APPLICATION_WEBSERVICE);
>OMFactory fac =3D OMAbstractFactory.getOMFactory ();
>OMNamespace omNs =3D fac.createOMNamespace("
> http://webservices.papo/xsd";, "tns");
>
>OMElement method =3D fac.createOMElement("getUserList", omNs);
>
>OMElement loginElement =3D fac.createOMElement("login", omNs);
>loginElement.addChild(fac.createOMText(loginElement, login));
>method.addChild(loginElement);
>
> OMElement passwordElement =3D fac.createOMElement("password",
> omNs)=
> ;
>passwordElement.addChild(fac.createOMText (passwordElement, new
> String(password)));
>method.addChild(passwordElement);
>Options options =3D new Options();
>options.setTo(targetEPR);
>options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
>
>try {
>ServiceClient sender =3D new ServiceClient();
>sender.setOptions(options);
>OMElement result =3D sender.sendReceive(method);
>OMElement firstElement =3D result.getFirstElement();
>if(firstElement.getLocalName().equals("message")) {
>throw new PapoException(firstElement.getText());
>}
>else {
>OMElement userList =3D result.getFirstElement();
>if (!userList.getText().equals("UserList")) {
>throw new PapoException("The xml receive is different
> from what expected. Unknown server response!!");
>}
>
>userList.getChildElements();
>OMElement firstNameElement =3D
> (OMElement)loginElement.getNextOMSibling();
>String firstName =3D firstNameElement.getText();
>
>OMElement lastNameElement =3D
> (OMElement)firstElement.getNextOMSibling();
>String lastName =3D lastNameElement.getText ();
>
>OMElement emailElement =3D
> (OMElement)lastNameElement.getNextOMSibling();
>String email =3D emailElement.getText();
>
>MainUser user =3D new MainUser(login);
>user.setFirstName(firstName);
>user.setLastName(lastName);
>user.setEmail(email);
>
>return new ArrayList();
>
>}
>}
>catch (AxisFault af) {
>af.printStackTrace();
>throw new PapoException(af.getMessage(), af);
>}
>
>}
>
> I have a ClassCastException for this line : OMElement result =3D
> sender.sendReceive(method);
>
> The web service is :
>
> public OMElement getUserList(OMElement element) throws XMLStreamException
> {
>   // Something that get a user object
>   if (user !=3D null) {
>  ApplicationServiceImpl asi =3D new ApplicationServiceImpl();
>
>  try {
>// 
>OMElement userListElement =3D fac.createOMElement("UserList",
> omNs)=
> ;
>UserList userList =3D asi.getUserList();
>for (int i =3D 0; i < userList.getUserList().size(); i++) {
>  UserLite userLite =3D userList.getUserList().get(i);
>  // 
>  OMElement userElement =3D fac.createOMElement("User", omNs);
>
>
>  // String
>  loginElement =3D fac.createOMElement("login", omNs);
>  loginElement.addChild(fac.createOMText (loginElement,
> userLite.getLogin()));
>  userElement.addChild(loginElement);
>
>  // boolean
>  OMElement statusElement =3D fac.createOMElement("status", omNs);
>  statusElement.addChild(fac.createOMText(statusElement,
> userLite.isAlive()));
>  userElement.addChild(statusElement);
>
>  // String
>  OMElement ipElement =3D fac.createOMElement("ip", omNs);
>  ipElement.addChild(fac.createOMText(ipElement, userLite.getLastIP
> ()));
>  userElement.addChild(ipElement);
>
>  // Date.toString 
>  OMElement lastUpdateElement =3D fac.createOMElement("lastUpdate",
> omNs);
>  lastUpdateElement.addChild(fac.createOMText(lastUpdateElement,
> userLite.getLastUpdate()));
>  userElement.addChild(lastUpdateElement);
>
>  // 
>  userListElement.addChild(userElement);
>}
>logger.debug("\tListe des utilisateurs cr=E9=E9 sous forme de
> messa=
> ge.
> ");
>// 
>method.addChild(userListElement);
>  }
>  catch (PapoException pe

[Axiom]Send receive an object with an ArrayList

2007-11-20 Thread Michael Bernagou
Hi,

I'm using Axiom method to sendReceive a list.
In fact, at the client level I call the server via a web service to get a
list of user :

Client :

public static List getUserList(String login, char[] password)
throws PapoException {
   EndpointReference targetEPR =3D new EndpointReference(baseUrl +
CoreVariables.APPLICATION_WEBSERVICE);
   OMFactory fac =3D OMAbstractFactory.getOMFactory();
   OMNamespace omNs =3D fac.createOMNamespace("
http://webservices.papo/xsd";, "tns");

   OMElement method =3D fac.createOMElement("getUserList", omNs);

   OMElement loginElement =3D fac.createOMElement("login", omNs);
   loginElement.addChild(fac.createOMText(loginElement, login));
   method.addChild(loginElement);

   OMElement passwordElement =3D fac.createOMElement("password", omNs)=
;
   passwordElement.addChild(fac.createOMText(passwordElement, new
String(password)));
   method.addChild(passwordElement);
   Options options =3D new Options();
   options.setTo(targetEPR);
   options.setTransportInProtocol(Constants.TRANSPORT_HTTP);

   try {
   ServiceClient sender =3D new ServiceClient();
   sender.setOptions(options);
   OMElement result =3D sender.sendReceive(method);
   OMElement firstElement =3D result.getFirstElement();
   if(firstElement.getLocalName().equals("message")) {
   throw new PapoException(firstElement.getText());
   }
   else {
   OMElement userList =3D result.getFirstElement();
   if (!userList.getText().equals("UserList")) {
   throw new PapoException("The xml receive is different
from what expected. Unknown server response!!");
   }

   userList.getChildElements();
   OMElement firstNameElement =3D
(OMElement)loginElement.getNextOMSibling();
   String firstName =3D firstNameElement.getText();

   OMElement lastNameElement =3D
(OMElement)firstElement.getNextOMSibling();
   String lastName =3D lastNameElement.getText();

   OMElement emailElement =3D
(OMElement)lastNameElement.getNextOMSibling();
   String email =3D emailElement.getText();

   MainUser user =3D new MainUser(login);
   user.setFirstName(firstName);
   user.setLastName(lastName);
   user.setEmail(email);

   return new ArrayList();

   }
   }
   catch (AxisFault af) {
   af.printStackTrace();
   throw new PapoException(af.getMessage(), af);
   }

   }

I have a ClassCastException for this line : OMElement result =3D
sender.sendReceive(method);

The web service is :

public OMElement getUserList(OMElement element) throws XMLStreamException {
  // Something that get a user object
  if (user !=3D null) {
 ApplicationServiceImpl asi =3D new ApplicationServiceImpl();

 try {
   // 
   OMElement userListElement =3D fac.createOMElement("UserList", omNs)=
;
   UserList userList =3D asi.getUserList();
   for (int i =3D 0; i < userList.getUserList().size(); i++) {
 UserLite userLite =3D userList.getUserList().get(i);
 // 
 OMElement userElement =3D fac.createOMElement("User", omNs);


 // String
 loginElement =3D fac.createOMElement("login", omNs);
 loginElement.addChild(fac.createOMText(loginElement,
userLite.getLogin()));
 userElement.addChild(loginElement);

 // boolean
 OMElement statusElement =3D fac.createOMElement("status", omNs);
 statusElement.addChild(fac.createOMText(statusElement,
userLite.isAlive()));
 userElement.addChild(statusElement);

 // String
 OMElement ipElement =3D fac.createOMElement("ip", omNs);
 ipElement.addChild(fac.createOMText(ipElement, userLite.getLastIP
()));
 userElement.addChild(ipElement);

 // Date.toString
 OMElement lastUpdateElement =3D fac.createOMElement("lastUpdate",
omNs);
 lastUpdateElement.addChild(fac.createOMText(lastUpdateElement,
userLite.getLastUpdate()));
 userElement.addChild(lastUpdateElement);

 // 
 userListElement.addChild(userElement);
   }
   logger.debug("\tListe des utilisateurs cr=E9=E9 sous forme de messa=
ge.
");
   // 
   method.addChild(userListElement);
 }
 catch (PapoException pe) {
   OMElement message =3D fac.createOMElement("errorMessage", omNs);
   message.addChild(fac.createOMText(message, "Unable to get the
refreshed user list! Try again later or check the server status"));
   method.addChild(message);
 }
   }
   else {
 OMElement message =3D fac.createOMElement("errorMessage", omNs);
 message.addChild(fac.createOMText(message, "Unable to get the
refreshed user list! Try again later or check the server status"));
 method.addChild(message);
   }
   return method;
 }

In debuggi