soapbind.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. //Jlib
  16. #include "jliball.hpp"
  17. #ifdef ESPHTTP_EXPORTS
  18. #define esp_http_decl DECL_EXPORT
  19. #else
  20. #define esp_http_decl DECL_IMPORT
  21. #endif
  22. //SCM Interfaces
  23. #include "esp.hpp"
  24. #include "soapesp.hpp"
  25. //ESP Core
  26. #include "espthread.hpp"
  27. //ESP Bindings
  28. #include "SOAP/Platform/soapmessage.hpp"
  29. #include "espbinding.hpp"
  30. #include "http/platform/httpbinding.hpp"
  31. class esp_http_decl CSoapComplexType : implements IRpcSerializable, public CInterface
  32. {
  33. protected:
  34. unsigned clvalue_;
  35. unsigned msg_id_;
  36. void *thunk_;
  37. public:
  38. IMPLEMENT_IINTERFACE;
  39. CSoapComplexType() : clvalue_(0), msg_id_(0), thunk_(NULL) { }
  40. void setClientValue(unsigned val){clvalue_=val;}
  41. unsigned getClientValue(){return clvalue_;}
  42. void setMessageId(unsigned val){msg_id_=val;}
  43. unsigned getMessageId(){return msg_id_;}
  44. void setThunkHandle(void * val){thunk_=val;}
  45. void * getThunkHandle(){return thunk_;}
  46. virtual void appendContent(IEspContext* ctx, MemoryBuffer& buffer, StringBuffer& mimetype);
  47. virtual void serializeJSONStruct(IEspContext* ctx, StringBuffer& s, const char *name);
  48. virtual void serializeStruct(IEspContext * ctx, StringBuffer & buffer, const char * rootname=NULL);
  49. virtual void serializeItem(IEspContext* ctx, StringBuffer& s, const char *name);
  50. virtual void serializeAttributes(IEspContext* ctx, StringBuffer& s)=0;
  51. virtual void serializeContent(IEspContext* ctx, StringBuffer& buffer, IProperties **pprops=NULL) = 0;
  52. virtual void serialize(IEspContext * ctx, StringBuffer & buffer, const char * rootname=NULL)
  53. {
  54. serializeStruct(ctx, buffer, rootname);
  55. }
  56. virtual const char *getNsURI()=0;
  57. virtual const char *getNsPrefix()=0;
  58. virtual const char *getRootName()=0;
  59. };
  60. class esp_http_decl CSoapResponseBinding : public CSoapComplexType,
  61. implements IRpcResponseBinding,
  62. implements IEspResponse
  63. {
  64. private:
  65. RpcMessageState state_;
  66. StringBuffer redirectUrl_;
  67. Owned<IMultiException> exceptions_;
  68. public:
  69. IMPLEMENT_IINTERFACE;
  70. CSoapResponseBinding()
  71. {
  72. state_=RPC_MESSAGE_OK;
  73. exceptions_.setown(MakeMultiException("CSoapResponseBinding"));
  74. }
  75. void setClientValue(unsigned val){clvalue_=val;}
  76. unsigned getClientValue(){return clvalue_;}
  77. void setMessageId(unsigned val){msg_id_=val;}
  78. unsigned getMessageId(){return msg_id_;}
  79. void setThunkHandle(void * val){thunk_=val;}
  80. void * getThunkHandle(){return thunk_;}
  81. void setRpcState(RpcMessageState state)
  82. {
  83. state_=state;
  84. }
  85. RpcMessageState getRpcState(){return state_;}
  86. virtual void setRedirectUrl(const char * url)
  87. {
  88. redirectUrl_.clear().append(url);
  89. }
  90. const char *getRedirectUrl() { return redirectUrl_.str(); }
  91. const IMultiException& getExceptions() { return *exceptions_; }
  92. void noteException(IException& e) { exceptions_->append(e); }
  93. void handleExceptions(IMultiException *me, const char *serv, const char *meth);
  94. };
  95. class esp_http_decl CSoapRequestBinding : public CSoapComplexType,
  96. implements IRpcRequestBinding,
  97. implements IEspRequest
  98. {
  99. private:
  100. StringBuffer url_;
  101. StringBuffer proxy_;
  102. StringBuffer userid_;
  103. StringBuffer password_;
  104. StringBuffer realm_;
  105. public:
  106. IMPLEMENT_IINTERFACE;
  107. CSoapRequestBinding(){}
  108. void setClientValue(unsigned val){clvalue_=val;}
  109. unsigned getClientValue(){return clvalue_;}
  110. void setMessageId(unsigned val){msg_id_=val;}
  111. unsigned getMessageId(){return msg_id_;}
  112. void setThunkHandle(void * val){thunk_=val;}
  113. void * getThunkHandle(){return thunk_;}
  114. void setUrl(const char *url){url_.clear().append(url);}
  115. const char * getUrl(){return url_.str();}
  116. void setProxyAddress(const char *proxy){proxy_.clear().append(proxy);}
  117. const char * getProxyAddress(){return proxy_.str();}
  118. void setUserId(const char *userid){userid_.clear().append(userid);}
  119. const char * getUserId(){return userid_.str();}
  120. void setPassword(const char *password){password_.clear().append(password);}
  121. const char * getPassword(){return password_.str();}
  122. void setRealm(const char *realm){realm_.clear().append(realm);}
  123. const char * getRealm(){return realm_.str();}
  124. void post(const char *proxy, const char* url, IRpcResponseBinding& response, const char *action=NULL);
  125. void post(IRpcResponseBinding& response)
  126. {
  127. post(getProxyAddress(), getUrl(), response);
  128. }
  129. virtual void serialize(IRpcMessage& rpc)
  130. {
  131. throw MakeStringException(-1,"Internal error: umimplmented function called: CSoapRequestBinding::serialize()");
  132. }
  133. };
  134. class esp_http_decl CSoapBinding : public CEspBinding
  135. {
  136. public:
  137. CSoapBinding();
  138. virtual ~CSoapBinding();
  139. virtual const char * getRpcType();
  140. virtual const char * getTransportType();
  141. virtual int processRequest(IRpcMessage* rpc_call, IRpcMessage* rpc_response);
  142. };
  143. typedef enum http_soap_log_level_ {hsl_none, hsl_all} http_soap_log_level;
  144. class esp_http_decl CHttpSoapBinding : public CSoapBinding, public EspHttpBinding
  145. {
  146. public:
  147. CHttpSoapBinding();
  148. CHttpSoapBinding(IPropertyTree* cfg, const char *bindname=NULL, const char *procname=NULL, http_soap_log_level level=hsl_none);
  149. virtual ~CHttpSoapBinding();
  150. http_soap_log_level log_level_;
  151. virtual const char * getTransportType();
  152. virtual int onSoapRequest(CHttpRequest* request, CHttpResponse* response);
  153. virtual void setHSLogLevel(http_soap_log_level level){log_level_=level;}
  154. virtual int onGetNavEvent(IEspContext & context, IHttpMessage * req, IHttpMessage * resp){return 0;}
  155. IEspContainer* queryContainer() { return m_container; }
  156. virtual int HandleSoapRequest(CHttpRequest* request, CHttpResponse* response);
  157. };
  158. void SetHTTPErrorStatus(int ErrorCode,CHttpResponse* response);
  159. #endif //_SOAPBIND_HPP__