ãJava ã«ãã RESTful ã·ã¹ãã æ§ç¯ã ãè¶ åå¼·ã«ãªã!!
Javaã«ããRESTfulã·ã¹ãã æ§ç¯
- ä½è : Bill Burke,arton,è éè¯äº
- åºç社/ã¡ã¼ã«ã¼: ãªã©ã¤ãªã¼ã¸ã£ãã³
- çºå£²æ¥: 2010/08/23
- ã¡ãã£ã¢: 大åæ¬
- è³¼å ¥: 28人 ã¯ãªãã¯: 804å
- ãã®ååãå«ãããã° (40件) ãè¦ã
ããï¼æ¬å½ã«ã¿ã¤ãã«å¿ä½ç¡ããªãã£ã¦æãæ¬ã§ããï¼
ããï¼ã¿ã¤ãã«ã«å½ãã¯ç¡ããã ãã©ï¼ããã 㨠REST ã«èå³ç¡ã人ã¯æã«åããªãã ãããªãã¨æã£ã¦ï¼ããã¯åãå¿ä½ç¡ãå
容ãªã®ã§ï¼ãã³ãã¿ããªèªãã¨è¯ãã¨æãï¼
ç°¡åã«èª¬æããã¨ï¼Java 㧠REST ãæ±ãããã« JAX-RS ã¨ãã API ããããã ãã©( JSR311 )ï¼ãã®ã¨ãã¹ãã¼ãã°ã«ã¼ãã®ä¸äººã§ããï¼ããã«ãã®å®è£ ã§ãã RESTEasy ã®ä½è ãæ¸ãã¦ããæ¬ã§ãï¼
ã§ï¼ãã®äººã¯å ã SOAP ã¨ãã®ã©ã¡ããã¨ãã㨠Fat ãªä»æ§å¤§å¥½ãã£ãã ã£ãã®ã§ï¼ãã®æ¬ã«ã¯è²ã ãªå´é¢ãããï¼
- (SOAP ãªã©ãããªããªã«ãã£ã¦ãã人ã®æè¦ãå«ã)REST èªä½ã®èª¬æ
- (JSR311 ã®ã¨ãã¹ãã¼ãã°ã«ã¼ãã®ä¸äººã¨ãã¦)Java ã®ã³ãã¥ããã£ã® REST ã«å¯¾ããä¸ã¤ã®èãæ¹
- (ä¸è¨ã¨åãã)JAX-RS ã®ä»æ§ã¨ä½¿ãæ¹
- (RESTEasy ã®ã³ããã¿ã¨ãã¦)ææ°ã® Java ä»æ§ããµãã ãã«ä½¿ã£ããã¬ã¼ã ã¯ã¼ã¯ã®ä½ãæ¹
ãªã©ãªã©ãRESTful ã«åã¾ããªãå 容ã§ã®ãã·ãªã ï¼
ããã« 1 é¨ã¨ 2 é¨ã«ãããã¦ãã¦ï¼1 é¨ã§ã¯ã©ã¡ããã¨è¨ãã¨ä»æ§ã«éããç½®ãã説æï¼ 2 é¨ã§ã¯ 1 é¨ã§æççã«èª¬æãããµã³ãã«ã³ã¼ãããã£ã¨æ·±ã説æãã¦ããï¼
åã㦠JAX-RS ã REST ã触ã人㯠ï¼é¨ãèªã¿ï¼å®éã«ã³ã¼ãã£ã³ã°ããããã«ãªã£ãã ããã« 2 é¨ã«ç´°ããªæ
å ±ããã(ã¢ããªã±ã¼ã·ã§ã³ã³ã³ããæ¯ã«ã©ã®ããã«ãããããã®ããå«ãã¦)ã®ã§ãã³ãã«ããä¸å㧠RESTful ãªã¢ããªã±ã¼ã·ã§ã³ãä½ããï¼
ã¾ãï¼DI ãã¼ã å¾ã®ãããå½ããåã«ãªã£ã Java ã§ææ°ã®ä»æ§ãé§ä½¿ãã¦æ¸ããããã¬ã¼ã ã¯ã¼ã¯ã¯æ®æ®µã®ã¢ããªã±ã¼ã·ã§ã³ã®è¨è¨ã«ãåã訳ã«ç«ã¤ï¼
ãã¨ãã°åãæåããä¸ä¾ãä¸ããã¨
@GET
ã¨ããã¢ããã¼ã·ã§ã³ãããï¼
ããã¯ï¼æå®ããã¢ãã¬ã¹ã« GET ã¡ã½ããã§ã¢ã¯ã»ã¹ããã£ãæã«å¼ã°ããããã«ããã¢ããã¼ã·ã§ã³ãªãã ãã©ï¼å®è£
ã§ã¯ã¡ã¿ã¢ããã¼ã·ã§ã³ã¨ããå½¢ãåã£ã¦ããï¼
ã©ãããäºãã¨è¨ãã¨ãã® GET ã¨ããã¢ããã¼ã·ã§ã³ããã¬ã¼ã ã¯ã¼ã¯ããã®ã¾ã¾ä½¿ãã®ã§ã¯ç¡ã
ããã«ããã« HttpMethod ã¨ããã¢ããã¼ã·ã§ã³ãä»ãã¦ããï¼
â¦â¦ @HttpMethod(HttpMethod.GET) public @interface GET{ } â¦â¦
ã¿ããã«ãªã£ã¦ãã®ã§ï¼
æ°ããç¬èªãªã¡ã½ããã追å ããæã«ãã¬ã¼ã ã¯ã¼ã¯ã®ã½ã¼ã¹ã³ã¼ãã«æãå
¥ããäºãªã
â¦â¦ @HttpMethod("LOCK") public @interface LOCK{ } â¦â¦
ã¿ããã«è¿½å åºæ¥ãï¼
Java ã®èãæ¹ã§å¤§äºãªåã®å
åºãã¨æ¡å¼µæ§ã®ä¸¡æ¹ãæããããã¯ããã¯ã§è¶
è¯ããªãã£ã¦æã£ãï¼
ä»ã«ãåå¤æ㧠valueOf() ã¡ã½ããã使ãã¨ããã¨ãï¼è¶
ã¯ã¼ã«ã ã¨æã£ã(ããã ãã§å¯¾å¿ã§ããã©ããã¼ã¯ã©ã¹ãå¢ãããï¼enum ãªã©ã«ã対å¿ã§ãããï¼ç¬èªã¯ã©ã¹ã§ããã®ã¡ã½ããä½ãã°è¯ãã ãã ã)
ãããã Java5 以éã®ãã¯ããã¯ããµãã ãã«å«ã¾ãã¦ã㦠REST é¢ä¿ç¡ãã¡ãã£ã¡ãã£åå¼·ã«ãªãï¼
ã¾ãï¼REST ã®è¨è¨ã§ãä»æ§ã ãã§ã¯å¯¾å¿åºæ¥ãªãäºã«ãã¡ããã¨ã©ããã£ã¦èããã°è¯ãããã®ã£ã¦ãï¼
ä¾ãã°ã·ã§ããã³ã°ãµã¤ããä½ãæã«æ³¨æã®ãã£ã³ã»ã«ãã©ããããï¼DELETE ã¡ã½ããã«ãã£ã³ã»ã«ã®æ©è½ããããã³ã°ããã®ã¯æ¬å½ã«ãã¼ã¿ãæ¶ãã®ã§ã¯ãªãã®ã§éãããã¨ã(ä½è
ã®çã¯æ¬æ¸ã«æ¸ããã¦ããã®ã§æ¯éèªãã§ã!!)
ã¾ãï¼JAX-RS ã®ä»æ§ã«ä»ã¯å ¥ã£ã¦ãªãã¦ã¤ã±ã¦ãªãã®ã¯ããããã°å¯¾å¿ã§ãããã©ï¼ã¨ãã¹ãã¼ãã°ã«ã¼ãããããèªèãã¦ããã次ã§ä»æ§ã«å ¥ãã¨æããã¨ããããã£ãäºã¾ã§æ£ç´ã«æ¸ããã¦ããã®ã§åå¼·ã«ãªãï¼
åã¯ãã¬ã¼ã ã¯ã¼ã¯ã使ãã¨ãã«ãã®ãã¬ã¼ã ã¯ã¼ã¯ãç¿å¾ããã®ã«ä¸çªã®è¿éã¯ãã®ãã¬ã¼ã ã¯ã¼ã¯ãã©ããªææ³ã§ä½ãããã®ããç¥ãã®ããä¸çªã ã¨æããã ãã©ï¼ãããå ¨é¨æ¥æ¬èªã§èª¬æããã¦ãã£ã¦ããã®ã¯åã幸ãã ã¨æãï¼ããã¯ã½ã¼ã¹ã³ã¼ãèªã¿è¾¼ãã ã API ãè¦ããããã°ããããããããªããã©ï¼ã³ã¼ãã®è¡éã«ããææ³ãªã©ãæ¸ããã¦ãã¦é¢ç½ããåå¼·ã«ãªãï¼
ã¨ããããã§ï¼REST ã«èå³ã®ãã人ã¯ãã¡ããï¼èå³ãç¡ãã¦ã Java5 以éã§ã¢ããªã±ã¼ã·ã§ã³æ¸ãã¦ãã人ã¯æ¯éèªãã¹ãã ã¨æãã¾ãï¼
ãã¸ã§é¢ç½ãã®ã§!!
åãä¿¡ç¨åºæ¥ãªã人㯠arton ããã®æç« ãèªãã§ã¿ã¦ãã ãã!!
http://www.artonx.org/diary/20100810.html#p01
ãã³ãé¢ç½ããè¯æ¸ãªã®ã§ã!!