ã¿ã¹ã¯ã®èª¬æ
ãProgrammer pragmatistããšããæ¬ã«ã¯ãããã¥ã¡ã³ãã«é¢ããç« ããããŸãã æ å ±ã®ãœãŒã¹ã¯1ã€ã ãã§ããå¿ èŠããããããã«åºã¥ããŠããã®æ å ±ã®æŽŸç圢åŒãçæãããŸãã ããšãã°ãããŒãã«ã®æ§é ã«é¢ãããã¹ãŠã®æ å ±ã¯1ã€ã®åœ¢åŒïŒä»»æã®é©åãŸãã¯ç¬èªã®åœ¢åŒã®ãã¡ã€ã«ïŒã§ä¿åãããããã«åºã¥ããŠããŒãã«èªäœãçæãããŸãããããã®ããŒãã«ã®ããã¥ã¡ã³ããããŒãã«ãæäœããããã®DAOãªããžã§ã¯ãã ãã®ã¢ãããŒãã®å©ç¹ã¯ãæ å ±ãç·šéããå¯äžã®å Žæããã®å ã®ãœãŒã¹ã§ãããããæ å ±ãæ瀺ãã掟ççãªåœ¢åŒã®éã«éåæåããªãããšã§ãã
æ¬ ç¹ã¯ãé¢å¿ã®ãããã¹ãŠã®äººããã®ãã¡ã€ã«ãç·šéã§ããªããã°ãªãããç®çã®åœ¢åŒãžã®ã³ã³ããŒã¿ãå¿ èŠã«ãªãããšã§ãã
WebãµãŒãã¹ã§ã¯ããããã®æŠå¿µã¯æåã«å¥çŽãšåŒã°ããæåŸã«å¥çŽãšåŒã°ããŸãã æåã«å¥çŽ-wsdlãæåã«äœæãããJavaã³ãŒããããããçæããããšãã æåŸã«å¥çŽ-å察ã«ãæåã®Javaã³ãŒããããã«å¿ããwsdlã
次ã®ãªã³ã¯ã§é·æãšçæã«ã€ããŠèªãããšãã§ããŸãïŒ docs.spring.io/spring-ws/sites/1.5/reference/html/why-contract-first.html stackoverflow.com/questions/763827/which-is-the-better- WebãµãŒãã¹ãžã®ã¢ãããŒãå¥çŽã®æåãŸãã¯æåŸã®å¥çŽ
ãã®èšäºã§ã¯ãåæ§ã®ãœãªã¥ãŒã·ã§ã³ãåŸãããã«ãèªå·±ææžåã䜿çšããŠSOAP WebãµãŒãã¹ãäœæããããšãæ€èšããŸããWebãµãŒãã¹ã«é¢ãããã¹ãŠã®æ å ±ãå«ãŸããŸãã ããã¯äžçš®ã®ãå¥çŽæåŸãã§ããããšãããããŸã-æåã«ã³ãŒããèšè¿°ããã次ã«ãã®WebãµãŒãã¹ã«é¢ããæ倧ã®æ å ±ãå«ãwsdl圢åŒã®ããã¥ã¡ã³ããååŸãããŸã-ãµãŒãã¹ãæ©èœãããã¹ãŠã®ã¡ãœãããšã¿ã€ãã«é¢ããã³ã¡ã³ããããã³ããŒã¿ã®æ£ç¢ºæ§ããã§ãã¯ããããžãã¯ã®ã»ãšãã© ãã®ãœãªã¥ãŒã·ã§ã³ã圹ç«ã€ã®ã¯ãªãã§ããïŒ ãã¹ãŠã®éçºãã³ãŒãã®èšè¿°ã«çŠç¹ãåãããwsdlãããã«åºã¥ããŠçæããããã®éã§ã¯ãªãå Žåã ãŸãã¯ãæåã«wsdlã§ããã¥ã¡ã³ãã管çããããšãå°é£ãªå Žåã ãã ããWebã¡ãœãããåæçšã«äœæãããŠããå Žåã¯ããã®åæãwsdlã«ä¿åããããšããå§ãããŸãã ã€ãŸã æåã«wsdlãäœæãããããããã¡ãœãããã¯ã©ã¹ãèªã¿åãå¯èœãªããã¥ã¡ã³ããçæãããŸãã ããããªããšããã§ã«äœæãããŠãããµãŒãã¹ã®ã³ã³ãã©ã€ã¢ã³ã¹ããã§ãã¯ããéã«åé¡ãçºçããŸãã ã¿ã¹ã¯ã
ãŸããxsdåŽã§å ¥åããŒã¿ã®æå¹æ§ã確èªããããšããå§ãããŸããããã«ãããWebãµãŒãã¹ã«æ¥ç¶ããã«ãªã¯ãšã¹ãã確èªã§ãããã®ããžãã¯ãïŒxsdã§ïŒè¡šç€ºããããµãŒãã¹ã®ã©ããã«é ç·ãããŸããã
ãœãªã¥ãŒã·ã§ã³ãªãã·ã§ã³
çŸåšãjax-wsã¢ããªã±ãŒã·ã§ã³ããwsdlãååŸã§ããŸãã ãã ããæšæºã®jax-ws / jaxbã¢ãããŒã·ã§ã³ã¯ãWebãµãŒãã¹ã®ããã¥ã¡ã³ãããµããŒãããŠããŸãã-ãã®ããããµãŒãããŒãã£ã®ãã¬ãŒã ã¯ãŒã¯ãæäŸããæ©èœã䜿çšããå¿ èŠããããŸãã å ·äœçã«ã¯ãApache CXFïŒjax-wsïŒã¯WSDLDocumentationã¢ãããŒã·ã§ã³ãæäŸããŸããããã¯ãWebã¡ãœããã«é©çšããããã®åŸwsdlã§çµããWebã¡ãœãããèšè¿°ããŸãã jaxb-facetsã©ã€ãã©ãªïŒ dsg.tuwien.ac.at/staff/hummer/tools/jaxb-facets.htmlãgithub.com/whummer/jaxb-facets ïŒã¯ãWebã¡ãœããã§äœ¿çšãããxmlãšã³ãã£ãã£ãææžåããããã«äœ¿çšãããŸãã Webã¡ãœããã®CXFãšåæ§ã«ãXML Beanã®ã¯ã©ã¹ãšãã£ãŒã«ããææžåã§ããŸãã ããã«ãXSDå¶éã®ãµããŒããè¿œå ããŸã-xmlãã£ãŒã«ãã®å€ã«å¯Ÿããè¿œå ã®å¶éã ïŒXSDå¶éã®èª¬æã¯ãã¡ãwww.w3schools.com/schema/schema_facets.asp ïŒããã¯ãå€ã®æ£ç¢ºæ§ããã§ãã¯ããããžãã¯ãå¿ é /ãªãã·ã§ã³ãããè€éã§ããå Žåã«äŸ¿å©ã§ãã jaxbã¯ãxsdã®æ€èšŒæ©èœãå®å šã«ã¯ãµããŒãããŠããŸããã å ·äœçã«ã¯ãæå°å€ãæ倧å€ã®å¶éãæå®ããæ£èŠè¡šçŸã䜿çšãã空ã®å€ã§æååãåŠçããããŸããŸãªæ¹æ³ã䜿çšããå€ã®é·ãã«å¶éãèšå®ã§ããŸãã
å®è£
äŸãšããŠãããã€ãã®ã¡ãœãããæã€åçŽãªWebãµãŒãã¹ãäœæããŸãããã
ãã®èšäºã§ã¯ãç¹å®ã®äŸãšã³ãŒãã説æããŸãã ãµãŒãã¹å šäœã¯dl.dropboxusercontent.com/u/7519092/jax-ws-example.zipããããŠã³ããŒãã§ããŸããããã¯IDEA mavenãããžã§ã¯ãã§ãã IDEAã§ã¯ãIDEAãããžã§ã¯ããã€ã³ããŒãããããMavenãããžã§ã¯ããã€ã³ããŒãããããšã§éãããšãã§ããŸãã Pom.xmlã¯wsdlãã¡ã€ã«ãçæããxsltã䜿çšããŠhtmlã«å€æããããã«æ§æãããŠããŸãããæ®å¿µãªãããã®wsdlã«ã¯jaxb-facetsã®ããã¥ã¡ã³ãã¿ã°ãå«ãŸããŠããŸããããwsdlã«ãã£ãŠçæãããŸãïŒãªã³ã¯<application path> / web_service / WebServiceïŒ wsdlïŒãã®ã¿ã°ã¯ã ãŸãããããžã§ã¯ãã§ã¯ãã¢ãããŒã·ã§ã³ã®äœ¿çšæ¹æ³ãç°ãªããŸããã¢ãããŒã·ã§ã³ã¯getã¡ãœããã«é©çšããããããã®äŸã§ã¯ã¯ã©ã¹ã®ãã£ãŒã«ãã«é©çšãããŸãã ããã¯ãèšäºãçãããããã«è¡ãããŸãã ã¯ã©ã¹ã®ãã£ãŒã«ãã«æ³šéãé©çšããã«ã¯ãã¡ãœãããååŸããªããã@ XmlAccessorTypeïŒXmlAccessType.FIELDïŒãæå®ããå¿ èŠããããŸãã
äŸ
äŸãšããŠãããã€ãã®ç¹å®ã®ã¿ã¹ã¯ãæ€èšããŸã
æ¥ä»ãšæå»ã®æ倧å€ãšæå°å€ã®å¶éã
æ¥ä»ã®å ŽåïŒ
@XmlSchemaType(name = "date") @Facets(minInclusive = "1900-01-01", maxInclusive = "9999-12-31Z") Date date;
çæãããxsdåè·¯ïŒ
<xs:element minOccurs="0" name="date"> <xs:simpleType> <xs:restriction base="xs:date"> <xs:maxInclusive value="9999-12-31Z"/> <xs:minInclusive value="1900-01-01"/> </xs:restriction> </xs:simpleType> </xs:element>
@XmlSchemaType(name = "dateTime") @Facets(minInclusive = "1900-01-01T00:00:00", maxInclusive = "9999-12-31T23:59:59") Date dateTime;
<xs:element minOccurs="0" name="dateTime"> <xs:simpleType> <xs:restriction base="xs:dateTime"> <xs:maxInclusive value="9999-12-31T23:59:59"/> <xs:minInclusive value="1900-01-01T00:00:00"/> </xs:restriction> </xs:simpleType> </xs:element>
ïŒjaxb-facetsã©ã€ãã©ãªã®Facetsã«ããèŠçŽïŒ
䜿çšããªããã°ãªããªãã£ãã®ã¯ DBMSã¯ãJavaã§äœ¿çšå¯èœãªæ¥ä»ç¯å²ããµããŒãããŠããŸããã§ããã ã€ãŸã WebãµãŒãã¹ã§ã¯ãããšãã°1000-01-01ãªã©ã®æ¥ä»ã転éã§ããŸããJavaã§ã¯æ£ãã解æãããŸãããDBMSãžã®æžã蟌ã¿æã«ãšã©ãŒãçºçããŸãã ãã®æ¥ä»ç¯å²ã¯ãµããŒããããŠããŸããã ãŸããåãå ¥ããããå€ãå¶éããããã«ããã®å¶éãå°å ¥ãããŠããŸãã
æ¥ä»ã«ã€ããŠã¯ãã¿ã€ã ãŸãŒã³ãèæ ®ããŠæ倧æ¥ä»ãäžããããŸãã ã¿ã€ã ãŸãŒã³ä»ãã®åºåæ¥ä»9999-12-31ããµããŒããããŠããå¿ èŠããããŸãïŒããšãã°ã9999-12-31 + 04ïŒ00ïŒã ãããè¡ãããªãå Žåããã®å€ãã·ãªã¢ã«åãããšãïŒã¯ã©ã€ã¢ã³ãã«æ»ããšãïŒãxsdæ€èšŒãšã©ãŒãçºçããŸãã
ç¹å®ã®ãã£ãŒã«ãé·ã®å¶é
@Facets(length = 16) String id;
<xs:element minOccurs="0" name="id"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:length value="16"/> </xs:restriction> </xs:simpleType> </xs:element>
ããšãã°ããã£ãŒã«ããç¹å®ã®é·ãã®äžæã®èå¥åãŸãã¯ç¹å®ã®é·ãã®ä»ã®èå¥åïŒãã¹ããŒããã«ãŒãã®çªå·ïŒã§ããå Žåã«å¿ èŠã§ãã
idã®å Žåãåå¥ã®ã¿ã€ãã®Idãåºå¥ã§ããŸãïŒ
public class Id { @Facets(length = 16) @XmlAttribute String attr; }
ãããŠã次ã®ããã«äœ¿çšããŸãã
Id id;
ãããã£ãŠãããã¯å€æ°ã§ããããšãæ確ã«ç€ºããŸã-ãã¹ãŠã®å¶éã¯æ©èœããŸãããäžæã®èå¥åã§ãã
ãã£ãŒã«ãã®ãªã»ãã
äžéšã®ãªãã·ã§ã³ãã£ãŒã«ãã¯ã¯ãªã¢ããå¿ èŠããããŸãã æååã®å Žåãããã¯éåžžã«ç°¡åã«è¡ãããŸã-空ã®ã¿ã°ãéä¿¡ããïŒããšãã°<name />ïŒãéæŽååïŒxmlãªã¯ãšã¹ããJavaãªããžã§ã¯ãã«å€æïŒãããšã空ã®æååã®ã¿ãååŸãããŸãïŒString.isEmptyïŒïŒ== trueïŒã ãŸããnullã«èšå®ããå¿ èŠãããæååãšããŠå®å šã«è§£éã§ããŸãã
ãã ããæ°å€ãŸãã¯æ¥ä»ããªã»ããããå¿ èŠãããå Žåã空ã®ã¿ã°ãæž¡ããšãšã©ãŒãçºçããŸãã
éæŽååãšã©ãŒïŒcvc-datatype-valid.1.2.1ïŒ ''㯠'integer'ã®æå¹ãªå€ã§ã¯ãããŸãã
ããã¯ç解ã§ãã-空ã®ã¿ã°ã¯æ°åãšããŠè¡šãããšãã§ããŸããïŒnullã¯èæ ®ãããŸãã-nullã¯ã¿ã°ããªãããšãæå³ããŸãïŒã
ããã¯ããã£ãŒã«ãã®ããã©ã«ãå€ã䜿çšããŠè§£æ±ºã§ããŸãã
@XmlElement(defaultValue = "-2147483648") Integer id;
<xs:element default="-2147483648" minOccurs="0" name="id" type="xs:int"/>
ããã«ãJavaã§ç©ºã®ã¿ã°ïŒ<id />ïŒãæž¡ããšãidå€æ°ã®å€ã¯-2147483648ã«ãªããŸãïŒããã¯Integer.MIN_VALUEã§ãïŒã ãã®ãœãªã¥ãŒã·ã§ã³ã¯ãNullãªããžã§ã¯ããã¿ãŒã³ã«å°ã䌌ãŠããŸã-nullå€ãæ瀺çã«æž¡ãããããšã瀺ãå¿ èŠãããå ŽåïŒå€ãæå®ããªãã£ãã ãã§ãªãïŒãç¹å¥ãªnullãªããžã§ã¯ããæž¡ããŸãã
en.wikipedia.org/wiki/Null_Object_pattern
æ¥ä»ã®å Žåãåãã¢ãããŒãã¯æ¬¡ã®ããã«ãªããŸãã
@XmlSchemaType(name = "date") @XmlElement(defaultValue = "1900-01-01") Date date;
<xs:element default="1900-01-01" minOccurs="0" name="date" type="xs:date"/>
@XmlSchemaType(name = "dateTime") @XmlElement(defaultValue = "1900-01-01T00:00:00") Date dateTime;
<xs:element default="1900-01-01T00:00:00" minOccurs="0" name="dateTime" type="xs:dateTime"/>
ããã¥ã¡ã³ããŒã·ã§ã³
ãã£ãŒã«ãã®ããã¥ã¡ã³ãåã¯ãããã¥ã¡ã³ãã¢ãããŒã·ã§ã³ïŒjaxb-facetsã©ã€ãã©ãªããïŒã䜿çšããŠè¡ãããŸãã
@XmlSchemaType(name = "date") @Documentation(" ") @Facets(minInclusive = "1900-01-01", maxInclusive = "9999-12-31Z") Date date;
<xs:element minOccurs="0" name="date"> <xs:annotation> <xs:documentation> </xs:documentation> </xs:annotation> <xs:simpleType> <xs:restriction base="xs:date"> <xs:maxInclusive value="9999-12-31Z"/> <xs:minInclusive value="1900-01-01"/> </xs:restriction> </xs:simpleType> </xs:element>
WebãµãŒãã¹ã¡ãœããã®ããã¥ã¡ã³ãåã¯ãCXFã®WSDLDocumentationã¢ãããŒã·ã§ã³ã䜿çšããŠè¡ãããŸãã
@WSDLDocumentation(" . XML Schema Restrictions") String facetsExampleMethod(FacetsExample request);
<wsdl:operation name="facetsExampleMethod"> <wsdl:documentation> . XML Schema Restrictions </wsdl:documentation> <wsdl:input message="tns:facetsExampleMethod" name="facetsExampleMethod"/> <wsdl:output message="tns:facetsExampleMethodResponse" name="facetsExampleMethodResponse"/> </wsdl:operation>
ãããã®ãã£ãŒã«ããšã¡ãœããã®è©³çŽ°ã«ã€ããŠã¯ãwsdlãåç §ããŠãã ããã
ãµãŒãã¹ããã¥ã¡ã³ãã®çæïŒwsdlããhtmlïŒ
çæãããwsdlãèªã¿åãå¯èœãªãã¥ãŒã«å€æããã«ã¯ãxsltãã¡ã€ã«tomi.vanek.sk/index.php?page=wsdl-viewerã䜿çšããŸããSoapUIã¯èªã¿åãå¯èœãªhtmlãçæã§ããŸãã ããã¯ãã¹ãŠStackOverflowã§èª¬æãããŠããŸãã
stackoverflow.com/questions/686103/generated-html-documentation-from-wsdlãã«ã段éã§ã®htmlãžã®å€æã¯pom.xmlã§å®è£ ãããŠããŸã次ã«ããã®ããŒãžã¯<application path> /WebService.htmlã§å©çšã§ããŸã
ããã€ãã®HTMLçæããŒãïŒ
Webã¡ãœããã®ãã©ã¡ãŒã¿ãŒã¯ã@ SOAPBindingïŒstyle = SOAPBinding.Style.RPCïŒãæå®ãããŠããå Žåã«ã®ã¿æ£ãã衚瀺ãããŸãã
ããã¥ã¡ã³ãã¢ãããŒã·ã§ã³ã¯ãã©ã³ã¿ã€ã ãå®è¡äžã®ãµãŒãã¹ããwsdlãçæããŠããå Žåã«ã®ã¿ãwsdlã«ããããã£ãŠHTMLããã¥ã¡ã³ãã«ååŸãããŸãã wsdlããã«ããããšããããã¥ã¡ã³ãã¯å«ãŸããŸããã ãªããã-ç§ã¯ç¥ããŸããã æãå¯èœæ§ãé«ãã®ã¯ãWSDLãžã§ãã¬ãŒã¿ãŒã®ãšã©ãŒã§ãã
jaxb-facetsã®ãã®ä»ã®æ©èœ
䜿çšããjaxb-facetsã®ãã®ä»ã®æ©èœã«ã€ããŠç°¡åã«èª¬æããŸãã
æ£èŠè¡šçŸã«ããå€ã®ç¢ºèª-Facets.patternã
空çœåŠçããžãã¯ã®èšå®-Facets.whiteSpaceã 空çœã¯èæ ®ãããåé€ãããã¹ããŒã¹ã«çœ®ãæããããŸãïŒã¿ãããã³æ¹è¡çšïŒã xsdãã€ãŸã Javaã³ãŒãã¯ã空çœæåã䜿çšããŠå€ããã®ãŸãŸååŸããŸãã ã¹ããŒã¹ã§æºãããããã£ãŒã«ãã空ãšããŠè§£éãããå¿ èŠãããå Žåãæååãã£ãŒã«ããå¿ é ã§ããããšã確èªãããšäŸ¿å©ã§ãã
äžè¬ã«ãjaxb-facetsã¯ãã¹ãŠã®xsdå¶éããµããŒãããŠããŸãã ããŒãžwww.w3schools.com/schema/schema_facets.aspã®æåŸã§ãããã«æ £ããããšãã§ããŸããææ°ããŒãžã§ã³ïŒ2.2.6ïŒã§ãxsïŒassertãµããŒããç»å ŽããŸããã äŸxsïŒIBM Webãµã€ãïŒ www.ibm.com/developerworks/en/library/x-xml11pt2 ïŒããã¢ãµãŒãããŸãã
<xs:element name="dimension"> <xs:complexType> <xs:attribute name="height" type="xs:int"/> <xs:attribute name="width" type="xs:int"/> <xs:assert test="@height < @width"/> </xs:complexType> </xs:element>
åè
äžè¬ã«ããµãŒãã¹ãããŒããããèšè¿°ãããŠããå Žåã¯ãæ£ããwsdlãäœæããããããJavaã³ãŒããšããã¥ã¡ã³ããæ¢ã«çæããŠããæ¹ãè¯ããšç¹°ãè¿ããŸãã ãã ãããã§ã«WebãµãŒãã¹ãäœæããŠããå Žåã¯ãXSDå¶éãè¿œå ãããšãã¯ã©ã€ã¢ã³ãåŽããééçã«ãªããŸã-å ¥åå€ããã§ãã¯ããããžãã¯ã衚瀺ãããŸãïŒãã¡ããããã¹ãŠã§ã¯ãããŸãã-å Žåã«ãã£ãŠã¯ãDBMSã«ã¢ã¯ã»ã¹ããã«ã¯ãšãªã®æ£ç¢ºæ§ããã§ãã¯ããããšã¯äžå¯èœã§ãïŒé¢é£ãªãœãŒã¹ïŒã ããã«ãããã¥ã¡ã³ãã®çæã«ãããå®éã®Webã¡ãœãããšãã©ã¡ãŒã¿ãŒãæè¡ãšã®å¯Ÿå¿ãç°¡åã«æ¯èŒã§ããŸãã å²ãåœãŠã ããããªããšãå ¥åããããWebã¡ãœããã®èŠæ±ãšåçã確èªããããçæãããwsdlã®è€éããç解ããå¿ èŠããããŸãã