diff options
author | Ulf Wiger <ulf@feuerlabs.com> | 2015-08-14 19:32:22 +0200 |
---|---|---|
committer | Ulf Wiger <ulf@feuerlabs.com> | 2015-08-14 19:32:22 +0200 |
commit | 2dd27e3c33de6c2b31e4cdc30a345b3c64e3040a (patch) | |
tree | 5620cfbed7605baa2c1325fbbc7ca56157164616 /components/rvi_common | |
parent | 54974ae9ead2200104cb35b5e34fff8030a06cc9 (diff) | |
download | rvi_core-2dd27e3c33de6c2b31e4cdc30a345b3c64e3040a.tar.gz |
added svc reg+call tests + bug fixes
Diffstat (limited to 'components/rvi_common')
-rw-r--r-- | components/rvi_common/src/exoport_exo_http.erl | 11 | ||||
-rw-r--r-- | components/rvi_common/src/rvi_common.erl | 35 |
2 files changed, 34 insertions, 12 deletions
diff --git a/components/rvi_common/src/exoport_exo_http.erl b/components/rvi_common/src/exoport_exo_http.erl index 193b730..95801c6 100644 --- a/components/rvi_common/src/exoport_exo_http.erl +++ b/components/rvi_common/src/exoport_exo_http.erl @@ -36,22 +36,25 @@ instance(SupMod, AppMod, Opts) -> handle_body(Socket, Request, Body, AppMod) when Request#http_request.method == 'POST' -> try decode_json(Body) of {call, Id, Method, Args} -> - case handle_rpc(AppMod, Method, Args) of + try handle_rpc(AppMod, Method, Args) of {ok, Reply} -> success_response(Socket, Id, Reply); ok -> ok; {error, Error} -> error_response(Socket, Id, Error) + catch + error:Reason -> + ?debug("~p:handle_rpc(~p, ~p, ~p) ERROR: ~p~n~p", + [?MODULE, AppMod, Method, Args, Reason, + erlang:get_stacktrace()]), + error_response(Socket, Id, internal_error) end; - {notification, Method, Args} -> handle_notification(AppMod, Method, Args), exo_http_server:response(Socket, undefined, 200, "OK", ""); - {error, _} -> error_response(Socket, parse_error) - catch error:_ -> exo_http_server:response(Socket, undefined, 501, diff --git a/components/rvi_common/src/rvi_common.erl b/components/rvi_common/src/rvi_common.erl index 8028917..39beabf 100644 --- a/components/rvi_common/src/rvi_common.erl +++ b/components/rvi_common/src/rvi_common.erl @@ -219,6 +219,13 @@ notification(Component, InArg = [ Val || { _Key, Val } <- InArgPropList ], InArgSpec = [ Key || { Key, _Val } <- InArgPropList ], %% Figure out how we are to invoke this MFA. + ?debug("~p:notification(", [?MODULE]), + ?debug(" Component : ~p", [Component]), + ?debug(" Module : ~p", [Module]), + ?debug(" Function : ~p", [Function]), + ?debug(" InArgPropList : ~p", [InArgPropList]), + ?debug(" CompSpec : ~p", [CompSpec]), + case get_module_type(Component, Module, CompSpec) of %% We have a gen_server { ok, gen_server } -> @@ -233,6 +240,11 @@ notification(Component, JSONArg = json_argument(InArg, InArgSpec), ?debug("Sending ~p:~p(~p) -> ~p.", [Module, Function, InArg, JSONArg]), send_json_notification(URL, atom_to_list(Function), JSONArg), + ok; + { error, _ } = Error -> + ?warning("get_module_type(~p,~p,~p) -> ~p", + [Component, Module, CompSpec, Error]), + %% ignore ok end. @@ -331,20 +343,27 @@ get_json_element_([], JSON) -> get_json_element_([Elem | T], JSON ) when is_atom(Elem) -> get_json_element_([atom_to_list(Elem) | T], JSON); -get_json_element_([Elem | T], {struct, JSON} ) -> - Res = get_json_element_(T, proplists:get_value(Elem, JSON, undefined)), - Res; - -get_json_element_([Elem | T], {array, JSON} ) -> - Res = get_json_element_(T, proplists:get_value(Elem, JSON, undefined)), - Res; +get_json_element_([Elem | T], {Type, JSON} ) when Type==array; Type==struct -> + case Elem of + {'OR', Alts} -> + get_json_element_(T, get_json_element_alt(Alts, JSON)); + _ -> + get_json_element_(T, proplists:get_value(Elem, JSON, undefined)) + end; get_json_element_(Path,JSON) -> ?warning("get_json_element_(): Unhandled: Path: ~p | JSON: ~p", [Path, JSON]), { error, undefined }. - +get_json_element_alt(Alts, [{K, V}|T]) -> + case lists:member(K, Alts) of + true -> V; + false -> get_json_element_alt(Alts, T) + end; +get_json_element_alt(_, []) -> + undefined. + json_reply(ArgList, JSON) -> retrieve_json_reply_elements(ArgList, JSON, []). |