java - Error Parsing XML response attributes with ksoap2 returns ClassCastException -


i'm trying figure out how cast response of consume of webservice, when casting response envelope.bodyin extended class object "biometricconfigurationresponse" i'm getting error:

java.lang.classcastexception: org.ksoap2.serialization.soapobject cannot cast org.tempuri.biometricconfigurationresponse

the service responding , if not cast dump right. ideas?

this i'm doing:

biometricconfigurationresponse response= null; soapobject obj = new soapobject (wsnamespace, methodname); soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); envelope.implicittypes = true; envelope.dotnet = true; envelope.setoutputsoapobject(obj); envelope.addmapping(wsnamespace, "biometricconfigurationresponse", new biometricconfigurationresponse().getclass());  httptransportse androidhttptransport = new httptransportse(wsurl); androidhttptransport.debug = true;   try {          string soapaction=wsnamespace + methodname;          androidhttptransport.call(soapaction, envelope);         system.out.println(androidhttptransport.requestdump);          response =  (biometricconfigurationresponse)envelope.bodyin;       }      catch (exception e) {          e.printstacktrace();     } 

and custom class

package org.tempuri;  import java.util.hashtable; import org.ksoap2.serialization.propertyinfo; import org.ksoap2.serialization.soapobject;  public final class biometricconfigurationresponse extends soapobject {     private int coderalgorithm;  private int templateformat;  private boolean juvenilemode;  private int qualitythreshold;  private boolean retryacquisition;  private boolean acceptbadqualityenrollment;  private boolean showqualitybar;  private boolean showqualitythreshold;  private int timeout;  private int timeoutqualitycoder;  private int enrollsecuritylevel;  private boolean securitylevelcompatibility;  private boolean liveimage;  private java.lang.string setculture;  private int authenticationscore;  public biometricconfigurationresponse() {     super("", ""); } public void setcoderalgorithm(int coderalgorithm) {     this.coderalgorithm = coderalgorithm; }  public int getcoderalgorithm(int coderalgorithm) {     return this.coderalgorithm; }  public void settemplateformat(int templateformat) {     this.templateformat = templateformat; }  public int gettemplateformat(int templateformat) {     return this.templateformat; }  public void setjuvenilemode(boolean juvenilemode) {     this.juvenilemode = juvenilemode; }  public boolean getjuvenilemode(boolean juvenilemode) {     return this.juvenilemode; }  public void setqualitythreshold(int qualitythreshold) {     this.qualitythreshold = qualitythreshold; }  public int getqualitythreshold(int qualitythreshold) {     return this.qualitythreshold; }  public void setretryacquisition(boolean retryacquisition) {     this.retryacquisition = retryacquisition; }  public boolean getretryacquisition(boolean retryacquisition) {     return this.retryacquisition; }  public void setacceptbadqualityenrollment(boolean acceptbadqualityenrollment) {     this.acceptbadqualityenrollment = acceptbadqualityenrollment; }  public boolean getacceptbadqualityenrollment(boolean acceptbadqualityenrollment) {     return this.acceptbadqualityenrollment; }  public void setshowqualitybar(boolean showqualitybar) {     this.showqualitybar = showqualitybar; }  public boolean getshowqualitybar(boolean showqualitybar) {     return this.showqualitybar; }  public void setshowqualitythreshold(boolean showqualitythreshold) {     this.showqualitythreshold = showqualitythreshold; }  public boolean getshowqualitythreshold(boolean showqualitythreshold) {     return this.showqualitythreshold; }  public void settimeout(int timeout) {     this.timeout = timeout; }  public int gettimeout(int timeout) {     return this.timeout; }  public void settimeoutqualitycoder(int timeoutqualitycoder) {     this.timeoutqualitycoder = timeoutqualitycoder; }  public int gettimeoutqualitycoder(int timeoutqualitycoder) {     return this.timeoutqualitycoder; }  public void setenrollsecuritylevel(int enrollsecuritylevel) {     this.enrollsecuritylevel = enrollsecuritylevel; }  public int getenrollsecuritylevel(int enrollsecuritylevel) {     return this.enrollsecuritylevel; }  public void setsecuritylevelcompatibility(boolean securitylevelcompatibility) {     this.securitylevelcompatibility = securitylevelcompatibility; }  public boolean getsecuritylevelcompatibility(boolean securitylevelcompatibility) {     return this.securitylevelcompatibility; }  public void setliveimage(boolean liveimage) {     this.liveimage = liveimage; }  public boolean getliveimage(boolean liveimage) {     return this.liveimage; }  public void setsetculture(java.lang.string setculture) {     this.setculture = setculture; }  public java.lang.string getsetculture(java.lang.string setculture) {     return this.setculture; }  public void setauthenticationscore(int authenticationscore) {     this.authenticationscore = authenticationscore; }  public int getauthenticationscore(int authenticationscore) {     return this.authenticationscore; }  public int getpropertycount() {     return 15; }  public object getproperty(int __index) {     switch(__index)  {     case 0: return new integer(coderalgorithm);     case 1: return new integer(templateformat);     case 2: return new boolean(juvenilemode);     case 3: return new integer(qualitythreshold);     case 4: return new boolean(retryacquisition);     case 5: return new boolean(acceptbadqualityenrollment);     case 6: return new boolean(showqualitybar);     case 7: return new boolean(showqualitythreshold);     case 8: return new integer(timeout);     case 9: return new integer(timeoutqualitycoder);     case 10: return new integer(enrollsecuritylevel);     case 11: return new boolean(securitylevelcompatibility);     case 12: return new boolean(liveimage);     case 13: return setculture;     case 14: return new integer(authenticationscore);     }     return null; }  public void setproperty(int __index, object __obj) {     switch(__index)  {     case 0: coderalgorithm = integer.parseint(__obj.tostring()); break;     case 1: templateformat = integer.parseint(__obj.tostring()); break;     case 2: juvenilemode = "true".equals(__obj.tostring()); break;     case 3: qualitythreshold = integer.parseint(__obj.tostring()); break;     case 4: retryacquisition = "true".equals(__obj.tostring()); break;     case 5: acceptbadqualityenrollment = "true".equals(__obj.tostring()); break;     case 6: showqualitybar = "true".equals(__obj.tostring()); break;     case 7: showqualitythreshold = "true".equals(__obj.tostring()); break;     case 8: timeout = integer.parseint(__obj.tostring()); break;     case 9: timeoutqualitycoder = integer.parseint(__obj.tostring()); break;     case 10: enrollsecuritylevel = integer.parseint(__obj.tostring()); break;     case 11: securitylevelcompatibility = "true".equals(__obj.tostring()); break;     case 12: liveimage = "true".equals(__obj.tostring()); break;     case 13: setculture = (java.lang.string) __obj; break;     case 14: authenticationscore = integer.parseint(__obj.tostring()); break;     } }  public void getpropertyinfo(int __index, hashtable __table, propertyinfo __info) {     switch(__index)  {     case 0:         __info.name = "coderalgorithm";         __info.type = integer.class; break;     case 1:         __info.name = "templateformat";         __info.type = integer.class; break;     case 2:         __info.name = "juvenilemode";         __info.type = boolean.class; break;     case 3:         __info.name = "qualitythreshold";         __info.type = integer.class; break;     case 4:         __info.name = "retryacquisition";         __info.type = boolean.class; break;     case 5:         __info.name = "acceptbadqualityenrollment";         __info.type = boolean.class; break;     case 6:         __info.name = "showqualitybar";         __info.type = boolean.class; break;     case 7:         __info.name = "showqualitythreshold";         __info.type = boolean.class; break;     case 8:         __info.name = "timeout";         __info.type = integer.class; break;     case 9:         __info.name = "timeoutqualitycoder";         __info.type = integer.class; break;     case 10:         __info.name = "enrollsecuritylevel";         __info.type = integer.class; break;     case 11:         __info.name = "securitylevelcompatibility";         __info.type = boolean.class; break;     case 12:         __info.name = "liveimage";         __info.type = boolean.class; break;     case 13:         __info.name = "setculture";         __info.type = java.lang.string.class; break;     case 14:         __info.name = "authenticationscore";         __info.type = integer.class; break;     } } } 

after several days of research understood wsdl autogenerated code parse properties not atrributes. did this:

first generate stub code wsdl in website: http://www.wsdl2code.com/pages/home.aspx

my webservice name "nutriment" son when call in mainactivity have this:

        nutriment nws= new nutriment();         biometricconfigurationresponse respuesta = nws.getbiometricconfiguration();          log.i(tag, string.valueof(respuesta.coderalgorithm));         log.i(tag, string.valueof(respuesta.templateformat)); 

but responses 0 in cases because wdsl stub files parsing properties not atributes, when open serialization generated file you'll got this:

import org.ksoap2.serialization.kvmserializable; import org.ksoap2.serialization.propertyinfo; import java.util.hashtable; import org.ksoap2.serialization.soapobject; import org.ksoap2.serialization.soapprimitive;  public class biometricconfigurationresponse implements kvmserializable {      public int coderalgorithm;     public int templateformat;       public biometricconfigurationresponse(){}      public biometricconfigurationresponse(soapobject soapobject)     {         if (soapobject == null)             return;         if (soapobject.hasproperty("coderalgorithm"))         {             object obj = soapobject.getproperty("coderalgorithm");             if (obj != null && obj.getclass().equals(soapobject.class)){                 soapprimitive j =(soapprimitive) obj;                 coderalgorithm = integer.parseint(j.tostring());                }            else if (obj!= null && obj instanceof number){                 coderalgorithm = (integer) obj;             }           }          if (soapobject.hasproperty("templateformat"))         {             object obj = soapobject.getproperty("templateformat");             if (obj != null && obj.getclass().equals(soapprimitive.class)){                 soapprimitive j =(soapprimitive) obj;                 templateformat = integer.parseint(j.tostring());             }else if (obj!= null && obj instanceof number){                 templateformat = (integer) obj;             }          }      }     @override     public object getproperty(int arg0) {         switch(arg0){             case 0:                 return coderalgorithm;             case 1:                 return templateformat;          }         return null;     }      @override     public int getpropertycount() {         return 15;     }      @override     public void getpropertyinfo(int index, @suppresswarnings("rawtypes") hashtable arg1, propertyinfo info) {         switch(index){             case 0:                 info.type = propertyinfo.integer_class;                 info.name = "coderalgorithm";                 break;             case 1:                 info.type = propertyinfo.integer_class;                 info.name = "templateformat";                 break;      }      @override     public void setproperty(int arg0, object arg1) {     }      @override     public string getinnertext() {         // todo auto-generated method stub         return null;     }      @override     public void setinnertext(string arg0) {         // todo auto-generated method stub      }  } 

the trick modify parsing instead of properties(e.g.):

if (soapobject.hasproperty("coderalgorithm")){      object obj = soapobject.getproperty("coderalgorithm");      if (obj != null && obj.getclass().equals(soapobject.class)){         soapprimitive j =(soapprimitive) obj;         coderalgorithm = integer.parseint(j.tostring());      }      else if (obj!= null && obj instanceof number){      coderalgorithm = (integer) obj;     } } 

get attributes (e.g.):

if (soapobject.hasattribute("coderalgorithm")) {     object obj = soapobject.getattribute("coderalgorithm");     if (obj != null && obj.getclass().equals(soapobject.class)){        soapprimitive j =(soapprimitive) obj;        coderalgorithm = integer.parseint(j.tostring());     }     else if (obj!= null && obj instanceof number){        coderalgorithm = (integer) obj;    }    else if (obj!= null && obj instanceof string){        coderalgorithm = integer.parseint(obj.tostring());   } } 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -