Erlang Mailing Lists

Author Message

<  Yaws mailing list  ~  Yaws & Dojo: json error (and maybe a fix)

Guest
Posted: Tue Aug 22, 2006 6:17 pm Reply with quote
Guest
Hi,

I'm trying to use Dojo's json service with yaws (on Win XP).
Otherwise it would seem to work, but when making a json call from dojo
with no arguments I get an error:

=ERROR REPORT==== 22-Aug-2006::12:28:09 ===
{yaws_rpc,126,
{html,client2erl,
"{\"params\":[],\"method\":\"contentB\",\"id\":10}",
{badmatch,{}}}}

It would seem that in function decode_handler_payload/2 the
following code causes problems:

{array, Args} = jsonrpc:s(Obj, params)

In this case jsonrpc:s(Obj, params) returns {}, which doesn't match
{array, Args}.

If I understand the code correctly, the reason jsonrpc:s(Obj, params)
returns {} can be found in json:parse_array/2

parse_array(C, Kv) ->
get_token(C, fun
(eof, C2) -> {done, {error, premature_eof}, C2};
(rsbrace, C2) -> Kv({}, C2); % empty array
(T, C2) -> parse_array([], T, C2, Kv)
end).

where {} is returned for empty array instead of {array, []}, which is
what decode_handler_payload/2 expects.

Replacing

(rsbrace, C2) -> Kv({}, C2); % empty array

with

(rsbrace, C2) -> Kv({array, []}, C2); % empty array

in json:parse_array worked for me but as I'm total newbie with
erlang/yaws/json, I'm not entirely confident that this is the
correct way to solve the problem.

Looking forward to hear your comments.

BR,
Juhani


-------------------------------------------------------------------------
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
rsaccon
Posted: Tue Aug 22, 2006 6:31 pm Reply with quote
User Joined: 09 Aug 2006 Posts: 144
Oh yeah, also trapped into this at my first days with yaws/dojo/JSON,
but I was even more novice and did the brain-dead workaround of using
just a dummy argument and only now I got reminded of that. To me, your
correction makes perfect sense.

On 8/22/06, juhani@juranki.com <juhani@juranki.com> wrote:
> Hi,
>
> I'm trying to use Dojo's json service with yaws (on Win XP).
> Otherwise it would seem to work, but when making a json call from dojo
> with no arguments I get an error:
>
> =ERROR REPORT==== 22-Aug-2006::12:28:09 ===
> {yaws_rpc,126,
> {html,client2erl,
> "{\"params\":[],\"method\":\"contentB\",\"id\":10}",
> {badmatch,{}}}}
>
> It would seem that in function decode_handler_payload/2 the
> following code causes problems:
>
> {array, Args} = jsonrpc:s(Obj, params)
>
> In this case jsonrpc:s(Obj, params) returns {}, which doesn't match
> {array, Args}.
>
> If I understand the code correctly, the reason jsonrpc:s(Obj, params)
> returns {} can be found in json:parse_array/2
>
> parse_array(C, Kv) ->
> get_token(C, fun
> (eof, C2) -> {done, {error, premature_eof}, C2};
> (rsbrace, C2) -> Kv({}, C2); % empty array
> (T, C2) -> parse_array([], T, C2, Kv)
> end).
>
> where {} is returned for empty array instead of {array, []}, which is
> what decode_handler_payload/2 expects.
>
> Replacing
>
> (rsbrace, C2) -> Kv({}, C2); % empty array
>
> with
>
> (rsbrace, C2) -> Kv({array, []}, C2); % empty array
>
> in json:parse_array worked for me but as I'm total newbie with
> erlang/yaws/json, I'm not entirely confident that this is the
> correct way to solve the problem.
>
> Looking forward to hear your comments.


--
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: Tue Aug 22, 2006 7:43 pm Reply with quote
User Joined: 20 Jul 2006 Posts: 55
Hello all!

Dear Claes, CC'ing you this mail, because it 100% makes sense to patch
this line in json:parse_array -- probably we have missed this case when
were patching json.erl behave like xmlrpc module - so this change

> Replacing
>
> (rsbrace, C2) -> Kv({}, C2); % empty array
>
> with
>
> (rsbrace, C2) -> Kv({array, []}, C2); % empty array

is correct. Probably it's easier to you to fix directly in working
files(json.erl , line 478) , than applying patch Smile

Thanks to juhani for discovering this bug Smile

/Gaspar

juhani@juranki.com wrote:
> Hi,
>
> I'm trying to use Dojo's json service with yaws (on Win XP).
> Otherwise it would seem to work, but when making a json call from dojo
> with no arguments I get an error:
>
> =ERROR REPORT==== 22-Aug-2006::12:28:09 ===
> {yaws_rpc,126,
> {html,client2erl,
> "{\"params\":[],\"method\":\"contentB\",\"id\":10}",
> {badmatch,{}}}}
>
> It would seem that in function decode_handler_payload/2 the
> following code causes problems:
>
> {array, Args} = jsonrpc:s(Obj, params)
>
> In this case jsonrpc:s(Obj, params) returns {}, which doesn't match
> {array, Args}.
>
> If I understand the code correctly, the reason jsonrpc:s(Obj, params)
> returns {} can be found in json:parse_array/2
>
> parse_array(C, Kv) ->
> get_token(C, fun
> (eof, C2) -> {done, {error, premature_eof}, C2};
> (rsbrace, C2) -> Kv({}, C2); % empty array
> (T, C2) -> parse_array([], T, C2, Kv)
> end).
>
> where {} is returned for empty array instead of {array, []}, which is
> what decode_handler_payload/2 expects.
>





> Replacing
>
> (rsbrace, C2) -> Kv({}, C2); % empty array
>
> with
>
> (rsbrace, C2) -> Kv({array, []}, C2); % empty array
>
> in json:parse_array worked for me but as I'm total newbie with
> erlang/yaws/json, I'm not entirely confident that this is the
> correct way to solve the problem.
>
> Looking forward to hear your comments.
>
> BR,
> Juhani
>
>

>


--
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
Guest
Posted: Wed Aug 23, 2006 7:39 am Reply with quote
Guest
Gaspar Chilingarov wrote:
> Hello all!
>
> Dear Claes, CC'ing you this mail, because it 100% makes sense to patch
> this line in json:parse_array -- probably we have missed this case when
> were patching json.erl behave like xmlrpc module - so this change
>
>> Replacing
>>
>> (rsbrace, C2) -> Kv({}, C2); % empty array
>>
>> with
>>
>> (rsbrace, C2) -> Kv({array, []}, C2); % empty array
>
> is correct. Probably it's easier to you to fix directly in working
> files(json.erl , line 478) , than applying patch Smile

Excellent, in CVS now.

/klacke

--
Claes Wikstrom -- Caps lock is nowhere and
http://www.tail-f.com -- everything is under control
cellphone: +46 70 2097763

-------------------------------------------------------------------------
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

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