[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[jfriends-ml 13536] 「 Jav による RESTful システム構築」を読む会第 2 回議事録



皆様
第2回議事録をお送りします。
よろしくお願いします。
根本



2011”N06ŒŽ25“ú “y—j“ú

ŽQ‰ÁŽÒ ‚‹´(“O)@–å˜e@‚‹´(’q)@“V–ì@¼‰i@ª–{@‘ºŽR@ŠâŽº@‹g–{@÷ˆä@¡ˆä@‰““¡@ª–{(‹L)

P33 ŒÚ‹q‚̍XV@‚æ‚è
 3.1.3 JAX-RS‚ÆJavaƒCƒ“ƒ^[ƒtƒFƒCƒX

P37 ‰º‹L•”•ª‚́u‚·‚ׂĂ̍Ēè‹`v‚Ƃ͉½‚Ì•W€‚ÅŒˆ‚Ü‚Á‚½‚±‚Æ‚È‚Ì‚©?
JAX-RSƒŒƒCƒ„[‚©?
JAX-RS‚ÌŽd—l‚ðŠm”FAƒNƒ‰ƒX’PˆÊ‚Å•K—v‚¾‚©‚ç‚©?
----------------------------------------------------
 public class CustomerResourceService implements CustomerResource {@POST
@Consumes("application/xml;charset=utf-8") public Response createCustomer(InputStream is) {
... ŽÀ‘• ...
}
‚±‚Ì—á‚ł́A 1‚‚̓Á’è‚̃ƒ\ƒbƒh‚ɑ΂µ‚ăCƒ“ƒ^[ƒtƒFƒCƒX‚Å’è‹`‚³‚ꂽƒƒ^ƒf[ƒ^‚ðƒI[ƒoƒ‰ƒCƒh ‚·‚邱‚Æ‚É‚È‚éBƒƒ\ƒbƒh‚ɑ΂·‚郁ƒ^ƒf[ƒ^‚ðƒI[ƒoƒ‰ƒCƒh‚·‚éê‡A•ÏX‘Ώۂª 1‚‚¾‚¯‚¾‚Æ‚µ‚Ä‚àA ‚»‚̃ƒ\ƒbƒh‚ɑ΂·‚é‚·‚ׂẴAƒmƒe[ƒVƒ‡ƒ“ƒƒ^ƒf[ƒ^‚̍Ďw’肪•K—v‚É‚È‚éB
----------------------------------------------------

P42 ‰º‹Lweb.xml‚ɉ—‚¢‚Ä
com.jaxrs.vendor.JaxrsVendorServlet ‚É‚æ‚Á‚Äinitparam‚ªˆá‚¤‚à‚Ì‚É‚È‚é‚Í‚¸
----------------------------------------------------
<?xml version="1.0"?>
 <web-app>
  <display-name>Archetype Created Web Application</display-name> <servlet>
  <servlet-name>Rest</servlet-name>
  <servlet-class>
    com.jaxrs.vendor.JaxrsVendorServlet   <-- ƒT[ƒuƒŒƒbƒg’è‹`
  </servlet-class>
  <init-param>
   <param-name>javax.ws.rs.Application</param-name> <param-value> <--‚±‚Ì–¼‘O‚ÍJAX-RS‚É‚æ‚Á‚ÄŒˆ‚Ü‚Á‚Ä‚¢‚é
   com.restfully.shop.services.ShoppingApplication </param-value>
  </init-param>
  </servlet>
  <servlet-mapping>
   <servlet-name>Rest</servlet-name>     <-- ƒT[ƒuƒŒƒbƒgŽÀ‘•
   <url-pattern>/*</url-pattern>
  </servlet-mapping>
 </web-app>
----------------------------------------------------

3Í‚É‘±‚¢‚āA15Í‚É”ò‚ñ‚Å“Ç‚Þ‚±‚Æ‚Æ‚·‚éB
15Í‚́A3Í‚ɑ΂·‚éƒnƒ“ƒYƒIƒ“‚Ì‚½‚߁B

Jetty‚ÍMaven‚ªƒTƒ|[ƒg‚·‚é‚Ì‚©
pom.xml ‚Í ant‚Ìbuild.xml ‚Æ“¯‚¶‚à‚Ì
pom.xml ‚ÍŽg‚¢‚É‚­‚¢Apom.xml‚ª‚Ü‚Æ‚à‚ɏ‘‚¯‚él‚ª‚¢‚È‚¢

p221 pom.xml‚Ì—á  Legacy layout‚Ƃ͉½‚©?
----------------------------------------------------
<name/>
 <description/><repositories>
  <repository>
   <id>java.net</id>
   <url>http://download.java.net/maven/1</url>
   <layout>legacy</layout>      <--  legacyƒŒƒCƒAƒEƒg‚Ƃ͉½‚©
  </repository>
  <repository>
   <id>maven repo</id>
   <name>maven repo</name>
   <url>http://repo1.maven.org/maven2/</url>
  </repository>
   <!-- For resteasy -->
  <repository>
   <id>jboss</id>
   <name>jboss repo</name>
   <url>http://repository.jboss.org/maven2</url>
 </repository>
</repositories>
----------------------------------------------------

4Í HTTPƒƒ\ƒbƒh‚ÆURIƒ}ƒbƒ`ƒ“ƒO
4.1 HTTPƒƒ\ƒbƒh‚̃oƒCƒ“ƒh
JAX-RS‚Ì•W€ƒƒ^ƒAƒmƒe[ƒVƒ‡ƒ“
 @javax.ws.rs.GET
 @javax.ws.rs.PUT
 @javax.ws.rs.POST
 @javax.ws.rs.DELETE
 @javax.ws.rs.HEAD
ƒƒ^ƒAƒmƒe[ƒVƒ‡ƒ“‚̉¿’l‚́APUT POST GET DELTE‚Ì•W€HTTPƒƒ\ƒbƒh‚ðŠg’£‚µ‚Ä“ÆŽ©‚ȃAƒmƒe[ƒVƒ‡ƒ“‚ðì‚邽‚߁B
—Ⴆ‚Î MOVEACOPYAMKCOLALOCKAUNLOCK ‚È‚Ç‚©‚ ‚肦‚éB
‚µ‚©‚µ‚±‚̂悤‚ÉŽ©—R‚ÉŠg’£‚µ‚Ä‚µ‚Ü‚Á‚āA‚±‚ê‚ÅRESTful‚Æ‚¢‚¦‚é‚Ì‚©B


4.2.3ƒ}ƒgƒŠƒbƒNƒXƒpƒ‰ƒ[ƒ^

‰º‹L•\‹L‚Å /e55‚Ì Å‰‚Ì/‚Í‚ ‚Á‚Ä‚à‚È‚­‚Ä‚à‘Š‘΃pƒXˆµ‚¢‚炵‚¢B
----------------------------------------------------
@Path("/mercedes")
public class MercedesService {@GET
@Path("/e55/{year}")
@Produces("image/jpeg")
public Jpeg getE55Picture(@PathParam("year") String year) {
...
}
----------------------------------------------------

ƒfƒBƒŒƒNƒgƒŠ–¼‚ª“ú–{Œê‚̏ꍇA•¶ŽšƒR[ƒh‚Í‹K’肳‚ê‚Ä‚¢‚é‚Ì‚©? •s–¾B

17Í
4Í‚̃Tƒ“ƒvƒ‹ƒR[ƒh

@PATCH ƒAƒmƒe[ƒVƒ‡ƒ“ ‚̉¿’l‚ª‚í‚©‚ç‚È‚¢A‚±‚ê‚͏ó‘Ô‚ðŽ‚Â‚Ì‚Å‚Í‚È‚¢‚Ì‚©B

5Í JAX-RSƒCƒ“ƒWƒFƒNƒVƒ‡ƒ“
5.1 Šî–{ JAX-RSƒAƒmƒe[ƒVƒ‡ƒ“‚ŃCƒ“ƒWƒFƒNƒg‚Å‚«‚é‘Ώۂ͕¡”‘¶Ý‚·‚éB

JAX-RSŽd—l‚ª‹K’è‚·‚éƒCƒ“ƒWƒFƒN ƒVƒ‡ƒ“ƒAƒmƒe[ƒVƒ‡ƒ“‚ðˆÈ‰º‚ÉŽ¦‚·B
 @javax.ws.rs.PathParam
 @javax.ws.rs.MatrixParam
 @javax.ws.rs.QueryParam
 @javax.ws.rs.FormParam
 @javax.ws.rs.HeaderParam
 @javax.ws.rs.CookieParam
 @javax.ws.rs.core.Context
5.2 @PathParam

5.3 @MatrixParam
----------------------------------------------------
@Path("/{make}")           <-- ‚±‚±‚ª cars/{make} ‚É‚È‚Á‚Ä‚¢‚È‚¢‚Ì‚ÍŒëA‚©?
public class CarResource {@GET
@Path("/{model}/{year}")
@Produces("image/jpeg")
public Jpeg getPicture(@PathParam("make") String make,
@PathParam("model") String model, @MatrixParam("color") String color) { ...
}
----------------------------------------------------

–ß‚è’l‚͂ЂƂÂ

ƒRƒŒƒNƒVƒ‡ƒ“

‰º‹LƒR[ƒh‚Ì List<String>‚Ì•”•ª‚ª‹C‚É‚È‚éA
Integer‚ð’è‹`‚µ‚½ê‡A“®ì‚·‚é‚Ì‚©B

----------------------------------------------------
import java.util.List;
@Path("/customers")
public class CustomerResource {@GET
@Produces("application/xml")
public String getCustomers(
@QueryParam("start") int start, @QueryParam("size") int size,
@QueryParam("orderBy") List<String> orderBy) { ...
}
}
----------------------------------------------------

ˆø”‚ÅGeneric‚ÍŽæ‚ê‚é‚© getTypeParameters‚ª‚ ‚邪Žæ‚ê‚é‚Ì‚Ígeneric method‚ÌŒ^ƒpƒ‰ƒ[ƒ^‚µ‚©•ª‚ç‚È‚¢‚Ì‚Å‚Í‚È‚¢‚Ì‚©B
  getGenericParameterTypes ‚Å TypeŽæ“¾‚Å‚«‚È‚¢‚©B
JAX-RS ‚© ServletFilter‚Å 400 Bad Request‚ð‚ЂÁ‚©‚¯‚½‚ç•Ö—˜‚Å‚Í‚È‚¢‚©B

5Í‚ªI‚í‚Á‚āA‚»‚̃Tƒ“ƒvƒ‹‚Ì 18Í‚ð“ǂ݁AŽŸ‰ñ‚Í6Í‚©‚çB

ˆÈã