Page 1 of 1

REST javascript implementation - Set parameter before invoke

Posted: Tue Apr 01, 2014 8:03 pm
by luke315774

I have this GenericSecurityContext :

Image

I want to set the "session" parameter in the javascript implementation before invoking the service call. So I've done :

Appery.BergerRESTImplementation = Appery.createClass(SecurityContext, {

invoke: function(service, settings) {
// Before invoke

Code: Select all

     settings.ssc_data.session = getSessionParam(localStorage.getItem("_user"), localStorage.getItem("_sessionid"), localStorage.getItem("_appserver"), localStorage.getItem("_environment")); 

     Appery.BergerRESTImplementation.$super.invoke.call(this, service, settings); 

}
});

The parameter is still set to the default value when the service get called. Is it the proper way of doing this?

Thank you for the help.


REST javascript implementation - Set parameter before invoke

Posted: Tue Apr 01, 2014 9:35 pm
by Igor

Hello,

What is codesettings.ssc_data.session/code in your code?
You could set header or some parameter
pre
code
invoke: function(service, settings) {
settings.data.session = "123&quot
settings.headers.session = "456&quot

Code: Select all

 Appery.BergerRESTImplementation.$super.invoke.call(this, service, settings);  

}
/code
/pre


REST javascript implementation - Set parameter before invoke

Posted: Wed Apr 02, 2014 10:54 am
by luke315774

I keep on getting the default value in my "session" parameter. Even with this code :

Appery.BergerRESTImplementation = Appery.createClass(SecurityContext, {

invoke: function(service, settings) {
// Before invoke
alert('before');

Code: Select all

     settings.data.session = "new session value"; 

     Appery.BergerRESTImplementation.$super.invoke.call(this, service, settings); 

     // After invoke 
     alert('after'); 

}

});

The console tell me settings.data.session is "undefined". How can I set a parameter in my custom Javascript implementation? The said parameter being declared in my service definition.


REST javascript implementation - Set parameter before invoke

Posted: Wed Apr 02, 2014 8:24 pm
by Maryna Brodina

Hello!

[quote:]The console tell me settings.data.session is "undefined"[/quote] could you clarify how do you check it? In console on network tab check if data specified in SecurityContext is sent?


REST javascript implementation - Set parameter before invoke

Posted: Thu Apr 03, 2014 12:09 pm
by luke315774

Hello,

this morning, it now work as expected. I'm sorry. There seem to be some strange behavior with service parameter sometime.

I'm happy it's working. Thanks


REST javascript implementation - Set parameter before invoke

Posted: Thu Apr 03, 2014 12:23 pm
by luke315774

Image

There you see it. "blablabla" is the default value in the service definition. As if this line as no effect at all on the session parameter.. : settings.data.session = "new session value";


REST javascript implementation - Set parameter before invoke

Posted: Thu Apr 03, 2014 2:11 pm
by Kateryna Grynko

Hi Luke,

You can write in parameter URL codehttp://example.com/?session={session}/code and add a request parameter 'session'. Appery.io will automatically replace {session} with a value of that parameter.


REST javascript implementation - Set parameter before invoke

Posted: Thu Apr 03, 2014 2:19 pm
by luke315774

That is exactly what I have done and it is not working. That is why I wrote here...

Here are screenshots of what I have. First, my generic service declaration :
Image

Second, my javascript implementation where I try to set my session parameter :

Image

Next, the actual service definition that use the generic security service :

Image

As you can see from my previous post, the value of session when executing is always the "Default" value set in the generic security service definition.

I must be doing something wrong?
Thank you for your help, I appreciate.


REST javascript implementation - Set parameter before invoke

Posted: Thu Apr 03, 2014 9:42 pm
by Alena Prykhodko

Luke,

You use Method=post and Content Type=xml, in this case in Security context Service settings.data - is a string, that includes xml. And settings.data.session = ...
won't have any effect,

You should add necessary xml tag into xml string storing in settings.data


REST javascript implementation - Set parameter before invoke

Posted: Fri Apr 04, 2014 12:57 pm
by luke315774

Ok cool.

Thank you. Your support is very appreciated and invaluable to the delivery of our project.