Erlang/OTP Forums

Author Message

<  Yaws mailing list  ~  Question about JSON Handler

rsaccon
Posted: Fri Aug 11, 2006 9:15 pm Reply with quote
User Joined: 09 Aug 2006 Posts: 144
I realized that I still do not understand every bit of the functional
concepts used for the JSON RPC Handlers.

I want to access to the Arg (from the Yaws HTTP request) from within
my JSON RPC Handler. But how do I pass that Arg to tha handler ?

To make my question clear, let's take the code below (copy pasted form
the yaws website). I simply want to pass to "counter" the Argument
"A". How can I do that ?

regards
Roberto


<erl module=sample_mod>

out(A) ->
Peer = if
tuple(A#arg.clisock),
element(1, A#arg.clisock) == sslsocket ->
ssl:peername(A#arg.clisock);
true ->
inet:peername(A#arg.clisock)
end,

{ok,{IP,_}} = Peer,
A2=A#arg{state = [{ip, IP}]},
yaws_rpc:handler_session(A2, {sample_mod, counter}).

counter([{ip, IP}] = _State, {call, test1, Value} = _Request, Session) ->
io:format("Request = ~p~n", [_Request]),
IPStr = io_lib:format("Client ip is ~p~n" , [ IP ]),
OldSession = io_lib:format("Request is: ~p~nOld session value "
"is ~p~n", [ _Request, Session ]),

case Session of
undefined -> % create new session
NewSession = 0;
10 -> % reset session after reaching 10
NewSession = undefined;
N ->
NewSession = N + 1
end,

NewVal = io_lib:format("New session value is ~p ~n", [ NewSession ]),
Str = lists:flatten([IPStr,OldSession,NewVal]),
{true, 0, NewSession, {response, Str }}.

</erl>

--
Roberto Saccon

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message
Gaspar
Posted: Sat Aug 12, 2006 9:09 am Reply with quote
User Joined: 20 Jul 2006 Posts: 55
Roberto Saccon wrote:
> I realized that I still do not understand every bit of the functional
> concepts used for the JSON RPC Handlers.
>
> I want to access to the Arg (from the Yaws HTTP request) from within
> my JSON RPC Handler. But how do I pass that Arg to tha handler ?
>

only Arg#arg.state is passed to handler, so if you vant to pass query
variables to handler -- then you should do somethingn like this:

Vars = yaws_api:query_parse(A),
A2=A#arg{state = [{ip, IP}, {query_vars, Vars}]},

so everything which you want pass to handler shoudl be processed
before yaws_rpc:handler_session call and put into #arg.state





--
Gaspar Chilingarov

System Administrator,
Network security consulting

t +37493 419763 (mob)
i 63174784
e nm@web.am

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message
rsaccon
Posted: Sat Aug 12, 2006 3:42 pm Reply with quote
User Joined: 09 Aug 2006 Posts: 144
Aaah, of course ! thanks yery much !

On 8/12/06, Gaspar Chilingarov <nm@web.am> wrote:
> Roberto Saccon wrote:
> > I realized that I still do not understand every bit of the functional
> > concepts used for the JSON RPC Handlers.
> >
> > I want to access to the Arg (from the Yaws HTTP request) from within
> > my JSON RPC Handler. But how do I pass that Arg to tha handler ?
> >
>
> only Arg#arg.state is passed to handler, so if you vant to pass query
> variables to handler -- then you should do somethingn like this:
>
> Vars = yaws_api:query_parse(A),
> A2=A#arg{state = [{ip, IP}, {query_vars, Vars}]},
>
> so everything which you want pass to handler shoudl be processed
> before yaws_rpc:handler_session call and put into #arg.state
>
>
>
>
>
> --
> Gaspar Chilingarov
>
> System Administrator,
> Network security consulting
>
> t +37493 419763 (mob)
> i 63174784
> e nm@web.am
>


--
Roberto Saccon

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum