{"id":175,"date":"2011-11-07T05:17:20","date_gmt":"2011-11-07T05:17:20","guid":{"rendered":"http:\/\/hhs1080.hosting.paran.com\/?p=175"},"modified":"2011-11-07T05:17:20","modified_gmt":"2011-11-07T05:17:20","slug":"175","status":"publish","type":"post","link":"https:\/\/blog.goorigo.com\/?p=175","title":{"rendered":"Intercepting requests"},"content":{"rendered":"<h2><a href=\"http:\/\/whiteship.tistory.com\/841\">Intercepting requests \uc608\uc81c<\/a><\/h2>\n<p><a href=\"http:\/\/whiteship.tistory.com\/category\/Spring\/Chapter%2013\">Spring\/Chapter 13 \ud83d\ude15<\/a>2007\/05\/17 12:36<\/p>\n<p>\ucd9c\ucc98 \ud83d\ude15<a href=\"http:\/\/whiteship.tistory.com\/841#footnote_link_841_1\">http:\/\/whiteship.tistory.com\/841#footnote_link_841_1<\/a><\/p>\n<div>\uc6f9\uc694\uccad\uc774 \ub4e4\uc5b4\uc654\uc744\ub54c \uc694\uccad url\uc5d0 \ub530\ub77c\uc11c \ud30c\ub77c\ubbf8\ud130\uac12\uc744 \uc14b\ud305\ud558\uc5ec view Resolver \uae4c\uc9c0 \uc804\ub2ec\ud574\uc8fc\ub294 \ub85c\uc9c1\uc774 \ud544\uc694\ud588\ub2e4.<\/div>\n<div>\uadf8\ub798\uc11c \uac80\uc0c9\uacb0\uacfc \uc544\ub798\uc640 \uac19\uc740 \ud328\ud134\uc73c\ub85c \ucc98\ub9ac\ud560\uc218\uc788\uc744\uac70\uac19\ub2e4.<\/div>\n<div>\uc5b4\ub5a4 \uc11c\ube44\uc2a4\ub97c \ub85c\uadf8\uc778 \ud55c \uc720\uc800\uc5d0\uac8c\ub9cc \uc81c\uacf5\ud558\uace0 \uc2f6\ub2e4\uba74&#8230;request\ub97c \ucc98\ub9ac\ud558\ub294 \uba54\uc18c\ub4dc \ub0b4\uc5d0\uc11c<\/p>\n<\/div>\n<div>\n<div>if (request.getSession.getAttribute(&#8220;user&#8221;) != null)<br \/>\nthrow LoginRequiredException();<\/div>\n<p>\uc774\ub7f0\uc2dd\uc73c\ub85c \uc608\uc678\ub97c \ubc1c\uc0dd\uc2dc\ud0a4\uace0 \uc774 \uc608\uc678\uac00 \ubc1c\uc0dd\ud560 \ub54c\ub9c8\ub2e4 \ub85c\uadf8\uc778 \ud398\uc774\uc9c0\ub85c \uc774\ub3d9 \uc2dc\ud0a4\uac8c \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\ud558\uc9c0\ub9cc \uc800\ub7f0 \ucf54\ub4dc\uac00 \uc5ec\ub7ec \ubd80\ubd84\uc5d0\uc11c \ud544\uc694\ud558\uac8c \ub420 \uac83\uc774\uace0 \uc774\uac83\uc744 AOP\ub97c \uc801\uc6a9\ud558\uc5ec Aspect\ub85c \ube7c\ub0b4\uace0 \uc2f6\uc5b4\uc9c0\ub294 \uac83\uc774 \ub2f9\uc5f0\ud569\ub2c8\ub2e4.<\/p>\n<p>\uadf8\ub7f0\ub370 Spring AOP\uac00 \uc870\uae08 \ubcf5\uc7a1\ud558\uc790\ub098\uc5f4(2.0 \uc5d0\uc11c\ub294?\ub9ce\uc774 \ub098\uc544\uc84c\uc9c0\ub9cc)&#8230;pointcut \uc815\uc758 \ud574\uc918\uc57c \ud558\ub294\ub370 \ubb38\ubc95\ub3c4 \uc880 \ud76c\ud55c\ud558\uace0 advice \uc885\ub958\ub3c4 \ub2e4\uc591\ud55c\ub370 \ud2b9\uc815 \uc778\uc790\ub97c \ubc1b\uc544\uc640\uc57c \ud558\ub294 \ubc29\ubc95\uc744 \uc368\uc57c \ud558\ub2c8\uae4c args \ud45c\ud604\uc2dd\uc744 \uc368\uc57c \ud558\uace0.. \ub4f1\ub4f1 \ubcf5\uc7a1\ud569\ub2c8\ub2e4.<\/p>\n<p>\uadf8\ub798\uc11c.. \uac04\ub2e8\ud558\uac8c HadlerMapping\uacfc HandlerInterceptor \ub97c \uc0ac\uc6a9\ud574\uc11c AOP\ub97c \uc801\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc694\ub140\uc11d\uc744 \uc0ac\uc6a9\ud558\uba74 HttpRequest\uc640 HttpResponse\ub97c \uc778\uc790\ub85c \ubc1b\ub294 Around Advice\ub97c \uc801\uc6a9\ud558\ub294 \uae30\ubd84\uc774 \ub4e4 \uac83\uc785\ub2c8\ub2e4.<\/p>\n<p>1. Handler Mapping \ub4f1\ub85d\ud558\uae30<br \/>\n&#8211; Handler Mapping\uc744 \uc5ec\ub7ec \uac1c \uc0ac\uc6a9\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uadf8\ub9ac\uace0 \uadf8 \ub4e4\uac04\uc758 \uc21c\uc11c\ub97c order \uc18d\uc131\uc744 \uc0ac\uc6a9\ud558\uc5ec \uc9c0\uc815\ud574 \uc904 \uc218 \uc788\uc2b5\ub2c8\ub2e4. viewResolver\ub97c \uc5ec\ub7ec \uac1c \ub4f1\ub85d\ud558\ub294 \uac70\ub791 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<div>? ? &lt;bean id=&#8221;handlerMapping&#8221;&gt;<br \/>\n&lt;property name=&#8221;order&#8221; value=&#8221;2&#8243; \/&gt;<br \/>\n&lt;\/bean&gt;<\/div>\n<p>\uae30\uc874\uc5d0 \uc0ac\uc6a9\ud558\ub358 HandlerMapping\uc740 BeanNameUrlHandlerMapping\uc73c\ub85c \uc554\ubb35\uc801\uc73c\ub85c<sup><a id=\"footnote_link_841_1\" href=\"http:\/\/whiteship.tistory.com\/841#footnote_841_1\">1<\/a><\/sup>?\uc0ac\uc6a9\ud558\uace0 \uc788\uc5c8\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\uc774 \ub140\uc11d\uc744 \uc704\uc5d0 \ubcf4\uc2dc\ub2e4\uc2dc\ud53c \uba85\uc2dc\uc801\uc73c\ub85c \ud45c\uae30\ud574 \uc8fc\uace0 \uc21c\uc11c\ub97c \ub450 \ubc88\uc9f8\ub85c \uc9c0\uc815\ud569\ub2c8\ub2e4. \ub2e4\uc74c\uc73c\ub85c\ub294 User\ub97c \uccb4\ud06c\ud574\uc57c \ud560 request\ub97c \ucc98\ub9ac\ud560 HandlerMapping\uc744?\ub4f1\ub85d\ud569\ub2c8\ub2e4.<\/p>\n<div>&lt;bean id=&#8221;userCheckHandlerMapping&#8221;<br \/>\n&gt;<br \/>\n&lt;property name=&#8221;order&#8221; value=&#8221;1&#8243; \/&gt;<br \/>\n&lt;property name=&#8221;interceptors&#8221;&gt;<br \/>\n&lt;list&gt;<br \/>\n&lt;ref bean=&#8221;memberCheckInterceptor&#8221;\/&gt;<br \/>\n&lt;\/list&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;property name=&#8221;mappings&#8221;&gt;<br \/>\n&lt;value&gt;<br \/>\n\/board\/createArticle.html = createArticleController<br \/>\n\/board\/createReply.html = createReplyController<br \/>\n\/createAuction.html = createLPAuctionController<br \/>\n\/auction\/insertAuctionReply.html = insertAuctionReplyController<br \/>\n\/fileUpload.html = uploadFileController<br \/>\n&lt;\/value&gt;<br \/>\n&lt;\/property&gt;<br \/>\n&lt;\/bean&gt;<\/div>\n<p>SimpleUrlHandlerMapping\uc744 \uc0ac\uc6a9\ud558\uc5ec \ub2e4\uc12f\uac1c\uc758 request\ub97c \ucc98\ub9ac\ud560 \uac83\uc785\ub2c8\ub2e4. \uc800 request \ub4e4\uc740 \ubaa8\ub450 memberCheckInterceptor\ub97c \uac70\uccd0\uac00\uac8c \ub418\uc5b4\uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\ub530\ub77c\uc11c \uc774\uc81c memberCheckInterceptor\ub9cc \uad6c\ud604\ud574 \uc8fc\uba74 \uad6c\ud604\uc774 \ub05d\ub0a9\ub2c8\ub2e4.<\/p>\n<p>2. Interceptor \ub9cc\ub4e4\uae30<\/p>\n<div>public class MemberCheckInterceptor extends HandlerInterceptorAdapter {@Override<br \/>\npublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {<br \/>\nif(request.getSession().getAttribute(&#8220;user&#8221;) != null)<br \/>\nreturn true;<br \/>\nelse {<br \/>\nresponse.sendRedirect(&#8220;http:\/\/localhost:8080\/classicMania\/login.html&#8221;);<br \/>\nreturn false;<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<\/div>\n<p>\uc640.. \uac04\ub2e8\ud569\ub2c8\ub2e4. user\ub77c\ub294 \uc774\ub984\uc758 \uac1d\uccb4\uac00 \uc138\uc158\uc5d0 \uc788\uc73c\uba74 \uacc4\uc18d request\ub97c \ucc98\ub9ac\ud558\uace0 \uc544\ub2c8\uba74 login \ud398\uc774\uc9c0\ub85c \ub118\uc5b4\uac00\ub3c4\ub85d \ud569\ub2c8\ub2e4. true\ub294 \uacc4\uc18d \ucc98\ub9ac false\ub294?\ucc98\ub9ac \uc548\ud558\uac8c \ud569\ub2c8\ub2e4. Around Advice\uc5d0\uc11c \ud574\ub2f9 \uba54\uc18c\ub4dc\ub97c \uc2e4\ud589 \ud560\uc9c0 \ub9d0\uc9c0 \uc120\ud0dd\ud560 \uc218 \uc788\uc5c8\ub358 \uac83\uacfc \uc720\uc0ac\ud558\uc9c0 \uc54a\ub098\ud6a8.<\/p>\n<p>3. \uc2e4\ud589<\/p>\n<div>\n<div>(1\/5)?<a href=\"http:\/\/whiteship.tistory.com\/841#\"><img loading=\"lazy\" src=\"http:\/\/whiteship.tistory.com\/image\/gallery\/gallery_prev.gif\" alt=\"PREVIOUS\" width=\"20\" height=\"16\" \/><\/a>?<a href=\"http:\/\/whiteship.tistory.com\/841#\"><img loading=\"lazy\" src=\"http:\/\/whiteship.tistory.com\/image\/gallery\/gallery_enlarge.gif\" alt=\"ZOOM\" width=\"70\" height=\"19\" \/><\/a>?<a href=\"http:\/\/whiteship.tistory.com\/841#\"><img loading=\"lazy\" src=\"http:\/\/whiteship.tistory.com\/image\/gallery\/gallery_next.gif\" alt=\"NEXT\" width=\"20\" height=\"16\" \/><\/a><\/div>\n<p><img loading=\"lazy\" src=\"http:\/\/cfs3.tistory.com\/upload_control\/download.blog?fhandle=YmxvZzgxNDhAZnMzLnRpc3RvcnkuY29tOi9hdHRhY2gvMS8xODcuanBn\" alt=\"\" width=\"400\" height=\"206\" \/><\/p>\n<\/div>\n<p>\ub85c\uadf8\uc778 \uc548 \ud55c \uc0c1\ud0dc\uc5d0\uc11c \ud30c\uc77c \uc5c5\ub85c\ub4dc \ud398\uc774\uc9c0\ub85c \uac00\ub824\uace0 \ud558\uba74 =&gt; \ub85c\uadf8\uc778 \ud398\uc774\uc9c0\ub85c \uc774\ub3d9<br \/>\n\ub85c\uadf8\uc778 \ud55c \uc0c1\ud0dc\ub77c\uc5d0\uc11c \ud30c\uc77c \uc5c5\ub85c\ub4dc \ud398\uc774\uc9c0\ub85c \uac00\ub824\uace0 \ud558\uba74 =&gt; \ud30c\uc77c \uc5c5\ub85c\ub4dc \ud398\uc774\uc9c0 \uc694\uccad\uc744 \ucc98\ub9ac\ud569\ub2c8\ub2e4.<\/p>\n<div>\n<ol>\n<li>\uba85\uc2dc\uc801\uc73c\ub85c handleMapping\uc744 \ub4f1\ub85d\ud558\uc9c0 \uc54a\uc73c\uba74 DispacherSevlet\uc774 \uc54c\uc544\uc11c \uc774\ub140\uc11d\uc744 \ub9cc\ub4e4\uc5b4\uc11c \uc0ac\uc6a9\ud558\uae30 \ub584\ubb38\uc774\ube48\ub2e4.?<a href=\"http:\/\/whiteship.tistory.com\/841#footnote_link_841_1\">[\ubcf8\ubb38\uc73c\ub85c]<\/a><\/li>\n<\/ol>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Intercepting requests \uc608\uc81c Spring\/Chapter 13 \ud83d\ude152007\/05\/17 12:36 \ucd9c\ucc98 \ud83d\ude15http:\/\/whiteship.tistory.com\/841#footnote_link_841_1 \uc6f9\uc694\uccad\uc774 \ub4e4\uc5b4\uc654\uc744\ub54c \uc694\uccad url\uc5d0 \ub530\ub77c\uc11c \ud30c\ub77c\ubbf8\ud130\uac12\uc744 \uc14b\ud305\ud558\uc5ec view Resolver \uae4c\uc9c0 \uc804\ub2ec\ud574\uc8fc\ub294 \ub85c\uc9c1\uc774 \ud544\uc694\ud588\ub2e4. \uadf8\ub798\uc11c \uac80\uc0c9\uacb0\uacfc \uc544\ub798\uc640 \uac19\uc740 \ud328\ud134\uc73c\ub85c \ucc98\ub9ac\ud560\uc218\uc788\uc744\uac70\uac19\ub2e4. \uc5b4\ub5a4 \uc11c\ube44\uc2a4\ub97c&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts\/175"}],"collection":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=175"}],"version-history":[{"count":0,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=\/wp\/v2\/posts\/175\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.goorigo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}