1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::collections::HashMap;
use xml::reader::{EventReader, XmlEvent};
use http;
#[derive(Debug)]
pub struct Operation {
pub url: String,
}
#[derive(Debug)]
pub struct Wsdl {
pub operations: HashMap<String, Operation>,
}
pub fn fetch(url: &str) -> http::Result<Wsdl> {
let response = try!(http::get(&url));
let mut bytes = response.body.as_bytes();
let mut operations = HashMap::new();
let parser = EventReader::new(&mut bytes);
for e in parser {
match e {
Ok(XmlEvent::StartElement { ref name, ref attributes, ref namespace }) => {
if name.to_string().contains("wsdl:operation") {
match (attributes.iter().find(|a| a.name.to_string() == "name"), namespace.get("impl")) {
(Some(name_attribute), Some(impl_url)) => {
operations.insert(name_attribute.value.to_string(), Operation {
url: impl_url.into(),
});
},
_ => (),
}
}
}
Err(e) => {
error!("Error: {}", e);
break;
}
_ => {}
}
}
Ok(Wsdl {
operations: operations
})
}