soapbind.hpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef _SOAPBIND_HPP__
  14. #define _SOAPBIND_HPP__
  15. #include "esphttp.hpp"
  16. //Jlib
  17. #include "jliball.hpp"
  18. //SCM Interfaces
  19. #include "esp.hpp"
  20. #include "soapesp.hpp"
  21. //ESP Core
  22. #include "espthread.hpp"
  23. //ESP Bindings
  24. #include "SOAP/Platform/soapmessage.hpp"
  25. #include "espbinding.hpp"
  26. #include "http/platform/httpbinding.hpp"
  27. class esp_http_decl CSoapComplexType : implements IRpcSerializable, public CInterface
  28. {
  29. protected:
  30. unsigned clvalue_;
  31. unsigned msg_id_;
  32. void *thunk_;
  33. public:
  34. IMPLEMENT_IINTERFACE;
  35. CSoapComplexType() : clvalue_(0), msg_id_(0), thunk_(NULL) { }
  36. void setClientValue(unsigned val){clvalue_=val;}
  37. unsigned getClientValue(){return clvalue_;}
  38. void setMessageId(unsigned val){msg_id_=val;}
  39. unsigned getMessageId(){return msg_id_;}
  40. void setThunkHandle(void * val){thunk_=val;}
  41. void * getThunkHandle(){return thunk_;}
  42. virtual void appendContent(IEspContext* ctx, MemoryBuffer& buffer, StringBuffer& mimetype);
  43. virtual void appendContent(IEspContext* ctx, StringBuffer& buffer, StringBuffer& mimetype);
  44. virtual void serializeJSONStruct(IEspContext* ctx, StringBuffer& s, const char *name);
  45. virtual void serializeStruct(IEspContext * ctx, StringBuffer & buffer, const char * rootname=NULL);
  46. virtual void serializeItem(IEspContext* ctx, StringBuffer& s, const char *name);
  47. virtual void serializeAttributes(IEspContext* ctx, StringBuffer& s)=0;
  48. virtual void serializeContent(IEspContext* ctx, StringBuffer& buffer, IProperties **pprops=NULL) = 0;
  49. virtual void serialize(IEspContext * ctx, StringBuffer & buffer, const char * rootname=NULL)
  50. {
  51. serializeStruct(ctx, buffer, rootname);
  52. }
  53. virtual const char *getNsURI()=0;
  54. virtual const char *getNsPrefix()=0;
  55. virtual const char *getRootName()=0;
  56. };
  57. class esp_http_decl CSoapResponseBinding : public CSoapComplexType,
  58. implements IRpcResponseBinding,
  59. implements IEspResponse
  60. {
  61. private:
  62. RpcMessageState state_;
  63. StringBuffer redirectUrl_;
  64. Owned<IMultiException> exceptions_;
  65. public:
  66. IMPLEMENT_IINTERFACE;
  67. CSoapResponseBinding()
  68. {
  69. state_=RPC_MESSAGE_OK;
  70. exceptions_.setown(MakeMultiException("CSoapResponseBinding"));
  71. }
  72. void setClientValue(unsigned val){clvalue_=val;}
  73. unsigned getClientValue(){return clvalue_;}
  74. void setMessageId(unsigned val){msg_id_=val;}
  75. unsigned getMessageId(){return msg_id_;}
  76. void setThunkHandle(void * val){thunk_=val;}
  77. void * getThunkHandle(){return thunk_;}
  78. void setRpcState(RpcMessageState state)
  79. {
  80. state_=state;
  81. }
  82. RpcMessageState getRpcState(){return state_;}
  83. virtual void setRedirectUrl(const char * url)
  84. {
  85. redirectUrl_.clear().append(url);
  86. }
  87. const char *getRedirectUrl() { return redirectUrl_.str(); }
  88. const IMultiException& getExceptions() { return *exceptions_; }
  89. void noteException(IException& e) { exceptions_->append(e); }
  90. void handleExceptions(IMultiException *me, const char *serv, const char *meth);
  91. };
  92. class esp_http_decl CSoapRequestBinding : public CSoapComplexType,
  93. implements IRpcRequestBinding,
  94. implements IEspRequest,
  95. implements IEspClientRpcSettings
  96. {
  97. private:
  98. StringBuffer url_;
  99. StringBuffer proxy_;
  100. StringBuffer userid_;
  101. StringBuffer password_;
  102. StringBuffer realm_;
  103. StringBuffer mtls_secret_;
  104. unsigned connectTimeoutMs_ = 0;
  105. unsigned readTimeoutSecs_ = 0;
  106. public:
  107. IMPLEMENT_IINTERFACE;
  108. CSoapRequestBinding(){}
  109. void setClientValue(unsigned val){clvalue_=val;}
  110. unsigned getClientValue(){return clvalue_;}
  111. void setMessageId(unsigned val){msg_id_=val;}
  112. unsigned getMessageId(){return msg_id_;}
  113. void setThunkHandle(void * val){thunk_=val;}
  114. void * getThunkHandle(){return thunk_;}
  115. void setConnectTimeOutMs(unsigned timeout) override {connectTimeoutMs_ = timeout;}
  116. unsigned getConnectTimeOutMs() override {return connectTimeoutMs_;}
  117. void setReadTimeOutSecs(unsigned timeout) override {readTimeoutSecs_ = timeout;}
  118. unsigned getReadTimeOutSecs() override {return readTimeoutSecs_;}
  119. void setUrl(const char *url){url_.clear().append(url);}
  120. const char * getUrl(){return url_.str();}
  121. void setProxyAddress(const char *proxy){proxy_.clear().append(proxy);}
  122. const char * getProxyAddress(){return proxy_.str();}
  123. //unorthodox naming to avoid name collisions with generated code
  124. void soap_setUserId(const char *userid){userid_.clear().append(userid);}
  125. const char * soap_getUserId(){return userid_.str();}
  126. //unorthodox naming to avoid name collisions with generated code
  127. void soap_setPassword(const char *password){password_.clear().append(password);}
  128. const char * soap_getPassword(){return password_.str();}
  129. //unorthodox naming to avoid name collisions with generated code
  130. void soap_setRealm(const char *realm){realm_.clear().append(realm);}
  131. const char * soap_getRealm(){return realm_.str();}
  132. void setMtlsSecretName(const char *name){mtls_secret_.set(name);}
  133. const char *getMtlsSecretName(){return mtls_secret_.str();}
  134. void post(const char *proxy, const char* url, IRpcResponseBinding& response, const char *action=NULL);
  135. void post(IRpcResponseBinding& response)
  136. {
  137. post(getProxyAddress(), getUrl(), response);
  138. }
  139. virtual void serialize(IRpcMessage& rpc)
  140. {
  141. throw MakeStringException(-1,"Internal error: umimplmented function called: CSoapRequestBinding::serialize()");
  142. }
  143. };
  144. class esp_http_decl CSoapBinding : public CEspBinding
  145. {
  146. public:
  147. CSoapBinding();
  148. virtual ~CSoapBinding();
  149. virtual const char * getRpcType();
  150. virtual const char * getTransportType();
  151. virtual int processRequest(IRpcMessage* rpc_call, IRpcMessage* rpc_response);
  152. };
  153. typedef enum http_soap_log_level_ {hsl_none, hsl_all} http_soap_log_level;
  154. class esp_http_decl CHttpSoapBinding : public CSoapBinding, public EspHttpBinding
  155. {
  156. public:
  157. CHttpSoapBinding();
  158. CHttpSoapBinding(IPropertyTree* cfg, const char *bindname=NULL, const char *procname=NULL, http_soap_log_level level=hsl_none);
  159. virtual ~CHttpSoapBinding();
  160. http_soap_log_level log_level_;
  161. virtual const char * getTransportType();
  162. virtual int onSoapRequest(CHttpRequest* request, CHttpResponse* response);
  163. virtual void setHSLogLevel(http_soap_log_level level){log_level_=level;}
  164. virtual int onGetNavEvent(IEspContext & context, IHttpMessage * req, IHttpMessage * resp){return 0;}
  165. IEspContainer* queryContainer() { return m_container; }
  166. virtual int HandleSoapRequest(CHttpRequest* request, CHttpResponse* response);
  167. virtual bool subscribeBindingToDali()
  168. {
  169. return this->getService()->subscribeServiceToDali();
  170. }
  171. virtual bool unsubscribeBindingFromDali()
  172. {
  173. return this->getService()->unsubscribeServiceFromDali();
  174. }
  175. virtual bool detachBindingFromDali()
  176. {
  177. return this->getService()->detachServiceFromDali();
  178. }
  179. virtual bool attachBindingToDali()
  180. {
  181. return this->getService()->attachServiceToDali();
  182. }
  183. virtual bool canDetachFromDali() {return true;}
  184. };
  185. void SetHTTPErrorStatus(int ErrorCode,CHttpResponse* response);
  186. #endif //_SOAPBIND_HPP__