Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align to cowboy 2.9.0 api #49

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/soap_cowboy_protocol.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ check_conformance(Soap_req, Cowboy_req, Cowboy_state, Version_module) ->

handle_xml(Soap_req, Cowboy_state, Version_module) ->
Cowboy_req = soap_req:server_req(Soap_req),
{ok, Message, Cowboy_req2} = cowboy_req:body(Cowboy_req),
{ok, Message, Cowboy_req2} = cowboy_req:read_body(Cowboy_req),
Soap_req2 = soap_req:set_server_req(Soap_req, Cowboy_req2),
Soap_req3 = soap_req:set_http_body(Soap_req2, Message),
Content_type = soap_req:content_type(Soap_req3),
Expand Down
36 changes: 18 additions & 18 deletions src/soap_server_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ new_req(Handler, Server, Options, Server_req) ->
%% function, rather than by the `init` function not being defined?
error:undef ->
{continue, soap_req:set_handler_state(New_req, Options)};
Class:Reason ->
Class:Reason:Stacktrace ->
Soap_error = #soap_error{type = server,
class = Class,
stacktrace = erlang:get_stacktrace(),
stacktrace = Stacktrace,
reason = Reason,
handler = Handler,
soap_req = New_req,
Expand Down Expand Up @@ -136,15 +136,15 @@ handle_message(Message, Soap_req) ->
{ok, SoapReq2, _Tail} ->
soap_req:http_response(SoapReq2)
catch
Class:Reason ->
Class:Reason:Stacktrace ->
Soap_error =
case {Class, Reason} of
{throw, #soap_error{}} ->
Reason;
{_, _} ->
#soap_error{type = client,
class = Class,
stacktrace = erlang:get_stacktrace(),
stacktrace = Stacktrace,
reason = Reason,
handler = Handler,
handler_state = Handler_state,
Expand Down Expand Up @@ -219,8 +219,8 @@ check_soap_conformance(Soap_req) ->
catch
error:Reason when Reason == function_clause; Reason == undef ->
default_conformance_check(Soap_req);
Class:Reason ->
throw(callback_error(Class, Reason, Soap_req, Handler_state))
Class:Reason:Stacktrace ->
throw(callback_error(Class, Reason, Soap_req, Handler_state, Stacktrace))
end.


Expand Down Expand Up @@ -316,10 +316,10 @@ xml_parser_cb_wrapped(Event, #p_state{state = _Parser_state,
%% TODO: differentiate more (perhaps improve erlsom error codes)
throw:#soap_error{} = Soap_error ->
throw(Soap_error#soap_error{soap_req = Soap_req, handler_state = Handler_state});
Class:Reason ->
Class:Reason:Stacktrace ->
throw(#soap_error{type = client,
class = Class,
stacktrace = erlang:get_stacktrace(),
stacktrace = Stacktrace,
reason = Reason,
handler = Handler,
handler_state = Handler_state,
Expand Down Expand Up @@ -471,11 +471,11 @@ xml_parser_cb({endElement, NS, "Body", _Prfx},
%% and encode it.
encode_soap_resp(Handler_resp)
catch
Class:Reason ->
Class:Reason:Stacktrace ->
throw(#soap_error{class = Class,
reason = Reason,
type = server,
stacktrace = erlang:get_stacktrace(),
stacktrace = Stacktrace,
description = "exception in handler module",
soap_req = Soap_req,
handler_state = Handler_s})
Expand Down Expand Up @@ -504,15 +504,15 @@ try_header_fun(Fun, Soap_req, Handler_s) ->
catch
error:function_clause ->
{ok, Soap_req, Handler_s};
Class:Reason ->
throw(callback_error(Class, Reason, Soap_req, Handler_s))
Class:Reason:Stacktrace ->
throw(callback_error(Class, Reason, Soap_req, Handler_s, Stacktrace))
end.

callback_error(Class, Reason, Soap_req, Handler_s) ->
callback_error(Class, Reason, Soap_req, Handler_s, Stacktrace) ->
#soap_error{class = Class,
reason = Reason,
type = server,
stacktrace = erlang:get_stacktrace(),
stacktrace = Stacktrace,
description = "an unexpected error occcurred",
soap_req = Soap_req,
handler_state = Handler_s}.
Expand All @@ -539,23 +539,23 @@ get_header_parser(Handler, Namespace, Soap_req, Handler_s) ->
catch
error:function_clause ->
Default(Namespace, Soap_req, Handler_s);
Class:Reason ->
Class:Reason:Stacktrace ->
throw(#soap_error{type = server,
description = "Header parser selection error",
stacktrace = erlang:get_stacktrace(),
stacktrace = Stacktrace,
class = Class, reason = Reason})
end.

parse_event(Parser, Event, State, Type) ->
try
Parser(Event, State)
catch
Class:Reason ->
Class:Reason:Stacktrace ->
%% Presumably failing to parse is a client error (incorrect xml) - but it
%% could also be a server error, of course - we don't really know.
throw(#soap_error{type = client,
description = "Parser error (" ++ Type ++ ")",
stacktrace = erlang:get_stacktrace(),
stacktrace = Stacktrace,
class = Class, reason = Reason})
end.

Expand Down