DCL 4.0
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 m_nMaxContentLength
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 99 of file EShopServlet.cpp.

100{
101 if (m_pSQLConnPool) {
102 delete m_pSQLConnPool;
103 m_pSQLConnPool = NULL;
104 }
105
106 if (m_pHead) {
107 delete m_pHead;
108 m_pHead = NULL;
109 }
110
111 if (m_pFoot) {
112 delete m_pFoot;
113 m_pFoot = NULL;
114 }
115
116 if (m_pViewOrder) {
117 delete m_pViewOrder;
118 m_pViewOrder = NULL;
119 }
120
121 if (m_pViewProduct) {
122 delete m_pViewProduct;
123 m_pViewProduct = NULL;
124 }
125
126 if (m_pViewShoppingBasket) {
127 delete m_pViewShoppingBasket;
128 m_pViewShoppingBasket = NULL;
129 }
130
132 __DCL_TRACE0(L"onCleanup()\n");
133}
#define NULL
Definition Config.h:340
#define __DCL_TRACE0(psz)
Definition Object.h:375
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#if __DCL_WINDOWS
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 {
52 __DCL_TRACE1(L"not found : %ls\n", strIniFile.data());
53 return;
54 }
55
56 String strSQLDriverName;
57 String strSQLConnectionString;
58
59 try
60 {
61 IniFile ini(strIniFile);
62
63#ifdef __DCL_DEBUG
64 String strEnableDebugOut = ini.getString(L"DEBUG", L"ENABLE_DEBUG_OUT");
65 if (strEnableDebugOut.compareNoCase(L"FALSE") == 0)
66 HttpServletEx::m_bEnableDebugOut = false;
67#endif
68
69 strSQLDriverName = ini.getString(L"DATABASE", L"DRIVER");
70 strSQLConnectionString = ini.getString(L"DATABASE", L"CONNECT");
71
72 __DCL_TRACE3(L"%ls, %ls, %ls\n",
73 strIniFile.data(),
74 strSQLDriverName.data(),
75 strSQLConnectionString.data()
76 );
77
78 __strTemplateDir = ini.getString(L"HTML_TEMPLATE", L"DIR");
79
80 m_pSQLConnPool = new SQLConnectionPool(
81 strSQLConnectionString,
82 strSQLDriverName
83 );
84
85 m_pHead = new TextTemplate(readTemplate(L"header.html"));
86 m_pFoot = new TextTemplate(readTemplate(L"footer.html"));
87 m_pViewProduct = new TextTemplate(readTemplate(L"view_product.html"));
88 m_pViewShoppingBasket = new TextTemplate(readTemplate(L"view_shopping_basket.html"));
89 m_pViewOrder = new TextTemplate(readTemplate(L"view_order.html"));
90 }
91 catch (Exception* e) {
92 __DCL_TRACE1(L"Init Failed %ls\n", e->toStringAll().data());
93 e->destroy();
94
95 onCleanup();
96 }
97}
#define INI_FILENAME
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:376
#define __DCL_TRACE3(fmt, arg1, arg2, arg3)
Definition Object.h:378
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 136 of file EShopServlet.cpp.

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

◆ readTemplate()

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

Definition at line 404 of file EShopServlet.cpp.

406{
407 String path = __strTemplateDir;
408 if (!path.endsWith(L"/")) {
409 path = path + L"/";
410 }
411 path = path + _filename;
412
413 __DCL_TRACE1(L"readTemplate [%ls]\n", path.data());
414
415 UTF8Decoder dec;
416 return Files::readText(path, dec);
417}
static String readText(const String &_filename) __DCL_THROWS1(IOException *)
Definition Files.cpp:437

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