DCL 3.7.4
Loading...
Searching...
No Matches
EShopServlet Class Reference

#include <EShopServlet.h>

Inheritance diagram for EShopServlet:
HttpServletEx HttpServlet Object

Public Member Functions

String readTemplate (const wchar_t *filename) const __DCL_THROWS1(IOException *)
Public Member Functions inherited from Object
virtual String toString () const
virtual void destroy ()
String className () const
bool isInstanceOf (const std::type_info &typeinfo) const
virtual const std::type_info & typeInfo () const

Protected Member Functions

virtual void onInitialize () __DCL_THROWS1(Exception *)
virtual void onCleanup () __DCL_THROWS1(Exception *)
virtual void onService (HttpServletContextEx &ctx) __DCL_THROWS1(Exception *)
Protected Member Functions inherited from Object
virtual ~Object ()
 Object ()

Additional Inherited Members

Static Public Member Functions inherited from HttpServlet
static bool __initialize (HttpServlet *_servlet, const DCL_HTTP_SERVLET_CONFIG *_config, void *hErrorReport)
static bool __cleanup (HttpServlet *_servlet, void *hErrorReport)
static bool __httpService (HttpServlet *_servlet, const DCL_HTTP_SERVLET_CONTEXT *_context, void *hErrorReport)
Protected Attributes inherited from HttpServletEx
size_t __maxContentLength
Protected Attributes inherited from HttpServlet
const wchar_t * __moduleName
const wchar_t * __configPath
const wchar_t * __tempPath
const DCL_HTTP_SERVER_API__SAPI

Detailed Description

Definition at line 20 of file EShopServlet.h.

Member Function Documentation

◆ onCleanup()

void EShopServlet::onCleanup ( )
protectedvirtual

Reimplemented from HttpServlet.

Definition at line 97 of file EShopServlet.cpp.

98{
99 if (__pSQLConnPool) {
100 delete __pSQLConnPool;
101 __pSQLConnPool = NULL;
102 }
103
104 if (__pHead) {
105 delete __pHead;
106 __pHead = NULL;
107 }
108
109 if (__pFoot) {
110 delete __pFoot;
111 __pFoot = NULL;
112 }
113
114 if (__pViewOrder) {
115 delete __pViewOrder;
116 __pViewOrder = NULL;
117 }
118
119 if (__pViewProduct) {
120 delete __pViewProduct;
121 __pViewProduct = NULL;
122 }
123
124 if (__pViewShoppingBasket) {
125 delete __pViewShoppingBasket;
126 __pViewShoppingBasket = NULL;
127 }
128
130 __DCL_TRACE0(L"onCleanup()\n");
131}
#define NULL
Definition Config.h:312
#define __DCL_TRACE0(psz)
Definition Object.h:398
virtual void onCleanup() __DCL_THROWS1(Exception *)

◆ onInitialize()

void EShopServlet::onInitialize ( )
protectedvirtual

Reimplemented from HttpServletEx.

Definition at line 39 of file EShopServlet.cpp.

40{
41 HttpServlet::onInitialize(); // 항상 true
42
43#ifdef __WINNT__
44#define INI_FILENAME L"HSAEShop_w.ini"
45#else
46#define INI_FILENAME L"HSAEShop.ini"
47#endif
48
49 String strIniFile = getIniFileName(INI_FILENAME);
50 if (strIniFile.isEmpty()) {
51 __DCL_TRACE1(L"not found : %ls\n", strIniFile.data());
52 return;
53 }
54
55 String strSQLDriverName;
56 String strSQLConnectionString;
57
58 try {
59 IniFile ini(strIniFile);
60
61#ifdef __DCL_DEBUG
62 String strEnableDebugOut = ini.getString(L"DEBUG", L"ENABLE_DEBUG_OUT");
63 if (strEnableDebugOut.compareNoCase(L"FALSE") == 0)
64 HttpServletEx::__enableDebugOut = false;
65#endif
66
67 strSQLDriverName = ini.getString(L"DATABASE", L"DRIVER");
68 strSQLConnectionString = ini.getString(L"DATABASE", L"CONNECT");
69
70 __DCL_TRACE3(L"%ls, %ls, %ls\n",
71 strIniFile.data(),
72 strSQLDriverName.data(),
73 strSQLConnectionString.data()
74 );
75
76 __strTemplateDir = ini.getString(L"HTML_TEMPLATE", L"DIR");
77
78 __pSQLConnPool = new SQLConnectionPool(
79 strSQLConnectionString,
80 strSQLDriverName
81 );
82
83 __pHead = new TextTemplate(readTemplate(L"header.html"));
84 __pFoot = new TextTemplate(readTemplate(L"footer.html"));
85 __pViewProduct = new TextTemplate(readTemplate(L"view_product.html"));
86 __pViewShoppingBasket = new TextTemplate(readTemplate(L"view_shopping_basket.html"));
87 __pViewOrder = new TextTemplate(readTemplate(L"view_order.html"));
88 }
89 catch (Exception* e) {
90 __DCL_TRACE1(L"Init Failed %ls\n", e->toStringAll().data());
91 e->destroy();
92
93 onCleanup();
94 }
95}
#define INI_FILENAME
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:399
#define __DCL_TRACE3(fmt, arg1, arg2, arg3)
Definition Object.h:401
virtual void onCleanup() __DCL_THROWS1(Exception *)
String readTemplate(const wchar_t *filename) const __DCL_THROWS1(IOException *)
virtual void destroy()
Definition Exception.cpp:74
String toStringAll() const
Definition Exception.cpp:45
virtual void onInitialize() __DCL_THROWS1(Exception *)

◆ onService()

void EShopServlet::onService ( HttpServletContextEx & ctx)
protectedvirtual

Implements HttpServletEx.

Definition at line 133 of file EShopServlet.cpp.

134{
135 if (!(ctx.methodNo() == HTTP_METHOD_GET
136 || ctx.methodNo() == HTTP_METHOD_POST)
137 ) {
138 // GET나 POST 아니면
139 ctx.setStatusCode(HTTP_STATUS_METHOD_NOT_ALLOWED);
140 return;
141 }
142
143 __DCL_ASSERT(__pSQLConnPool != NULL);
144 __DCL_ASSERT(__pHead != NULL);
145 __DCL_ASSERT(__pFoot != NULL);
146 __DCL_ASSERT(__pViewProduct != NULL);
147
148 SQLConnection* pSQLConn = __pSQLConnPool->getConnection();
149 if (!pSQLConn) {
150 printError(ctx, L"데이터베이스 서버에 연결할 수 없습니다.");
151 return;
152 }
153
154 try {
155 if (pSQLConn->canTransact()) {
156 pSQLConn->startTrans();
157 }
158
159 Writer& out = ctx.writer();
160 EShopSession session(ctx, pSQLConn);
161 switch(session.command()) {
162 case CM_LOGIN: {
163 if (session.login(ctx.__formMap))
164 session.setCommand(CM_VIEW_PRODUCT);
165 else
166 session.setCommand(CM_VIEW_LOGIN_FORM);
167 break;
168 }
169 case CM_LOGOUT: {
170 session.logout();
171 session.setCommand(CM_ABOUT);
172 }
173 }
174
175 // 복사본을 만들어 템플릿의 메크로들을 완성한다.
176
177 printPageHeader(out, session);
178
179 switch(session.command()) {
180 case CM_VIEW_PRODUCT: {
181 onViewProduct(ctx, session);
182 break;
183 }
184 case CM_VIEW_LOGIN_FORM: {
185 printLoginForm(out);
186 break;
187 }
189 onViewShoppingBasket(ctx, session);
190 break;
191 }
192 case CM_ORDER :
193 case CM_VIEW_ORDER: {
194 onViewOrder(ctx, session);
195 break;
196 }
197 case CM_VIEW_QNA: {
198 VisitorBook vb(
201 L"vcm",
202 *this);
203 if (!vb.onVisitorBook(ctx, out, pSQLConn)) {
204 printFile(out, L"notfound.html");
205 }
206 break;
207 }
208 case CM_SALES_REPORT: {
209 if (session.isAdmin())
210 onViewSalesReport(ctx, session);
211 else
212 printLoginForm(out);
213 break;
214 }
216 session.onViewSessions(
217 ctx.__queryMap,
218 out,
221 L"vses",
222 *this
223 );
224 break;
225 }
226 case CM_ABOUT: {
227 printFile(out, L"about.html");
228 break;
229 }
230 default: {
231 printFile(out, L"notfound.html");
232 }
233 }
234
235 if (pSQLConn->inTransaction()) {
236 pSQLConn->commitTrans();
237 }
238 __pSQLConnPool->release(pSQLConn);
239 pSQLConn = NULL;
240
241 TextTemplate tplFooter = *__pFoot;
242 out << tplFooter;
243
244 ctx.setContentType(L"text/html");
245 ctx.setStatusCode(HTTP_STATUS_OK); // HTTP_OK
246 }
247 catch (Exception* _e) {
248 if (pSQLConn) {
249 if (pSQLConn->inTransaction()) {
250 pSQLConn->rollbackTrans();
251 }
252 __pSQLConnPool->release(pSQLConn);
253 }
254 throw _e;
255 }
256}
#define COMMAND_STR
@ CM_VIEW_SHOPPING_BASKET
@ CM_VIEW_PRODUCT
@ CM_ABOUT
@ CM_SESSION_MANAGEMENT
@ CM_LOGIN
@ CM_ORDER
@ CM_VIEW_ORDER
@ CM_VIEW_QNA
@ CM_LOGOUT
@ CM_VIEW_LOGIN_FORM
@ CM_SALES_REPORT
@ HTTP_METHOD_POST
@ HTTP_METHOD_GET
@ HTTP_STATUS_METHOD_NOT_ALLOWED
@ HTTP_STATUS_OK
#define __DCL_ASSERT(expr)
Definition Object.h:394
StringWriter & writer()
bool canTransact() const
void rollbackTrans() __DCL_THROWS1(SQLException *)
bool inTransaction() const
void commitTrans() __DCL_THROWS1(SQLException *)
void startTrans() __DCL_THROWS1(SQLException *)

◆ readTemplate()

String EShopServlet::readTemplate ( const wchar_t * filename) const

Definition at line 394 of file EShopServlet.cpp.

396{
397 String path = __strTemplateDir;
398 if (!path.endsWith(L"/")) {
399 path = path + L"/";
400 }
401 path = path + _filename;
402
403 __DCL_TRACE1(L"readTemplate [%ls]\n", path.data());
404
405 UTF8Decoder dec;
406 return Files::readText(path, dec);
407}
static String readText(const String &_filename) __DCL_THROWS1(IOException *)
Definition Files.cpp:435

The documentation for this class was generated from the following files: