android - Volley does not call getParams for my custom request? -
please, volley automatically add params url? me it's not working , when looking sources, cant find call of getparams method.. should build url myself? it's no problem @ all, thought when there such method getparams, me:)
update: below code..
public class bundlerequest extends com.android.volley.request<bundle>{ private string token; private onauthtokenvalidatorresponselistener mlistener; private final map<string, string> mparams = new hashmap<string, string>();; public bundlerequest(int method, string url, response.errorlistener listener) { super(method, url, listener); } public bundlerequest(int method, string url,onauthtokenvalidatorresponselistener providedlistener, response.errorlistener listener, string token) { super(method, url, listener); this.token = token; mlistener = providedlistener; mparams.put(authenticatorconfig.token_validation_paramname, token); } @override public map<string, string> getparams() throws authfailureerror { return mparams; } @override protected response<bundle> parsenetworkresponse(networkresponse httpresponse) { switch (httpresponse.statuscode) { case authtokenvalidator.token_valid_response_code: //token ok jsonobject response; try { response = new jsonobject(new string(httpresponse.data, httpheaderparser.parsecharset(httpresponse.headers))); bundle userdataresponse = new bundle(); userdataresponse.putint("responsecode", httpresponse.statuscode); userdataresponse.putstring("username", response.getstring("user_id")); userdataresponse.putstring("email", response.getstring("user_email")); userdataresponse.putstring("expiresin", response.getstring("expires_in")); userdataresponse.putstring("scope", response.getjsonarray("scope").getstring(0)); userdataresponse.putstring("token", token); return response.success(userdataresponse, httpheaderparser.parsecacheheaders(httpresponse)); } catch (unsupportedencodingexception e) { e.printstacktrace(); return response.error(new volleyerror("unsupported encoding")); } catch (jsonexception e) { e.printstacktrace(); return response.error(new volleyerror("problem while parsing json")); } case authtokenvalidator.token_invalid_response_code: //token not valid mlistener.onvalidatorresponse(httpresponse.statuscode); try { mlistener.onvalidatorresponse(parseonerrorresponse(new string(httpresponse.data, httpheaderparser.parsecharset(httpresponse.headers)))); } catch (unsupportedencodingexception e) { e.printstacktrace(); } default: return response.error(new volleyerror("error status code:" + httpresponse.statuscode)); } } protected int parseonerrorresponse(string responsebody) { try { jsonobject response = new jsonobject(responsebody); string moreinfo = response.getstring("more_info"); if (moreinfo.equals("token not recognised")) { return authtokenvalidator.token_was_not_recognised; } else if (moreinfo.equals("token has expired")) { return authtokenvalidator.token_has_expired; } else if (moreinfo.equals("client doesn't exist anymore")) { return authtokenvalidator.client_does_not_exist_anymore; } else if (moreinfo.equals("client locked")) { return authtokenvalidator.client_is_locked; } else { return authtokenvalidator.unknown_error; } } catch (jsonexception e) { e.printstacktrace(); return authtokenvalidator.unknown_error; } } @override protected void deliverresponse(bundle response) { mlistener.ongetuserdataresponse(response); } }
actually params parameter redundant
getparams()
not called on method, seems you'll have add url before send request.
check out javadoc:
returns map of parameters used post or put request.
can throw {@link authfailureerror} authentication may required provide these values.
note can directly override {@link #getbody()} custom data.
@throws authfailureerror in event of auth failure
Comments
Post a Comment