DCL 4.0
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// #ifndef __DCL_COLLECTION_H__
13// #include <dcl/core/Collection.h>
14// #endif
15
16#ifndef __DCL_HTTP_SERVER_EXTENSION_H__
18#endif
19#ifndef __DCL_HTTP_HEADER_H__
20#include <dcl/HttpHeader.h>
21#endif
22
23__DCL_BEGIN_NAMESPACE
24
25/*
26Object
27 HttpServletContext;
28 HttpServletContextEx;
29 HttpServlet;
30 HttpServletEx;
31*/
32
34{
36public :
38 const DCL_HTTP_SERVER_API* _SAPI,
39 const DCL_HTTP_SERVLET_CONTEXT* _context
40 );
41 virtual ~HttpServletContext();
42
43 // request
44 String remoteAddr() const;
45 unsigned int remotePort() const;
46 String method() const;
47 unsigned int methodNo() const;
48 String path() const;
49 String queryString() const;
50 String contentType() const;
51 size_t contentLength() const;
52 String scriptFilename() const;
53 String scriptData() const;
54
55 const String& resContentType() const;
56
57 ByteString getHttpHeader(const char* _name = NULL) const;
58 ByteString getCgiVariable(const char* _name = NULL) const;
59 String getHttpHeader(const wchar_t* _name = NULL) const;
60 String getCgiVariable(const wchar_t* _name = NULL) const;
61
62 size_t read(void* pv, size_t n) __DCL_THROWS1(IOException*);
63
64 // response
65 void setStatusCode(unsigned int uHttpStatusCode);
66 void setContentType(const wchar_t* _contentType, const wchar_t* pszCharset = NULL);
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 return FALSE; \
139 } \
140 else { \
141 if (!HttpServlet::__initialize( \
142 __servlet__, \
143 pConfig, \
144 hErrorReport \
145 ) \
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(__TIMESTAMP__), \
186 DCL_BUILD_FLAG, \
187 DCL_HTTP_SERVLET_MODULE, \
188 Description, \
189 DCL_HTTP_SERVER_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:340
#define DCLCAPI
Definition Config.h:100
#define __DCL_THROWS1(e)
Definition Config.h:167
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:210
void CharsetConvertException *size_t n
Definition SQLField.cpp:253
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