U E D R , A S I H C RSS

Project Prometheus/Cook Book


1. Python ์—์„œ์˜ ํ•œ๊ธ€ ์‚ฌ์šฉ

2. java regular expression

~cpp 
String find = "(http|https)+://([^ \t\n<>()"]+)" 	// ํŒจํ„ด ์„ค์ •
Pattern pattern = Pattern.compile( find );		// ํŒจํ„ด ์ปดํŒŒ์ผ
Matcher matcher = pattern.matcher( html );		// ํŒจํ„ด ์ฐพ๊ธฐ
matcher.group(1);					// ์‚ฌ์šฉ (๊ต์ฒดํ•˜๊ฑฐ๋‚˜ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ํ• ์ˆ˜ ์žˆ์Œ)

regular expression ํŒจํ„ด์„ ์ •์˜ํ•˜๊ธฐ ์œ„ํ•ด์„œ Komodo ๋ฅผ ์ด์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ๋˜๋Š” Seminar:TddRegularExpression์„ ์‹œ๋„ํ•ด๋ณด๋Š” ๊ฒƒ๋„ ์ข‹๋‹ค. 1002 ๋Š” Python Interpreter ๋ฅผ ์ด์šฉ, ํ‘œํ˜„์‹์„ ์ฐพ์•„๋ƒˆ๋‹ค.

3. servlet ์—์„œ ํ•œ๊ธ€ ์ถœ๋ ฅ

~cpp setContentType ์—์„œ charset ์— euc-kr ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.
~cpp 
public class HelloWorldApp extends HttpServlet {
    protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
        httpServletResponse.setContentType("text/html; charset=euc-kr");

        PrintWriter out = httpServletResponse.getWriter();

        out.println("<HTML> " +
                "ํ•œ๊ธ€ ํ…Œ์ŠคํŠธ..." +
                "</HTML>");

    }
}

4. ์“ฐ๊ธฐ ์ข‹์€ ํƒ€์ด๋จธ


๋ฌผ๋ฆฌ์ ์ธ ๋ชจ๋ž˜์‹œ๊ณ„๊ฐ€ ์—†์„ ๊ฒฝ์šฐ ์‚ฌ์šฉํ• ๋งŒํ•œ ๋ชจ๋ž˜์‹œ๊ณ„ ์†Œํ”„ํŠธ์›จ์–ด
  • ๋ฉ€ํ‹ฐ ํƒ€์ด๋จธ http://www.programming.de/cpp/timer.zip
    ๋™์‹œ์— 10๊ฐœ์˜ ํƒ€์ด๋จธ ์„ค์ • ๊ฐ€๋Šฅ. ์นด์šดํŠธ ๋‹ค์šด, ์นด์šดํŠธ ์—… ๊ฐ€๋Šฅ. ๋ฉˆ์ท„๋‹ค๊ฐ€ ํ”„๋กœ๊ทธ๋žจ์„ ๋‹ค์‹œ ์‹œ์ž‘ํ•  ๋•Œ ์ง€๋‚œ ์‹œ๊ฐ„์—์„œ resume ๊ฐ€๋Šฅ. ๋‹จ, ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜ ๋ฒ„๊ทธ๊ฐ€ ์žˆ๋‹ค.
  • ๋งˆ์ดํฌ๋กœ ์—๊ทธ ํƒ€์ด๋จธ http://users.informatik.fh-hamburg.de/~rohde_i/eggtimer/mr-egg-z.zip
    ๋‹จ์ˆœํ•˜์ง€๋งŒ ๋งค์šฐ ํŽธ๋ฆฌํ•œ ํƒ€์ด๋จธ. ํƒœ์Šคํฌ ๋ฐ”์—์„œ ๋‚จ์€ ์‹œ๊ฐ„์„ ํ™•์ธ ๊ฐ€๋Šฅ

6. HTTP Protocol

7. HTTP GET, POST ๋„˜๊ธฐ๊ธฐ

Python ์—์„œ๋Š” urllib ์™€ httplib ๋ฅผ ์ด์šฉํ•œ๋‹ค. Python document ์˜ httplib - examples ๋ฅผ ์ฐธ์กฐํ•˜๋ฉด GET ์˜ ์˜ˆ์™€ POST ์˜ ์˜ˆ๊ฐ€ ๋‚˜์˜จ๋‹ค.

Java ์—์„œ๋Š” HttpURLConnection ์„ ์ด์šฉํ•œ๋‹ค. ๊ด€๋ จ ์ฝ”๋“œ๋Š” http://www.javafaq.nu/tips/servlets/index.shtml ๋ฅผ ์ฐธ์กฐ.
~cpp 
Connection.setRequestProperty("Content-Type", "text/plain");

8. HttpUrlConnection ์—์„œ GET,POST ๋„˜๊ธธ๋•Œ ์ฃผ์˜์‚ฌํ•ญ

Python ์—์„œ์˜ string.urlencode ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ GET,POST ๋กœ ๋„˜๊ธฐ๊ธฐ ์ „ ํŒŒ๋ผ๋ฉ”ํ„ฐ์— ๋Œ€ํ•ด URL Encoding ์ด ํ•„์š”ํ•˜๋‹ค. URLEncoder ๋ผ๋Š” ํด๋ž˜์Šค๋ฅผ ์ด์šฉํ•˜๋ฉด ๋œ๋‹ค.

~cpp 
import java.net.URLEncoder;
.
.
.
URLEncoder.encode (paramString, "UTF-8");

9. GET, POST ์ธ์ž์˜ ๋‚ด์šฉ์ค‘ ํ•œ๊ธ€์„ ๋ฐ›์„๋•Œ ์ฃผ์˜ ์‚ฌํ•ญ

~cpp 
protected void service(
	HttpServletRequest request,
	HttpServletResponse response)
	throws ServletException, IOException {
	//super.service(request, response);
	response.setContentType("text/html; charset=euc-kr");
	request.setCharacterEncoding("KSC5601");

	String serviceName = (String) request.getParameter("service");
getParameter ๊ฐ€ ํ˜ธ์ถœ๋˜๊ธฐ ์ „์— request์˜ ์ธ์ฝ”๋”ฉ์ด ์„ธํŒ…๋˜์–ด์•ผ ํ•œ๋‹ค. ํ˜„์žฌ Prometheus์˜ Controller์˜ ๊ฒฝ์šฐ service ์˜ ๋ช…์„ ๋ณด๊ณ  ๊ฐ๊ฐ์˜ ์„œ๋น„์Šค์—๊ฒŒ ์‹คํ–‰ ๊ถŒํ•œ์„ ๋„˜๊ธฐ๋Š”๋ฐ, ๊ฐ€์žฅ ์ฒ˜์Œ์— request์˜ characterEncoding ์„ ์„ธํŒ…ํ•ด์•ผ ํ•œ๋‹ค. ์ฐจํ›„ JSP/Servlet ์ปจํ…Œ์ด๋„ˆ๋“ค์˜ ์—…๊ทธ๋ ˆ์ด๋“œ ๋˜์–ด์•ผ ํ•  ๋‚ด์šฉ์œผ๋กœ ์ƒ๊ฐ๋จ ์ž์„ธํ•œ ๋‚ด์šฉ์€ http://javaservice.net/~java/bbs/read.cgi?m=appserver&b=engine&c=r_p&n=957572615 ์ฐธ๊ณ 

10. HTTP Cookie ๋„˜๊ธฐ๊ธฐ

Cookie ๋Š” ๋ณด๋‚ด๋Š”์ชฝ HTTP Protocol ์˜ Header ๋ถ€๋ถ„์— 'Cookie: a=1; b=2; c=3' ์‹์œผ๋กœ ์“ฐ์—ฌ์ง„๋‹ค.
๋ฐ›๋Š”์ชฝ์—์„œ๋Š” "Set-Cookie: a=10" ... ์‹์œผ๋กœ ๋‚ ๋ผ์˜จ๋‹ค.

๋‹ค์Œ์€ Python ์„ ์ด์šฉ, Cookie, GET/POST ๋ณ€์ˆ˜๋“ค์„ ์ฑ„์šด๋’ค ํ•ด๋‹น ์‚ฌ์ดํŠธ์˜ ๊ฒฐ๊ณผ๋ฌผ์„ ์ธ์‡„ํ•˜๋Š” ์†Œ์Šค.
cookieSend.py

11. Resin

12. default root ์ •์˜ & ํฌํŠธ ์ˆ˜์ •

root ๋””๋ ‰ํ† ๋ฆฌ๋Š” <doc-dir> ํƒœ๊ทธ๋ถ€๋ถ„์„, port ๋Š” <http port='____'> ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ•œ๋‹ค.
๋‘˜ ๋‹ค <http-server> ํƒœ๊ทธ ํ•˜์œ„์— ์žˆ๋‹ค.

13. default utility

resin ์—์„œ ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ๋ณ€๊ฒฝํ•˜๊ฑฐ๋‚˜ resin ์ด ์‹คํ–‰๋ ๋•Œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ƒ๊ธฐ๋Š” ๋””๋ ‰ํ† ๋ฆฌ๋“ค(example ๋“ฑ)์ด ์žˆ๋‹ค.
์ด๋Š” <web-app> ๋ผ๋Š” ํƒœ๊ทธ๋กœ ์ •์˜๋˜์–ด์žˆ๋‹ค. ์‚ญ์ œํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด '/' ์™ธ์˜ ๋‹ค๋ฅธ web-app์— ๋“ฑ๋ก๋œ ๊ฒƒ๋“ค์„ ์‚ญ์ œํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

14. Resin ์—์„œ DB POOL Setting

resin.conf ์— ๋‹ค์Œ์„ ์…‹ํŒ…ํ•ด์ค€๋‹ค. (<caucho.com> ํƒœ๊ทธ ์•ˆ์ชฝ์— ์‚ฝ์ž…)
~cpp 
<resource-ref>
  <res-ref-name>jdbc/'reference ์ด๋ฆ„'</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <init-param driver-name="org.gjt.mm.mysql.Driver ์‹์œผ๋กœ ๋“œ๋ผ์ด๋ฒ„ ์ด๋ฆ„"/>
  <init-param url="jdbc:mysql://์„œ๋ฒ„์ฃผ์†Œ:์„œ๋ฒ„IP/reference ์ด๋ฆ„"/>
  <init-param user="DB ์‚ฌ์šฉ์ž ID"/>
  <init-param password="DB ์‚ฌ์šฉ์ž Password"/>
  <init-param max-connections="20"/>
  <init-param enable-transaction="false"/>
</resource-ref>

15. Resin ์„ NT,2000 ์˜ Service ๋กœ ๋“ฑ๋ก

resin ์„ ์‹คํ–‰ํ•  ๋•Œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‹คํ–‰
~cpp 
httpd -install
๊ทธ๋ฆฌ๊ณ , ์ œ์–ดํŒ-๊ด€๋ฆฌ๋„๊ตฌ-์„œ๋น„์Šค ์—์„œ resin web server ์„œ๋น„์Šค๋ฅผ ์‹œ์ž‘ ์‹œํ‚จ๋‹ค.

16. JNDI๋กœ resin์—์„œ JDBC ์ฝ”๋“œ ์ž‘์„ฑ ์ผ๋ฐ˜์ ์ธ ์ˆœ์„œ

  1. Context - environment ์–ป๊ณ 
  2. environment ๋ณ€์ˆ˜๋ฅผ ๊ทผ๊ฑฐ๋กœ Data Source ์–ป๊ณ 
  3. Data Source ๋ฅผ ๊ทผ๊ฑฐ๋กœ Connection ์–ป๊ณ  Connection ์„ ์ด์šฉ.
  4. Connection ๊ฐ์ฒด๋กœ Statement ๊ฐ์ฒด๋ฅผ ์–ป๊ณ 
  5. Statement ๊ฐ์ฒด๋กœ SQL ์ˆ˜ํ–‰. ResultSet ๊ฐ์ฒด ์–ป๊ธฐ.
  6. ResultSet ๊ฐ์ฒด ์ด์šฉํ•˜๊ธฐ.


~cpp 
        Context env = ( Context )( new InitialContext().lookup( "java:comp/env" ) );
        DataSource source = ( DataSource )( env.lookup( "jdbc/zeropage" ) );
        conn = source.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("......... some query statement ...................");
        while (rs.next()) {
                rs.getString(1);   // ์ˆœ์„œ์— ๋”ฐ๋ผ.. ์ฒซ๋ฒˆ์งธ : 1๋ฒˆ... 
        .
        .
        .
        }

ZeroPageServer ์›น ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“ค์–ด์„œ ๋ฏธ๋ฆฌ ์ฝ์–ด๋ณผ ์†Œ์Šค๋ฅผ ์ฃผ์‹  ์„ ์šฐํ˜•์—๊ฒŒ ๊ฐ์‚ฌ๋“œ๋ฆฌ๋ฉฐ~! ํ˜• ๋•ํƒ์—
resin ์…‹ํŒ… & JDBC ์ ‘๊ทผ ๋ฐฉ๋ฒ• ํ•œ๋ฐฉ์— ๋˜์—ˆ์–ด์—ฌ..~ -- PP ํŒ€ ์ผ๋™

17. ETC

18. ZeroPageServer ์—์„œ UnitTest

ZeroPageServer ์— ๋ฆด๋ฆฌ์ฆˆ ํ•œ๋’ค UnitTest ํ•˜๊ธฐ.

build_zpLocal.xml ( .../Prometheus/bin ์— ๋นŒ๋“œํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ ) ๋ฅผ ์ด์šฉ, ์‹คํ–‰๋˜๋Š” ์œ„์น˜์™€ ๊ด€๊ณ„์—†๋Š” ๊ณณ์— ์ผ๋‹จ ์ปดํŒŒ์ผ์„ ํ•˜๊ณ , ํ…Œ์ŠคํŠธ๋ฅผ ๋Œ๋ฆฌ๊ฒŒ ํ•œ๋‹ค.
~cpp 
.../Prometheus$ ant -buildfile build_zpLocal.xml
.../Prometheus$ java -cp "$CLASSPATH:./bin" junit.textui.TestRunner org.zeropage.prometheus.test.AllAllTests
.........................................
...............................
Time: 189.444

OK (72 tests)
  • Ant ์—์„œ JUnit ์„ ์‹คํ–‰์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค. ์ถ”ํ›„ ์•Œ์•„๋ณผ๊ฒƒ.~!

19. ์•ˆ์ „ํ•˜๊ฒŒ UI ์ˆ˜์ •ํ•˜๊ธฐ

Ant ๋ฅผ ์ด์šฉํ•˜๋ฉด ๋œ๋‹ค. Ant ์˜ ๊ฒฝ์šฐ ์ปดํŒŒ์ผ & ๋ฐฐํฌํ• ๋•Œ ์ˆ˜์ •๋œ ํ™”์ผ๋งŒ ๋ฎ์–ด์“ฐ๊ธฐ๋ฅผ ํ•œ๋‹ค. CVS & Ant ์กฐํ•ฉ์ด๋ฉด ํ•ด๊ฒฐ์ด๋ผ ์ƒ๊ฐ.


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:24:05
Processing time 0.0129 sec