You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by Shu <sh...@esker.fr> on 2001/04/19 11:50:40 UTC
RE: Help!
Hi Giovanni,
You can use BeanSerializer to extract the data instead of
XMLParameterSerializer which allows you to deserialize a XML document with 1
root element (this is why only the first element is returned).
To do this, you must firstly define a bean class that represents the return
values. In your case, it should be like this:
public class Rights
{
public boolean interroga;
public boolean prenota;
public boolean cancella;
public boolean rinvia;
public boolean getInterroga() { return(interroga); }
public void setInterroga(boolean interroga) { this.interroga =
interroga; }
public boolean getPrenota() { return(prenota); }
public void setPrenota(boolean interroga) { this.prenota = prenota; }
public boolean getCancella() { return(cancella); }
public void setCancella(boolean cancella) { this.cancella =
ancella; }
public boolean getRinvia() { return(rinvia); }
public void setRinvia(boolean rinvia) { this.rinvia = rinvia; }
public String toString()
{
return("Interroga=" + interroga +
" Prenota=" + prenota +
" Cancella=" + cancella +
" Rinvia=" + rinvia);
}
}
Secondly, you must mapping "result" tag to this bean before invoking remote
method. Here is a sample code:
public static void main(String[] args) throws Exception
{
...
SOAPMappingRegistry smr = new SOAPMappingRegistry();
ParameterSerializer ps = new ParameterSerializer();
BeanSerializer bs = new BeanSerializer();
BooleanDeserializer bd = new BooleanDeserializer();
smr.mapTypes (null, RPCConstants.Q_ELEM_PARAMETER, Parameter.class,
null, ps);
smr.mapTypes(null,new
QName("http://tempuri.org/","result"),Rights.class,null,bs);
smr.mapTypes(null,new
QName("http://tempuri.org/","Interroga"),null,null,bd);
smr.mapTypes(null,new
QName("http://tempuri.org/","Prenota"),null,null,bd);
smr.mapTypes(null,new
QName("http://tempuri.org/","Cancella"),null,null,bd);
smr.mapTypes(null,new
QName("http://tempuri.org/","Rinvia"),null,null,bd);
...
Response resp = call.invoke(url,"http://tempuri.org/LogIn");
// Print the returned string
org.apache.soap.rpc.Parameter ret = resp.getReturnValue();
Rights value = (Rights)ret.getValue();
System.out.println(value);
}
Regards,
Herve
> -----Message d'origine-----
> De : Giovanni Ruggiero [mailto:ruggiero@cefriel.it]
> Envoyé : mercredi 18 avril 2001 19:46
> À : shu@esker.fr
> Objet : Help!
>
>
> Dear Herve!
>
> First of all thanks a lot for your mail.
>
> Please could you help me once more, I don't know anyone else who to ask!
>
> Could you suggest me how can I extract the value of:
>
> <Interroga>False</Interroga>
> <Prenota>False</Prenota>
> <Cancella>False</Cancella>
> <Rinvia>False</Rinvia>
>
> inside the <result>...</result> tags
>
> the complete response I got is:
>
> -------------------------------------
> <?xml version="1.0"?>
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
> xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/1999/XMLSchema">
> <soap:Body>
> <LogInResponse xmlns="http://tempuri.org/">
> <result>
> <Interroga>False</Interroga>
> <Prenota>False</Prenota>
> <Cancella>False</Cancella>
> <Rinvia>False</Rinvia>
> </result>
> </LogInResponse>
> </soap:Body>
> </soap:Envelope>
> ------------------------------------------------------
>
> and the client code I'm using to invoce the server is:
>
> --------------------------------
> public class Login
> {
> public static void main(String[] args) throws Exception
> {
>
> // Address of SOAP router
> URL url=new
> URL("http://localhost:8060/Autenticazione/Autenticazione.asmx");
>
>
> SOAPMappingRegistry smr = new SOAPMappingRegistry();
>
> ParameterSerializer ps = new ParameterSerializer();
>
> // I try to map "result as an XMLParameter------------
>
> XMLParameterSerializer xps = new XMLParameterSerializer();
>
> smr.mapTypes (null, RPCConstants.Q_ELEM_PARAMETER, Parameter.class,
> null, ps);
>
> smr.mapTypes (null, new QName("http://tempuri.org/", "result"), null,
> null, xsp);
>
>
>
> // create the transport and set parameters
> SOAPHTTPConnection st = new SOAPHTTPConnection();
>
> String username = "Giovanni";
> String password = "Ruggiero";
> Vector params = new Vector();
>
> // Build the call
>
> Call call=new Call();
>
> call.setSOAPTransport(st);
> call.setSOAPMappingRegistry(smr);
> call.setTargetObjectURI("http://tempuri.org/");
> call.setMethodName("LogIn");
> call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/");
>
> params.addElement(new Parameter("username", String.class, username,
> null));
> params.addElement(new Parameter("password", String.class, password,
> null));
>
> call.setParams(params);
>
>
> // Invoke the call to the SOAP server
> Response resp = call.invoke(url,"http://tempuri.org/LogIn");
>
>
> // Print the returned string
>
> org.apache.soap.rpc.Parameter ret = resp.getReturnValue();
> Object value = ret.getValue();
> System.out.println(value);
>
> /* Debug bits-------
>
> System.out.println(value);
> System.out.println("YYY: " + value.getClass());
> // prendo l'elemento Interroga
> value = ((Parameter)value).getValue();
> Element element = ((Element)value);
>
> System.out.println("NomeElement: " + element.getNodeName());
> NodeList nl = element.getChildNodes();
> System.out.println("Lunghezza lista: " + nl.getLength());
> Text t = (Text)nl.item(0);
> System.out.println("Nome: " + t.getNodeName());
> System.out.println("Valure: " + t);
> ---------------------------*/
> }
> }
>
> ----------------------------
>
> I defined an XMLParameterSerializer for "result"
> It seems it recognize it but the returned value contains only the first
> element namely "Interroga" but not the other.
>
> Do you have any hints
>
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: soap-user-unsubscribe@xml.apache.org
For additional commands, email: soap-user-help@xml.apache.org