Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 723 lines (621 sloc) 27.572 kB
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
1 %%%-------------------------------------------------------------------
2 %%% Created : 29 Nov 2006 by Torbjorn Tornkvist <tobbe@tornkvist.org>
3 %%% Author : Willem de Jong (w.a.de.jong@gmail.com).
4 %%% Desc. : Common SOAP code.
5 %%%-------------------------------------------------------------------
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
6
7 %%% modified (WdJ, May 2007): deal with imports in the WSDL.
8 %%% modified (WdJ, August 2007): the WSDL can contain more than 1 schema
9
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
10 -module(yaws_soap_lib).
11
455578a @vinoski major trailing whitespace cleanup
vinoski authored
12 -export([initModel/1, initModel/2,
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
13 initModelFile/1,
14 config_file_xsd/0,
813f032 @ericliang support on addtional specified prefix when rpc call by method: yaws_s…
ericliang authored
15 call/3, call/4, call/5, call/6,
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
16 call_attach/4, call_attach/5, call_attach/7,
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
17 write_hrl/2, write_hrl/3,
18 findHeader/2,
19 parseMessage/2,
20 makeFault/2,
21 is_wsdl/1, wsdl_model/1, wsdl_op_service/1,
455578a @vinoski major trailing whitespace cleanup
vinoski authored
22 wsdl_op_port/1, wsdl_op_operation/1,
23 wsdl_op_binding/1, wsdl_op_address/1,
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
24 wsdl_op_action/1, wsdl_operations/1,
25 get_operation/2
26 ]).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
27
28
29 %%% For testing...
30 -export([qtest/0]).
31
32
33 -include("../include/soap.hrl").
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
34
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
35 -define(HTTP_REQ_TIMEOUT, 20000).
36
455578a @vinoski major trailing whitespace cleanup
vinoski authored
37 %%-define(dbg(X,Y),
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
38 %% error_logger:info_msg("*dbg ~p(~p): " X,
39 %% [?MODULE, ?LINE | Y])).
40 -define(dbg(X,Y), true).
41
42
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
43 -record(yaws_soap_config, {atts, xsd_path, user_module, wsdl_file, add_files}).
44 -record(xsd_file, {atts, name, prefix, import_specs}).
45 -record(import_specs, {atts, namespace, prefix, location}).
358c69d @vinoski remove compile time dependencies on erlsom hrl files (Mikael Karlsson)
vinoski authored
46
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
47 -define(DefaultPrefix, "p").
48
49
50 %%%
51 %%% Writes the header file (record definitions) for a WSDL file
52 %%%
f44be6a @klacke all calls to old deprecated guard tests removed
authored
53 write_hrl(WsdlURL, Output) when is_list(WsdlURL) ->
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
54 write_hrl(initModel(WsdlURL), Output);
f44be6a @klacke all calls to old deprecated guard tests removed
authored
55 write_hrl(#wsdl{model = Model}, Output) when is_list(Output) ->
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
56 erlsom:write_hrl(Model, Output).
57
7811247 @vinoski whitespace cleanup
vinoski authored
58 write_hrl(WsdlURL, Output, PrefixOrOptions)
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
59 when is_list(WsdlURL),is_list(PrefixOrOptions) ->
60 write_hrl(initModel(WsdlURL, PrefixOrOptions), Output).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
61
62
63
64 %%% For testing only...
65 qtest() ->
6e96a14 @klacke indendation cleanup
authored
66 call("http://www.webservicex.net/WeatherForecast.asmx?WSDL",
67 "GetWeatherByPlaceName",
68 ["Boston"]).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
69
70 %%% --------------------------------------------------------------------
71 %%% Access functions
72 %%% --------------------------------------------------------------------
f44be6a @klacke all calls to old deprecated guard tests removed
authored
73 is_wsdl(Wsdl) when is_record(Wsdl,wsdl) -> true;
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
74 is_wsdl(_) -> false.
75
76 wsdl_operations(#wsdl{operations = Ops}) -> Ops.
77
78 wsdl_model(#wsdl{model = Model}) -> Model.
79
80 wsdl_op_service(#operation{service = Service}) -> Service.
81
82 wsdl_op_port(#operation{port = Port}) -> Port.
83
84 wsdl_op_operation(#operation{operation = Op}) -> Op.
85
86 wsdl_op_binding(#operation{binding = Binding}) -> Binding.
87
88 wsdl_op_address(#operation{address = Address}) -> Address.
89
90 wsdl_op_action(#operation{action = Action}) -> Action.
91
6e96a14 @klacke indendation cleanup
authored
92
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
93 %%% --------------------------------------------------------------------
94 %%% For Quick deployment
95 %%% --------------------------------------------------------------------
f44be6a @klacke all calls to old deprecated guard tests removed
authored
96 call(WsdlURL, Operation, ListOfData) when is_list(WsdlURL) ->
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
97 Wsdl = initModel(WsdlURL, ?DefaultPrefix),
98 call(Wsdl, Operation, ListOfData);
f44be6a @klacke all calls to old deprecated guard tests removed
authored
99 call(Wsdl, Operation, ListOfData) when is_record(Wsdl, wsdl) ->
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
100 case get_operation(Wsdl#wsdl.operations, Operation) of
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
101 {ok, Op} ->
102 Msg = mk_msg(?DefaultPrefix, Operation, ListOfData),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
103 call(Wsdl, Operation, Op#operation.port,
f44be6a @klacke all calls to old deprecated guard tests removed
authored
104 Op#operation.service, [], Msg);
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
105 Else ->
106 Else
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
107 end.
108
55dbc0b Adding yaws_soap_lib:call/4 which takes the acual Header and Body mes…
Tobbe Tornquist authored
109 %%% --------------------------------------------------------------------
813f032 @ericliang support on addtional specified prefix when rpc call by method: yaws_s…
ericliang authored
110 %%% With additional specified prefix
111 %%% --------------------------------------------------------------------
112 call(WsdlURL, Operation, ListOfData, prefix, Prefix) when is_list(WsdlURL) ->
6e96a14 @klacke indendation cleanup
authored
113 Wsdl = initModel(WsdlURL, Prefix),
114 call(Wsdl, Operation, ListOfData, prefix, Prefix );
813f032 @ericliang support on addtional specified prefix when rpc call by method: yaws_s…
ericliang authored
115 call(Wsdl, Operation, ListOfData, prefix, Prefix) when is_record(Wsdl, wsdl) ->
6e96a14 @klacke indendation cleanup
authored
116 case get_operation(Wsdl#wsdl.operations, Operation) of
813f032 @ericliang support on addtional specified prefix when rpc call by method: yaws_s…
ericliang authored
117 {ok, Op} ->
118 Msg = mk_msg(Prefix, Operation, ListOfData),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
119 call(Wsdl, Operation, Op#operation.port,
813f032 @ericliang support on addtional specified prefix when rpc call by method: yaws_s…
ericliang authored
120 Op#operation.service, [], Msg);
121 Else ->
122 Else
123 end.
124
125
126 %%% --------------------------------------------------------------------
55dbc0b Adding yaws_soap_lib:call/4 which takes the acual Header and Body mes…
Tobbe Tornquist authored
127 %%% Takes the actual records for the Header and Body message.
128 %%% --------------------------------------------------------------------
f44be6a @klacke all calls to old deprecated guard tests removed
authored
129 call(WsdlURL, Operation, Header, Msg) when is_list(WsdlURL) ->
f584826 *** empty log message ***
Tobbe Tornquist authored
130 Wsdl = initModel(WsdlURL, ?DefaultPrefix),
131 call(Wsdl, Operation, Header, Msg);
f44be6a @klacke all calls to old deprecated guard tests removed
authored
132 call(Wsdl, Operation, Header, Msg) when is_record(Wsdl, wsdl) ->
55dbc0b Adding yaws_soap_lib:call/4 which takes the acual Header and Body mes…
Tobbe Tornquist authored
133 case get_operation(Wsdl#wsdl.operations, Operation) of
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
134 {ok, Op} ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
135 call(Wsdl, Operation, Op#operation.port, Op#operation.service,
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
136 Header, Msg);
137 Else ->
138 Else
55dbc0b Adding yaws_soap_lib:call/4 which takes the acual Header and Body mes…
Tobbe Tornquist authored
139 end.
140
141
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
142 mk_msg(Prefix, Operation, ListOfData) ->
143 list_to_tuple([list_to_atom(Prefix++":"++Operation), % record name
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
144 [] % anyAttribs
145 | ListOfData]). % rest of record data
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
146
455578a @vinoski major trailing whitespace cleanup
vinoski authored
147 get_operation([#operation{operation = X} = Op|_], X) ->
f44be6a @klacke all calls to old deprecated guard tests removed
authored
148 {ok, Op};
455578a @vinoski major trailing whitespace cleanup
vinoski authored
149 get_operation([_|T], Op) ->
f44be6a @klacke all calls to old deprecated guard tests removed
authored
150 get_operation(T, Op);
455578a @vinoski major trailing whitespace cleanup
vinoski authored
151 get_operation([], _Op) ->
f44be6a @klacke all calls to old deprecated guard tests removed
authored
152 {error, "operation not found"}.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
153
154
155 %%% --------------------------------------------------------------------
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
156 %%% Make a SOAP request (no attachments)
157 %%% --------------------------------------------------------------------
158 call(Wsdl, Operation, Port, Service, Headers, Message) ->
6e96a14 @klacke indendation cleanup
authored
159 call_attach(Wsdl, Operation, Port, Service, Headers, Message, []).
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
160
161
162 %%% --------------------------------------------------------------------
163 %%% For Quick deployment (with attachments)
164 %%% --------------------------------------------------------------------
455578a @vinoski major trailing whitespace cleanup
vinoski authored
165 call_attach(WsdlURL, Operation, ListOfData, Attachments)
f44be6a @klacke all calls to old deprecated guard tests removed
authored
166 when is_list(WsdlURL) ->
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
167 Wsdl = initModel(WsdlURL, ?DefaultPrefix),
168 call_attach(Wsdl, Operation, ListOfData, Attachments);
455578a @vinoski major trailing whitespace cleanup
vinoski authored
169 call_attach(Wsdl, Operation, ListOfData, Attachments)
f44be6a @klacke all calls to old deprecated guard tests removed
authored
170 when is_record(Wsdl, wsdl) ->
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
171 case get_operation(Wsdl#wsdl.operations, Operation) of
172 {ok, Op} ->
173 Msg = mk_msg(?DefaultPrefix, Operation, ListOfData),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
174 call_attach(Wsdl, Operation, Op#operation.port,
f44be6a @klacke all calls to old deprecated guard tests removed
authored
175 Op#operation.service, [], Msg, Attachments);
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
176 Else ->
177 Else
178 end.
179
180 %%% --------------------------------------------------------------------
455578a @vinoski major trailing whitespace cleanup
vinoski authored
181 %%% Takes the actual records for the Header and Body message
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
182 %%% (with attachments)
183 %%% --------------------------------------------------------------------
455578a @vinoski major trailing whitespace cleanup
vinoski authored
184 call_attach(WsdlURL, Operation, Header, Msg, Attachments)
f44be6a @klacke all calls to old deprecated guard tests removed
authored
185 when is_list(WsdlURL) ->
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
186 Wsdl = initModel(WsdlURL, ?DefaultPrefix),
187 call_attach(Wsdl, Operation, Header, Msg, Attachments);
455578a @vinoski major trailing whitespace cleanup
vinoski authored
188 call_attach(Wsdl, Operation, Header, Msg, Attachments)
f44be6a @klacke all calls to old deprecated guard tests removed
authored
189 when is_record(Wsdl, wsdl) ->
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
190 case get_operation(Wsdl#wsdl.operations, Operation) of
191 {ok, Op} ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
192 call_attach(Wsdl, Operation, Op#operation.port,
193 Op#operation.service,
6e96a14 @klacke indendation cleanup
authored
194 Header, Msg, Attachments);
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
195 Else ->
196 Else
197 end.
6e96a14 @klacke indendation cleanup
authored
198
199
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
200 %%% --------------------------------------------------------------------
201 %%% Make a SOAP request (with attachments)
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
202 %%% --------------------------------------------------------------------
455578a @vinoski major trailing whitespace cleanup
vinoski authored
203 call_attach(#wsdl{operations = Operations, model = Model},
f44be6a @klacke all calls to old deprecated guard tests removed
authored
204 Operation, Port, Service, Headers, Message, Attachments) ->
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
205 %% find the operation
206 case findOperation(Operation, Port, Service, Operations) of
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
207 #operation{address = URL, action = SoapAction} ->
208 %% Add the Soap envelope
209 Envelope = mk_envelope(Message, Headers),
210 %% Encode the message
211 case erlsom:write(Envelope, Model) of
212 {ok, XmlMessage} ->
6e96a14 @klacke indendation cleanup
authored
213
455578a @vinoski major trailing whitespace cleanup
vinoski authored
214 {ContentType, Request} =
f44be6a @klacke all calls to old deprecated guard tests removed
authored
215 make_request_body(XmlMessage, Attachments),
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
216 HttpHeaders = [],
217 HttpClientOptions = [],
218 ?dbg("+++ Request = ~p~n", [Request]),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
219 HttpRes = http_request(URL, SoapAction, Request,
220 HttpClientOptions, HttpHeaders,
f44be6a @klacke all calls to old deprecated guard tests removed
authored
221 ContentType),
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
222 ?dbg("+++ HttpRes = ~p~n", [HttpRes]),
223 case HttpRes of
224 {ok, _Code, _ReturnHeaders, Body} ->
225 parseMessage(Body, Model);
455578a @vinoski major trailing whitespace cleanup
vinoski authored
226 Error ->
227 %% in case of HTTP error: return
f44be6a @klacke all calls to old deprecated guard tests removed
authored
228 %% {error, description}
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
229 Error
230 end;
231 {error, EncodingError} ->
232 {error, {encoding_error, EncodingError}}
233 end;
234 false ->
235 {error, {unknown_operation, Operation}}
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
236 end.
237
238 %%%
239 %%% returns {ok, Header, Body} | {error, Error}
240 %%%
241 parseMessage(Message, #wsdl{model = Model}) ->
242 parseMessage(Message, Model);
243 %%
244 parseMessage(Message, Model) ->
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
245 case erlsom:scan(Message, Model) of
246 {ok, #'soap:Envelope'{'Body' = #'soap:Body'{choice = Body},
247 'Header' = undefined}, _} ->
248 {ok, undefined, Body};
249 {ok, #'soap:Envelope'{'Body' = #'soap:Body'{choice = Body},
250 'Header' = #'soap:Header'{choice = Header}}, _} ->
251 {ok, Header, Body};
252 {error, ErrorMessage} ->
253 {error, {decoding, ErrorMessage}}
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
254 end.
255
256
257 findOperation(_Operation, _Port, _Service, []) ->
258 false;
455578a @vinoski major trailing whitespace cleanup
vinoski authored
259 findOperation(Operation, Port, Service,
260 [Op = #operation{operation = Operation,
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
261 port = Port, service = Service} | _]) ->
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
262 Op;
263 findOperation(Operation, Port, Service, [#operation{} | Tail]) ->
264 findOperation(Operation, Port, Service, Tail).
265
266
f44be6a @klacke all calls to old deprecated guard tests removed
authored
267 mk_envelope(M, H) when is_tuple(M) -> mk_envelope([M], H);
268 mk_envelope(M, H) when is_tuple(H) -> mk_envelope(M, [H]);
82cd8e6 *** empty log message ***
Tobbe Tornquist authored
269 %%
f44be6a @klacke all calls to old deprecated guard tests removed
authored
270 mk_envelope(Messages, []) when is_list(Messages) ->
82cd8e6 *** empty log message ***
Tobbe Tornquist authored
271 #'soap:Envelope'{'Body' = #'soap:Body'{choice = Messages}};
f44be6a @klacke all calls to old deprecated guard tests removed
authored
272 mk_envelope(Messages, Headers) when is_list(Messages),is_list(Headers) ->
82cd8e6 *** empty log message ***
Tobbe Tornquist authored
273 #'soap:Envelope'{'Body' = #'soap:Body'{choice = Messages},
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
274 'Header' = #'soap:Header'{choice = Headers}}.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
275
455578a @vinoski major trailing whitespace cleanup
vinoski authored
276 %%% --------------------------------------------------------------------
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
277 %%% Parse a WSDL file and return a 'Model'
455578a @vinoski major trailing whitespace cleanup
vinoski authored
278 %%% --------------------------------------------------------------------
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
279 initModel(WsdlFile) ->
280 initModel(WsdlFile, ?DefaultPrefix).
281
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
282 %% PrefixOrOptions can be a property list that contains the options
7811247 @vinoski whitespace cleanup
vinoski authored
283 %% for Erlsom, or a String. If it is a string, this is used as the
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
284 %% Erlsom 'prefix' option (and the other options are left unspecified).
285 initModel(WsdlFile, PrefixOrOptions) ->
286 Options = case is_string(PrefixOrOptions) of
287 no ->
288 %% It is an option list
7811247 @vinoski whitespace cleanup
vinoski authored
289 %% Add the default prefix at the end - it will only be used
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
290 %% if no other prefix is specified
291 PrefixOrOptions ++ [{prefix, ?DefaultPrefix}];
292 _ ->
293 %% just the prefix
294 [{prefix, PrefixOrOptions}]
295 end,
455578a @vinoski major trailing whitespace cleanup
vinoski authored
296 PrivDir = priv_dir(),
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
297 initModel2(WsdlFile, Options, PrivDir, undefined, undefined).
6e96a14 @klacke indendation cleanup
authored
298
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
299 initModelFile(ConfigFile) ->
300 {ok, ConfigSchema} = erlsom:compile_xsd(config_file_xsd()),
301 %% read (parse) the config file
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
302 {ok, Config, _} = erlsom:scan_file(ConfigFile, ConfigSchema),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
303 #yaws_soap_config{xsd_path = XsdPath,
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
304 wsdl_file = Wsdl,
305 add_files = AddFiles} = Config,
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
306 #xsd_file{name = WsdlFile, prefix = Prefix, import_specs = Import} = Wsdl,
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
307 initModel2(WsdlFile, [{prefix, Prefix}], XsdPath, Import, AddFiles).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
308
455578a @vinoski major trailing whitespace cleanup
vinoski authored
309 priv_dir() ->
358c69d @vinoski remove compile time dependencies on erlsom hrl files (Mikael Karlsson)
vinoski authored
310 case code:priv_dir(yaws) of
311 {error, bad_name} ->
6e96a14 @klacke indendation cleanup
authored
312 filename:join([filename:dirname(code:which(yaws)),"..", "priv"]);
358c69d @vinoski remove compile time dependencies on erlsom hrl files (Mikael Karlsson)
vinoski authored
313 A ->
314 A
315 end.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
316
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
317 initModel2(WsdlFile, ErlsomOptions, Path, Import, AddFiles) ->
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
318 WsdlName = filename:join([Path, "wsdl.xsd"]),
319 IncludeWsdl = {"http://schemas.xmlsoap.org/wsdl/", "wsdl", WsdlName},
6e96a14 @klacke indendation cleanup
authored
320 {ok, WsdlModel} = erlsom:compile_xsd_file(
455578a @vinoski major trailing whitespace cleanup
vinoski authored
321 filename:join([Path, "soap.xsd"]),
6e96a14 @klacke indendation cleanup
authored
322 [{prefix, "soap"},
323 {include_files, [IncludeWsdl]}]),
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
324 %% add the xsd model (since xsd is also used in the wsdl)
325 WsdlModel2 = erlsom:add_xsd_model(WsdlModel),
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
326 Options = ErlsomOptions ++ makeOptions(Import),
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
327 %% parse Wsdl
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
328 {Model, Operations} = parseWsdls([WsdlFile], WsdlModel2,
6e96a14 @klacke indendation cleanup
authored
329 Options, {undefined, []}),
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
330 %% TODO: add files as required
331 %% now compile envelope.xsd, and add Model
6e96a14 @klacke indendation cleanup
authored
332 {ok, EnvelopeModel} = erlsom:compile_xsd_file(
333 filename:join([Path, "envelope.xsd"]),
334 [{prefix, "soap"}]),
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
335 SoapModel = erlsom:add_model(EnvelopeModel, Model),
336 SoapModel2 = addModels(AddFiles, SoapModel),
337 #wsdl{operations = Operations, model = SoapModel2}.
338
339
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
340 %%% --------------------------------------------------------------------
341 %%% Parse a list of WSDLs and import (recursively)
342 %%% Returns {Model, Operations}
343 %%% --------------------------------------------------------------------
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
344 parseWsdls([], _WsdlModel, _Options, Acc) ->
6e96a14 @klacke indendation cleanup
authored
345 Acc;
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
346 parseWsdls([WsdlFile | Tail], WsdlModel, Options, {AccModel, AccOperations}) ->
6e96a14 @klacke indendation cleanup
authored
347 {ok, WsdlFileContent} = get_url_file(rmsp(WsdlFile)),
348 {ok, ParsedWsdl, _} = erlsom:scan(WsdlFileContent, WsdlModel),
349 %% get the xsd elements from this model, and hand it over to erlsom_compile.
350 Xsds = getXsdsFromWsdl(ParsedWsdl),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
351 %% Now we need to build a list: [{Namespace, Xsd, Prefix}, ...] for
6e96a14 @klacke indendation cleanup
authored
352 %% all the Xsds in the WSDL.
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
353 %% This list is used when a schema includes one of the other schemas.
354 %% The AXIS java2wsdl tool generates wsdls that depend on this feature.
6e96a14 @klacke indendation cleanup
authored
355 ImportList = makeImportList(Xsds, []),
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
356 Model2 = addSchemas(Xsds, AccModel, Options, ImportList),
6e96a14 @klacke indendation cleanup
authored
357 Ports = getPorts(ParsedWsdl),
358 Operations = getOperations(ParsedWsdl, Ports),
359 Imports = getImports(ParsedWsdl),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
360 Acc2 = {Model2, Operations ++ AccOperations},
361 %% process imports (recursively, so that imports in the imported files are
6e96a14 @klacke indendation cleanup
authored
362 %% processed as well).
455578a @vinoski major trailing whitespace cleanup
vinoski authored
363 %% For the moment, the namespace is ignored on operations etc.
6e96a14 @klacke indendation cleanup
authored
364 %% this makes it a bit easier to deal with imported wsdl's.
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
365 Acc3 = parseWsdls(Imports, WsdlModel, Options, Acc2),
366 parseWsdls(Tail, WsdlModel, Options, Acc3).
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
367
368 %%% --------------------------------------------------------------------
369 %%% build a list: [{Namespace, Xsd}, ...] for all the Xsds in the WSDL.
455578a @vinoski major trailing whitespace cleanup
vinoski authored
370 %%% This list is used when a schema inlcudes one of the other schemas.
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
371 %%% The AXIS java2wsdl tool generates wsdls that depend on this feature.
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
372 makeImportList([], Acc) ->
6e96a14 @klacke indendation cleanup
authored
373 Acc;
358c69d @vinoski remove compile time dependencies on erlsom hrl files (Mikael Karlsson)
vinoski authored
374 makeImportList([ Xsd | Tail], Acc) ->
6e96a14 @klacke indendation cleanup
authored
375 makeImportList(Tail, [{erlsom_lib:getTargetNamespaceFromXsd(Xsd),
376 undefined, Xsd} | Acc]).
358c69d @vinoski remove compile time dependencies on erlsom hrl files (Mikael Karlsson)
vinoski authored
377
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
378
379 %%% --------------------------------------------------------------------
380 %%% compile each of the schemas, and add it to the model.
381 %%% Returns Model
382 %%% (TODO: using the same prefix for all XSDS makes no sense)
383 %%% --------------------------------------------------------------------
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
384 addSchemas([], AccModel, _Options, _ImportList) ->
6e96a14 @klacke indendation cleanup
authored
385 AccModel;
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
386 addSchemas([Xsd| Tail], AccModel, Options, ImportList) ->
6e96a14 @klacke indendation cleanup
authored
387 Model2 = case Xsd of
455578a @vinoski major trailing whitespace cleanup
vinoski authored
388 undefined ->
6e96a14 @klacke indendation cleanup
authored
389 AccModel;
455578a @vinoski major trailing whitespace cleanup
vinoski authored
390 _ ->
391 {ok, Model} =
6e96a14 @klacke indendation cleanup
authored
392 erlsom_compile:compile_parsed_xsd(
455578a @vinoski major trailing whitespace cleanup
vinoski authored
393 Xsd,
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
394 [{include_files, ImportList} |Options]),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
395 case AccModel of
6e96a14 @klacke indendation cleanup
authored
396 undefined -> Model;
397 _ -> erlsom:add_model(AccModel, Model)
398 end
399 end,
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
400 addSchemas(Tail, Model2, Options, ImportList).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
401
402 %%% --------------------------------------------------------------------
403 %%% Get a file from an URL spec.
404 %%% --------------------------------------------------------------------
405 get_url_file("http://"++_ = URL) ->
ca1c8b1 @karlsson Fixed a number of compiler warnings and html validation errors
karlsson authored
406 case httpc:request(URL) of
455578a @vinoski major trailing whitespace cleanup
vinoski authored
407 {ok,{{_HTTP,200,_OK}, _Headers, Body}} ->
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
408 {ok, Body};
455578a @vinoski major trailing whitespace cleanup
vinoski authored
409 {ok,{{_HTTP,RC,Emsg}, _Headers, _Body}} ->
410 error_logger:error_msg("~p: http-request got: ~p~n",
6e96a14 @klacke indendation cleanup
authored
411 [?MODULE, {RC, Emsg}]),
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
412 {error, "failed to retrieve: "++URL};
455578a @vinoski major trailing whitespace cleanup
vinoski authored
413 {error, Reason} ->
414 error_logger:error_msg("~p: http-request failed: ~p~n",
6e96a14 @klacke indendation cleanup
authored
415 [?MODULE, Reason]),
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
416 {error, "failed to retrieve: "++URL}
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
417 end;
418 get_url_file("file://"++Fname) ->
419 {ok, Bin} = file:read_file(Fname),
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
420 {ok, binary_to_list(Bin)};
421 %% added this, since this is what is used in many WSDLs (i.e.: just a filename).
422 get_url_file(Fname) ->
423 {ok, Bin} = file:read_file(Fname),
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
424 {ok, binary_to_list(Bin)}.
425
426
427 %%% --------------------------------------------------------------------
428 %%% Make a HTTP Request
429 %%% --------------------------------------------------------------------
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
430 http_request(URL, SoapAction, Request, Options, Headers, ContentType) ->
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
431 case code:ensure_loaded(ibrowse) of
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
432 {module, ibrowse} ->
433 %% If ibrowse exist in the path then let's use it...
455578a @vinoski major trailing whitespace cleanup
vinoski authored
434 ibrowse_request(URL, SoapAction, Request, Options,
6e96a14 @klacke indendation cleanup
authored
435 Headers, ContentType);
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
436 _ ->
437 %% ...otherwise, let's use the OTP http client.
455578a @vinoski major trailing whitespace cleanup
vinoski authored
438 inets_request(URL, SoapAction, Request, Options,
6e96a14 @klacke indendation cleanup
authored
439 Headers, ContentType)
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
440 end.
441
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
442 inets_request(URL, SoapAction, Request, Options, Headers, ContentType) ->
28f44b0 @vinoski allow caller to set Host header for SOAP requests
vinoski authored
443 NHeaders = [{"SOAPAction", SoapAction}|Headers],
444 NewHeaders = case proplists:get_value("Host", NHeaders) of
445 undefined ->
446 [{"Host", "localhost:8800"}|NHeaders];
447 _ ->
448 NHeaders
449 end,
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
450 NewOptions = [{cookies, enabled}|Options],
ca1c8b1 @karlsson Fixed a number of compiler warnings and html validation errors
karlsson authored
451 httpc:set_options(NewOptions),
452 case httpc:request(post,
6e96a14 @klacke indendation cleanup
authored
453 {URL,NewHeaders,
454 ContentType,
455 Request},
456 [{timeout,?HTTP_REQ_TIMEOUT}],
455578a @vinoski major trailing whitespace cleanup
vinoski authored
457 [{sync, true}, {full_result, true},
6e96a14 @klacke indendation cleanup
authored
458 {body_format, string}]) of
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
459 {ok,{{_HTTP,200,_OK},ResponseHeaders,ResponseBody}} ->
460 {ok, 200, ResponseHeaders, ResponseBody};
461 {ok,{{_HTTP,500,_Descr},ResponseHeaders,ResponseBody}} ->
462 {ok, 500, ResponseHeaders, ResponseBody};
463 {ok,{{_HTTP,ErrorCode,_Descr},ResponseHeaders,ResponseBody}} ->
464 {ok, ErrorCode, ResponseHeaders, ResponseBody};
465 Other ->
466 Other
467 end.
468
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
469 ibrowse_request(URL, SoapAction, Request, Options, Headers, ContentType) ->
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
470 case start_ibrowse() of
471 ok ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
472 NewHeaders = [{"Content-Type", ContentType},
6e96a14 @klacke indendation cleanup
authored
473 {"SOAPAction", SoapAction} | Headers],
9e6c9e1 @vinoski revert SOAP response MIME type to "text/xml"
vinoski authored
474 case ibrowse:send_req(URL, NewHeaders, post, Request, Options) of
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
475 {ok, Status, ResponseHeaders, ResponseBody} ->
9e6c9e1 @vinoski revert SOAP response MIME type to "text/xml"
vinoski authored
476 {ok, list_to_integer(Status), ResponseHeaders, ResponseBody};
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
477 {error, Reason} ->
478 {error, Reason}
479 end;
480 error ->
481 {error, "could not start ibrowse"}
482 end.
483
484 start_ibrowse() ->
485 case ibrowse:start() of
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
486 {ok, _} -> ok;
487 {error, {already_started, _}} -> ok;
488 _ -> error
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
489 end.
490
491
492 rmsp(Str) -> string:strip(Str, left).
493
494
0cfaa30 @nygge Add DIME support for SOAP
nygge authored
495 make_request_body(Content, []) ->
b6e60f0 @vinoski revert "remove support for SOAP DIME attachments"
vinoski authored
496 {"application/xml; charset=utf-8",
497 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"++ Content};
498 make_request_body(Content, AttachedFiles) ->
499 {"application/dime",
500 yaws_dime:encode("<?xml version=\"1.0\" encoding=\"utf-8\"?>" ++ Content,
501 AttachedFiles)}.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
502
503 makeFault(FaultCode, FaultString) ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
504 try
6e96a14 @klacke indendation cleanup
authored
505 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
506 "<SOAP-ENV:Body>"
507 "<SOAP-ENV:Fault>"
508 "<faultcode>SOAP-ENV:" ++ FaultCode ++ "</faultcode>" ++
509 "<faultstring>" ++ FaultString ++ "</faultstring>" ++
510 "</SOAP-ENV:Fault>"
511 "</SOAP-ENV:Body>"
512 "</SOAP-ENV:Envelope>"
513 catch
514 _:_ ->
515 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">"
516 "<SOAP-ENV:Body>"
517 "<SOAP-ENV:Fault>"
518 "<faultcode>SOAP-ENV:Server</faultcode>"
519 "<faultstring>Server error</faultstring>"
520 "</SOAP-ENV:Fault>"
521 "</SOAP-ENV:Body>"
522 "</SOAP-ENV:Envelope>"
523 end.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
524
455578a @vinoski major trailing whitespace cleanup
vinoski authored
525 %% record http_header is not defined??
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
526 findHeader(Label, Headers) ->
527 findHeader0(yaws:to_lower(Label), Headers).
528
529 findHeader0(_Label, []) ->
6e96a14 @klacke indendation cleanup
authored
530 undefined;
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
531 findHeader0(Label, [{_,_,Hdr,_,Val}|T]) ->
532 case {Label, yaws:to_lower(Hdr)} of
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
533 {X,X} -> Val;
534 _ -> findHeader0(Label, T)
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
535 end;
536 findHeader0(_Label, undefined) ->
6e96a14 @klacke indendation cleanup
authored
537 undefined.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
538
539
455578a @vinoski major trailing whitespace cleanup
vinoski authored
540 makeOptions(undefined) ->
6e96a14 @klacke indendation cleanup
authored
541 [];
455578a @vinoski major trailing whitespace cleanup
vinoski authored
542 makeOptions(Import) ->
6e96a14 @klacke indendation cleanup
authored
543 lists:map(fun makeOption/1, Import).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
544
545 %% -record(import_specs, {atts, namespace, prefix, location}).
546 makeOption(#import_specs{namespace = Ns, prefix = Pf, location = Lc}) ->
6e96a14 @klacke indendation cleanup
authored
547 {Ns, Pf, Lc}.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
548
549
550 addModels(undefined, Model) ->
6e96a14 @klacke indendation cleanup
authored
551 Model;
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
552 addModels(Import, Model) ->
6e96a14 @klacke indendation cleanup
authored
553 lists:foldl(fun addModel/2, Model, Import).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
554
555 %% -record(xsd_file, {atts, name, prefix, import_specs}).
556 addModel(undefined, Acc) ->
6e96a14 @klacke indendation cleanup
authored
557 Acc;
455578a @vinoski major trailing whitespace cleanup
vinoski authored
558 addModel(#xsd_file{name = XsdFile, prefix = Prefix, import_specs = Import},
6e96a14 @klacke indendation cleanup
authored
559 Acc) ->
560 Options = makeOptions(Import),
561 {ok, Model2} = erlsom:add_xsd_file(XsdFile, [{prefix, Prefix}|Options],Acc),
562 Model2.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
563
564 %% returns [#port{}]
565 %% -record(port, {service, port, binding, address}).
566 getPorts(ParsedWsdl) ->
6e96a14 @klacke indendation cleanup
authored
567 Services = getTopLevelElements(ParsedWsdl, 'wsdl:tService'),
568 getPortsFromServices(Services, []).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
569
570 getPortsFromServices([], Acc) ->
6e96a14 @klacke indendation cleanup
authored
571 Acc;
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
572 getPortsFromServices([Service|Tail], Acc) ->
6e96a14 @klacke indendation cleanup
authored
573 getPortsFromServices(Tail, getPortsFromService(Service) ++ Acc).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
574
575 getPortsFromService(#'wsdl:tService'{name = Name, port = Ports}) ->
6e96a14 @klacke indendation cleanup
authored
576 getPortsInfo(Ports, Name, []).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
577
578 getPortsInfo([], _Name, Acc) ->
6e96a14 @klacke indendation cleanup
authored
579 Acc;
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
580
581 getPortsInfo([#'wsdl:tPort'{name = Name,
582 binding = Binding,
455578a @vinoski major trailing whitespace cleanup
vinoski authored
583 choice =
584 [#'soap:tAddress'{location = URL}]} | Tail],
6e96a14 @klacke indendation cleanup
authored
585 ServiceName, Acc) ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
586 getPortsInfo(Tail, ServiceName, [#port{service = ServiceName,
587 port = Name,
588 binding = Binding,
6e96a14 @klacke indendation cleanup
authored
589 address = URL}|Acc]);
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
590 %% non-soap bindings are ignored.
591 getPortsInfo([#'wsdl:tPort'{} | Tail], ServiceName, Acc) ->
6e96a14 @klacke indendation cleanup
authored
592 getPortsInfo(Tail, ServiceName, Acc).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
593
594
595 getTopLevelElements(#'wsdl:tDefinitions'{choice = TLElements}, Type) ->
6e96a14 @klacke indendation cleanup
authored
596 getTopLevelElements(TLElements, Type, []).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
597
598 getTopLevelElements([], _Type, Acc) ->
6e96a14 @klacke indendation cleanup
authored
599 Acc;
600 getTopLevelElements([#'wsdl:anyTopLevelOptionalElement'{choice = Tuple}| Tail],
601 Type, Acc) ->
602 case element(1, Tuple) of
603 Type -> getTopLevelElements(Tail, Type, [Tuple|Acc]);
604 _ -> getTopLevelElements(Tail, Type, Acc)
605 end.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
606
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
607 getImports(Definitions) ->
6e96a14 @klacke indendation cleanup
authored
608 Imports = getTopLevelElements(Definitions, 'wsdl:tImport'),
609 lists:map(fun(Import) -> Import#'wsdl:tImport'.location end, Imports).
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
610
455578a @vinoski major trailing whitespace cleanup
vinoski authored
611 %% returns [#operation{}]
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
612 getOperations(ParsedWsdl, Ports) ->
6e96a14 @klacke indendation cleanup
authored
613 Bindings = getTopLevelElements(ParsedWsdl, 'wsdl:tBinding'),
614 getOperationsFromBindings(Bindings, Ports, []).
615
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
616 getOperationsFromBindings([], _Ports, Acc) ->
6e96a14 @klacke indendation cleanup
authored
617 Acc;
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
618 getOperationsFromBindings([Binding|Tail], Ports, Acc) ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
619 getOperationsFromBindings(Tail, Ports,
6e96a14 @klacke indendation cleanup
authored
620 getOperationsFromBinding(Binding, Ports) ++ Acc).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
621
455578a @vinoski major trailing whitespace cleanup
vinoski authored
622 getOperationsFromBinding(#'wsdl:tBinding'{name = BindingName,
623 type = BindingType,
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
624 choice = _Choice,
625 operation = Operations}, Ports) ->
6e96a14 @klacke indendation cleanup
authored
626 %% TODO: get soap info from Choice
455578a @vinoski major trailing whitespace cleanup
vinoski authored
627 getOperationsFromOperations(Operations, BindingName, BindingType,
6e96a14 @klacke indendation cleanup
authored
628 Operations, Ports, []).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
629
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
630 getOperationsFromOperations([], _BindingName, _BindingType, _Operations, _Ports, Acc) ->
6e96a14 @klacke indendation cleanup
authored
631 Acc;
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
632
455578a @vinoski major trailing whitespace cleanup
vinoski authored
633 getOperationsFromOperations([#'wsdl:tBindingOperation'{name = Name,
6e96a14 @klacke indendation cleanup
authored
634 choice = Choice} | Tail],
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
635 BindingName, BindingType, Operations, Ports, Acc) ->
6e96a14 @klacke indendation cleanup
authored
636 %% get SOAP action from Choice,
455578a @vinoski major trailing whitespace cleanup
vinoski authored
637 case Choice of
6e96a14 @klacke indendation cleanup
authored
638 [#'soap:tOperation'{soapAction = Action}] ->
639 %% lookup Binding in Ports, and create a combined result
640 Ports2 = searchPorts(BindingName, Ports),
455578a @vinoski major trailing whitespace cleanup
vinoski authored
641 %% for each port, make an operation record
6e96a14 @klacke indendation cleanup
authored
642 CombinedPorts = combinePorts(Ports2, Name, BindingName, Action),
643 getOperationsFromOperations(
455578a @vinoski major trailing whitespace cleanup
vinoski authored
644 Tail, BindingName, BindingType,
6e96a14 @klacke indendation cleanup
authored
645 Operations, Ports, CombinedPorts ++ Acc);
646 _ ->
455578a @vinoski major trailing whitespace cleanup
vinoski authored
647 getOperationsFromOperations(Tail, BindingName, BindingType,
6e96a14 @klacke indendation cleanup
authored
648 Operations, Ports, Acc)
649 end.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
650
651 combinePorts(Ports, Name, BindingName, Action) ->
6e96a14 @klacke indendation cleanup
authored
652 combinePorts(Ports, Name, BindingName, Action, []).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
653
654 combinePorts([], _Name, _BindingName, _Action, Acc) ->
6e96a14 @klacke indendation cleanup
authored
655 Acc;
455578a @vinoski major trailing whitespace cleanup
vinoski authored
656 combinePorts([#port{service = Service,
657 port = PortName,
658 address = Address} | Tail],
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
659 Name, BindingName, Action, Acc) ->
6e96a14 @klacke indendation cleanup
authored
660 combinePorts(Tail, Name, BindingName, Action,
455578a @vinoski major trailing whitespace cleanup
vinoski authored
661 [#operation{service = Service,
662 port = PortName, operation = Name,
663 binding = BindingName,
6e96a14 @klacke indendation cleanup
authored
664 address = Address, action = Action} | Acc]).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
665
666 searchPorts(BindingName, Ports) ->
6e96a14 @klacke indendation cleanup
authored
667 searchPorts(BindingName, Ports, []).
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
668
669 searchPorts(_BindingName, [], Acc) ->
6e96a14 @klacke indendation cleanup
authored
670 Acc;
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
671 searchPorts(BindingName, [Port | Tail], Acc) ->
6e96a14 @klacke indendation cleanup
authored
672 PortBinding = erlsom_lib:localName(Port#port.binding),
673 case PortBinding of
674 BindingName ->
675 searchPorts(BindingName, Tail, [Port | Acc]);
676 _ ->
677 searchPorts(BindingName, Tail, Acc)
678 end.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
679
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
680 %% copied from yaws/json.erl
681 is_string([]) -> yes;
682 is_string(List) -> is_string(List, non_unicode).
683
684 is_string([C|Rest], non_unicode) when C >= 0, C =< 255 -> is_string(Rest, non_unicode);
685 is_string([C|Rest], _) when C =< 65000 -> is_string(Rest, unicode);
686 is_string([], non_unicode) -> yes;
687 is_string([], unicode) -> unicode;
688 is_string(_, _) -> no.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
689
58e1291 Adding support for: imports in the WSDL and support for more than one…
Tobbe Tornquist authored
690 getXsdsFromWsdl(Definitions) ->
6e96a14 @klacke indendation cleanup
authored
691 case getTopLevelElements(Definitions, 'wsdl:tTypes') of
692 [#'wsdl:tTypes'{choice = Xsds}] -> Xsds;
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
693 [] -> []
6e96a14 @klacke indendation cleanup
authored
694 end.
c332fc2 Adding SOAP processing capabilities to Yaws.
Tobbe Tornquist authored
695
696 config_file_xsd() ->
6e96a14 @klacke indendation cleanup
authored
697 "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
698 " <xs:element name=\"yaws_soap_config\">"
699 " <xs:complexType>"
700 " <xs:sequence>"
701 " <xs:element name=\"xsd_path\" type=\"xs:string\" minOccurs=\"0\"/>"
702 " <xs:element name=\"user_module\" type=\"xs:string\"/>"
703 " <xs:element name=\"wsdl_file\" type=\"xsd_file\"/>"
704 " <xs:element name=\"add_file\" type=\"xsd_file\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>"
705 " </xs:sequence>"
706 " </xs:complexType>"
707 " </xs:element>"
708 " <xs:complexType name=\"xsd_file\">"
709 " <xs:sequence>"
710 " <xs:element name=\"import_specs\" type=\"import_specs\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>"
711 " </xs:sequence>"
712 " <xs:attribute name=\"name\" type=\"string\" use=\"required\"/>"
713 " <xs:attribute name=\"prefix\" type=\"string\"/>"
714 " </xs:complexType>"
715 " <xs:complexType name=\"import_specs\">"
716 " <xs:attribute name=\"namespace\" type=\"string\" use=\"required\"/>"
717 " <xs:attribute name=\"prefix\" type=\"string\"/>"
718 " <xs:attribute name=\"location\" type=\"string\"/>"
719 " </xs:complexType>"
720 "</xs:schema>".
ec553ff @willemdj Allow to pass options to erlsom (fix issue #65)
willemdj authored
721
722
Something went wrong with that request. Please try again.