DCL 3.7.4
Loading...
Searching...
No Matches
HttpServlet.h
Go to the documentation of this file.
1#ifndef __DCL_HTTP_SERVLET_H__
2#define __DCL_HTTP_SERVLET_H__ 20050530
3
4// HTTP Server -let
5#ifndef __DCL_OBJECT_H__
6#include <dcl/Object.h>
7#endif
8
9#ifndef __DCL_EXCEPTION_H__
10#include <dcl/Exception.h>
11#endif
12
13#ifndef __DCL_HTTP_SERVER_EXTENSION_H__
15#endif
16#ifndef __DCL_HTTP_HEADER_H__
17#include <dcl/HttpHeader.h>
18#endif
19
20__DCL_BEGIN_NAMESPACE
21
22/*
23Object
24 HttpServletContext;
25 HttpServletContextEx;
26 HttpServlet;
27 HttpServletEx;
28*/
29
31{
33public :
35 const DCL_HTTP_SERVER_API* _SAPI,
36 const DCL_HTTP_SERVLET_CONTEXT* _context
37 );
38 virtual ~HttpServletContext();
39
40 // request
41 String remoteAddr() const;
42 unsigned int remotePort() const;
43 String method() const;
44 unsigned int methodNo() const;
45 String path() const;
46 String queryString() const;
47 String contentType() const;
48 size_t contentLength() const;
49 String scriptFilename() const;
50 String scriptData() const;
51
52 const String& resContentType() const;
53
54 ByteString getHttpHeader(const char* _name = NULL) const;
55 ByteString getCgiVariable(const char* _name = NULL) const;
56 String getHttpHeader(const wchar_t* _name = NULL) const;
57 String getCgiVariable(const wchar_t* _name = NULL) const;
58
59 size_t read(void* pv, size_t n) __DCL_THROWS1(IOException*);
60
61 // response
62 void setStatusCode(unsigned int uHttpStatusCode);
63 void setContentType(
64 const wchar_t* _contentType,
65 const wchar_t* pszCharset = NULL
66 );
67 void addHeader(const HttpHeader& httpHeader);
68 void flushHeader();
69
70 void write(const void* pv, size_t n) __DCL_THROWS1(IOException*);
71
72protected:
75
76 String __contentType; // response Content-Type
77 unsigned int __statusCode;
78 StringBuilder __responseHeaders;
80};
81
83{
85public:
87 String getIniFileName(const wchar_t* _basename = NULL) const;
88
89protected:
90 // implement
91 virtual void onInitialize()
93 virtual void onCleanup()
95 virtual void onHttpService(
96 const DCL_HTTP_SERVLET_CONTEXT* pContext
98
99protected:
100 const wchar_t* __moduleName;
101 const wchar_t* __configPath;
102 const wchar_t* __tempPath;
104
105public:
106 // internal function
107 static bool __initialize(
108 HttpServlet* _servlet,
109 const DCL_HTTP_SERVLET_CONFIG* _config,
110 void* hErrorReport
111 );
112
113 static bool __cleanup(
114 HttpServlet* _servlet,
115 void* hErrorReport
116 );
117
118 static bool __httpService(
119 HttpServlet* _servlet,
120 const DCL_HTTP_SERVLET_CONTEXT* _context,
121 void* hErrorReport
122 );
123};
124
125#define HTTP_SERVLET_INSTANCE(ServletClass, Description) \
126static HttpServlet* __servlet__ = NULL; \
127static BOOL ModuleInitialize( \
128 const DCL_HTTP_SERVLET_CONFIG* pConfig, \
129 void* hErrorReport \
130) \
131{ \
132 __servlet__ = new ServletClass; \
133 if (!__servlet__) { \
134 pConfig->pSAPI->pfnReportError( \
135 hErrorReport, \
136 L"Out of Memory", \
137 13 \
138 ); \
139 return FALSE; \
140 } \
141 else { \
142 if (!HttpServlet::__initialize( \
143 __servlet__, \
144 pConfig, \
145 hErrorReport \
146 )) { \
147 delete __servlet__; \
148 __servlet__ = NULL; \
149 return FALSE; \
150 } \
151 } \
152 return TRUE; \
153} \
154\
155static BOOL ModuleCleanup( \
156 void* hErrorReport \
157) \
158{ \
159 BOOL bResult = HttpServlet::__cleanup( \
160 __servlet__, \
161 hErrorReport \
162 ); \
163 delete __servlet__; \
164 __servlet__ = NULL; \
165 return bResult; \
166} \
167\
168static BOOL ModuleHttpService( \
169 const DCL_HTTP_SERVLET_CONTEXT* pContext, \
170 void* hErrorReport \
171) \
172 { \
173 return HttpServlet::__httpService( \
174 __servlet__, \
175 pContext, \
176 hErrorReport \
177 ); \
178}\
179\
180extern "C" { \
181DCL_DSO_EXPORT \
182DCL_HTTP_SERVLET DCL_DSO_ENTRY_POINT = { \
183 sizeof(DCL_HTTP_SERVLET), \
184 DCL_VERSION, \
185 __T(__BUILD_TIMESTAMP__), \
186 DCL_BUILD_FLAG, \
187 DCL_HTTP_SERVLET_MODULE, \
188 Description, \
189 DCL_HTTP_VERSION, \
190 ModuleInitialize, \
191 ModuleCleanup, \
192 ModuleHttpService \
193}; \
194} \
195
196__DCL_END_NAMESPACE
197
198#endif // __DCL_HTTP_SERVLET_H__
#define NULL
Definition Config.h:312
#define DCLCAPI
Definition Config.h:95
#define __DCL_THROWS1(e)
Definition Config.h:152
struct _DCL_HTTP_SERVLET_CONTEXT DCL_HTTP_SERVLET_CONTEXT
struct _DCL_HTTP_SERVER_API DCL_HTTP_SERVER_API
struct _DCL_HTTP_SERVLET_CONFIG DCL_HTTP_SERVLET_CONFIG
#define DECLARE_CLASSINFO(class_name)
Definition Object.h:227
const DCL_HTTP_SERVLET_CONTEXT * __context
Definition HttpServlet.h:74
unsigned int __statusCode
Definition HttpServlet.h:77
const DCL_HTTP_SERVER_API * __SAPI
Definition HttpServlet.h:73
StringBuilder __responseHeaders
Definition HttpServlet.h:78
static bool __cleanup(HttpServlet *_servlet, void *hErrorReport)
virtual void onInitialize() __DCL_THROWS1(Exception *)
static bool __httpService(HttpServlet *_servlet, const DCL_HTTP_SERVLET_CONTEXT *_context, void *hErrorReport)
virtual void onHttpService(const DCL_HTTP_SERVLET_CONTEXT *pContext)=0__DCL_THROWS1(Exception *)
const DCL_HTTP_SERVER_API * __SAPI
const wchar_t * __moduleName
const wchar_t * __configPath
virtual void onCleanup() __DCL_THROWS1(Exception *)
const wchar_t * __tempPath
static bool __initialize(HttpServlet *_servlet, const DCL_HTTP_SERVLET_CONFIG *_config, void *hErrorReport)
Object()
Definition Object.cpp:183