23 #include "SoapHandler.h"
25 SoapHandler::SoapHandler() {
30 SoapHandler::~SoapHandler() {
36 Logger logger = Logger::getLogger(
"SoapHandler");
37 string meth,ws_name,env;
38 ws_name = req->getFile();
40 logger.info(
"request => "+req->getContent());
45 Document doc = parser.getDocument(req->getContent());
46 soapenv = doc.getRootElement();
49 if(soapenv.getChildElements().size()==1
50 && soapenv.getChildElements().at(0).getTagName()==
"Body")
51 soapbody = soapenv.getChildElements().at(0);
52 else if(soapenv.getChildElements().size()==2
53 && soapenv.getChildElements().at(1).getTagName()==
"Body")
54 soapbody = soapenv.getChildElements().at(1);
56 Element method = soapbody.getChildElements().at(0);
58 meth = method.getTagName();
59 string methodname = meth + ws_name;
61 void *mkr = dlsym(dlib, methodname.c_str());
64 typedef string (*WsPtr) (
Element);
66 string outpt = f(method);
67 typedef map<string,string> AttributeList;
68 AttributeList attl = soapbody.getAttributes();
69 AttributeList::iterator it;
70 string bod =
"<" + soapbody.getTagNameSpc();
71 for(it=attl.begin();it!=attl.end();it++)
73 bod.append(
" " + it->first +
"=\"" + it->second +
"\" ");
75 bod.append(
">"+outpt +
"</" + soapbody.getTagNameSpc()+
">");
76 attl = soapenv.getAttributes();
77 env =
"<" + soapenv.getTagNameSpc();
78 for(it=attl.begin();it!=attl.end();it++)
80 env.append(
" " + it->first +
"=\"" + it->second +
"\" ");
82 env.append(
">"+bod +
"</" + soapenv.getTagNameSpc()+
">");
87 typedef map<string,string> AttributeList;
88 AttributeList attl = soapbody.getAttributes();
89 AttributeList::iterator it;
90 string bod =
"<" + soapbody.getTagNameSpc();
91 for(it=attl.begin();it!=attl.end();it++)
93 bod.append(
" " + it->first +
"=\"" + it->second +
"\" ");
95 bod.append(
"><soap-fault><faultcode>soap:Server</faultcode><faultstring>Operation not supported</faultstring><faultactor/><detail>No such method error</detail><soap-fault></" + soapbody.getTagNameSpc()+
">");
96 attl = soapenv.getAttributes();
97 env =
"<" + soapenv.getTagNameSpc();
98 for(it=attl.begin();it!=attl.end();it++)
100 env.append(
" " + it->first +
"=\"" + it->second +
"\" ");
102 env.append(
">"+bod +
"</" + soapenv.getTagNameSpc()+
">");
104 logger <<
"\n----------------------------------------------------------------------------\n" << flush;
105 logger << env <<
"\n----------------------------------------------------------------------------\n" << flush;
109 typedef map<string,string> AttributeList;
110 AttributeList attl = soapbody.getAttributes();
111 AttributeList::iterator it;
112 string bod =
"<" + soapbody.getTagNameSpc();
113 for(it=attl.begin();it!=attl.end();it++)
115 bod.append(
" " + it->first +
"=\"" + it->second +
"\" ");
117 bod.append(
"><soap-fault><faultcode>soap:Server</faultcode><faultstring>"+fault+
"</faultstring><detail></detail><soap-fault></" + soapbody.getTagNameSpc()+
">");
118 attl = soapenv.getAttributes();
119 env =
"<" + soapenv.getTagNameSpc();
120 for(it=attl.begin();it!=attl.end();it++)
122 env.append(
" " + it->first +
"=\"" + it->second +
"\" ");
124 env.append(
">"+bod +
"</" + soapenv.getTagNameSpc()+
">");
125 logger << (
"Soap fault - " + fault) << flush;
129 typedef map<string,string> AttributeList;
130 AttributeList attl = soapbody.getAttributes();
131 AttributeList::iterator it;
132 string bod =
"<" + soapbody.getTagNameSpc();
133 for(it=attl.begin();it!=attl.end();it++)
135 bod.append(
" " + it->first +
"=\"" + it->second +
"\" ");
137 bod.append(
"><soap-fault><faultcode>soap:Server</faultcode><faultstring>"+e->what()+
"</faultstring><detail></detail><soap-fault></" + soapbody.getTagNameSpc()+
">");
138 attl = soapenv.getAttributes();
139 env =
"<" + soapenv.getTagNameSpc();
140 for(it=attl.begin();it!=attl.end();it++)
142 env.append(
" " + it->first +
"=\"" + it->second +
"\" ");
144 env.append(
">"+bod +
"</" + soapenv.getTagNameSpc()+
">");
145 logger << (
"Soap fault - " + e->what()) << flush;
149 typedef map<string,string> AttributeList;
150 AttributeList attl = soapbody.getAttributes();
151 AttributeList::iterator it;
152 string bod =
"<" + soapbody.getTagNameSpc();
153 for(it=attl.begin();it!=attl.end();it++)
155 bod.append(
" " + it->first +
"=\"" + it->second +
"\" ");
157 bod.append(
"><soap-fault><faultcode>soap:Server</faultcode><faultstring>Standard Exception</faultstring><detail></detail><soap-fault></" + soapbody.getTagNameSpc()+
">");
158 attl = soapenv.getAttributes();
159 env =
"<" + soapenv.getTagNameSpc();
160 for(it=attl.begin();it!=attl.end();it++)
162 env.append(
" " + it->first +
"=\"" + it->second +
"\" ");
164 env.append(
">"+bod +
"</" + soapenv.getTagNameSpc()+
">");
165 logger <<
"Soap Standard Exception" << flush;
167 res.setHTTPResponseStatus(HTTPResponseStatus::Ok);
168 res.setContent_type(xmlcnttype);
169 res.setContent_str(env);