Вы находитесь на странице: 1из 401

Web-

Web-
Web- J2EE

WEB-
Java

-
-
2003

681.3.068
32.973.202
12

12

. .
Web- Java. .:
-, 2003. 400 : .
ISBN 5-94157-227-1
Web- ,
Internet XML WWW.
, Web, Java, . XML, SOAP, WSDL, UDDI ,
Web-. Java
, . Web-.
, Web- . , - Web-.

681.3.068
32.973.202
:

.
.







Via Design

02429 24.07.00. 21.02.03.


70x100Vie. . . . . 32,25.
3000 . 748
"-", 198005, -, ., 29.
, No 77.99.02.953..001537.03.02
13.03.2002 . .

""
199034, -, 9 , 12.

ISBN 5-94157-227-1

. ., 2003
, "-", 2003

1. XML

DTD

XML
XSD



:

XSD

XML


XML
XML SAX2 API
XML Java
JDO
XML DOM API
Node
Document
Element
DOM-
XML
XSL
XML HTML

14

21
23
25
26
28
32
33
40
43
45
48
50
51
51
52
53
63
64
..65
67
68
70
74
75
77
81

2. Web Services

XML-RPC
SOAP
SOAP
SOAP
SOAP
Java Web-
Web-
WSDL
Web-
UDDI
WS-Inspection Web-
JAXR
Web Services
3. SOAP Web Services

SOAP-
<Fault>

SOAP


SOAP

HTTP
GET
SMTP
SOAP-
MIME- multipart/related
SOAP-
DIME
SOAP-
Axis
Axis
Web- Axis
Axis

WSDL
Axis

83

88
92
93
96
97
99
107
111
112
113
123
127
133
134

135
138
140
143
145
147
148
149
151
155
157
158
159
159
163
164
166
167
167
168
169
170
176
178


4. Web Services WSDL

183

WSDL
WSDL
SOAP
HTTP
-
WSDL
JWSDL WSDL4J

183
193
193
196
201
202
206

5. Web Services UDDI


UDDI
<businessEntity>
<businessService>
<bindingTemplate>
<tModel>
<publisherAssertion>
UDDI

Web-
UDDI API
IBM UDDI4J
JAXR
JAXR
6. Web Services
SOAP-
Node
SOAPElement
SOAP-
SOAPMessage
SOAP-
SOAP-
SOAP-
AttachmeniPart

SOAPFault.

WS-Routing

SOAP-

212
213
216
219
220
221
223
223
225
226
227
228
234
235
247
248
248
248
249
251
252
254
257
258
262
262
265
266
271
272

JAXMServlet

Web- JAX-RPC
Web-
Web-

Web-
jaxrpc-ri.xml
JAX-RPC
7. Web Services J2EE

EJB
Session-
session-
MDB-
EJB-
Web- -

Web-

JAX-RPC
Web-

274
278
281
283
287
287
288
291
292
295
305

306
307
314
315
317
321
323
324
328
332
335

8.

337






Java

XML
XML
XML
Java XML
SOAP-
"WS-Security"
?

338
338
339
340
340
341
341
342
343
344
349
352
357
359
363


9. Web Services
SOAP
WSDL
UDDI

WSFL
WS-I
WS-Basic
?

364

364
365
366
366
367
376
377
380

382

384



"Web Services" ("Web-").
, ,
Web Services, ,
.
" " ,
. Web
Services?
.

. .
[10],
. , ,
.
: , , . .
. ,
. ,
. , , . : RPC (Remote Procedure Call), DCOM, RMI (Remote
Method Invocation), CORBA.
, . RPC, DCOM, RMI
.
- .
.

Web Services IBM, Microsoft UserLand


, .
"" ,
ASCII, Latin I, 866, 1251, KOI-8 Unicode:
UTF-8, UTF-16. .
XML
(extensible Markup Language, ).
,
XML. XML. Web Services SOAP (Simple Object Access Protocol). , XML SOAP, Web-,
, .
Web Services
, SOAP, , HTTP
(HyperText Transfer Protocol). , HTTP,
. ,
HTTP-, ,
.
. Web- SMTP (Simple Mail Transfer Protocol),
TCP (Transmission Control
Protocol). He .
Web Services
. Web-. , Web-,
.
WSDL (Web Services Description Language, Web-).
XML. , Web-,
. ,
, Web- WSDL.
, , , , Web-
, WSDL.
Web, ,
Web- . Web- ,
XML

_70

UDDI (Universal Discovery, Description and Integration).


, IBM, Microsoft, Hewlett Packard, SAP AG,
UDDI. ,
Web-,
Web- .
, Web Services " " SOAP, WSDL UDDI. "",
HTTP. , Web Services
.
, , , Web-, ,
.
.
Web Services
. . Microsoft Web Services Microsoft
.NET. .
[12]. IBM, Sun Microsystems Web Services Java.
.

Web Services Java


Java, Sun Microsystems, : "
", . ,
- Java. , ,
, JVM (Java Virtual Machine,
Java), .
, JVM
.
! ,
, ,
, ,
. ""
.

11

Java ?
CGI, ASP, PHP, JavaScript, Perl, Python?

Java. He ,
, JVM, ,
, . ,
JVM , .
, Java .
Java. ,
JVM , .
Web Services . Web-,
Java,
JVM. J2EE-cepBep (Java 2 Enterprise Edition)
Web-.
, Java Web Services.
Java . JDK (Java Developer Kit, Java) XML
XML. Web-.
Java XML, XML- .
JSP (Java Server Page) Web
Services .
Web-.
EJB (Enterprise JavaBeans) Web-,
.
,
Web Services, Web-. Web- .
(RAD)
(IDE, Integrated Development Environment) Java
"", Web-
.
, Java Web
Services. , Web

j[2

Services Java. Java Web


Services Web Services.


, Web Services
XML. 1 XML . XSD
(XML Schema Definition Language, XML), . XSD,
.
, 1 Java,
, XML, a
, ,
.
2 Web Services .
, Web
Services, , , Web-
. Web
Services -
Web-. , Web Services,
. Web WSDL Web-
UDDI.
2, Web Services , Web-.
Web- . 3, 4 5
" ",
Web Services SOAP, WSDL UDDI. , ,
, .
6, Java Web Services. , ,
Java Web Services. , , , Java Web Services.
Web-, Java,
. , , -

13_

, J2EE. Web- J2EE


J2EE-cepBepa 7. , , Web- J2EE-cepBepa , Web- . , ,
Web- J2EE-cepeep .
Web- . Web Services ,
, Web-, .
, ,
Web Services ,
Web-. 8. .
8 .
, 9 Web
Services .

XML
Web- HTML (HyperText
Markup Language, ) . ,
, HTML.
HTML,
, , .
! , "", , , . , "" HTML.
HTML, .
HTML , Web-. , , , .
HTML
, "".
HTML . , .
CSS (Cascading Style Sheet) SSI
(Server Side Include) -

1. XML

15

. ,
- , .
. 1986
SGML (Standard Generalized Markup Language),
HTML. SGML
, , . , SGML, DTD (Document Type
Definition) , .
SGML-
.
,
.

. ,
: , , , , , , , ,
.
, ,
, - ,
. ,
.
SGML , . ,
, . , man- Solaris Operational Environment
SGML.
SGML HTML
XML. SGML, , Web- . XML ,
, , .
XML , ,
. . , , .
, , ,
, , , , ,
, , : .

Web- Java

_/6

,
, 1.1.
1.1. XML-
<?xml version="l.0" encoding="Windows-1251"?>
<!DOCTYPE notebook SYSTEM "ntb.dtd">
<notebook>
<person>
<name>
<first-name>MBaH</first-name>
<second-name>neTpoBM4</second-name>
<surname>CMflopoB</surname>
</name>
<birthday>25.03.1977</birthday>
<address>
<street>Caoa, 23-15</street>
<city>ypioroiHCK</city>
<zip>123456</zip>
</address>
<phone-list>
<work-phone>265432K/work-phone>
<work-phone>2654023</work-phone>
<home-phone>3456781</home-phone>
</phone-list>
</person>
<person>
<name>
<first-name>MapMH</first-name>
<second-name>neTpoBHa</second-name>

1. XML

77

<surname>CMflopoBa</surname>
</name>
<birthday>17.05.1969</birthday>
<address>
<street>HroflHaH, 17</street>
<city>epa</city>
<zip>23456K/zip>
</address>
<phone-list>
<home-phone>2334455</home-phone>
</phone-list>
</person>
</notebook>

XML ,
.
XML (XML declaration),
1.1, XML, ,
XML (standaione="yes"/"no")-
UTF-8.
XML
(root element), 1.1 <notebook>.
, (Document Type
Declaration). (He DTD!) DOCTYPE. 1.1.
DOCTYPE DTD:
<!DOCYPE notebook [ DTD ]>

DTD
XML. . DTD , SYSTEM PUBLIC.
SYSTEM URI (Universal Resource Identifier, -

18

Web- Java

) DTD,
.

PUBLIC,

XML- .
, :
> </ >
,
.
XML, HTML, . (empty
),
"/>", :
<br />
, XML, HTML,
.
1.1 , XML . , ,
. ,
, ,
. . . 1.1 , 1.1.

work-phone

home-phone

. 1.1. XML
XML . , ,
f i r s t , second surname
<name>;
<name first="HBaH" !="" ="" />
HTML XML
.

1. XML

19

.
, , ,
. . ,
<work-phone> <home-phone>, <phone-iist>, <phone-iist>. , <name> , , , . <name> "/>". 1.2
.
1.2. XML-
<?xml version="1.0" encoding="Windows-1251"?>
<!DOCTYPE notebook SYSTEM "ntb.dtd">
<notebook>
<person>
<name first="MBaH" 1="" =""
<birthday>25.03.1977</birthday>
<address>
<street>CaflOBaH, 23-15</street>
<city>ypronMHCK</city>
<zip>123456</zip>
</address>
<phone-list>
<work-phone>265432K/work-phone>
<work-phone>2654023</work-phone>
<home-phone>34 5 67 81</home-phone>
</phone-list>
</person>
<person>

20

Web- Java
<name first="MapnH" !="" ="" />
<birthday>17.05.1969</birthday>
<address>
<street>HroflHaH, 17</street>
<city>epa</city>
<zip>23456K/zip>
</address>
<phone-list>
<home-phone>2334455</home-phone>
</phone-list>

</person>
</notebook>

. , , ,
. <city> type,
: , , . :
< c i t y type="ropofl">MocKBa</city>


<notebook>, <person>, <name>, <address>, <street>, <city>, <zip>, <phonei i s t > , <work-phone>, <home-phone>
, . .
.
<notebook>
<person>.
<person> <name>, <address> <phone-iist>.
<name> .
<name> f i r s t , second, surname, .
<address> <street>, <city>

1. XML

21

<street> <city> .
<zip> .
<city> type,
, . .
<phone-iist> <work-phone> <home-phone>.
<work-phone> <home-phone> , .
, XML, . :
DTD, XML SGML,
XSD.

DTD
DTD 1.3.
' 1.3. DTD XML
<!ELEMENT notebook (person)*>
<!ELEMENT person (name, birthday?, address*, phone-list?)>
<!ELEMENT name EMPTY>
<!ATTLIST name
first CDATA #IMPLIED
second CDATA #IMPLIED
surname CDATA #REQUIRED>
<!ELEMENT birthday (#PCDATA)>
<!ELEMENT address (street, city, zip)?>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ATTLIST city
type ( | I ) "">
<!ELEMENT zip (#PCDATA)>
<!ELEMENT phone-list (work-phone*, home-phone*)>
<!ELEMENT work-phone (#PCDATA)>
<!ELEMENT home-phone (#PCDATA)>

Web- Java

22

, DTD .
. ELEMENT ,
.
.
. EMPTY 1.3
.
ATTLIST .
, .
, CDATA (Character
DATA), Unicode, . type <city>,
, . .
:
#REQUIRED ,

#IMPLIED ,

#FIXED , DTD.
, ELEMENT ATTLIST, ANY,
ENTITY. ANY MIXED, , / . ENTITY
, DTD, MIXED


, . PCDATA (Parsed Character
DATA) Unicode, .
, , "
" , " ". " ". ,
, .
DTD , , ntb.dtd,
, 1.1 1.2. XML, :
<!DOCTYPE notebook [ DTD ]>

DTD XML
, , -

1. XML

23

. (validating parsers). , XML, . , IBM xml4j,


WebSphere.
, http://www.alphaworks.ibm.com/ xml4j.jar, xerces.jar xercesSamples.jar.
Sun Microsystems
JAXP (Java API for XML Processing,
Java XML), J2SDK
Standard Edition, J2SDK Enterprise Edition [10]. ,
Java XML Pack
http://java.sun.com/xml/.
Microsoft MSXML
(Microsoft XML Parser), http://msdn.microsoft.com/xml/.
, , , Apache Xerces 2,
XML, .
http://xml.apache.org/xerces2-j/.
DTD
XML. , DTD , . , 1.3 DTD , <birthday> . DTD
XML. XSD.
XML (XML Schema).
, XML,
XML .


XML , , XML , - . , .
, (namespace). ,
,

24

Web- Java

. xmins :
<ntb:notebook xmlns:ntb = "http://some.firm.com/2003/ntbml">

, ntb , ntb:notebook. , http://some.firm.com/2003/ntbml,


ntb, :
<ntb:city ntb:type="oceo">opeoo</ntb:city>

, , n t b : c i t y ,
QName (Qualified Name).
URI. URI,
http://some.firm.com/2003/ntbml,
.
XML , , . Web-.
, ,
http://www.w3.org/TR/1999/REC-xmlnames-19990114/, ,
DNS- ,
. URI , . URL (Universal Resource
Locator, ) , XML, XML.
SGML XML
, , . , DTD . . , Xerces
setNamespaceAware(true) .
xmins XML,
.
, xmins,
. ,
:
<ntb:notebook
xmlns:ntb = "http://some.firm.com/2003/ntbml"
xmins:bk

= "http://some.firm.com/2003/bookral">

1. XML

25

, , ,
(default namespace). , XHTML
HTML XML . ,
t i t l e . HTML,
:
<html xmlns = "http://www.w3.org/1999/xhtml"
xmlns:ntb = "http://some.firm.com/2002/ntbml">
<head>
<title>MoH <^^1>
</head>
<body>
<ntb:book>
<ntb:title>Co3flaHMe Java Web Services</ntb:title>
</ntb:book>
</body>
</html>

XHTML,
http://www.w3.org/1999/xhtml, ,
, .
.
, ,
.
, , XML.

XML
2001 W3C (WWW Consortium) XML XSD.
XML (XML Schema),
XML.
XML XML.
(components),

Web- Java

XML. <schema>. XML


. XML, http://www.w3.org/xml/schema/, 13 ,
, , .
XSD XML. (simple)
XML , . ,
(complex) / .
XML , .
. .

XSD
XSD , , ,
, , URI. .


XSD : decimal, float
double.

decimal ,
: 123.45, 0.1234567689345 . : . XSD
, ,
18 . java.math.BigDecimai,
Java API (Application Programming Interface,
) [9].
float double IEEE75485
Java [9]. .


integer decimal, .
: -34567, 123456789012345 . java.math.Biglnteger [9].

1. XML

27

long, int, short byte Java. integer,


: byte
short, int, .
nonPositivelnteger negativelnteger integer


.
nonNegativelnteger positivelnteger integer


.
nonNegativelnteger

unsignedLong, unsignedlnt, unsignedShort unsignedByte.


string Unicode. j a v a . i a n g . s t r i n g .
normaiizedstring string ,
' , ' v \ t ' .
token normaiizedstring , ,
.
token . language RFC 1766, , ru, en, de, fr.
NMTOKEN . name XML ,
, , , , ,
( X, , , m, L, 1
) . name .
name NCName (Non-Colonized Name) , , , ,
ID, ENTITY, IDREF, XML, .

duration

, ,
(IY), (2), (3D),

PIY2M3DTIOH3OM45S

28_

Web- Java

(), () (4 5s).
, , 120 120 , 120
120 .
dateTime CCYY-MM-DDThh:mm:ss, Ha, 2003-04-2509:30:05. -
.
time hh:mm:ss.
d a t e CCYY-MM-DD.
gYearMonth CCYY-MM.
gMonthDay -MM-DD.
gYear CCYY, gMonth -, gDay -DD.


16-
: 0B2F, 3560 , h e x B i n a r y ,

Base64 [10], base64Binary.


, XML.
URI anyURi.
(qualified name, ,
, , QName.
NOTATION DTD XML. ,
, , .


XML .
(restriction) , (list)
(union) .
<simpleType>,

<xsd:simpleType =" "> -c/xsd:simpleType>

1. XML

29

<restriction>, base , , . ,
zip :
<xsd:simpleType name="zip">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9]{6}" />
</xsd:restrictions
</xsd:simpleType>
zip , 100000 999999:
<xsd:simpleType name="zip">
<xsd:restriction base="xsd:positivelnteger">
<xsd:minlnclusive value="100000" />
<xsd:maxlnclusive value="999999" />
</xsd:restriction>
</xsd:simpleType>
<pattern>, <maxinciusive> , , (facets). :
<maxExciusive> , ;
<maxinciusive> ;
<minExclusive> , ;
<mininciusive> ;
<totaioigits> decimal;
<f ractionDigits> ;
<iength> ;

Web- Java

<maxLength> ;
<minLength> ;
<enumeration> ;
<pattern> [8];
<whitespace> s t r i n g
' , ' , x\t'.
value :

preserve ,

replace ,

collapse
, .

- , (fundamental facets):
ordered ,
:
false ,
p a r t i a l ,
t o t a l ;
bounded true false;
c a r d i n a l i t y
finite countably infinite;

numeric , , true
false.

,
-. <pattern>
<enumeration> ,
"". , , "".

- , ,
, . -

1. XML

31

, XML , :
<days>21 34 55 4 6</days>
<iist>, itemType
.
<iist>. ,
XML <days> :
<xsd:element name="days" type="listOfInteger" />

l i s t o f integer :
<xsd:simpleType name="listOfInteger">
<xsd:restriction>
<xsd:simpleType>
<xsd:list itemType="xsd:integer" />
</xsd:simpleType>
<xsd:maxLength value="5" />
</xsd:restriction>
</xsd:simpleType>
<iength>, <minLength>,
<maxLength>, <enumeration>, <pattern>.
<days> .

- <union>,
memberTypes . :
<xsd:union memberTypes="xsd:string xsd:integer listOflnteger" />
<union>
, . :
<xsd:attribute name="size">
<xsd:s impleType>

32

Web- Java
<xsd:union>
<xsd:simpleType>
<xsd:restriction base="xsd:positivelnteger">
<xsd:minlnclusive value="8"/>
<xsd:maxlnclusive value="72"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType>
<xsd:restriction base="xsd:NMTOKEN">
<xsd:enumeration value="small"/>
<xsd:enumeration value="medium"/>
<xsd:enumeration value="large"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:union>

</xsd:simpleType>
</xsd:attribute>

size , , :
<font size='large"> K/font>
<font size='12'> TeKCT</font>


, XML,
<element>:
<xsd:element =" " type="TMn "
.0=" "
05=" " />

minoccurs maxOccurs
1. , , -

1. XML

33

XML . <eiement>:
<xsd:element =" " >

</xsd:element>

:
< x s d : a t t r i b u t e name=" " type="Tnn "
=" " default="3Ha4eHne " />

use :
optional ( );

required ;

prohibited .
,
.
, default .
, ,
<attribute>:
<xsd:attribute =" ">

</xsd:attribute>


, ,
/ .
<compiexType>, :
<xsd:complexType =" " > Tnna</xsd:complexType>

name ,
<complexType> , , /
.

, , ,
. .
2 . 748

34

Web- Java


, , . , , <name> 1.2.
<attribute>, , :
<xsd:complexType name="imageType">
< x s d : a t t r i b u t e name="href" type="xsd:anyURI" />'
</xsd:complexType>
<image>
imageType!
<xsd:element name="image" type="imageType" />
XML :
<image href="http://some.com/images/myface.gif" />


,
.
<simpieContent>.
<restriction>, <extension>c base, () .
<extension> . , :
<xsd:complexType name="calcResultType">
<xsd:simpleContent>
<xsd:extension base="xsd:decimal">
<xsd:attribute name="unit" type="xsd:string" />
<xsd:attribute name="precision"
type="xsd:nonNegativeInteger" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
: "
caicResuitType ,

1. XML

35

xsd:decimal. , unit precision".


<resuit> :
<xsd:element name="result" type="calcResultType" />
XML
<result unit="cM" precision="2">123.25</result>

<restriction>, ,
/ , ,
base. :
<xsd:complexType name="calcResultType">
<xsd:simpleContent>
<xsd:restriction base="xsd:decimal">
<xsd:totalDigits value="8" />
<xsd:attribute name="unit" type="xsd:string" />
<xsd:attribute name="precision"
type="xsd:nonNegative!nteger" />
</xsd:restriction>
</xsd:simpleContent>
</xsd:complexType>


, , , , <address>,
<phone-iist> 1.2, , , (model group)
. , , , , , , .
. <sequence>,
<all> <choice>.

<sequence> ,
.
, , . :

Web- Java
<xsd:complexType name="bookType">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="author" type="xsd:normalizedString"
minOccurs="0" />
<xsd:element name="title" type="xsd:normalizedstring" />
<xsd:element name="pages" type="xsd:positivelnteger"
minOccurs="0" />
<xsd:element name="publisher" type="xsd:normalizedString"
minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
:
<xsd:element name="book" type="bookType" />
<author>, < t i t l e > , <pages> <publisher>
<> . XML :
<book>
<author>M. , . IfeTpoB</author>
<title>3onoToJi TeneHOK</title>
<> </>
</book>
<xsd:sequence> <xsd:ali>,
<author>, < t i t i e > , <pages> <pubiisher>
.
<choice> ,
. , , <pubiisher>, . :
<xsd:complexType name="bookType">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="author" type="xsd:normalizedString"
minOccurs="0" />

1. XML

37

<xsd:element name="title" type="xsd:normalizedString" />


<xsd:element name="pages" type="xsd:positivelnteger"
minOccurs="0" />
<xsd:choice>
<xsd:element name="publisher" type="xsd:normalizedString"
minOccurs="0" />
<xsd:element name="magazine" type="xsd:normalizedString"
minOccurs="0" />
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
, <choice> <sequence>. , , <sequence> <choice>. .
,
, , <choice>
maxOccurs="unbounded".

< a l l > <sequence> <choice>.

<aii> <sequence>
<choice>. , <sequence> <choice>
<aii>. , <all>, , , maxoccurs .


, , , , , , .
<compiexContent>. ,
<simpieContent>, <extension>,
, <restriction>,
. base,
<simpiecontent>,
, !

Web- Java
, , , <>:
<xsd:complexType name="newBookType">
<xsd:complexContent>
<xsd:extension base="bookType">
<xsd:sequence>
<xsd:element name="year" type="xsd:gYear">
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
< r e s t r i c t i o n >
, . ,
newbookType :
<xsd:complexType name="newBookType">
<xsd:complexContent>
<xsd:restriction base="bookType">
<xsd:sequence>
<xsd:element name="author" type="xsd:normalizedString"
minOccurs="0" />
<xsd:element name="title" type="xsd:normalizedstring" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

1. XML

39

. , ? ?
, XSD -
, . ,
. XSD
. . , Java
object, .
anySimpieType .
, .
,
, , :
<xsd:complexType name="bookType">
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="author" type="xsd:normalizedString"
minOccurs="0" />
<xsd:element name="title" type="xsd:normalizedString" />
<xsd:element name="pages" type="xsd:positivelnteger"
minOccurs="0" />
<xsd:element name="publisher" type="xsd:normalizedString"
minOccurs="0" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

40_

Web- Java

XSD ,
. , Java
"extends object" .
XSD .

:
1.4 , 1.2.
j 1.4, XML

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="notebook" type="notebookType" />
<xsd:complexType name="notebookType">
<xsd:element name="person" type="personType"
minOccurs="0" maxOccurs="unbounded" />
</xsd:complexType>
<xsd:complexType name="personType">
<xsd:sequence>
<xsd:element name="name">
<xsd:complexType>
<xsd:attribute name="first" type="xsd:string"
use="optional" />
<xsd:attribute name="second" type="xsd:string"
use="optional" />
<xsd:attribute name="surname" type="xsd:string"
use="required" />
</xsd:complexType>
</xsd:element>

1. XML
<xsd:element name="birthday" type="ruDate" minOccurs="0" />
<xsd:element name="address" type="addressType"
minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="phone-list" type="phone-listType"
minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="addressType" >
<xsd:sequence>
<xsd:element name="street" type="xsd:string" />
<xsd:element name="city" type="cityType" />
<xsd:element name="zip" type="xsd:positivelnteger" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name='cityType'>
<xsd:simpleContent>
<xsd:extension base='xsd:string' >
<xsd:attribute name='type' type='placeType'
default='' />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:simpleType name="placeType">
<xsd:restriction base = "xsd:string">
<xsd:enumeration value="ropofl" />
<xsd:enumeration value="oceo" />
<xsd:enumeration value="flepeBHH" />

41

42

Web- Java

</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="phone-listType">
<xsd:element name="work-phone" type="xsd:string"
minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="home-phone" type="xsd:string"
minOccurs="0" maxOccurs="unbounded" />
</xsd:complexType>
<xsd:simpleType name="ruDate">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9]{2}.[0-9]{2}.[0-9]{4}" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

1.4, XML, , XML


XML http://www.w3.org/2001/XMLSchema.
xsd." , ,
xs.

, ,
notebook, notebookType.
. 1.4 .
notebookType ( ).
, , ,
person personType.
personType . ,
name, birthday, address phone-list.
name f i r s t

1. XML

43_

second string, xsd.


surname string.
1.4 addressType, pnonelistType ruDate. ruDate , XML date 2003-02-22, 22.02.2003.
ruDate (restriction) s t r i n g . (pattern) .. [8].


1.4 .
. XML, , . . 1.4 name.
1.5 .
1.5. XML
<?xml version='1.0'?>
<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema1>
<xsd:element name='notebook'>
<xsd:complexType>
<xsd:sequence>
<xsd:element name='person' maxOccurs='unbounded'>
<xsd:complexType>
<xsd:sequence>
<xsd: element name='name'>
<xsd:complexType>
<xsd:attribute name='first'
type='xsd:string' use='optional' />
<xsd:attribute name='second'
type='xsd:string' use='optional' />

44

Web- Java
<xsd:attribute name='surname'
type='xsd:string' use='required1 />
</xsd:complexType>
</xsd:element>
<xsd:element name='birthday'>
<xsd:simpleType>
<xsd:restriction base='xsd:string'>
<xsd:pattern value='[0-9]{2}.[0-9]{2}.[0-9]{4}' />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name='address' maxOccurs='unbounded'>
<xsd:complexType>
<xsd:sequence>
<xsd:element name='street' type='xsd:string1 />
<xsd:element name='city'>
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base='xsd:string'>
<xsd:attribute name='type' type='xsd:string'
use='optional' default='gorod' />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element name='zip' type='xsd:positivelnteger' />
</xsd:sequence>
</xsd:complexType>

1. XML

45

</xsd:element>
<xsd:element name='phone-list'>
<xsd:complexType>
<xsd:sequence>
<xsd:element name='work-phone' type='xsd:string'
minOccurs='0' maxOccurs='unbounded' />
<xsd:element name='home-phone' type='xsd:string'
minOccurs='0' maxOccurs='unbounded' />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

,
. ,
XML.

XSD
, ,
http://www.w3.org/2001/
XMLSchema. , ,
xs xsd, 1.4 1.5. "" "" .
,

46_

Web- Java

.
(target namespace). targetNamespace,
<xsd:schema targetNamespace="http://some.firm.com/2003/ntbNames">
, ,
http://some.firm.com/
2003/ntbNames. 1.6 , 1.5 XML
http://www.w3.org/2001/XMLSchema
. , ,
ntb, .
1.6. XML
<?xml version='1.0'?>
<schema xmlns='http://www.w3.org/2001/XMLSchema'
targetNamespace='http://some.firm.com/2003/ntbNames'
xmlns:ntb='http://some.firm.com/2003/ntbNames1>
<element name='ntb:notebook>
<complexType>
<sequence>
<element name='person' maxOccurs='unbounded'>
<complexType>
<sequence>
<element name='name'>
<complexType>
<attribute name='first'
type='string' use='optional' />
<attribute name='second'
type='string' use='optional' />
<attribute name='surname'
type='string' use='required' />

1. XML
</complexType>
</element>
=I

<element name birthday'>


<simpleType>
<restriction base='string'>
<pattern value='[0-9]{2}.[0-9]{2}.[0-9]{4}' />
</restriction>
</simpleType>
</element>
<element name='address ' maxOccurs='unbounded'>
<complexType>
<sequence>
<element name='street' type='string' />
<element name='city' type='string' />
<element name='zip' type='positivelnteger' />
</sequence>
</complexType>
</element>
<element name='phone-list'>
<complexType>
<sequence>
<element name='work-phone' type='string'
minOccurs='0' raaxOccurs='unbounded'/>
<element name='home-phone' type='string'
minOccurs='0' maxOccurs='unbounded'/>
</sequence>
</coraplexType>
</element>

47

48

Web- Java
</sequence>
</complexType>
</element>

</sequence>
</complexType>
</element>
</schema>

1.6 http://www.w3.org/2001/XMLSchema, xsd .


, , <schema>.
, . 1.6 <notebook>. name, address
.
XML
. XSD : type, n i l , schemaLocation, noNamespaceSchemaLocation,
,
XML, (XML
schema instance).
http://www.w3.org/2001/XMLSchema-instance.
xsi, :
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


, .
: <inciude> <import>. :
<xsd:include xsi:schemaLocation="names.xsd" />
xsi: schemaLocation.
,
names.xsd. , ,
, targetNamespace.

1. XML

49

, names.xsd . ,
names.xsd <inciude>.
, . <redef ine>, :
<xsd:redefine schemaLocation="names.xsd">
<xsd:simpleType name="nameType">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="40"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:redefine>
,
<import>. ,
A.xsd :
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://some.firm.com/someNames">,
B.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://some.firm.com/anotherNames">
C.xsd. :
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://some.firm.com/yetAnotherNames"
xmlns:prl="http://some.firm.com/someNames"
xmlns:pr2="http://some.firm.com/anotherNames">
<xsd:import namespace="http://some.firm.com/someNames"
xsi:schemaLocation="A.xsd" />
<xsd:import namespace="http://some.firm.com/anotherNames"
xsi:schemaLocation="B.xsd" />

Web- Java

C.xsd ,
A.xsd B.xsd, p r i 2 .
<include> <import> .
xsi:schemaLocation URI,
.

XML
-, XML
, - ( ),
. . -, . , ,
XSV (XML Schema Validator) (ftp://ftp.cogsci.ed.ac.uk/pub/XSV/):
$ xsv ntb.xml ntbl.xsd ntb2.xsd
-, , setProperty ,
. , , Xerces.
,
. ,
XML. .
1.
, noNamespaceSchemaLocation,
URI:
<notebook xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ntb.xsd">
, ,
targetNamespace.
2.
, schemaLocation,
,
.
, :
<notebook xmlns="http://some.firm.com/2003/ntbNames"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http: //some. firm.com/someNames A.xsd

1. XML

51

http://some.firm.com/anotherNames B.xsd"
xmlns:prl="http://some.firm.com/someNames"
xmlns:pr2="http://some.firm.com/anotherNames">
,
A.xsd B.xsd, p r l 2 .


XSD ,
. , .
.
, XML. :
Schematron http://www.ascc.net/xml/resource/schematron/,
RELAX NG (Regular Language Description for XML, New Generation, XML ) http://www.oasisopen.org/committees/relax-ng/;
Relax TREX,
Relax http://www.xml.gr.jp/relax/,
TREX (Tree Regular Expressions for XML, XML) http://www.thaiopensource.com/trex/,
DDML (Document Definition
),
http://purl.oclc.org/NET/ddml/.

Markup Language, XSchema

DCD (Document Content Description, ), SOX (One's Schema for Object-Oriented XML,
- XML), XDR (XML-Data Reduced,
XML-).
.
, XSD, , .


XML
(processing instructions). -
. :
<? ?>

52

Web- Java

XML XML-
. XML , .
. XML . ,
, , , , XML.
, , (parse)
.

XML
(lexical parsing) XML.
(tokens), , , ,
.
.
(scanners). j a v a . u t i i . s t r i n g T o k e n i z e r
java.io.streamTokenizer Java 2 SDK Standard
Edition.
(grammar parsing). , , , , , , , .
-, (parsers).
.
XML , XML-.
Java.
.
, ,
, (treebased parsing). , , XML
.
.
, , (event-based parsing). -
XML: , , . : startElement(), endElement(), characters()

1. XML

53

, ,
.
SAX
(Simple API for XML Parsing, API XML),
(David Megginson).
http://www.saxproject.org/. , SAX2. SAX2 , ,
Xerces2.
Java 2 Standard Edition Enterprise Edition JAXP XML. , DOM API (Document Object Model API, API
), ,
, JAXP,
SAX API, SAX-. SAX2
org.xml.sax, org.xml.sax.ext, org.xml.sax.helpers,
javax.xml.parsers. .

XML SAX2API
SAX2 org.xml.sax.ContentHandler, : , , , ,
. SAX2 - , ,
. ,
.

public void startDocument();
.
<', ,

public void startElement(String uri, String name,


String qname, Attributes attrs);
,
: u r i , name
qname,
a t t r s , . ,

54

Web- Java

null. , a t t r s .
"</", ,

public void endElement(String uri, String name, String qname);



public void characters(char[] ch, int start, int length);
ch,
start length.

public void processinglnstruction(String target, String data);


- target
data.
, ,

public void ignorableWhitespace(char[] ch, int start, int length);

ch ,
s t a r t length.
org.xml.sax.ContentHandler org.xml.sax.
helpers.DefauitHandier. .
, .
SAX2 .
XML ,
- . XML
, JDO (Java Data
Objects). (data binding) JDO.
Java.
Java,
.
1.7. ,
public class Address)
private String street, city, zip, type = "";

1. XML
public Address() {}
public String getStreet(){ return street; }
public void setStreet(String street){ this.street = street; }
public String getCity(){ return city; }
public void setCity(String city){ this.city = city; }
public String getZip(){ return zip; }
public void setZip(String zip){ this.zip = zip; }
public String getType(){ return type; }
public void setType(String type){ this.type = type; }
public String toString(){
return "Address: " + street + " " + city + " " + zip;

1.8. ,
public class Person{
private String firstName, secondName, surname, birthday;
private Vector address;
private Vector workPhone;
private Vector homePhone;
public Person(){}
public Person(String firstName, String secondName,
String surname){
this.firstName = firstName;
this.secondName = secondName;
this.surname = surname;

public String getFirstName(){ return firstName; }


public void setFirstNaroe(String firstName){

55

56

Web- Java
this.firstName = firstName;

1
public String getSecondName(){ return secondName; }
public void setSecondName(String secondName){
this.secondName = secondName;

public String getSurname(){ return surname; }


public void setSurname(String surname)!
this.surname = surname;

public String getBirthday(){ return birthday; }


public void setBirthday(String birthday))
this.birthday = birthday;

public void addAddress(Address addr){


if (address == null) address = new Vector();
address.add(addr);
}
public Vector getAddress(){ return address; }
public void removeAddress(Address addr){
if (address != null) address.remove(addr);

public void addWorkPhone(String phone){


if (workPhone == null) workPhone = new Vector();
workPhone.add(new Integer(phone));
}
public Vector getWorkPhone(){ return workPhone; }
public void removeWorkPhone(String phone)(
if (workPhone != null)
workPhone.remove(new Integer(phone));

1. XML

57

}
public void addHomePhone(String phone)(
if (homePhone = null) homePhone = new Vector();
homePhone.add(new Integer(phone));
public Vector getHomePhone(){ return homePhone; }
public void removeHomePhone(String phone){
if (homePhone != null)
homePhone.remove(new Integer(phone));

public String toStringO {


return "Person: " + surname;

Java, , ,
Java.
1.9 - NotebookHandler , 1.2. NotebookHandler
, Person, 1.8.
:

1.9. - XML
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import j avax.xml.parsers.*;
import java.util.*;
import j ava.io.*;
public class NotebookHandler extends DefaultHandler{
static final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
static final String W3C_XML_SCHEMA =

56

Web- Java
"http://www.w3.org/2001/XMLSchema";
Person person;
Address address;
static Vector pers = new Vector();
boolean inBirthday, inStreet, inCity, inZip,
inWorkPhone, inHomePhone;

public void startElement(String uri, String name,


String qname, Attributes attrs)
throws SAXException{
if (qname.equals("name"))
person = new Person(attrs.getValue("first") ,
attrs.getValuet"second"), attrs.getValue("surname"));
else if (qname.equals("birthday"))
inBirthday = true;
else if (qname.equals("address"))
address = new Address();
else if (qname.equals("street"))
inStreet = true;
else if (qname.equals("city")){
inCity = true;
if (attrs != null) address.setType(attrs.getValue("type"));
}else if (qname.equals("zip"))
inZip = true;
else if (qname.equals("work") )

1. XML
inWorkPhone = true;
else if (qname.equals("home"))
inHomePhone = true;
}
public void characters(char[] buf, int offset, int len)
throws SAXExceptionf
String s = new String(buf, offset, len);
if (inBirthday){
person.setBirthday(s);
inBirthday = false;
}else if (inStreet){
address.setStreet(s);
inStreet = false;
}else if (inCity){
address.setCity(s);
inCity = false;
}else if (inZip){
address.setzip(s);
inZip = false;
}else if (inWorkPhone){
person.addWorkPhone(s);
inWorkPhone = false;
}else if (inHomePhone){
person.addHomePhone(s);

59

60

Web- Java
inHomePhone = f a l s e ;

public void endElement(String uri, String name,


String qname) throws SAXException{
if (qname.equals("address")){
person.addAddress(address);
address = null;
(else if (qname.equals("person")){
pers.add(person);
person = null;

public static void main(String[] args){


if (args.length < 1){
System.err.println("Usage: Java Notebook ntb.xml");
System.exit(1);
}
try{
NotebookHandler handler = new NotebookHandler();
SAXParserFactory fact = SAXParserFactory.newInstance ();
fact.setNamespaceAware(true);
fact.setValidating(true);
SAXParser saxParser = fact.newSAXParser();
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA)
File f = new File(args[0]);

1. XML
saxParser.parse(f, handler);
for (int = 0; < pers.size (); k++)
System.out.println(((Person)pers.get(k)).getSurnarae());
}catch(SAXNotRecognizedException x){

System.err.println(" : " +
JAXP_SCHEMA_LANGUAGE);
System.exit(1);
}catch(Exception ex){
System.err.println(ex) ;

public void warning(SAXParseException ex){


System.err.println("Warning: " + ex);
System.err.println("line = " + ex.getLineNumber() +
" col = " + ex.getColumnNumber());

public void error(SAXParseException ex){


System.err.println("Error: " + ex);
System.err.println("line = " + ex.getLineNumber() +
" col = " + ex.getColumnNumber());

public void fatalError(SAXParseException ex){


System.err.println("Fatal error: " + ex);
System.err.println("line = " + ex.getLineNumber()
" col = " + ex.getColumnNumber());

61

62

Web- Java

- ,
. main
1.9.
, SAX-napcep SAXParser , newSAXParser () .
-, , newinstance ().
- void setFeature(String name,
boolean value) , .
,
fact.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
, fact, .
SAX
http://www.saxproject.org/. , .
- void setValidating(true),
1.9, ,
. void setNamespaceAware(true),
- ,
.
- ,
parse , .
javax.xml.parsers. SAXParser parse (). parse(File, DefauitHandier), 1.9,
,
inputstream, inputsource, URI
inputsource.
setProperty . 1.9 , XSD.
JAXP, JAXP 1.2.

s e t v a l i d a t i n g ( t r u e ) ,
. ErrorHandier,
, , :

1. XML

63

public void warning(SAXParserException ex);


public void error(SAXParserException ex);
public void fatalError(SAXParserException ex);
DefauitHandier .
ErrorHandier. 1.9. SAXParserException , . getLineNumber () getColumnNumber (), 1.9.

XML Java
Address Person,
XML. XML
,
XML Java
.
Sun Microsystems JAXB,
. JAXB
,
http://java.sun.com/xml/jaxb/. JAXB
XML DTD.
, JAXB, XSD. , .
JAXB xjc (XML-Java Compiler). DTD Java
, Java. ,

$ xjc -roots notebook ntb.dtd -d sources
ntb.dtd 1.3 sources (
) Address.java, Name.java,
Notebook.java, Person.java, PhoneList.java Java.
-roots , .
DTD xjc (binding language) XML. , XSD, . -, JAXB XSD.

64

Web- Java

ntb.xjs (XML-Java binding schema), :


$ xjc ntb.dtd ntb.xjs -d sources

xjc javac Java.


,
XML unmarshaio, , , , Java XML marshal . xjc , Notebook.

JDO
Java
XML, ,
, .
Sun Microsystems JDO
JDO.
http://www.jcp.org/jsr/detail/12.jsp http://accessl.sun.com/jdo/.
JDO ,
XML, ,
EIS (Enterprise Information
System). :
JDO SPI (JDO Service Provider Interface)
, , , , , ;
javax. jdo.spi;
JDO API (JDO Application Programming Interface) , , , ;
javax.jdo.

, JDO ,
Sun . .
Prism Technologies, http://www.prismtechnologies.com/, OpenFusion JDO.
SolarMetric, http://www.solarmetric.com/,
JDO Kodo JDO.
WebLogic, WebSphere, JBoss.

1. XML

65

, JDO http://www.jdocentral.com/.
, JDO,
JDO, .
Exolab,
Castor. http://castor.exolab.org/.
Castor . , Java XML,
, :
Person person = (Person)Unmarshaller.unmarshal(
Person.class, new FileReader("person.xml"));

, Java XML
:
Marshaller.marshall(person, new FileWriter("person.xml"));
XML,
XSD, (mapping file).

XML DOM API


, SAX-napcep
, , .
, .
W3C D0M, http://www.w3.org/D0M/. XML
. , , ,
. ,
, ,
. , .
Sun Microsystems D0M javax.
xml.parsers org.w3c.dom, JAXP. :
DocumentBuilderFactory fact =
DocumentBuilderFactory.newInstance();
3 . 748

66

Web- Java

DocumentBuilder builder = fact.newDocumentBuilder();


Document doc = builder.parse("ntb.xml");

parse ()
Document. DocumentBuilder
par s e n , URL, ,
File inputsource.
Document, Node,
. Node
.
Element, , XML. , , . Attr.
CDATASection, Comment, Text, Entity,
EntityReference, Processinglnstruction, Notation
XML.
. 1.2 , ,
1.2. , , ,
. .
D O M Echo.,.;:,...........

... ..,:...

.;'.::. _ a

1 3 Document
0 DocType notebook

^ Element notebook
QText
" Element person
QText
Element person
QText
Q Element name
QText
Element birthday
QText 17051969

\
\t
:

QTex!
-C3 Element address
QText
9 C3 Element phone list
QText
9 Element home-phone
0 Text 2334455
QText
DText
QText

. 1.2. XML

1. XML

67_

Node
Node :
ATTRIBUTE_NODE Attr, ;
CDATA_SECTION_NODE CDADASection,
CDATA;

COMMENT_NODE comment, ;
DOCUMENT_FRAGMENT_NODE DocumentFragment
;
DOCUMENT_NODE Document;
DOCUMENT_TYPE_NODE Document;
ELEMENT_NODE Element;
ENTITY_NODE Entity ENTITY;
ENTITY_REFERENCE_NODE EntityReference
;
Q NOTATION_NODE Notation;
PROCESSING_INSTRUCTION_NODE Processinglnstruction, ;
TEXT_NODE Text .
Node .
:
public short getNodeType();
:
public String getNodeName();
, , :
public String getNodeValue();
, XML,
NamedNodeMap, Element, :
public boolean hasAttributes();
:
public NamedNodeMap getAttributes();
null, .
, -:

68

Web- Java

public boolean hasChildNodes();


, NodeList
:
public NodeList getChildNodes();
:
public Node getFirstChildO ;
public Node getLastChildO;
:
public Node getParentNode();
, :
public Node getPreviousSibling();
public Node getNextSibling();
:
public Document getOwnerDocument();
.
- newchild :
public Node appendChild(Node newChild);
- newchild
refchild :
public Node insertBefore(Node newChild, Node refChild);
- oldchild newchild :
public Node replaceChild(Node newChild, Node oldChild);
, - :
public Node removeChild(Node c h i l d ) ;

Document
Document Node .
public DocumentType getDocType();
DocumentType.
getNameO, getEntitied (), getNotations () DocumentType .

1. XML

69

public Element getDocumentElement();

,
public NodeList getElementsByTagName(String name);
public NodeList getElementsByTagNameNS(String uri, String qname);
public Element getElementByld(String id);
tag , , ID.

.


public Element createElement(String name);
public Element createElementNS(String uri, String name);
CDATA_SECTION_NODE
public CDATASection createCDATASection(String name);
ENTITY_REFERENCE_NODE
public EntityReference createEntityReference(String name);

PROCESSING_INSTRUCTION_NODE
public Processinglnstruction createProcessinglnstruction(String name);
TEXT_NODE
public TextNode createTextNode(String name);
- name
public Attr createAttribute(String name);
public Attr createAttributeNS(String uri, String name);
-
public Comment createComment(String comment);
,

public DocumentFragment createDocumentFragment();
, , , ,

public Node importNode(Node importedNode, boolean deep);
.
true, .

70

Web- Java

Element
Element Node
XML ,
.
public String getTagName();
, , .
name

public boolean hasAttribute(String name);
public boolean hasAttributeNS(String uri, String name);
u r i , URI; name , .
Attr
name
public Attr getAttributeNode(String name);
public Attr getAttributeNodeNS(String uri, String name);
public String getAttribute(String name);
public String getAttributeNS(String uri, String name);

public Attr removeAttributeNode(Attr name);
public void removeAttribute(String name);
public void removeAttributeNS(String uri, String name);

public void setAttribute(String name, String value);
public void setAttributeNS(String uri, String name, String value);

public Attr setAttributeNode(String name);
public Attr setAttributeNodeNS(Attr name);
-:
public NodeList getElrmentsByTagName(String name);
public NodeList getElrmentsByTagNameNS(String uri, String name);
, , , ,
.

1. XML

71

,
XML. 1.2 . 1.10.
1.10. DOM API
import org.w3c.dom. *;
import javax.xml.parsers .*;
import org.xml.sax.*;
class ErrHand implements ErrorHandler{
public void warning(SAXParseException ex){
System.err.println("Warning: " + ex);
System.err.printlnC'line = " + ex.getLineNumber() +
" col = " + ex.getColumnNumber());

public void error(SAXParseException ex){


S y s t e m . e r r . p r i n t l n ( " E r r o r : " + ex);
S y s t e m . e r r . p r i n t l n ( " l i n e = " + ex.getLineNumber() +
" col = " + ex.getColumnNumber());

public void fatalError(SAXParseException ex){


S y s t e m . e r r . p r i n t l n ( " F a t a l e r r o r : " + ex);
S y s t e m . e r r . p r i n t l n ( " l i n e = " + ex.getLineNumber() +
" col = " + ex.getColumnNumber());

public class TreeProcessDOMf


static final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage"
static final String W3C_XML_SCHEMA =

72

Web- Java
"http://www.w3.org/2001/XMLSchema";

public static void main(String[] args) throws Exception}


if (args.length != 3){
System.err.println("Usage: Java TreeProcessDOM " +
"<file-name>.xml {worklhome} <phone>");
System.exit(-1);
}
DocumentBuilderFactory fact =
DocumentBuilderFactory.newInstance() ;
fact.setNamespaceAware(true);
fact.setValidating(true);
try{
fact.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
}catch(IllegalArgumentException x){
System.err.println(" : " +
JAXP_SCHEMA_LANGUAGE);
System.exit(-1);
}
DocumentBuilder builder = fact.newDocumentBuilder();
builder.setErrorHandler(new ErrHand());
Document doc = builder.parse(args[0]);
NodeList list = doc.getElementsByTagName("notebook");
int n = list.getLength();
if (n == 0) {
System.err.println(" .");

1. XML
System.exit(-1);
}

Node thisNode = null;

for (int = 0; < n; k++){


thisNode = list.item(k);
String elemName = null;
if (thisNode.getFirstChildO instanceof Element){
elemName = (thisNode.getFirstChildO).getNodeName();
if (elemName.equals("name")){
if (!thisNode.hasAttributes()){
System.err.println(" " + elemName);
System.exit(1);
}
NamedNodeMap attrs = thisNode.getAttributes();
Node attr = attrs.getNamedltern("surname");
if (attr instanceof Attr)
if (((Attr)attr).getValue().equals("")) break;

NodeList topics = ((Element)thisNode)


.getElementsByTagName("phone-list")
Node newNode;
if (args[1].equals("work"))

73_

74_

Web- Java
newNode = doc.createElement("work-phone");
else newNode = doc.createElement("home-phone");

Text textNode = doc.createTextNode(args[2]);


newNode.appendChild(textNode);
thisNode.appendChild(newNode);

, ,
JTree Swing [10]. . 1.2. DomEcho
"Web Services Tutorial". , ,
http://java.sun.com/webservices/tutorial.html. Xerces samples/ui/
Treeview, JTree
Swing.

DOM-
D0M
OMG (Object Management Grou) IDL (Interface Definition
Language, ) Java. Java W3C , org.w3c.dom. , , DOM API .
.
JDOM
D0M, ,
JDOM [6J. ,
http://www.jdom.org/. , XML Java.
dom4j W3C
D0M, DOM API. dom4j http://www.dom4j.org/.

1. XML

75_

(The Mind Electric), http://www.themindelectric.com/, GLUE GAIA, GLUE EXML


(Electric XML) EXML+ (Electric XML+).
W3C DOM, , .

XML
, D0M .
XML, HTML, PDF
. JAXP javax.xmi.transform,
javax.xml.transform.dom, javax.xml.transform.sax, javax.xml.transform.stream,


XSLT (XML Stylesheet Language for Transformations) Java.
XSLT W3 , XSL (XML Stylesheet Language).
XSL
http://www.w3.org/Style/XSL/.
, javax.xml.transform. *,
XSLT,
Xalan, Apache Software Foundation,
http://xml.apache.org/xalan-j/.
Source.
Source :
public String getSystemldO ;
public void setSystemId(String id);

source . DOMSource
D0M, SAXsource
streamSource SAX- . DOMSource ,
SAXSource , S t r e a m S o u r c e

. .
Result. -,
source.
DOMResult, SAXResult S t r e a m R e s u l t . -

76_

Web- Java

. , ContentHandier, , , .
Transformer. DOM XML, .
TransformerFactory transFactory =
TransformerFactory.newlnstance();
Transformer transformer = transFactory.newTransformer();
DOMSource source = new DOMSource(document);
File newXMLFile = new F i l e ( " n t b l . x m l " ) ;
FileOutputStream fos = new FileOutputStream(newXMLFile);
StreamResult r e s u l t = new StreamResult(fos);
transformer.transform(source, r e s u l t ) ;
newlnstance transFactory -.
public void setAttrbute(String name, String value);
Trans formerFactory
. .
-
Transformer. , , , XSL.
Transformer
public void setParameter(String name, String value);
,
public void setOutputProperties(Properties out);
public void setOutputProperty(String name, String value);
. name
,
outputKeys, . :

CDATA_SECTION_ELEMENTS
DOCTYPEPUBLIC

CDATA

PUBLIC

1. XML

77

DOCTYPE_SYSTEM SYSTEM
.
ENCODING ,
encoding XML.
INDENT . "yes" "".
MEDIATYPE - .
METHOD , "xmi", "html" "text".
OMIT_XML_DECLARATION XML. "yes"
"".
STANDALONE ,
standalone XML. "yes" "".
VERSION XML version XML.
,
:
transformer.setOutputProperty(OutputKeys.ENCODING, "Windows-1251");

document Node DOMSource . ,


, - , DOMSource .
, result, newCourses.xmi transform .
XSL.

XSL
HTML CSS,
HTML: , , .
.
XML, , .
XML XML, XSL (XML Stylesheet Language).

XSL

http://www.w3.org/1999/XSL/Transform. -

Web- Java

xsi. ,
XSL <xsl:styiesheet>.
, 1.11.
1.11. XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet

version="l.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="CP866"/>
</xsl:stylesheet>

xsi , , , text
( html xmi), 8 66. MS Windows.
Transformer, 1.11, , XML,
, .
, , simple.xsl.
XML
:
<?xml version="1.0" encoding="Windows-1251"?>
<?xml-stylesheet type="text/xsl" href="simple.xsl"?>
<notebook>
<! >

XML-napcep, , , XSLT, , simple.xsl.



, , , 1.12.
[ 1.12. XML
import j ava.io.*;
import javax.xml.transform.*;
impo r t j avax.xml.t rans form. s t rearn. *;
public class

SimpleTransform{

1. XML

79

public static void main(String[] args)


throws TransformerExceptionf
if (args.length != 2){
System.out.println("Usage: " +
"Java SimpleTransform xmlFileName xsltFileName");
System.exit(1);

File xmlFile = new File(args[0]);


File xsltFile = new File(args[1]);
Source xmlSource = new StreamSource(xmlFile) ;
Source xsltSource = new StreamSource(xsltFile);
Result result = new StreamResult(System.out);
TransformerFactory transFact =
TransformerFactory.newInstance();
Transformer trans =
transFact.newTransformer(xsltSource)
trans.transform(xmlSource, result);


Java SimpleTransform ntb.xml simple.xsl
ntb.xml.
. ,
,
- Transformer , 1.13.
1.13.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="l.0"

80

Web- Java
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" encoding="CP866" />


<xsl:template match="person">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="name">
<xsl:value-of select="@first" />

<xsl:text> </xsl:text>

<xsl:value-of select="@second" /> <xsl:text> </xsl:text>


<xsl:value-of select="@surname" />
</xsl:template>
<xsl:template match="address">
<xsl:value-of select="street" /> <xsl:text> </xsl:text>
<xsl:value-of select="city" />

<xsl:text> </xsl:text>

<xsl:value-of select="zip" />


</xsl:template>
<xsl:template match="phone-list">
<xsl:value-of select="work-phone" /> <xsl:text>S#xA;</xsl:text>
<xsl:value-of select="home-phone" /> <xsl:text>&#xA;</xsl:text>
</xsl:template>
</xsl:stylesheet>

XSL
.
"" XSLT [5]. (Michael H. )

1. XML

81

XSLT- Saxon,
http://users.iclway.co.uk/mhkay/saxon/index.html.

XSLT [2], XSLT. XSLT- .


, XSL, XSLT (XSL Transform), XSL FO (XSL
Formatting Objects)
XPath (XML Path Language), , .

XML HTML
XSL Transformer XML HTML. . 1.14 ,
1.2.
1.14. XML HTML
<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet

version="l.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="Windows-1251"/>
<xsl:template match="/">
<htmlxheadxtitle>AflpecHaH Kti;KKa</titlex/head>
<2>, </2>
<xsl:apply-templates />
</bodyx/html>
</xsl:template>
<xsl:template match="name">
<p />

Web- Java

82

<xsl:value-of select="@first" /> <xsl:text> </xsl:text>


<xsl:value-of select="@second" /> <xsl:text> </xsl:text>
<xsl:value-of select="@surname" /> <br />
</xsl:template>
<xsl:template match="address">
<br />
<xsl:value-of select="street" /> <xsl:text> </xsl:text>
<xsl:value-of select="city" /> <xsl:text> </xsl:text>
<xsl:value-of select="zip" /> <br />
</xsl:template>
<xsl:template match="phone-list">
: <xsl:value-of select="work-phone" /> <br />
: <xsl:value-of select="home-phone" /> <br />
</xsl:template>
</xsl:stylesheet>

, , ntb.xsl,
XML, :
<?xml version="1.0" encoding="Windows-1251"?>
<?xml-stylesheet type="text/xsl" href="ntb.xsl"?>
<notebook>
< ! >

, "" XML XSLT, ,


Mozilla Internet Explorer,
1.14.

$ Java SimpleTransform ntb.xml ntb.xsl > ntb.html

HTML-.

Web Services
, " " WWW (World Wide Web, "
", Web Webster). .
: Mozilla, Opera, Internet
Explorer, Netscape Communicator , . Web- , WWW,
, Web-, , . Web- . URL, -
http://www.some.com/coolpage.html,
.
HTTP, .
- Web-,
80.
, HTTP,
, .
WWW HTML, ,
HTTP, .
HTML, , ,
ASCII-,
.
.
, WWW, , , , HTML-,

84

Web- Java

, .

, , , .
,
, (distributed) . (remote) .
. , .
: RPC, RMI, DCOM, COM+, CORBA,
.NET. : BSD, Java Microsoft Windows.
CORBA , , CORBA
.
80-
Xerox RPC
(Remote Procedure Call). RPC ,
, (stub).
, , (marshall) , .
(marshalling).
. ,
, , , , . ,
, (unmarshall) ,
, , ,
(marshall) .
(unmarshall)
.
RPC .
[10] . RPC
.
RPC.
, , .

2. Web Services

85

[10], ,
, ,
,
.
, -, , : , , , . Web-, , Web-, ,
, ,
, Web- . 2.1.

HTTP

/
Web-

. 2 . 1 . - WWW

- . "", . .
.
,
. "",
, . , , ,
.
, , "",
, "", .
WWW "" "" Web-.
.
.
-,
, , , -

86

Web- Java

(middleware) .
, , . . Java (application server). : BEA WebLogic, JBoss, IBM WebSphere, Sun
ONE Application Server, Oracle9i Application Server, Sybase EAServer, IONA
Orbix E2A, Borland Enterprise Server . Microsoft
Corporation IIS (Internet Information Services).
. : , ,
. Java Web-
JSP. , , Web-. Java EJB-
EJB. . 2.2.

Web-

* - )

JSP

EJB-
S e s s i o n

E n t i t y

B e a n

B e a n

. 2 . 2 .

, . , : RPC,
RMI, DCOM, CORBA, , (tightly
coupled) . , , . : MS Windows, Linux
Apple Macintosh, Solaris, Linux, Free BSD, AIX, HP UX,
UNIX . , ,
. Java .
,
, (loosely

2. Web Services

87

coupled) . , Web-
. , -. ,
, .
, Web- ,
HTTP , .
.
,
. , .
Web Services , Web-
. , . "
" , WWW,
HTML HTTP. HTML

XML. , . XML,
, . XML
,
ASCII-.
, Web Services , WWW
XML, HTTP
Web-. .
, Web Services,
Web-. ,
W3C " Web Services",
http://www.w3.org/TR/wsa-reqs. :
"A Web service is a software application identified by a URI, whose interfaces and
binding are capable of being defined, described and discovered by XML artifacts
and supports direct interactions with other software applications using XML based
messages via internet-based protocols".
:
"Web Service , URI, ,
XML. , XML".
Web Service ,
Web-. , XML-,
. Web- : , Web-

88

Web- Java

. , "Web Services", , , . ,
Web- -, a Web
Services , -. , Web
Service ,
.
. "Web Service"
, ("Web
Service"), "Web-", , Web-, "Web-".
, Web-
, XML.
XML-RPC,
XML. .

XML-RPC
XML
,
1999 (Dave Winer), XML-RPC XML XML-RPC. http://www.xmlrpc.com/spec.
XML-RPC, Frontier
(http://www.userland.com/). XML-RPC : Java, Perl, Python, C/C++, Ruby.
XML-RPC , XML.

public String getWeatherForecast(String location);
.
location, .
.
XML-RPC , , :
<?xml version="1.0"?>
<methodCall>

2. Web Services

89

<methodName>getWeatherForecast</methodName>
<params>
<param>
<value>
<string>rarB0KMHO</string>
</value>
</param>
</params>
</methodCall>

<methodcaii>.
<methodName>,
, <params>,
.
<methodName> ,
AZ, az, 09, , ,
.
<params> <param>, .
<param>
<vaiue>. , . . 2.1 .
2.1. XML-RPC

< i 4 > < i n t >


<boolean>

4-
0 (false) 1 (true)

<string>

ASCII

<double>

8-

<dateTime . i s o 8 601>

CCYYMMDDTHH:MM:SS

<base64>

Base 64

<array>

<struct>

90

Web- Java

<string>.
2.1,
.
- :
<>
<data>
<valuexint>12</intx/value>
<value>raj50KHHO</value>
<value><boolean>0</boolean></value>
<value><i4>-3K/i4x/value>
</data>
</array>

<array> <data>, <vaiue> . , ,


. ,
.
- :
<struct>
<member>
<name>day</name>
<valuexi4>18</i4x/value>
</member>
<member>
<name>month</name>
<valuexi4>ll</i4x/value>
</member>
</struct>

Pascal.
, <member>.
<name> , <vaiue> , .
, .

2. Web Services

91

XML <methodCali> HTTP


POST
Content-Type: text/xml
, ,
XML
<?xml version="l.0"?>
<methodResponse>
<params>
<param>
<value>ByflyT </1>
</param>
</params>
</methodResponse>


<methodResponse> <params>,
<param> <vaiue>.
,
<methodResponse> <params> <fauit>.
:
<?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<valuexint>4</intx/value>
</member>
<membe r>

92

Web- Java
<name>faultString</name>
<value>Too many parameters.</value>
</member>
</struct>

</value>
</fault>
</methodResponse>
<fauit> <vaiue>,
, fauitcode
f a u i t s t r i n g .
.
.
XML-RPC. , ,
. DTD XML. , ,
,
.
, XML-RPC
, . . SOAP.

SOAP
SOAP 1998 UserLand
Microsoft, W3C, . http://www.w3.org/TR/SOAP/.
SOAP ,
(message) XML.
, ,
- . SOAP , .
XML <Enveiope> <Header> <Body>. SOAP :

2. Web Services

93

<?xml v e r s i o n - . ' ?>


<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope">
<env:Header>
< ! >
</env:Header>
<env:Body>
< ! >
</env:Body>
</env:Envelope>
, . . ,
SOAP, ,
, XML. RPC-, XML.

SOAP
SOAP
, , ,
. .
, , , :
<?xml version='1.0' ?>
<env:Envelope
Kmlns:env="http://www.w3.org/2002/06/soap-envelope">
<env:Body>
<met:getWeatherForecast env:encodingStyle=
"http://www.w3.org/2002/0 6/soap-encoding"

94

Web- Java
xmlns:met="http://www.meteoservice.com/">
<met: location>ra,moKMHo</met: location>
</met:getWeatherForecast>

</env:Body>
</env:Envelope>
,
.
XML, . XML, . ,
encodingstyie.
http://www.w3.org/2002/06/soap-encoding

SOAP, .
SOAP.

-
SMTP.

SOAP- . HTTP
HTTP GET.
POST

Content-Type: application/soap+xml;
:
<?xml version='1.0' ?>
<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope">
<env:Body>
<met:getWeatherForecastResponse
env:encodingStyle="http://www.w3.org/2002/06/soap-encoding"
xmlns:rpc="http://www.w3.org/2002/06/soap-rpc"
xmlns:met="http://www.meteoservice.com/">
<rpc:result>met:forecast</rpc:result>
<met:forecast>ByflyT /met:forecast>

2. Web Services

95

</met:getWeatherForecastResponse>
</env:Body>
</env:Enve1ope>

, , ,
, "Response", .
. <resuit>.
http://www.w3.org/2002/06/ soap-rpc.

met: forecast, , XML.
<met:forecast>

http://www.meteoservice.com/.

, <resuit>.
SOAP,
http://www.w3.org/2002/06/soap-encoding,
XSD ('. 1).
, :
<?xml version="1.0"?>
<env:Envelope
env:encodingStyle="http://www.w3.org/2002/06/soap-encoding"
xmlns:env="http://www.w3.org/2002/06/soap-envelope"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<met:getWeatherForecast
xmlns:met="http://www.meteoservice.com/">
<met:location xsi:type="xsd:string">

</met:location>

Web- Java
</met:getWeatherForecast>
</env:Body>
</env:Envelope>
, XSD, SOAP-
.
, , :
<person enc:arrayType="xsd:string[3]" xsi:type="enc:Array">
<></>
<></>
<></>
</person>
.
, :
<person>
<firstname>HBaH</firstname>
<secondname>neTpoBM4</secondname>
<surname>CMflopoB</surname>
</person>
.

SOAP
SOAP - ,
XML .

. :
<?xml v e r s i o n = 4 . 0 " ?>
<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope">
<env:Header>
<! -->
</env:Header>

2. Web Services

97

<env:Body>
<ms:passport xmlns:ms="http://burou.org/">
<ms:series>13-XM</ms:series>
<ms:number>123456</ms:number>
</ms:passport>
</env:Body>
</env:Envelope>


. HTTP,
- , , SMTP .
SOAP ,
, W3C XML, XML-RPC, SOAP . (XML
Protocol). (eXtreme Programming). , , XMLP (XML Protocol). . ,
XMLP. , , SOAP, .

SOAP
, Web- , .
SOAP- SOAP-.
http://www.soapware.org/.
, Web-
IBM, Microsoft, Sun, Oracle SOAP-.
IBM SOAP- SOAP4J, Apache
Software Foundation, Apache SOAP (http://xml.apache.org/SOAP/). IBM WebSphere .
4 . 748

98

Web- Java

Apache, , XMLP, Apache SOAP, XMLP Axis (http://xml.apache.org/axis/). XMLP,


Apache extensible Interaction System.
Apache SOAP 3, Apache SOAP. Axis XMLP , Axis
,
SOAP. Axis IBM WebSphere
Application Server (http://www-3.ibm.com/software/webservers/)
.
SOAP- IBM Web- WSTK (Web Services Toolkit) (http://www.alphaworks.ibm.com/
tech/webservicestoolkit), Axis. ,
Web-
IBM WebSphere Studio (http://www-4.ibm.com/software/webservers/studio/).
Sun Microsystems
javax.xmi.soap, SAAJ (SOAP with Attachments API for Java)
SAAJ. ,
, SOAP-
.

javax.xmi.messaging, JAXM (Java API for XML Messaging).


SOAP- JMS (Java Message Service).
, javax.xmi. soap javax.xmi.messaging, SOAP. . SOAP
Sun javax.xmi. . JAX-RPC (Java API for XML-RPC).
RMI, a SOAP "" RMI
JRMP (Java Remote Method Protocol) CORBA (Internet
Inter-ORB Protocol).
Sun J2EE
(http://java.sun.com/j2ee/) Sun ONE Application
Server (http://wwws.sun.com/software/products/appsrvr/). , Web- WSDP (Web Services
Developer
Pack)
(http://java.sun.com/webservices/webservicepack.html).

Web-
Sun ONE Studio (http://wwws.sun.com/software/sundev/jde/).

2. Web Services

99

Microsoft SOAP
SOAP Microsoft SOAP
Toolkit (http://msdn.microsoft.com/webservices/downloads/)
Web- IIS ISAPI- ASP-. ,
Web- Microsoft Visual Studio .NET
(http://msdn.microsoft.com/vstudio/).
Oracle (http://www.oracle.com/) Apache SOAP, , OC4J (Oracle9iAS Containers
for J2EE), Oracle9i Application Server.
Web- Oracle JDeveloper.
Borland Software Corporation Axis Apache SOAP BES (Borland Enterprise Server)
(http://www.borland.com/besappserver/). Web-
Borland JBuilder (http://www.borland.com/jbuilder/)
Borland Web Services Kit.
(The Mind Electric) Web GLUE (http://www.themindelectric.com/glue/).
.
SOAP,
, .

Java Web-
Java.
Meteoservice.
Web- . getweatherForecast . ,
.
2.1 Web-.
- 2.1. , Web-
public class MeteoServicef
public String getweatherForecast(String location);
return location + ": ";

100

Web- Java

Axis Web-.
Meteoservi.ee MeteoService.jws (
"jws" "Java Web Service"),
axis , Axis. axis webapps .
, Web- . , Meteoservice Web. SOAP-, Web-
MeteoService.jws, ,
".jws", Axis, AxisServiet. Axis .
2.2 , Java, Axis.
2.2. , Axis
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.net.*;
public class MeteoServiceClient{
public s t a t i c void main(String[] args) throws Exception;
if (args.length != 1){
System.err.println("Usage: " +
"Java MeteoServiceClient <location>");
System.exit(1);
}

Service

service = new Service();

Call call =

String

(Call)service.createCallO;

endpoint =

"http: //www.meteo.com: 8080/axis/MeteoService. jws";

2. Web Services

101

call.setTargetEndpointAddress(new URL(endpoint));
call.setOperationName(new QName("getWeatherForecast"));
String r e s u l t =
(String)call.invoke(new Object[]{new S t r i n g ( a r g s [ 0 ] ) } ) ;
System.out.println(" : " + r e s u l t ) ;
}
2.2 :
$ javac MeteoServiceClient.Java
-:
$ java MeteoServiceClient
.
, URL Web, MeteoService.jws, . Axis .
, Axis 2.2. service. Web-.
c a l l , HTTP, SOAP-.
c a l l Web- Web- "getWeatherForecast".
, Axis Web-
invoke ().
Web-.
, URL.
AxisServiet, ,
Web-. SOAP-, , MeteoService.jws . Axis MeteoService. class
getWeatherForecast , . Axis SOAP- .
Axis invoke ().
- Web-, 2.2, , .

102

Web- Java

, Axis
, HTTP- , 2.3.
; 2.3. SOAP-
<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>

<getWeatherForecast>
<argO xsi:type="xsd:string">rafl!OKMHO</argO>
</getWeatherForecast>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

, , , , Java. Axis , .
. Web Services Java, 2.4 , Java, Axis.
2.4.
import java.net.*;
import j ava.io.*;
public class MeteoServiceClient2{
public static void main(String!] args)

2. Web Services
if (args.length != 1){
System.err.println("Usage: " +
"java MeteoServiceClient2 <location>");
System.exit(1);

String message =
"<?xml v e r s i o n = ' 1 . 0 ' encodingsUTF-8'?>" +
"<SOAP-ENV:Envelope" +
"SOAP-ENV:encodingStyle=" +
"'http://schemas.xmlsoap.org/soap/encoding/'" +
"xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'" +
"xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
"xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'>" +
"<SOAP-ENV:Body>" +
"<getWeatherForecast>" +
"<argO xsi:type='xsd:string'>" + args[O] + "</argO>" +
"</getWeatherForecast>" +
"</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>" ;
try{
byte[] data = message.getBytes("K0I8-R");
URL url =
new URL("http://www.meteo.com:8080/axis/MeteoService.jws");
URLConnection uc = url.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false) ;
uc.setRequestProperty("Content-Type",
"text/xml;charset=\"utf-8\"") ;

103

104

Web- Java
uc.setRequestProperty("Content-Length",
""+ message.length ());
uc.connect();
DataOutputStream dos =
new DataOutputStream(uc.getOutputStreamO);
dos.write(data, 0, data.length);
dos.close();
BufferedReader br = new BufferedReader(
new InputStreamReader(
uc.getlnputStreamO, "KOI8-R"));
String res = null;
while ((res = br.readLine()) != null)
System.out.println(res);
br.close();
}catch(Exception e){
System.err.println("From client: " + e ) ;
e.printStackTrace(System.out);

, 2.4, 2.5.
2.5. SOAP-
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>

2. Web Services

105

<SOAP-ENV:Body>
<getWeatherForecastResponse
SOAP-ENV:encodingStyle=
'http://schemas.xmlsoap.org/soap/encoding/1>
<getWeatherForecastResult xsi:type='xsd:string'>
:
</getWeatherForecastResult>
</getWeatherForecastResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
, , 2.4, ,
SOAP- 2.5,
. SAX-napcep,
1. .
, Axis , SOAP-, AxisServiet. , Java Web- JSP, , , EJB SLSB
(Stateless Session Beam) MDB (MessageDriven Bean).
Axis , , , 2.6.
2.6. .
import java.io.*;
import java.util.*;
import javax.servlet.http.*;
public class MeteoServiceServlet extends HttpServletf
public String getWeatherForecast(String location))

return location + ": ";

public void doPost(HttpServletRequest req,

106

Web- Java

HttpServletResponse resp){
try{
req.setCharacterEncoding("K0I8-R") ;
BufferedReader br = req.getReader();
String message = "", buf = "", location = "";
while ((buf = br.readLine()) != null)
message += buf;
// SOAP- message SAX-
// location.
resp.setContentType("text/xml; charset=\"utf-8\"");
String response =
"<?xml version='1.0' encoding='UTF-8'?>" +
"<SOAP-ENV:Envelope" +
"Kmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'" +
"xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
"<SOAP-ENV:Body>" +
"<getWeatherForecastResponse" +
"SOAP-ENV:encodingStyle=" +
'http://schemas.xmlsoap.org/soap/encoding/'>" +
"<getWeatherForecastResult xsi:type='xsd:string'>" +
getWeatherForecast(location) +
"</getWeatherForecastResult>" +
"</getWeatherForecastResponse>" +
"</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>";
PrintWriter pw = resp.getWriter();
pw.println(response);

2. Web Services

107

pw. flush () ;
pw. close () ;
}catch(Exception e){
System.err.println(e);


getWeatherForecast ().
EJB.
, Java Web-
Java,
J2SDK SE, J2SDK WSDP. http://java.sun.com/.

Web-
Web- ,
JSP, JWS- , ,
. Web- , .
, Web-,
.

Java, IDL, CORBA,
header- . Web- ,
, , . Web- W3C WSDL XML. http://www.w3.org/TR/wsdl.
XML WSDL <def i n i t i o n s x name . , . WSDL
. WSDL
XSD (. ) SOAP.
WSDL ,
, tns (Target
NameSpace).

108

Web- Java

.
<types> XSD, Web-.
, XSD.
<message> SOAP-: , , . <part>,
.
<portType> Web-, (endpoint) (port) .
, .
<operation>, :
, , . , , <input> <output>,
<fauit>.
<t>inding> :
SOAP, HTTP, HTML, XML MIME- . Web- ,
.
<service> Web- .
<port>, Web-, <binding> .
.
<import> XSD- WSDL
WSDL-.
<documentation> .
WSDL.
, <types>, <message> <portType> , Web-, ,
, .
<binding> , Web-, : HTTP, SMTP - ,
.
, <service> , Web-,
<binding> Web-.
2.6 , WSDL- .

2. Web Services
2.6. WSDL
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="MeteoService"
targetNamespace="http://www.meteo.com/wsdl/MeteoService.wsdl"
xmlns="http://www.w3.org/2002/07/wsdl"
xmlns:soap="http://www.w3.org/2002/07/wsdl/soapl2"
xmlns:tns="http://www.mi.com/wsdl/MeteoService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="ForecastRequest">
<part name="location" type="xsd:string" />
</message>
<message name="ForecastResponse">
<part name="forecast" type="xsd:string" />
</message>
<portType name="Meteo_PortType">
<operation name="getWeatherForecast">
<input message="tns:ForecastRequest" />
<output message="tns:ForecastResponse" />
</operation>
</portType>
<binding name="Meteo_Binding" type="tns:Meteo_PortType">
<soap:binding style=="rpc"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getWeatherForecast">
<soap:operation soapAction="getWeatherForecast" />
<input>
<soap:body encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"

109

110

Web- Java
namespace="urn:MeteoService"
use="encoded" />
</input>
<output>
<soap:body encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:MeteoService"
use="encoded" />
</output>
</operation>

</binding>
<service name="Meteo_Service">
<documentation>WSDL File for MeteoService</documentation>
<port binding="tns:Meteo_Binding" name="Meteo_Port">
<soap:address
location="http://www.meteo.com:8080/servlet/MeteoServlet" />
</port>
</service>
</definitions>
2.6 <definitions>
"MeteoService"
. <message>.
"ForecastRequest" "ForecastResponse".
xsd: string. XSD. location,
getweatherForecast . , ,
forecast, xsd: s t r i n g .
" F o r e c a s t R e q u e s t " "ForecastResponse" <portType>
Web-. <operation>. , Web "Meteo_PortType" ,

2. Web Services

111

"getweatherForecast" , . <operation> <input> <output>


.
, <binding> , , SOAP- ,
HTTP,
<soap:binding style="rcp"
transport="http://schemas.xmlsoap.org/soap/http" />
SOAP "document"

style.

, SOAP.
, <service> ,
Web-.
WSDL 4,
WSDL-.

WSDL
WSDL 2.6 . .
Web- ,
WSDL-, Web-. ,
Web- Apache Axis
Java2WSDL, WSDL-
Java. IBM WSTK, Axis,
java2wsdi,
.
$ java2wsdl MeteoService

MeteoService.wsdl,
<portType> ,
.
, Axis :
WSDL- wsDL2java Java,
Web-. IBM WSTK wsDL2java
wsdi2java. :
$ wsdl2java MeteoService.wsdl
GLUE The Mind Electric.

112

Web- Java

Microsoft SOAP Toolkit wsdigen3. exe,


WSDL Generator,
wsdlstb3.exe, WSDL-.
Sun Microsystems JWSDL (Java
API for WSDL), WSDL Java .
, , WSDL.
IBM WSTK, WSDL4J (WSDL for Java).
WSTK ,
http://www-124.ibm.com/developerworks/projects/wsdl4j/.
WSDL , Web- , WSDL-. GLUE invoke, Web- WSDL. , :
$ invoke http://www.meteo.com:8080/services/MeteoService.wsdl

.
IBM WSIF (Web Services Invocation
Framework), Web- Tomcat
Apache SOAP. , ,
:
$ Java clients.Dynamiclnvoker \
http://www.meteo.com:8080/services/MeteoService.wsdl \
getWeatherForecast

, .
WSIF .

Web-
Web- ,
URI. Web- ,
, Web- .
Web-, RMI,
JNDI CORBA Naming Service,
NIS, UNIX. : " "
.

2. Web Services

113

Web-. : , UDDI - ebXML Registry (electronic business


XML Registry). .
IBM Microsoft Web-, WS-Inspection (Web Services Inspection
Language).
Web-
. 2.3.

. 2.3. Web-


Web-.

UDDI
, UDDI IBM
(http://www-3.ibm.com/services/uddi/)

Microsoft

(http://uddi.microsoft.com/).

.
UDDI http://www.uddi.org/ - . UDDI, . UDDI.
UDDI (UDDI Business Registry) (nodes),
. Web-, , UDDI-.
"" UDDI- , ,

114

Web- Java

. ,
Web-, UDDI
.
UDDI-,
, IBM https://www3.ibm.com/services/uddi/v2beta/protect/registry.html,
Hewlett Packard https://uddi.hp.com/uddi/index.jsp,
Microsoft https://uddi.rte.microsoft.com/register.aspx.
UDDI- . , (public) .
Web- Web-.
(private) ,
. UDDI-
UDDI.
UDDI
.
.
- XML- <businessEntity>
- Web-: UUID (Unique Universal
Identifier),
businessKey, <name>,
, , , URL. ,
.
- <businessServices>,
<businessEntity> - , .
<businessservice>. UUID , serviceKey,
<name>,
. ,
Web-.
<bindingTempiates>, <businessservice> - . , , URL- Web-, ,
, WSDL IDL. <bindingTemplate>. bindingKey UUID . <bindingTempiate>
<tModei>.
<tModei> (technical Model) . . XML.

2.

Web

Services

1J5_

.
<pubiisherAssertion> ( peer-peer) ( parent-child). ,
. identity
. , . ,
<businessEntity> .
<subscription> , -
.
, XML, UDDI-, :
<businessEntity businessKey="Krao4 UUID">
<businessServices>
<businessService serviceKey="Krao4 UUID">
<bindingTemplates>
<bindingTemplate =" OUID">
< ! -->
</bindingTemplate>
< ! >
</bindingTemplates>
</businessService>
< ! >
</businessServices>
</businessEntity>

UDDI- ,
Web-, , , Web. . -

116

Web- Java

s a v e x x x O ,
Web- f ind_xxx () get_xxx {).
UDDI.
UDDI . Java UDDI4J (UDDI for Java),
IBM (http://www.uddi4j.org/). ,
, UDDI.
UDDI- UDDI4J UDDiProxy.
, (proxy), UDDI.
, . UDDI4J 5.
2.7 ,
UDDI-, .
2.7. UDDI-
import com.ibm.uddi.*;
import com.ibm.uddi.datatype.business.*;
import com.ibm.uddi.response.*;
import com.ibm.uddi.client.*;
import org.w3c.dom.Element;
import java.util.Vector;
import java.util.Properties;
public class SaveMeteoService{
public static void main (String[] args){
SaveMeteoService app = new SaveMeteoService();
UDDiProxy proxy = new UDDIProxy();
try{
// UDDI-:
// IBM
proxy.setInquiryURL("http://www-3.ibm.com/services/" +

2. Web Services

117

"uddi/testregistry/inquiryapi");
proxy.setPublishURL("https://www-3.ibm.com/services/" +
"uddi/testregistry/protect/publishapi");
// IBM
// proxy.setlnquiryURLC'http://www-3.ibm.com/services/" +
//
"uddi/inquiryapi");
// proxy.setPublishURL("https://www-3.ibm.com/services/" +
//
"uddi/protect/publishapi");
// Microsoft
// proxy.setlnquiryURL(
//

"http://test.uddi.microsoft.com/inquire");

// proxy.setPublishURL(
//

"https://test.uddi.microsoft.com/publish");
// Microsoft

// proxy.setlnquiryURLC'http://uddi.microsoft.com/inquire");
// proxy.setPublishURL("https://uddi.microsoft.com/publish");
// Hewlett Packard
// proxy.setlnquiryURL("http://uddi.hp.com/inquire");
// proxy.setPublishURL("https://uddi.hp.com/publish");
// WSTK
// proxy.setlnquiryURL(
//

"http://localhost:8080/services/uddi/inquiryapi");

// proxy.setPublishURL(
//

"http://localhost:8080/services/uddi/publishapi");
// UDDI-.
AuthToken token = proxy.get_authToken(
"userid", "password");
System.out.println(
" : " + token.getAuthlnfoString());
System.out.println(" Meteo Service");

118

Web- Java
Vector entities = new Vector();
// <businessEntity>.
// UUID .
BusinessEntity be = new BusinessEntity("", "MeteoService");
entities.addElement(be);
// Web-
BusinessDetail bd =
proxy.save_business(token.getAuthlnfoString(), entities);
// UUID.
Vector businessEntities = bd.getBusinessEntityVector();
BusinessEntity returnedBusinessEntity =
(BusinessEntity)(businessEntities.elementAt(0));
System.out.println(" UUID: " +
returnedBusinessEntity.getBusinessKey());
System.out.println(" Web-:");
//
// Web-, "".
BusinessList = proxy.find_business("M", null, 0 ) ;
Vector businessInfoVector =
bl.getBusinessInfos().getBusinessInfoVector();
for (int i = 0; i < businessInfoVector.size(); i++){
Businesslnfo businesslnfo =
(Businesslnfo)businessInfoVector.elementAt(i);
System.out.println(businesslnfo.getNameString());

}catch(UDDIException e){

2. Web Services

119

DispositionReport dr = e.getDispositionReport();
if (dr != null){
System.out.println(
"ODDIException faultCode:" + e.getFaultCode() +
"\n operator:" + dr.getOperator() +
"\n generic:"

+ dr.getGeneric() +

"\n errno:"

+ dr.getErrno() +

"\n errCode:"

+ dr.getErrCode() +

"\n errlnfoText:" + dr.getErrlnfoText());


}
e.printStackTrace();
}catch(Exception e){
System.err.println("From proxy: " + e ) ;

ebXML
- ebXML :
UN/CEFACT (United Nations Centre for Trade Facilitation and Electronic
Business) (http://www.uncefact.org/)
OASIS (Organization for the
Advancement of Structured Information Standards) (http://www.oasis-open.org/).
ebXML ,
, IBM Sun. ebXML http://www.ebxml.org/.
ebXML , 2
(Business to Business). , Web-
, . ebXML (http://www.ebxml/org/specs/) . ebXML
, .
ebXML , (parties),
(Business Collaboration).

120

Web- Java

ebXML , : (Collaboration
Protocol Profile) (Collaboration Protocol
Agreement).


XML, -, , ,
, . , .
, ,
.
XML, , :
<CollaborationProtocolProfile
xmlns="http://www.ebxml.org/namespaces/tradePartner"
xmlns:ds="http://www.w3.org/2000/09/xmldsigft"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="l.l">
<PartyInfo>
< ! - >
</PartyInfo>
<Packaging id="ID">
< ! XML- >
</Packaging>
<ds:Signature>
< ! () >
</ds:Signature>
< () </Comment>
</CollaborationProtocolProfile>

,
. .

2. Web Services

121_


XML, .
-, , , .
XML, , :
<CollaborationProtocolAgreement
xmlns="http://www.ebxml.org/namespaces/tradePartner"
xmlns:bpm="http://www.ebxml.org/namespaces/businessProcess"
xmlns:ds = "http://www.w3.org/2000/09/xmldsigtt"
xmlns:xlink = "http://www.w3.org/1999/xlink"
11=" "
version="l. 2">
< ! : proposed, agreed, signed >
<Status value = "proposed"/>
<Start>flaTa coi\naineHMH</Start>
<End>flaTa </>
< ! >
<ConversationConstraints invocationLimit = "100"
concurrentConversations = "4"/>
<PartyInfo>
< ! >
</PartyInfo>
<PartyInfo>
< ! >
</PartyInfo>
<Packaging id="H
< ! >
</Packaging>
<ds:Signature>

122

Web- Java

< ! - - () >
</ds:Signature>
<1:> ()</Comment>
</CollaborationProtocolAgreement>


, .
, , (repository)
.

(messages).
:
1. , , ebXML.
2. , , .
3. , .
4. , .
5. / ebXML.
6. .

ebXML
, , Java ebXML. Sun EJB, Sun ebXML Registry/Repository
Implementation. iPlanet
Application Server. Oracle.
Sun
http://wwws.sun.com/software/xml/
developers/regrep/.
ebXML EBXMIRR (OASIS ebXML Registry Reference Implementation Project).

2. Web Services

http://ebxmirr.sourceforge.net/.

123

WS-lnspection Web-
UDDI ebXML Web-,
, , . Web-.
Web- , .
WS-lnspection IBM
Microsoft 2001 . Web- Web-. WSInspection : Web-
WSIL (WS-lnspection Language) XML. wsil . , , wsil
Web-.
Web- WSIL XML <inspection>,
.
<inspection>
Web- <abstract>, ,
Web- <service> / <iink>.
<service> <link>.

<service> Web-
<abstract>, <name>
<description>, l o c a t i o n URI- XML, Web-. WSDL,
.
<description>
referencedNamespace.
<description> <abstract>,
, . Web-
location.
<link> <service> ,
<description>, referencedNamespace location

124

Web- Java

<iink>.
WSIL- UDDI.
location ,
.
, WSIL- :
inspection
xmlns="http://schemas.xmlsoap.org/ws/2001/10/inspection/">
<abstract>KpaTKoe Web-cnya;6bi</abstract>
<service>
<abstract>KpaTKoe Web-yejiyr*i</abstract>
<> </>
<description referencedNamespace="anpec URI"
location="aflpec URI">
<abstract>KpaTKoe onncaHne</abstract>
< ! >
</description>
</service>
<link referencedNamespace="aflpec URI"
location="anpec URI">
<abstract>KpaTKoe onncaHne</abstract>
< ! >

</inspection>

2. Web Sen/ices

125_

2.8 , WSIL- .
; 2.8. WSIL

<?xml version="1.0"?>
<inspection
xmlns="http://schemas.xmlsoap.org/ws/2001/10/inspection/">
<service>
<name>MeteoService</name>
<description
referencedNamespace="http://schemas.xmlsoap.org/wsdl/"
location="http://www.meteo.com/wsdl/MeteoService.wsdl" />
</service>
</inspection>

WSDL- , , , MeteoService.wsii, .
, , : http://www.meteo.com/common/wsil/inspection.wsil,
Web-, . WS-Inspection , ,
WS-Inspection,
inspection.wsil. , ,
IBM http://www.ibm.com/inspection.wsil http://www.xmethods.com/
inspection.wsil Web-,
. inspection.wsil , .
, "" WS-Inspection. WS-Inspection,
, WSIL4J,
IBM WSTK.
WSIL4J Java- WS-Inspection
Java.
wsiLServiet. wsil .

126

Web- Java

Web- WSIL-, .
wsiLProxy. wsiLServiet,
WSIL-
WSDL , , Web-.
Web-.
2.9
WS-lnspection WSIL4J.
.
2.9. WS-lnspection
import
import
import
import

com.ibm.wsil. *;
com. ibm.wsil.client .*;
com.ibm.wstk.wsdl.*;
java.util.*;

public class MeteoWSInspection{


public static void main(String[] args){
if (args.length < 2){
System.err.println(
"Usage: MeteoWSInspection <URL> <serviceName>");
System.exit(1);

try{
WSILProxy proxy = new WSILProxy(args[0]);
WSDLDocument[] wsdlDocs =
proxy.getWSDLDocumentByServiceName(args[1]);
for ( i n t k = 0; k < wsdlDocs.length; k++)
System.out.println(wsdlDocs[k].serializeToXMLO)
}catch(Exception

e){

System.err.println(e);

2. Web Services

127

JAXR
,
Web-: UDDI, ebXML, WS-Inspection. , .
.
,
Web-.
Sun
JAXR (Java API for XML Registries).
Sun WSDP. JAXR. Registry Browser.

$ jaxr-browser

WSDP ,
RegistryServerServiet. Web-
Tomcat Apache Xindice
(, , "--", ),
WSDP. Tomcat
:
$ cd $WSDP_HOME/bin
$ startup
$ xindice-start

, .
:
$ registry-server-test run-cli-request -Dxml/GetAuthToken.xml

Xindice WSDP
Indri. :
$ registry-server-test run-indri
5, JAXR.
JAXR , , (service provider) . UDDI
ebXML, ,

Web- Java

128

JAXR.
. 2.4.
JAXR- Web-
JAXR

UDDI
ebXML

ebXML

. 2.4. Web-
JAXR javax.xml. r e g i s t r y
javax.xml.registry.infomodei.
, , .
connection.
-
ConnectionFactory. newinstanceO
, setProperties , createConnectiont)
connection.
,
getRegistryService() Connection
Registryservice, . , getBusinessQueryManager ()
BusinessQueryManager, findxxx () .
2.10 ,
JAXR.
2.10. JAXR
import javax.xml.registry.*;
import j avax.xml.registry.infomodei.*;
import j ava.net.*;

2. Web Services
import java.util.*;
public class JAXRClient{
public static void main(String[] args){
// .
String queryURL =
"http://www-3.ibm.com/services/uddi/inquiryapi";
//"http://uddi.rte.microsoft.com/inquire";
//"http://localhost:8080/registry-server/RegistryServerServlet";
if (args.length < 1){
System.out.println("Usage: Java JAXRClient <name>");
System.exit(1);
}
JAXRClient jq = new JAXRClient();
String httpProxyHost = "localhost";
String httpProxyPort = "8080";
Properties props = new Properties();
props.setProperty("j avax.xml.registry.queryManagerURL",
queryURL);
props.setProperty("com.sun.xml.registry.http.proxyHost",
httpProxyHost);
props.setProperty("com.sun.xml.registry.http.proxyPort",
httpProxyPort);
Connection connection = null;
try{
ConnectionFactory factory =
ConnectionFactory.newInstance();
factory.setProperties(props);
5 . 748

129

130

Web- Java
connection = factory.createConnection();
System.out.println(" ");
RegistryService rs = connection.getRegistryServi.ee();
BusinessQueryManager bqm = rs.getBusinessQueryManager();
Collection findQualifiers = new ArrayList();
findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
Collection namePatterns = new ArrayList();
namePatterns.add("%" + args[0] + " % " ) ;
// .
BulkResponse response =
bqm.findOrganizations(findQualifiers,
namePatterns, null, null, null, null);
Collection orgs = response.getCollection();
// .
Iterator orglter = orgs.iterator();
while (orglter.hasNext ()){
Organization org = (Organization) orglter.next();
System.out.println(": " +
org.getName().getValue());
System.out.println(": " +
org.getDescription().getValue());
System.out.println(": " +
org.getKey().getld() ) ;
//
User pc = org.getPrimaryContact();

2. Web Services
if (pc != null)(

PersonName pcName = pc.getPersonName();

System.out.println(": " +
pcName.getFullName());
Collection phNums =
pc.getTelephoneNumbers(null);
Iterator phlter = phNums.iterator();
while (phlter.hasNext()){
TelephoneNumber num =
(TelephoneNumber)phlter.next();
System.out.println(" : " +
num.getNumber()) ;
}
Collection eAddrs = pc.getEmailAddresses();
Iterator ealter = eAddrs.iterator();
while (ealter.hasNext())(
EmailAddress eAd =
(EmailAddress) ealter.next();
System.out.println("E-mail: " +
eAd.getAddress());
}
}
//
Collection services = org.getServices();
Iterator svclter = services.iterator();

131

132

Web- Java
while (svclter.hasNext()){
Service svc = (Service) svclter.next();
System.out.println(" : " +
svc.getName().getValue());
System.out.println(" : " +
svc.getDescription().getValue{));
Collection serviceBindings =
svc.getServiceBindings();
Iterator sblter = serviceBindings.iterator();
while (sblter.hasNext()){
ServiceBinding sb =
(ServiceBinding)sblter.next() ;
System.out.println(" URI: " +
sb.getAccessURK) ) ;
}
}

System.out.println("

") ;

}
}catch(Exception

e){

e.printStackTrace();
}finally!

if

(connection

!= n u l l )

try{
connection.close();
}catch(JAXRException

je){}

133

2. Web Services

Web Services
, Web- . , Web- . ,
,
. . 2.5.
UDDI, ebXML, WS-lnspection
WSDL, WSFL, WSML
SOAP, XML-RPC, WS-Security
HTTP, HTTPS, SMTP

. 2 . 5 . Web Services

SOAP Web Services


, Web- , XML.
XML, XML SOAP. SOAP
1998
(Dave Winer), Microsoft Userland. " "
.
, Web- . , .
"Service Oriented Architecture
Protocol", . ,
SOAP 1.2 , "SOAP" .
1999 W3C
(http://www.w3.org/).
2000 SOAP 1.1. ,
SOAP, XML,
. XML
SOAP 1.1

http://schemas.xmlsoap.org/soap/envelope/.
SOAP 1.2 2001 , http://www.w3.org/2001/06/soap-envelope.
, , 1.1
1.2 SOAP. SOAP "VersionMismatch",
.

3. SOAP Web Sen/ices

135

, SOAP 1.1 . 1.2 , , , SOAP::Lite, Apache SOAP 2.3, Apache Axis.


1.2, 1.1.
SOAP
http://www.w3.org/TR/SOAP/. , , .
SOAP ,
.

http://www.w3.org/TR/soapl2-partl/,
http://www.w3.org/2002/06/soap-envelope. ,
SOAP 1.2 : parti part2.
. partO , SOAP 1.2.

SOAP-
SOAP- XML, .
XML <Enveiope>.
<Enveiope> xmins, ,
, . <Header>, , <Body>, . 1.1 <Body> , .
1.2 - <Body>. , SOAP- :
<?xml version="1.0" ?>
<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope">
<env:Header>

<! >
</env:Header>
<env:Body>

136

Web- Java
< ! >

</env:Body>
</env:Envelope>

<Header>, ,
<Enveiope>. xmlns,
actor, URI SOAP-,
.
, SOAP- SOAP .
. /
SOAP- (SOAP nodes). SOAP
.
, , Microsoft WS-Routing.
actor SOAP- ,
.
http://schemas.xmlsoap.org/soap/actor/next actor ,
, .
actor , . SOAP.
1.2 actor role, SOAP .
SOAP-.
http://www.w3.org/2002/06/soap-envelope/role/ultimateReceiver
, , .

http://www.w3.org/2002/06/soap-envelope/role/next . , .

http://www.w3.org/2002/06/soap-envelope/role/none
SOAP-.

, ,
, , ,
- URI.
role URI,
, .
, , ,
URI http://www.w3.oi-g/2002/06/soap-envelope/role/ultimateReceiver.

3. SOAP Web Services

137

role , ,
, .
<Header>, mustunderstand, 1. . mustunderstand 1, SOAP- , ,
.
.
SOAP 1.2 false, 1 true.
<Header> ,
(entries) . 1.2
(blocks) . .
role actor
mustunderstand. .
SOAP, , , role.
3.1 .
3.1.

<env:Header>
<t:Transaction
xmlns: t="http: //some. com/transaction"
env:role=
"http://www.w3.org/2002/06/soap-envelope/role/ultimateReceiver"
env:mustUnderstand="1">
5
</t:Transaction>
</env:Header>

, , .
role, actor mustunderstand.
<Body> <Header>,
, SOAP-, . <Body> , . ,
<Fauit>, .

138

Web- Java

<Fault>
SOAP-, SOAP-,
, SOAP, <Fauit>
.
, <Fauit> SOAP 1.1 , .
<fauitcode> , .
, .
<faultstring> ,
.
<fauitactor> URI , . , SOAP, . SOAP- , SOAP-
.
<detaii> ,
<Body> , . , .
:
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<env:Fault>
<faultcode>env:MustUnderstand</faultcode>
<faultstring>SOAP Must Understand Error</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>

3. SOAP Web Services

139

SOAP 1.2 <Fauit>.


http://www.w3.org/2002/06/soap-envelope,
.
.
<code>.
<vaiue>
<subcode>, , -, <vaiue> <subcode>, .
<Reason>. xmi:iang,
(. ), .
.
<Node> URI SOAP-, .
<Roie> SOAP-, .
<Detaii> , <Body>
, .
3.2 , . ,
SOAP-
.
3.2.
<?xml version='1.0' ?>
<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope"
xmlns:rpc='http://www.w3.org/2002/06/soap-rpc1>
<env:Body>
<env:Fault>
<env:Code>
<env:Value>env:Sender</env:Value>
<env:Subcode>

140

Web- Java
<env:Value>rpc:BadArguments</env:Value>
</env:Subcode>
</env:Code>
<env:Reason>Processing Error</env:Reason>
<env:Detail>
<e:myfaultdetails
xmlns:e="http://www.example.org/faults">
<message>Name does not match</message>
<errorcode>999</errorcode>
</e:myfaultdetails>
</env:Detail>
</env:Fault>

</env:Body>
</env:Envelope>


. 1.1 .
versionMismatch . ,
.
MustUnderstand , mustUnderstand
1, , .
c l i e n t XML, , . .

3. SOAP Web Services

141

server
.
1.2 .
Q versionMismatch . ,
, XML, .
<upgrade>, <enveiope> , . 3.3.
MustUnderstand , mustUnderstand
t r u e , ,
.
<Misunderstood>, qname . 3.4 ,
, 3.1 .
DataEncodingUnknown ,
, .
sender XML, , . .
Receiver
, , XML.
- .
, <subcode>, 3.2.
3.3. VersionMlsmatch
<?xml version="1.0" ?>
<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope">
<env:Header>
<upg:Upgrade

142

Web- Java
xmlns:upg="http://www.w3.org/2002/06/soap-upgrade">
<envelope qnarae="nsl:Envelope"
xmlns:nsl="http://www.w3.org/2002/06/soap-envelope"/>
<envelope qname="ns2:Envelope"
xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/"/>
</upg:Upgrade>

</env:Header>
<env:Body>
<env:Fault>
<env:Code>
<env:Value>env:VersionMismatch</env:Value>
</env:Code>
<env:Reason>Version Mismatch</env:Reason>
</env:Fault>
</env:Body>
</env:Envelope>
.4. MustUnderstand
<?xml v e r s i o n = " l . 0 " ?>
<env:Envelope xmlns:env='http://www.w3.org/2002/06/soap-envelope'
xmlns:flt='http://www.w3.org/2002/06/soap-faults' >
<env:Header>
<fIt:Misunderstood qname='t:Transaction'
xmlns:t='http://some.com/transaction' />

3. SOAP Web Services

143

</env:Header>
<env:Body>
<env:Fault>
<env:Code>
<env:Value>env:MustUnderstand</env:Value>
</env:Code>
<env:Reason>
One or more mandatory headers not understood
</env:Reason>
</env:Fault>
</env:Body>
</env:Envelope>

SOAP
SOAP- : , ,
, , . , , XML.
, XSD,
1. , , ,
encodingstyie. encodingstyle SOAP-,
SOAP 1.2 <Enveiope>.
encodingstyle
, ,
. , - encodingstyle.
, SOAP 1.1, http://schemas.xmlsoap.org/soap/encoding/. SOAP 1.2
http://www.w3.org/2002/06/soap-encoding.
, ,

144

Web- Java

enc SOAP-ENC. :
<someelem
xmlns:enc="http://www.w3.org/2002/06/soap-encoding"
env:encodingStyle="http://www.w3.org/2002/06/soap-encoding"
xmlns:env="http://www.w3.org/2002/06/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xralns:xsd="http://www.w3.org/2001/XMLSchema">
, . SOAP .
, , XSD, 1. .
SOAP
XSD, ,
, XSD. , : , ,
, .
,
XML, XSD. XSD. , <enc:int> int, XSD.
:
<enc:int>37</enc:int>

, ,
.
. , id:
<enc:int id="age">37</enc:int>

id, <enc:int>, , ref


:
<personAge ref="#age" />

# , .
ref , HTML,
. :
<person>
<></>

3. SOAP Web Services

145

<address ref="http://some.com/addr.xml#Ivanov" />


</person>

SOAP 1.1 ref href.


,
XML xsi:type (. 7), ,
<age xsi:type="xsd:int">37</age>
2.25+3.46i :
<argO xsi:type="complex">
<re xsi:type="xsd:double">2.25</re>
<im xsi:type="xsd:double">3.4 6</im>
</argO>

XML, XSD,
.

http://schemas.xmlsoap.org/soap/encoding/
Array. , . . ,
SOAP-, , , :
<element name="arr" type="enc:Array" />
SOAP- :
<arr enc:arrayType="xsd:string[3]">
<item>MBaHOB</item>
<item>neTpoB</item>
<item>CMflopoB</item>
</arr>
SOAP-:
<arr xsi:type="enc:Array" enc:arrayType="xsd:string[3]">
<item>MBaHOB</item>
<item>neTpoB</item>

146

Web- Java

<item>CMflopoB</item>
</arr>
,
.
.
.
, , , , " "
i n t [ 5 ] , " "
int [, ] . ,
, :
<tabl xsi:type="enc:Array" enc:arrayType="xsd:int[, ] [10]">
, ,
:
<list xsi:type="enc:Array" enc:arrayType="xsd:string[2][]">
, :
<tabl xsi:type="enc:Array" enc:arrayType="xsd:int[15,10]">
: , .
( , ,
item), .
XML, XSD, , . :
<addr enc:arrayType="xsd:anySimpleType[2]">
<enc: ^1>, 23</enc: string>
<enc:int>2347 65</enc:int>
</addr>
.
. , SOAP 1.1 , . offset :
<arr xsi:type="env:Array"
enc:arrayType="xsd:string[5]"

enc:offset="[2]">

3, SOAP Web Services

147

<item>3neMeHT 3</item>
<^> 4</item>
</arr>

SOAP 1.1 ,
(" "). ,
10 , 2 4.
position, ,
100 , :
<arr xsi:type="enc:Array" enc:arrayType="xsd:string[10,10]">
<item enc:position="[2,5]"> [2,5]</item>
<item enc:position="[5,3]"> [5,3]</item>
</arr>

SOAP 1.2 , . .

. XML, .
XML. , , . :
<person>
<></>
<secondname>IleTpoBH4</secondname>
<lastname>OmopoB</lastname>
</person>

, , . , <> , <authors> :
<>

148

Web- Java

<authors>
<> </>
<> </>
</authors>
</>

<>:
<>
<title>3ooo eeo</title>
</">
neTpoB</author>
</aBook>

,
. XML - .


, ,
XSD, .
Web-. ,
- , , XSD.
, encodingstyie.
Java. Java , XML,
SOAP (serialization), (deserialization).
Java, , .
SOAP Java XML.
, WSDL.
, Web-, , -

3. SOAP Web Services

149

.
Web Services Web-. Web-.

SOAP
, , .
<Body> ,
. . ,
.
SOAP 1.2 , , ,
.
, , SOAP-
public String getAddress(String name, int number);

:
String address = getld("", 2345678);

:
3.5. SOAP-
<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Body>
<getAddress xmlns="http://www.gts.com/inquiries"
env:encodingStyle="http://www.w3.org/2002/06/soap-encoding">
<name xsi:type="xsd:string">I4BaHOB</name>

150

Web- Java
<number xsi:type="xsd:int">2345678</number>
</getAddress>

</env:Body>
</env:Envelope>

SOAP 1.1 <Body> . ,


"Response".
,
. .
. .
3.6 ,
getAddress () SOAP 1.1.
3.6. . SOAP 1.1
<env:Envelope
xmlns:env="http://schemes.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Body>
<getAddressResponse env:encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/">
< r e s u l t xsi:type="xsd:string">CaflOBaH, 25-4</result>
</getAddressResponse>
</env:Body>
</env:Envelope>

SOAP 1.2 -. , .
<rpc: resuit>, -

3. SOAP Web Services

http://www.w3. org/2002/06/soap-rpc.
. :

151

<rpc:result>address</rpc:result>
<address>CaflOBan, 25-4</address>
,
.
SOAP 1.2
, .
, .
3.7
getAddress SOAP 1.2.

3.7. . SOAP 1.2


<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Body>
<getAddressResponse
xmlns:rpc="http://www.w3.org/2002/06/soap-rpc"
env:encodingStyle="http://www.w3.org/2002/06/soap-encoding">
<rpc:result>address</rpc:result>

<address> , 25-4</address>
</getAddressResponse>
</env:Body>
</env:Envelope>


, ,

152

Web- Java

. , , Web- ,
:
public class Person)
String name; // .
int age; // .
public Person(){}
public Person(String name, int age){
this.name = name;
this.age = age;

public String getName(){ return name; }


public void setName(String name){ this.name = name; }
public int getAge(){ return age; }
public void setAgefint age){ this.age = age; }
}

:
public class Employee!
Person pers; // ,
int numb; // .
public Employee(){}
public Person getPerson(){ return pers; }
public void setPerson(Person pers){ this.pers = pers; }
public int getNumb(){ return numb; }
public void setNumb(int numb)) this.numb = numb; }

, Web-, info, , ,
:
public int[] getClockNumbers(Person person);

3. SOAP Web Services

153

getClockNumbers :
Person ivanov = new Person("", "27");
Info inf = new Info();
int[] numbs = inf.getClockNumbers(ivanov);
ivanov , 3.9.
3.9.
<?xml v e r s i o n = ' 1 . 0 ' ?>
<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Body>
<getClockNumbers env:encodingStyle=
"http://www.w3.org/2002/06/soap-encoding">
<person
xmlns:enc="http://www.w3.org/2002/06/soap-encoding">
<name xsi:type="xsd:string">MBaHOB</name>
<age xsi:type="xsd:int">27</age>
</person>
</getClockNumbers>
</env:Body>
</env:Envelope>

ivanov , 3.10.

j.,

. . . . . . .

) 3.10.
<?xml version='1.0' ?>
<env:Envelope

154

Web- Java

xmlns:env="http://www.w3.org/2002/06/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Body>
<getClockNumbers
env:encodingStyle=
"http://www.w3.org/2002/06/soap-encoding">
<params
xmlns:enc="http://www.w3.org/2002/06/soap-encoding"
xsi:type="enc:Array"
enc:arrayType="xsd:anyType[2]">
<item xsi:type="xsd:string">MBaHOB</item>
<item xsi:type="xsd:int">27</item>
</params >
</getClockNumbers>
</env:Body>
</env:Envelope>
getciockNumbers (),
, 3.11.
:

3.11.

<?xml v e r s i o n = ' 1 . 0 ' ?>


<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Body>
<getClockNumbersResponse

3. SOAP Web Services

155

env:encodingStyle=
"http://www.w3.org/2002/06/soap-encoding">
<return
xmlns:enc="http://www.w3.org/2002/06/soap-encoding/"
xsi:type="enc:Array" enc:arrayType="xsd:int[4]">
<item
<item
<item
<item

xsi:type="xsd:int">678456</item>
xsi:type="xsd:int">256830</item>
xsi:type="xsd:int">132587</item>
xsi:type="xsd:int">563904</item>

</return>
</getClockNuinbersResponse>
</env:Body>
</env:Envelope>

HTTP
, SOAP- . , : HTTP, SMTP, FTP, . SOAP - .
SOAP- .
, SOAP- Web-
WWW HTTP. POST
GET. SOAP -
POST-.
SOAP 1.2 POST- Content-Type MIME- application - soap+xmi. ,
SOAP 1.2 HTTP- :
POST /services/InfoServlet HTTP/1.1
Host: some.com

156

Web- Java

Content-Type: application/soap+xml; charset="utf-8"


Content-Length: nnnn
<?xml version='1.0' ?>
<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope">
<!-30- >
</env:Envelope>

, HTTP- , HTTP.
SOAP 1.1 text/xmi HTTP soAPAction ,
URI SOAP-, :
POST /services/InfoServlet HTTP/1.1
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
SOAPAction: "http://some.org/abc#MyMessage"
<?xml version='1.0' ?>
<env:Enve1ope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<!SOAP- >
</env:Envelope>

URI, soAPAction ,
-,
HTTP-. , , ,
URI, HTTP-
POST. SOAPAction , .
SOAP 1.2 SOAPAction, , , action HTTP- contentType, , SOAPAction. :
Content-Type: application/soap+xml; \
charset="utf-8"; action="http://some.org/abc#MyMessage"

3. SOAP Web Services

157

GET
SOAP 1.2 SOAP-
HTTP- GET. GET- , , , SOAP-. ,
SOAP- - SOAP, , GET. , name age
getciockNumbers , ,
GET-:
GET /services/InfoServlet?name=I4BaHOB&age=27 HTTP/1.1
Host: some.com
Accept:

text/html,

application/soap+xml

GET-, Accept, application/


soap+xmi SOAP-.
, SOAP 1.2 SOAP HTTP- SOAP POST.
3.12 getciockNumbers .
, 3.12, SOAP- POST
POST /services/InfoServlet?name=MBaHOB&age=27 HTTP/1.1
Host: some.com
Content-Type: application/soap+xml; charset="utf-8"
Content-Length: 553
<?xml version='1.0' ?>
<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Body>
<getClockNumbers
env:encodingStyle=

158

Web- Java
"http://www.w3.org/2002/06/soap-encoding">
<person
xmlns:enc="http://www.w3.org/2 002/0 6/soap-encoding">
<name xsi:type="xsd:string">MBaHOB</name>
<age xsi:type="xsd:int">27</age>
</person>
</getClockNumbers>

</env:Body>
</env:Envelope>
, :
/1.1 200
Content-Type: application/soap+xml; charset="utf-8"
Content-Length: nnnn
<?xml version='1.0' ?>
<env:Envelope
xmlns:env="http://www.w3.org/2002/06/soap-envelope" >
<! SOAP- >
</env:Envelope>
SOAP- Web-
200 OK, a 400 Bad Request 500 I n t e r n a l Server E r r o r .
400 SOAP- "sender",
500 "versionMismatch", "MustUnderstand",
"Receiver".

SMTP
SOAP- 1.2 ,
"SOAP 1.2 Email" ("SOAP Version 1.2 Email

3. SOAP Web Services

159

Binding") (http://www.w3.org/TR/soapl2-email/). ,
SOAP-,
, . SOAP- .
, SOAP-:
From: ivan@some.com
: petr@another.com
Subject: Some Message
Date: Mon, 18 Nov 2002 13:20:00 GMT
Message-Id: <EE4 92E16A09009027 6D208424 960C0C@some.com>
<?xml version='1.0' ?>
<env:Enve1ope
xmlns:env="http://www.w3.org/2002/06/soap-envelope">
... SOAP- ...
</env:Envelope>

SOAP-

SOAP-, :
, , , . GIF, JPEG, PDF. POST HTTP , , MIME- text, image, audio,
video, application, multipart, message. SOAP- . 1-
multipart, RFC 2046.

MIME- multipart/related
multipart , -
, . , HTTP-.
multipart , , , .
,
, , . ,

160

Web- Java

, ,
. .
/ ASCII-
Java "\\".

CRLF,

C/C++,

boundary
Content-Type HTTP- ,
.
:
Content-Type:

multipart/related;

boundary=vT45fke0nS34x

, , :
vT45fke0nS34x
, , :
vT45fke0nS34x

,
. Content-Type,

Content-Type: text/plain; charset="US-ASCII"

multipart : a l t e r n a t i v e , p a r a l l e l , related.
Web Services related.
multipart/related RFC 2387. , .
(start) , . s t a r t
content-Type MIME-. s t a r t , . type contentType. :
Content-Type: multipart/related;
boundary=delimeter;
start="<ivanl206@some.com>";
type=text/xml;
start-info="-o -df type"
, , .
Web Services SOAP-,
.

3. SOAP Web Services

161

multipart/related
content-ID, ,
. RFC 1521, RFC 1873
RFC 2045 , . :
Content-ID: <ivanl206@some.com>

s t a r t . .
s t a r t - i n f o Content-Type , , . ,
-.
contentDisposition, RFC 1806. , , inline, , attachment. , . filename ,
. :
Content-Disposition: attachment; filename=myface.gif
MIME- multipart/related. , : HTML- GIF.
MIME-Version: 1.0
Content-Type: multipart/related; boundary=delimeter; type=text/html
delimeter
Content-Type: text/html; charset="windows-1251"
<html><body><p>
- , ,
<img src="cid: myface2409@some. net">
.
</body></html>
delimeter
Content-ID: myface2409@some.net
Content-Type: image/gif
Content-Transfer-Encoding: base64
6 . 748

162

Web- Java

R01GODlhGAGgAPEAAP/////ZRaCgoAAAACH+PUNvcHlyaWdodCAoQykgMTk5
NSBJRVRGLiBVbmFldGhvcml6ZWQgZHVwbGljYXRpb24gcHJvaGliaXRlZC4A
... ...
delimeter
, HTML- <img>, URL cid: (Content-ID),
RFC 2111. cid:
Content-ID .
RFC 2557 content-Location,
. URL, ,
Content-ID. Content-Location
Content-.
Content- , URL,
. ,
cid. , Content-Location
.
MIME-Version: 1.0
Content-Type: multipart/related; boundary=delimeter; type=text/html
delimeter
Content-Type: text/html; charset="windows-1251"
<html><body><p>
- , ,
<img src="cid:myface2409@some.net">
<img src="images/myface2409.gif">
.
</body></html>
delimeter
Content-ID: myface2409@some.net
Content-Location: images/myface2409.gif
Content-Type: image/gif
Content-Transfer-Encoding: base64
ROlGODlhGAGgAPEAAP/////ZRaCgoAAAACH+ PUNvcHlyaWdodCAoQykgMTk5

3. SOAP Web Services

163

NSBJRVRGLiBVbmFldGhvcml6ZWQgZHVwbGljYXRpb24gcHJvaGliaXRlZC4A
... ...
delimeter

SOAP-
2000 W3C "SOAP-
" (http://www.w3.org/TR/SOAP-attachments/),
SOAP 1.1. SOAP MIME- multipart/related HTTP. .
1. SOAP- MIME-
multipart/related.
2. MIME- text/xmi.
3. content-ID, a HTTP, MIME-,
content-Type s t a r t ,
content-ID .
Content-ID / Content-Location.
4. MIME- SOAP href.
3.13 SOAP-,
GIF JPEG.
3.13. POST- SOAP-
POST /services/SomeServlet HTTP/1.1
Host: wv7W.some.com
Content-Type: multipart/related; boundary=delimeter; type=text/xml;
start="<info2709.xml@some.com>"
Content-Length: XXXX
SOAPAction: http://some.com/services/InfoServlet
delimeter
Content-Type: text/xmi; charset=utf-8
Content-Transfer-Encoding: 8bit
Content-ID: <info2709.xml@some.com>

164

Web- Java

<?xml version='1.0' ?>


<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<ns:todayinf
xmlns:ns="http://some.com/infonames">
<ns:map href="cid:info2709.gif@some.com" />
<ns:map href="cid:info2709.jpeg@some.com" />
</ns:todayinfo>
</env:Body>
</env:Enve1ope >
delimeter
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-ID: <info2709.gif@some.com>
... GIF- base64...
delimeter
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
Content-ID: <info2709.jpegSsome.com>
... JPEG...
delimeter

, MIME-, SOAP-,
SMTP.

DIME
2001 , IBM
Microsoft DIME (Direct Internet Message
Encapsulation) ,
MIME- m u l t i p a r t . 2002

DIME.

http://www.ibm.com/developerworks/ws-dime/.
DIME ,
(record). , -

3. SOAP Web Services

165

. :
(
,
( TYPE);

DATA_LENGTH);

URI, MIME- - -

URI ( ID).
232 - 1 . .
. TYPE
TYPE_LENGTH, TYPE, URI, MIME- -
T Y P E T . URI, TYPEJT OxOi, MIME- 0x02. ,
, TYPE_LENGTH . T Y P E T
0x04, .
TYPE_LENGTH DATA_LENGTH .

ID URI. , IDLENGTH, ,
4.
, .
DIME, 1.
, , .
DIME MIME- application/dime.
DIME DIME.
DIME- 1 (Message
Begin), 1 ME (Message End). , , 1.
. ,
. CF (Chunk Flag), 1, CF .
, DIME , Web- .
DIME- SOAP-
"WS-Attachments".
http://www.ibm.com/developerworks/ws-attach.html.

166

Web- Java

DIME, SOAP-,
SOAP- .
, , , MIME.
DIME SOAP-.
TYPE SOAP 1.1
http://schemas.xmlsoap.org/soap/envelope/,
SOAP 1.2 appiication/soap+xmi.
,
. href.
DIME . .
POST- HTTP Content-Type application/dime.
, DIME , MIME- multipart. ,
DIME, .
, ,
, .
.
, DIME
- , . DIME .

SOAP-
, Web Services ,
SOAP- SOAP-.
.
1. "", IBM WebSphere Studio, Sun ONE Studio, Eclipse,
IntelliJ IDEA, Microsoft Visual Studio .NET, Borland JBuilder .
Web-. , Web- .
2. , : Apache
SOAP, Apache Axis, TME GLUE, Microsoft SOAP Toolkit.

3. SOAP Web Services

167

.
, Web-.
3. , :
Sun SAAJ, JAXM, JAX-RPC, JAXR, IBM WSTK. Web-.
4. : Java, Perl, C/C++, #, VB.NET .
, , Web-.
,
Web-.
- , .
, , [9, 10].
, 67 .
Web- Apache Axis. ,
: IBM
WebSphere, BEA WebLogic, Sun ONE Application Server.
Web-, Tomcat, Resin, JBoss. ,
Axis , .
Axis.

Axis
Axis (Apache extensible Interaction System)
(http://xml.apache.org/axis/), W3C, , Sun SAAJ, JAXM, JAX-RPC. 6. , Axis SOAP- simpieAxisServer
WSDL Java .

Axis
Axis . axis $AXis_HOME/webapps/ webapps
, . axis/WEBiNF/lib/ XML-napcepa, , xerces.jar,

168

Web- Java

. Axis Web-, . , ,
, http://localhost:8080/axis/
Axis.
Axis , ,
axis.jar, commons-logging.jar, jaxrpc.jar, Iog4j-1.2.4.jar,
tt-bytecode.jar xerces.jar. ( , , )
CLASSPATH , . lib, ext, common endorsed
.
Axis AxisServiet. , ,
, http://locaIhost:8080/axis/servlet/AxisServlet.
"And now Some Services" Web, .
Axis Web-. axis/WEB-INF/dasses/samples/. ,
Web-.
$AXIS_HOME/samples/.

Web- Axis
Web-, Axis,
. Java, Web-,
, , ".jws",
axis .
Web- EchoService, . Web-
getEcho (), SOAP-.
EchoService, getEcho , 3.14.
3.14. Web- EchoService
public class EchoService{
public String getEcho(String req){
return req;

'

3. SOAP Web Services

169

3.14 EchoService.jws
axis . , Web- . EchoService, Axis
Web-.

Axis
, Web-,
Axis, . 3.15
Web- EchoService 3.14.
| 3.15. Web- EchoService
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import java.net.*;
public class EchoServiceClient{
public s t a t i c void main(String[] args) throws Exception)
if

(args.length != 1)(
System.err.println(
"Usage: Java EchoServiceClient <request>");
System.exit(1);

Service service = new Service();


Call call = (Call)service.createCallO;
String endpoint =
"http://localhost:8080/axis/EchoService.jws"
call.setTargetEndpointAddress(new URL(endpoint))
call.setOperationName("getEcho");
String request = args[0];
String response =

170

Web- Java
(String)call.invoke(new Object[]{request});
System.out.println(": " + request);
System.out.println(": " + response);

3.15 service c a l l JAX-RPC.


, Axis.
6. 3.15, Web- c a l l . Web-
endpoint Web- getEcho. Web . request. ,
c a l l invoke , Web-.


Web-, JWS-
Axis, ,
. , Web- Java, , - SOAP,
Web-, Axis. Axis
(Deployment
Descriptor), Web- . DD-. , DD- Web- Web-.
DD- XML
<depioyment>. DD-

http://xml.apache.org/axis/wsdd/.
DD- Axis.
http://xml.apache.org/axis/wsdd/
providers/java. :
<deployment
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<giobaiconfiguration>
Web-.

3. SOAP Web Services

171

<handier>, type -, Axis, , <handler>. - SOAP JAX-RPC, 6. <handier>


name.
<option ="" value="3Ha4eHne" />,

<handler>. :
<option name="namespace"
value="http://tempuri.org/wsdl/2002/12/" />

<parameter ="" value="3Ha4eirae" />

Web-, ,
<parameter name="adminPassword" value="v2xYUcm" />

. <parameter> <service>, Web-. , :


<service name="AdminService" provider="java:MSG">
<parameter name="methodName" value="AdminService" />
<parameter name="enableRemoteAdmin" value="false" />
<parameter name="className" value="org.apache.axis.utils.Admin" />
<parameter name="allowedMethods" value="*"/>
</service>
Web- AdminService, Axis. Admin, AdminService (-, - ). ,
enabieRemoteAdmin, Web-. value. ,
aiiowedMethods, (public) .
value
. , .
provider <service> - SOAP. Handler
JAX-RPC
-
GenericHandler BasicHandler.

172

Web- Java

Axis BasicProvider BasicHandier.


BasicProvider, , JavaProvider,
MsgProvider RPCProvider.
s t y l e <service>
provider Web-. , , provider="java:RPC"
styie="RPC".
RPCProvider. style="document". Axis

styie="wrapped". XML Axis . Web-, provider="java:MSG"


styie="message", , Axis XML, Java.
MsgProvider.
Web- <operation>. name
, Web-, returnType . returnQName
DD-.
<parameter>. :
<operation name="getEcho"
returnQName="echo" returnType="xsd:string">
<parameter name="req" type="xsd:string" />
</operation>
<service>, Web-, , <requestFiow> <responseFiow>. <handier> -, . :
<service name="test">
<parameter name="className" value="test.Implementation"/>
<parameter name="allowedMethods" value="*"/>
<namespace>http://testservice/</namespace>
< reque s t Flow>
<handler type="java:MyHandlerClass"/>

3. SOAP Web Services


<handler

173

type="somethingIDefinedPreviously"/>

</requestFlow>
</service>
<transport> SOAP-. name. <transport>,
Axis, pivot, SOAP-, , HTTPSender, Axis. :
<transport name="SimpleHTTP" pivot="HTTPSender">
<requestFlow>
<handler name="HTTPActionHandler"
type="j ava:org.apache.axis.handlers.http.HTTPActionHandler"/>
</requestFlow>
</transport>

.
<typeMapping qname="xml-MMH" classname="MMH "
serializer="MMH " deserializer="MMH " />
classname Java. s e r i a i i z e r d e s e r i a l i z e r ,
. :
<typeMapping
xmlns:ns="http://soapinterop.org/"
qname="ns:ArrayOf_apachesoap_Map"
type="Java:java.util.HashMap[]"
serializer="org.apache.axis.encoding.ser.ArraySerializerFactory"
deserializer="org.apache.axis.encoding.ser.ArrayDeserializerFactory"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />

<beanMapping ="1-" languageSpecificType="MMH " />

174

Web- Java

, Java,
JavaBean. getxxx () setxxx {),
Java XML Axis,
Serializer Deserializer, ,
BeanSeriaiizer BeanDeseriaiizer. JavaBean . :
<beanMapping qnarrie="reg: Service"
languageSpecificType="java:samples.bidbuy.Service"/>
3.16 Web-
AdminService, Axis.
3.16. Web-
<deployment
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="adminPassword" value="admin" />
<parameter name="sendXsiTypes" value="true" />
<parameter name="sendMultiRefs" value="true" />
<parameter name="sendXMLDeclaration" value="true" />
<requestFlow>
<handler type="java:org.apache.axis.handlers.JWSHandler" />
</requestFlow>
</globalConfiguration>
<handler name="Authenticate"
type="j ava:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
<handler name="LocalResponder"
type="Java:org.apache.axis.transport.local,LocalResponder"/>
<handler name="URLMapper"
type="Java:org.apache.axis.handlers.http.URLMapper"/>
chandler name="MsgDispatcher"

3. SOAP Web Services

175

type="java:org.apache.axis.providers.java.MsgProvider"/>
<handler name="RPCDispatcher"
type="j ava:org.apache.axis.providers.j ava.RPCProvider"/>
<service name="AdminService" provider="java:MSG">
<parameter naitie="methodName" value="AdminService" />
<parameter name="enableRemoteAdmin" value="false" />
<parameter name="className" value="org.apache.axis.utils.Admin" />
</service>
<service name="JWSProcessor" provider="Handler">
<parameter name="handlerClass"
value="org.apache.axis.handlers.JWSProcessor" />
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper" />
<handler
type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
</requestFlow>
</transport>
<transport name="local">
<responseFlow>
<handler
type="Java:org.apache.axis.transport.local.LocalResponder" />
</responseFlow>
</transport>
</deployment>

176

Web- Java

DD-
deploy.wsdd.

$ Java org.apache.axis.client.http.AdminClient deploy.wsdd

AdminClient Web- Axis.



Processing f i l e deploy.wsdd
<Admin>Done processing</Admin>

Web-,
URL, , http://localhost:8080/axis/services/EchoService.
AdminClient Web, .
$ Java org.apache.axis.client.http.AdminClient list
Web- Web- undeploy.wsdd.
DD-,
<undeployment>.
Web- Web-, AdminClient , . , , 3.18.

WSDL
DD- , Axis.
Web-. Axis Web WSDL.
Axis WSDL (. 2, 4),
. Internet Explorer
http://localhost:8080/axis/EchoService.jws?WSDL, Web- Echoservice, WSDL.
java2wsDL.

WSDL- Java
Axis
WSDL. Axis
Java2wsDL. :
$ Java org.apache.axis.wsdl.Java2WSDL -o echo.wsdl \
-l"http://localhost:8080/axis/services/echo" \
-n "urn:echo" -p"echoservice" urn:echo EchoService

3. SOAP Web Services

177

-
WSDL- echo.wsdl.
-1 URI, , echo,
WSDL-.
- WSDL-
urn:echo.

- :
echoservice , urn:echo .
, Echoservice , WSDL.

echo.wsdl WSDL Echoservice.

Web- WSDL-
Web- WSDL
Web- wsDL2Java. :
$ Java org.apache.axis.wsdl.WSDL.2Java -o . -d Session -s \

-p echo.ws echo.wsdl

- , . . , -.
-d Web-
:
Application Web- ;
Request
Web- ( );
session Web- .
-s , ,
Web-.
- echo.ws,
.
, WSDL-
echo.wsdl.

178

Web- Java

echo ws,
, RMI-, ,
, RMI.
DD- deploy.wsdd. undeploy.wsdd.
EchoServiceSoapBindinglmpl.java, Web-, RMI [10].
RMI EchoServicePortType.java,
EchoServiceSoapBindingStub.java.
getEchoServicePort -,
EchoService.java.
,
echo/ws:
$ javac echo/ws/*.Java

ws Web-
:
$ Java org.apache.axis.client.AdminClient deploy.wsdd

Axis
Axis
. session, simpiesession, SOAP, AxisHttpSession, cookie [10].
SOAP-
<sessionio>, .
simpleSessionHandier. .
setCookie Cookie [10] HTTP-.


Session
public void set(String key, Object value);
key value.

3. SOAP Web Services

179


public Enumeration getKeysQ;
key
public Object get(String key);
key
public void remove(String key);
, timeout,

public void setTimeout(int timeout);


. .

public int getTimeout();
,
public void touch();
Session. "" , ,
.
simplesession session,
, ,
public long getLastAccessTime() ;
.
AxisHttpSession
HttpSession,

public AxisHttpSession(HttpSession session);


, req,
public AxisHttpSession(HttpServletRequest req);
, session,

public void setRep(HttpSession session);
public HttpSession getRep();

Axis
"" Web- SimpleSession AxisHttpSession, Axis , -

180

Web- Java

. Web,
. Web-
3.17.
* 3.17. Web-,
public class HelloSessionf
private String lastName = " " ;
public String sayHello(String name){
String resp = " " ;
if

(name.equals(lastName))
resp = " , ";

else

resp = ", ";

lastName = name;
return resp + name + "\n";

Axis Web- Heiiosession,


, <parameter>,
"Session" "scope":
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:j ava="http://xml.apache.org/axis/wsdd/providers/j ava">
<service name="HelloSession" provider="java:RPC">
<parameter name="className" value="HelloSession" />
<parameter name="methodName" value="sayHello" />
<parameter name="scope" value="Session"/>
</service>
</deployment>

3. SOAP Web Services

181

Web- WSDL, wsDL2Java -d session,


, .
.
.
public void setMaintainSession(boolean session);
- stub, Axis JAX-RPC. Axis, , Adminciient wsDL2Java, stub, HeiioSessionSoapBindingStub. , 3.18.
, 3.18, Web- sayHelloO
. Web- : ", ",
" , ".
; 3.18. Web-,
public class HelloSessionClient{
public static void main(String[] args){
String name = "";
if (args[0] != null) name = args[0];
// - HelloSession WSDL2Java.
HelloSession fact = new HelloSession();
HelloSessionPortType service =
fact.getHelloSessionPort();
HeiioSessionSoapBindingStub stub =
(HeiioSessionSoapBindingStub)service;
stub.setMaintainSession(true);
try{

182

Web- Ja
System.out.println(service.sayHello(name));
System.out.println(service.sayHello(name));
}catch(Exception e){
System.out.println(e);

Web Services
WSDL
2 , Web-
, JSP, JWS-, EJB , Web- , , , ,
Web-.
, , UDDI ebXML,
Web-.
, Web-, , ,
.
Web-
WSDL, W3C. XML. http://www.w3.org/TR/wsdI. WSDL 1.2,
.

WSDL
XML WSDL <definitions>. name . , .
WSDL . , WSDL -

184

Web- Java

XSD (. 1)
SOAP. WSDL .
WSDL 1.2
http://www.w3.org/2002/07/wsdl. , targetNamespace,
tns (target namespace).
<definitions> . ,
, <types>,
. , name.
. , <definitions>.
<types> , Web-, XSD .
, Web- ,
XSD.
<message> SOAP-: , , . <part>, WSDL .
<part>
. <part>
MIME- "multipart/related".
<binding>.
<portType> Web-,
WSDL (endpoint) (port) . Web-, WSDL
.
, Java,
. <operation>,
. , . : " ", " ",
: " " , , " ". , ,
<input> <output>, <fauit>. <message>, <input>, <output> <fault>
message.

4. Web Services WSDL

185

<serviceType> <portType> , Web-.


.
<binding> : , SOAP HTTP, ,
: HTML, XML MIME- .
<message> , . , .
<service> Web- .
<port>, Web-, <binding> .
.
<import> XSD- WSDL
WSDL-.
Q <documentation> .
WSDL.
, <types>, <message> <portType> , Web-, ,
, .
<binding> , Web-, : HTTP, SMTP - ,
.
, <service> , Web-,
<binding> Web-.
WSDL 4.1.
. Web-:
[?] , ;
[*] ,
;
[+] ,
;
,
.

186

Web- Java

j 4,1. WSDL-
<?xml version="1.0" ?>
<wsdl:definitions ="" [?]
targetNamespace="i*fleHT^MKaTop "
xmlns:=" " [*] >
<import =" "
location="URI-anpec" /> [*]
<wsdl:documentation> [?]

</wsdl: documentation
<wsdl:types> [?]
<wsdl:documentation> [?]
.
</wsdl:documentation
<xsd:schema>

[*]

<! >
</xsd:schema>
</wsdl:types>
<wsdl:message =""> [*]
<wsdl:documentat ion> [?]
SOAP-
.
</wsdl:documentation
<part =" ( )"
element="XSD-HMq " [?]
type="XSD-Tnn " [?] /> [*]
</wsdl:message>

4. Web Services WSDL


<wsdl:portType =""> [*]
<wsdl:documentation [?]
Web-
().
</wsdl:documentation
<wsdl:operation =" "> [*]
<wsdl:documentation [?]
(input)
(output, fault) .
</wsdl:documentat ion>
<wsdl:input message="HMH . <message>"> [?]
<wsdl:documentation [?]
.
</wsdl:documentation>
</wsdl:input>
<wsdl:output message="HMH . <message>"> [?]
<wsdl:documentation> [?]
.
</wsdl:documentation
</wsdl:output>
<wsdl:fault =""
message="MMH . <message>"> [*]
<wsdl:documentation> [?]
.
</wsdl:documentation
</wsdl:fault>
</wsdl: operation
</wsdl:portType>
<wsdl:serviceType =""> [*]

187

188

Web- Java
<wsdl:portType =" . <portType>"/> [+]

</wsdl:serviceType>
<wsdl:binding =""
=" . <portType>"> [*]
<wsdl:documentation . . . / > [ ? ]

,
.
.

<wsdl:operation =""> [*]


<wsdl:documentation . . . / > [ ? ]

,
.

<wsdl:input> [? ]
<wsdl:documentation . . . / > [ ? ]

,
.

</wsdl:input>
<wsdl:output> [?]
<wsdl:documentation . . . / > [ ? ]

4. Web Services WSDL


,
.

</wsdl:output>
<wsdl:fault =""> [*]
<wsdl:documentation . . . /> [?]
<!
,
.

</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service =""
serviceType="HMH . <serviceType>"> [*]
<wsdl:documentation> [?]
Web- .
</wsdl:documentation
<wsdl:port =""
binding="wuw . <binding>"> [*]
<wsdl:documentation .

./>[?]


Web-,
, <binding>.

189

190

Web- Java
</wsdl:port>

</wsdl:service>
</wsdl:definitions>
SOAP, HTTP, FTP,
SMTP
WSDL ,
.
. 3.14 Java
Web-,
:
public class EchoService{
public String getEcho(String req){
return req;

4.2 Web- WSDL, SOAP.


4.2. Web- EchoService
<?xml version="1.0" encoding="UTF-8" ?>
<definitions
targetNamespace="http://echoservice.com/echoservice.wsdl"
xmlns="http://www.w3.org/2002/07/wsdl"
xmlns:tns="http://echoservice.com/echoservice.wsdl"
xmlns:soap="http://www.w3.org/2002/07/wsdl/soapl2"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="getEchoRequest">
<part name="req" type="xsd:string" />
</message>
<message name="getEchoResponse">
<part name="return" type="xsd:string" />
</message>

4. Web Services WSDL

191

<portType name="EchoServicePort">
<operation name="getEcho">
<input message="tns:getEchoRequest" name="getEchoRequest" />
<output message="tns:getEchoResponse" name="getEchoResponse" />
</operation>
</portType>
<binding name="EchoServiceSoapBinding" type="tns:EchoServicePort">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getEcho">
<soap:operation soapAction="" />
<input name="getEchoRequest">
<soap:body encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://echoservice.com/echoservice.wsdl"
use="encoded" />
</input>
<output name="getEchoResponse">
<soap:body encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://echoservice.com/echoservice.wsdl"
use="encoded" />
</output>
</operation>

192

Web- Java

</binding>
<service name="EchoServService">
<port binding="tns:EchoServiceSoapBinding" name="EchoService">
<soap:address location=
"http://localhost:8080/axis/EchoService.jws" />
</port>
</service>
</definitions>

4.2 <definitions>
.
<message>. "getEchoRequest" "getEchoResponse". xsd: string.
XSD. req,
getEchoO . , , return,
xsd: string.
"getEchoRequest" "getEchoResponse"
<portType> Web. <operation>. , Web , "getEcho" , . <operation>
<input> <output> .
, <binding> SOAP- ,
HTTP,

<soap:binding style="rcp"
transport="http://schemas.xmlsoap.org/soap/http" />
SOAP, style "document".
<binding> , SOAP.
, <service> <port>
<binding> <address>, , Web-.

4. Web Services WSDL

193

4.2 soap . ,
WSDL 1.2.

WSDL
WSDL 1.2 Web-
SOAP, GET POST HTTP -.
XML, .

SOAP
SOAP <binding>
<service>, , <port>, WSDL
. WSDL 1.2

http://www.w3.org/2002/07/wsdl/soapl2. ,
soap.
<binding>
<soap:binding>, s t y l e ("document") ("") SOAP. . ,
t r a n s p o r t UR1
SOAP-.

HTTP
"http://schemas.xmlsoap.org/soap/http",

.
<operation> , <binding>
<soap:operation>.

style, "" "document",
soAPAction soapAction.
<input> <output>, <operation>, <soap:header> <soap:body>, <fault>
<soap:fauit>. <soap:header> <soap: headerfaultx
use, "literal" "encoded".
.
7 . 748

194

Web- Java

"encoded" use ,
, type,
namespace encodingStyle.
"literal" use , .
<port>, <service>,
<soap:address>, location
Web- URI.
4.2.
4.3 SOAP (
soap) WSDL. , 4.1.
. 4.3. SOAP
<definitions .... >
<binding .... >
<soap;binding style="rpc | document" [?]
transport="cTpoKa URI" />
operation .... >
<soap:operation soapAction="CTpoKa URI" [?]
style="rpc I document" [?] /> [?]
<input>
<soap:body u s e = " l i t e r a l I encoded"
encodingStyle="cTpoKH URI"
="" [
<soap: header message="HMH" =""
u s e = " l i t e r a l I encoded"
encodingStyle="uri-list" [?]
="" [?]
<soap:headerfault

4. Web Services WSDL

use="literal I encoded"
encodingStyle="cTpoKH URI"
=""
</soap:header>
</input>
<output>
<soap:body parts="HMH" [?]
use="literal | encoded" [?]
encodingStyle="cTpoKH URI"
="" [
<soap:header message="HMH" part="HMH"
u s e = " l i t e r a l I encoded"
encodingStyle="cTpoKH URI" [?]
="" [?]
<soap:headerfault
=""
part=""
use="literal | encoded"
encodingStyle="cTpoKH URI"
=""
</soap:header>
</output>
<fault>
<soap:fault =""
use="literal I encoded"
encodingStyle="cTpoKH URI"
=""
</fault>
</operation>

195

196

Web- Java

</binding>
<service .... >
<port ... . >
<soap:address location="aflpec URI" />
</port>
</service>
</definitions>

HTTP
HTTP
http://www.w3.org/2002/07/wsdl/http. , http.
HTTP .
<http:binding>, <binding>, , HTTP. verb,
HTTP- "GET"
"POST".
<http:address>, <port> <service>, location
Web- URI.
<http:operation>, <operation>
<binding>, location URI . <http:address>
Web-.

<http:urlEncoded/> <http: urlReplacement/>. -

<input> / <output> GET POST.


<http:uriEncoded/> , MIME-
"application/x-www-form-urlencoded", ,
"=", , ,
16- .
4.4. HTTP.

4. Web Services WSDL

197

; 4.4. HTTP
<definitions .... >
<binding . . . . >
<http:binding verb="GET | POST" />
<operation .... >
<http:operation 11=" URI" />
<input .... >
<http:urlEncoded/> [?]
<http:urlReplacement/> [?]
</input>
<output .... >
<http:urlEncoded/> [?]
<http:urlReplacement/> [?]
</output>
</operation>
</binding>
<service>
<port .... >
<http:address location="aflpec Web- URI" />
</port>
</service>
</definitions>
. HTTP- GET POST. :
GET /services/EmpService?empid=123456 HTTP/1.1

198

Web- Java

empid . Web EmpService


XML,
<emp xmlns="http://some.com/emp" >
<> . .</>
<age>27</age>
<position>MHs;eHep</position>
</>

Web-
WSDL, 4.5.
4.5. WSDL HTTP
<definitions
xmlns="http://www.w3.org/2002/07/wsdl"
xmlns:http="http://www.w3.org/2002/07/wsdl/http"
xmlns:tns="http://some.com/emp"
targetNamespace="http://some.com/emp"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:mime="http://www.w3.org/2002/07/wsdl/mime">
<types>
<xsd:schema attributeFormDefault="qualified"
elementFormDefault="qualified"
targetNamespace="http://some.com/emp">
<xsd:element name="emp"
type="tns:EmpInfoType" />
<xsd:complexType name="EmplnfoType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" />
<xsd:element name="age" type="xsd:int" />

4. Web Services WSDL


<xsd:element name="position" t y p e = " x s d : s t r i n g " />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</types>
<message name="EmpIn">
<part name="empid" type="xsd:string" />
</message>
<message name="EmpOut">
<part name="EmpInfo" element="tns:emp" />
</message>
<portType name="EmpPortType">
<operation name="EmployeeInfo">
<input message="tns:EmpIn" />
<output message="tns:EmpOut" />
</operation>
</portType>
<binding name="EmpGET" type="tns:EmpPortType">
<http:binding verb="GET" />
<operation name="Employee">
<http:operation Iocation="/Emplnfo" />
<input>

199

200

Web- Java
<http:urlEncoded/>
</input>
<output>
<mime:mimeXml part="EmpInfo" />
</output>
</operation>

</binding>
<binding name="EmpPOST" type="tns:EmpPortType">
<http:binding verb="POST" />
<operation name="Employee">
<http:operation Iocation="/Emplnfo" />
<input>
<mime: content
type="application/x-www-form-urlencoded" />
</input>
<output>
<mime:mimeXml part="EmpInfo" />
</output>
</operation>
</binding>
<service name="Employee">
<port name="EmpGETPort" binding="tns:EmpGET">
<http:address
location="http://some.com:8080/services/Empservice" />

4. Web Services WSDL

20?

</port>
<port name="EmpPOSTPort" binding="tns:EmpPOST">
<http:address
location="http://some.com:8080/services/EmpService" />
</port>
</service>
</definitions>

Ml ME-
WSDL, 4.5 , MIME-. http://www.w3.org/2002/07/wsdl/mime.
, mime.
-.
<mime:content> .
name ,
type MIME- , :
<mime:content type="text/xml" />
<mime:content type="image/jpeg" />
type " ", ,
<mime: content type="*/*" />
<mime:multipartRelated> <mime:part>, MIME- "multipart/related" name. :
<mime:multipartRelated>
<mime:part>
<soap:body parts="contract" use="literal" />
</mime:part>
<mime:part>
<mime:content part="signature" type="image/jpeg"/>

202

Web- Java

</mime:part>
</mime:multipartRelated>

<mime:mimexmi> MIME-, XML. part


, ,
.
MIME- <input> / <output> <operation>, <binding>. 4.6.
4.6. MIME-
definitions

....

>

<binding . . . . >
<operation . . . . >
<input . . . . >

<! >
</input>
<output .... >
<! >
</output>
</operation>
</binding>
</definitions>

WSDL
WSDL 4.2 4.5 .
WSDL . Web- , -

4. Web Services WSDL

203

WSDL-, Web. , 3 Web Apache Axis Java2wsDL,


WSDL- Java, Web-.
IBM WSTK, Axis,
java2wsdi, .
.
$ java2wsdl EchoService
EchoService.wsdl,
<portType> ,
. 4.6 .
= 4.6. Web- EchoService, Axis
<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions
targetNamespace=
"http://localhost:8080/axis/EchoService.jws/axis/EchoService.jws"
xmlns="http://schemas.xmlsoap.org/wsdl/"

xmlns : chesoap= "http: //xml. apache. org/xml-soap"


xmlns:impl=
"http://localhost:8080/axis/EchoService.jws/axis/EchoService.jws-impl"
xmlns:intf=
"http://localhost:8080/axis/EchoService.jws/axis/EchoService.jws"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema
targetNamespace="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<element name="any" nillable="true" type="xsd:any" />

204

Web- Java
</schema>

</wsdl:types>
<wsdl:message name="getEchoRequest">
<wsdl:part name="req" type="xsd:any" />
</wsdl:message>
<wsdl:message name="getEchoResponse">
<wsdl:part name="return" type="xsd:any" />
</wsdl:message>
<wsdl:portType name="EchoService">
<wsdl:operation name="getEcho" parameterOrder="req">
<wsdl:input message="intf:getEchoRequest"
name="getEchoRequest" />
<wsdl:output mes sage="int f:getEchoResponse"
name="getEchoResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="EchoServiceSoapBinding"
type="intf:EchoService">
<wsdlsoap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="getEcho">
<wsdlsoap:operation soapAction="" />
<wsdl:input name="getEchoRequest">
<wsdlsoap:body encodingStyle=

4. Web Services WSDL

205

"http://schemas.xmlsoap.org/soap/encoding/"
namespace=
"http://localhost:8080/axis/EchoService.jws/axis/EchoService.jws"
use="encoded" />
</wsdl:input>
<wsdl:output name="getEchoResponse">
<wsdlsoap:body encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
namespace=
"http://localhost:8080/axis/EchoService.jws/axis/EchoService.jws"
use="encoded" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="EchoServiceService">
<wsdl:port binding="intf:EchoServiceSoapBinding"
name="EchoService">
<wsdlsoap:address location=
"http://localhost:8080/axis/EchoService.jws" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
, Axis :
WSDL- wsDL2java Java,
Web-. IBM WSTK wsDL2java
wsdi2java. :
$ wsdl2java EchoService.wsdl

206

Web- Java

GLUE The Mind Electric.


Microsoft SOAP Toolkit wsdlgen3.exe,
WSDL Generator,
wsdistb3.exe, WSDL-.
Sun Microsystems JWSDL (Java
API for WSDL), WSDL Java .
, , WSDL.
IBM WSTK, WSDL4J (WSDL for Java).
WSTK ,
http://www-124.ibm.com/developerworks/projects/wsdl4j/. .
WSDL , Web- , WSDL-. GLUE invoke, Web- WSDL. , :
$ invoke http://some.com:8080/services/EchoService.wsdl
Web-.
IBM WSIF (Web Services Invocation Framework), Web- Tomcat Apache
SOAP. , , :
$ Java clients.Dynamiclnvoker \
http://some.com:8080/services/EchoService.wsdl \
getEcho

, .
D y n a m i c l n v o k e r

WSIF .

JWSDL WSDL4J
JWSDL ,
javax.wsdi .
com. ibm. wsdl , IBM WSDL4J.
javax.wsdi ,
XML- WSDL-: Definition, Types, Message, PortType,
Binding, Service, : Operation, Part, Input,

4. Web Services WSDL

207

Output, Port, BindingOperation, Bindinglnput, BindingOutput, BindingFault. getxxxo , setxxx () .


Definition, , createXxxO,
, ,
Message msg = def.createMessage();
addxxxo WSDL, :
def.addMessage(msg);
Definition newDefinition() WSDLFactory javax.wsdl. factory:
Definition def = fact.newDefinition();
WSDLFactory, , newinstance , :
WSDLFactory fact = WSDLFactory.newinstance();
-,

javax.wsdl.factory.WSDLFactory,

jre/lib/wsdl.properties, .
, :
public static WSDLFactory newinstance(String factory);
Definition, - WSDLFactory wsDLReader, WSDL,
wsDLWriter, WSDL. WSDLReader WSDLWriter javax.wsdl.xml.

newWSDLReader ()

newwsDLWriter () :
WSDLReader reader = fact.newWSDLReader();
WSDLWriter writer = fact.newWSDLWriter();
reader
public void setFeature(String name, boolean value);
WSDL wsDLReader:
"javax.wsdl.verbose" true, System, out;
"javax.wsdl.importDocuments" true, , false .

208

Web- Java

true.
reader , readwsDLO
Definition, WSDL, :
Definition def = rdr.readWSDL("sample.wsdl");

4.7 ,
JWSDL sample.wsdl, WSDL,
.
4.7. WSDL
import javax.wsdl.*;
import javax.wsdl.factory.*;
import j avax.wsdl.xml.*;
public class ReadWSDL{
public static void main(String[] args){
try{
WSDLFactory fact = WSDLFactory.newInstance();
WSDLReader reader = fact.newWSDLReader();
reader.setFeature("javax.wsdl.verbose", false);
reader.setFeature("javax.wsdl.importDocuments", true),
Definition def = reader.readWSDL(null, "sample.wsdl")
Service service = def.getService(
new QName("http://some.com/wsdl",
"SomeService"));
Port port = service.getPort("SomePort");
Binding binding = port.getBinding();
PortType portType = binding.getPortType();
Map messages = def.getMessages();

4. Web Services WSDL

209

Iterator msglt = messages.values .iterator();


while (msglt.hasNext()){
Message msg = (Message)msglt.next();
if (!msg.isUndefined())
System.out.println(msg.getQName());
}
List operations = portType.getOperations();
Iterator oplt = operations.iterator();
while (opIt.hasNext()){
Operation operation = (Operation)oplt.next();
if (!operation.isUndefined())
System.out.println(operation.getName());
}
}catch(WSDLException e){
System.err.println(e);

4.8 WSDL JWSDL.


'. 4.8. WSDL
import j avax.wsdl.*;
import j avax.wsdl.factory.*;
import j avax.wsdl.xml.*;
public class WriteWSDLf
public static void main(String[] args)
try{

210

Web- Java
WSDLFactory fact = WSDLFactory.newInstance();
WSDLWriter writer = fact.newWSDLWriter();
writer.writeWSDL(def, System.out);
Definition def = fact.newDefinition() ;
Part parti = def.createPart();
Part part2 = def.createPart();
Message msgl = def.createMessage();
Message msg2 = def.createMessage();
Input input = def.createlnput();
Output output = def.createOutput();
Operation operation = def.createOperation();
PortType portType = def.createPortType();
String tns = "http://some.com/wsdl";
def.setQName(new QName(tns, "SomeService"));
def.setTargetNamespace(tns);
def.addNamespace("tns", tns);
String xsd = "http://www.w3.org/2001/XMLSchema";
def.addNamespace("xsd", xsd);
parti.setName("symbol");
parti.setTypeName(new QName(xsd, "string"));
msgl.setQName(new QName(tns, "getQuotelnput"));
msgl.addPart(parti);
msgl.setUndefined(false);
def.addMessage(msgl);
part2.setName("quote");
part2.setTypeName(new QName(xsd, "float"));
msg2.setQName(new QName(tns, "getQuoteOutput"));

4. Web Services WSDL


msg2.addPart(part2);
msg2.setUndefined(false);
def.addMessage(msg2) ;
input.setMessage(msgl);
output.setMessage(msg2) ;
operation.setName("getQuote") ;
operation.setlnput(input);
operation.setOutput(output);
operation.setUndefined(false);
portType.setQName(new QName(tns, "GetQuote"));
portType.addOperation(operation) ;
portType.setUndefined(false) ;
def.addPortType(portType);
}catch(WSDLException e){
System.err.println(e);

211

Web Services
UDDI
2 Web .
: , UDDI - ebXML Registry
(electronic business XML Registry). , ebXML, Web-,
. , , : ,
, , , ,
.
Web-
2.3.
, UDDI IBM
(http://www-3.ibm.com/services/uddi/)

Microsoft

(http://uddi.microsoft.com/).

,
, IBM Microsot, Oracle, Hewlett-Packard
SAP AG. UDDI http://www.uddi.org/ - . , UDDI,
.
UDDI.
UDDI (UDDI Business Registry) (nodes),
. Web-, , UDDI-.
"" UDDI- , ,
. ,

5. Web Services UDDI

213

Web-, UDDI
.
UDDI-.
:
IBM,
https://www-3.ibm.com/services/uddi/v2beta/protect/registry.html;
Hewlett Packard,
https://uddi.hp.com/uddi/index.jsp;
Q Microsoft
https://uddi.rte.microsoft.com/register.aspx;
SAP AG http://udditest.sap.com/.
UDDI-
. , (public) . Web-
Web-.
(private) , .
UDDI- UDDI
http://www.uddi.org/solutions.html#registrars.

UDDI
UDDI
.

.
- <businessEntity>
- Web-: UUID (Unique
Universal Identifier), businessKey, <name>,
,
, , URL. ,
.
- <businessServices>,
<businessEntity> - , .
<businessservice>. UUID , serviceKey,
<name>,

214

Web- Java

. ,
Web-.
<bindingTempiates>, <businessservice> . , , URL- Web-, ,
, WSDL IDL.
<bindingTempiate>. bindingKey UUID . <bindingTempiate>
<tModel>.

<tModei> (technical Model) . . XML.


.
<pubiisherAssertion> ( "peer-peer")
( "parent-child").
,
. "identity"
.
<fromKey> <toKey>, <keyedReference>. , . ,
<businessEntity> .
<operationaiinfo> , , .
G <subsc-ription> , -
.
UDDI. UDDI 3.0 "urn:uddi-org:api_v3".
UUID, , : "uddi:example.com: 1" "uddi:example.com:sales-division:53".
UUID : "4CD7E4BC648B-426D-9936-443EAAC8AE23".
5.1 XML, UDDI -.
, . 5.1 , 4:

5. Web Services UDDI

215

[?] , ;
[*] ,
;
[+] , ;
,
.
| 5.1. UDDI- -
<businessEntity businessKey="Kjno4 UUID" [?] >
<name 1="" [?] ></> [+]
<buslnessServices>

[?]

<businessService serviceKey="KJU04 UUID" [?] > [+]


<bindingTemplates> [?]
<bindingTemplate =" UUID" [?] > [+]
< ! >
</bindingTemplate>
</bindingTemplates>
</businessService>
</businessServices>
</businessEntity>
. <businessServices>
<bindingTempiates> , <businessService> <bindingTemplate> COOT.
.
.

216

Web- Java

<businessEntity>
<businessEntity>
businessKey, 5.1.
UUID -. ,
UUID UDDI.
<businessEntity> , <name>. .
<discoveryURLs> <discoveryURL>, ,
-.
Q <name>, ,
.
description:^ , , , .
<contacts> <contact>, , , , :
<description> ;
<personName> ;
<phone> ;
<emaii>
;

<address>, .

<businessService>.

<identifierBag>

.
<keyedReference>. :
tModeiKey, UUDI <tModei>,
, keyvaiue . keyName
.

5. Web Services UDDI

217

. , tModeiKey
,
.
<categoryBag>
<keyedReference>, , , .
<keyedReferenceGroup>
tModeiKey <keyedReference>.

, , . <identifierBag>,
<categoryBag> keyName , , , , tModeiKey.
- , <Signature>.
, <businessEntity> UDDI . 5.2 .
5.2. -
<businessEntity
businessKey="677cfala-2717-4 620-be39-6631bb74b6el">
<discoveryORLs>
<discoveryURL useType="businessEntity">
http://uddi.hp.com/discovery?
4>businessKey=677cfala-2717-4 620-be39-6631bb74b6el
</discoveryURL>
</discoveryURLs>
<name xml:lang="en">Weather Service</name>
<description xml:lang="RU-ru">

218

Web- Java
.

</description>
<contacts>
<contact useType="Technical support">
<description xml:lang="RU-ru">
.
</description>
<personName>onepaTop . . CnflopoB</personName>
<phone>234-45-67</phone>
<phone>234-45-38</phone>
<email>sidor@some.com</email>
<address>318123 , , 23-6</address>
</contact>
</contacts>
<businessServices>
<! -. >
</businessServices>
<identifierBag>
<keyedReference
tModelKey="uddi:ubr.uddi.org:identifier:dnb.com:D-U-N-S"
keyName="HP"
keyValue="31-626-8655" />
</identifierBag>
<categoryBag>

5. Web Services UDDI

219

<keyedReference
tModelKey="uddi:c0b9fel3-179f-413d-8a5b-5004db8e5bb2"
keyValue="61" />
<keyedReference
tModelKey=Muuid:c0b9fel3-179f-413d-8a5b-5004db8e5bb2"
keyValue="51419" />
</categoryBag>
</businessEntity>

<businessService>
<businessService>, -,
serviceKey businessKey.
serviceKey UUID . , UDDI.
businessKey UUID
<businessEntity>. , <businessService>
< b u s i n e s s E n t i t y > .

<businessService> . , <name>, , <description>, <bindingTemplates> <categoryBag> <Signature>.


5.3 -.
5.3. -
<businessService
serviceKey="d8091de4-0a4a-4061-9979-5dl9131aece5"
businessKey="677cfala-2717-4620-be39-6631bb74b6el">
<name xml:lang="en">Meteo Service</name>
<description xml:lang="RU-ru">
.
</description>

220

Web- Java

<bindingTemplates>
<! . >
</bindingTemplates>
</businessService>

<bindingTemplate>
<bindingTempiate>,
,
bindingKey serviceKey.
bindingKey UUID .
, UDDI.
serviceKey UUID <businessService>,
.
<bindingTempiate>
<description>
<accessPoint>, Web-, URL . UDDI
<hostingRedirector>, UDDI 3.0 .
, <bindingTempiate> .
<categoryBag> <Signature>.
<tModelinstanceDetaiis>
<tModeiinstanceinfo>, <tModei> tModeiKey. ,
<tModelInstanceInfo> < d e s c r i p t i o n >
<instanceDetails>. <instanceDetails>,
, <overviewDoc>,
URL, <instanceParms>,
.
5.4 .
5.4. UDDI
<bindingTemplate
bindingKey=n942595d7-0311-48b7-9c65-995748a3a8af"

5. Web Services UDDI

221

serviceKey="d8091de4-0a4a-4061-9979-5dl9131aece5">
<accessPoint URLType="http">
http://some.com/services/MeteoService
</accessPoint>
<tModelInstanceDetails>
<tModelIns tanceInfo
M

tModelKey= uddi:42fab02f-300a-4315-aa4a-f97242ff6953">
<instanceDetails>
<overviewDoc>
<overviewURL>
http://some.com/services/MeteoService?WSDL
</overviewURL>
</overviewDoc>
</instanceDetails>
</tModelInstanceInfo>
</tModelInstanceDetails>
</bindingTemplate>

<tModel>
<tModei>,
-, : tModeiKey, UUID, deleted, " t r u e " ( ), "false", ,

222

Web- Java

. tModeiKey ,
UUID UDDI.
<tModei> <name>
URI :
<description>, <overviewDoc>, <identifierBag>, <categoryBag>
<signature>. .
5.5 .
5.5. UDDI
<tModel
tModelKey="uddi:42fab02f-300a-4315-aa4a-f97242ff6953">
<name>Meteo Service Interface</name>
<description xml:lang="RU-ru">

.
</description>
<overviewDoc>
<description xml:lang="RU-ru">
WSDL .
</description>
<overviewURL>
http://some.com/services/ifaces/meteoservice.wsdl
</overviewURL>
</overviewDoc>
<categoryBag>
<keyedReference

5. Web Services UDDI

223

tModelKey= n uddi:clacf26d-9672-4404-9d70-39b756e62ab4"
keyValue="wsdlSpec" />
< keyedRe fe rence
tModelKey= 1 'uddi:c0b9fel3-179f-413d-8a5b-5004db8e5bb2"
keyValue="514191" />
</categoryBag>
</tModel>

<publisherAssertion>
<pubiisherAssertion>, , .
<fromKey>, <toKey> <keyedReference>
, <signature>.
<keyedReference> . tModelKey
.
<fromKey> <toKey> UUID
, 5.6.
' 5.6.
<publisherAssertion>
<fromKey>677cfala-2717-4620-be39-6631bb74b6el</fromKey>
<toKey>677cfala-2717-4620-be27-6631bb45b34</toKey>
<keyedReference
tModelKey='uddi:807a2c6a-ee22-470d-adc7-e0424a337c03'
keyValue='peer-peer'/>
</publisherAssertion>

UDDI
UDDI- ,
Web-, , , Web-

224

Web- Java

- . ,
UDDI API, :
Web-
save_xxx;
Web- get_xxxDetaiis;
Web- f ind_xxx;
delete_xxx.
"" , , "business",
"service", "binding" "tModel".
UDDI , API,
"", XML. , " "
XML. XML ,
UDDI API
Java, - .
UDDI XML, ,
Web- :
<find_service businessKey="" generic="3.0" xmlns="urn:uddi-org:api_v3">
<name>Meteo Service</name>
</find_service>

SOAP- Web, UDDI. Web-


"Meteo Service" UUID SOAP, Web-

<serviceList>, :
<serviceList generic="3." operator="HP"
truncated="false"
xmlns="urn:uddi-org:api_v3">
<servicelnfos>
<servicelnfo

serviceKey="7cl9ab87-lbc5-4fb6-841b
businessKey="">

<name xml:lang="en">Meteo Service</name>

5. Web Services UDDI

225

</serviceInfo>
</serviceInfos>
</serviceList>
API :
Inquiry API , ;
Publish API , Web-,
.
API.


Inquiry API 9 XML,
. :
serviceKey UUID , ;
maxRows , ;
listHead , .
( ) <findQuaiifiers>.
, , <binarySort>, <caseSensitiveSort>,
<caseInsensitiveSort>, <sortByNameAsc>, <sortByNameDesc>, <sortByDateAsc>,
<sortByDateDesc>.

Inquiry API.
find_business <businessEntity>

()
<authlnfo>,
<categoryBag>,
<discoveryURLs>,
<identifierBag>,
<name>,
<findQualifiers>,
<find_tModel>, <find_relatedBusinesses>, <tModelBag>. <businessEntity>
(SOAP-) <businessList>.
find_relatedBusinesses - ,
, , <authinfo>,
<findQualifiers>, <keyedreference>,
<fromKey>, <toKey>, <businessKey>. <relatedBusinessesList>.
8 . 748

226

Web- Java

f i n d s e r v i c e <businessService>
<authlnfo>,
<categoryBag>,
<name>,
<findQualifiers>,
<find_tModei>, <tModeiBag>.
<serviceList>.

find_binding

<bindingTempiate> , ( ) <authlnfo>, <categoryBag>, <findQualifiers>,


<find_tModei>, <tModelBag>. , <bindingTempiate>, (SOAP-)
<bindingDetail>.
find_tModei <tModei> , <authlnfo>, <categoryBag>, <identifierBag>, <name>,
<findQuaiifiers>. <tModeiList>.
get_businessDetail <businessEntity>
businessKey, UUID
. <businessDetail>.
get_serviceDetail <businessservice> serviceKey, UUID . <serviceDetail>.
get_bindingDetail <bindingTemplate>
bindingKey, UUID
. <bindingDetaii>.
gettModelDetail <tModel>
tModeiKey, UUID . <tModeiDetaii>.
get_operationallnfo <operationallnfo>
entityKey, UUID . <operationaiinfos>.

Web-
Publish API , , UDDI, Web-. .
savejousiness <businessEntity>
, .
01 delete_business <businessEntity>, businessKey, UUID .

5. Web Services UDDI

227

save_service <businessService>
, .

deiete_service <businessService>, serviceKey, UUID .



save_binding

<bindingTempiate> , .
delete_binding <bindingTemplate>, bindingKey, UUID
.
save_tModei <tModei> , .
deiete_tModei <tModei>, tModeiKey, UUID .

add_pubiisherAssertions

<publisherAssertion> .

set_pubiisherAssertions

<publisherAssertion>.

delete_publisherAssertions <publisherAssertion>.

get_pubiisherAssertions

<pubiisherAssertions>, ,
.
get_assertionStatusReport -
<assertionStatusReport>.
get_registeredinfo Web-.

UDDI API
, UDDI API,
UDDI, XML,
.
, , SOAP UDDI.

228

Web- Java

IBM UDDI4J
,
. Java
UDDI4J (UDDI for Java), IBM
(http://www.uddi4j.org/). UDDI4J IBM WSTK.
, UDDI4J,
UDDI-.
UDDI - UDDiProxy,
UDDI4J. UDDiProxy UDDI API. ,
UDDI API: save_business (), f ind_service () .
, SOAP-:
ServiceList, BusinessList, BindingDetail, TModelList ,
com. ibm.uddi. response.
UDDIProxy, UDDI API,
, UDDI API:
Authlnfo, FindQualifiers, FindQualifier, IdentifierBag, CategoryBag,
TModelBag, BindingKey, BusinessKey, ServiceKey , com.ibm.uddi.util.

UDDI API.
UDDI API,
UDDI4J, UDDI API

SaveBusiness,
SaveService,
SaveTModel,
FindBusiness,
FindService, DeleteBusiness, GetServiceDetail -

com.ibm.uddi.request.
UDDIElement.
- ,
public org.w3c.dom.Element send(UDDIElement el, boolean inquiry);
XML,
- DOM-.
- ,

UDDI:
BusinessEntity,
BusinessServices,
BusinessService,
BindingTemplates, BindingTemplate, TModel . com.ibm.uddi.datatype .

5.7 , UDDI4J
Web- UDDI-.

5. Web Services UDDI


; 5.7. Web- UDDI-
import
import
import
import
import
import

com.ibm.uddi.*;
com.ibm.uddi.datatype.business.*;
com.ibm.uddi.response.*;
com.ibm.uddi.client.*;
org.w3c.dom.Element;
Java.util.Vector;

import Java.util.Properties;
public class SaveSomeService{
public static void main (String[] args){
SaveSomeService app = new SaveSomeService();
UDDIProxy proxy = new UDDIProxy();
try{
// UDDI-:
// IBM
proxy.setInquiryURL("http://www-3.ibm.com/services/" +
"uddi/testregistry/inquiryapi");
proxy.setPublishURL("https://www-3.ibm.com/services/" +
"uddi/testregistry/protect/publishapi");
// IBM
// proxy.setlnquiryURL("http://www-3.ibm.com/services/" +
//

"uddi/inquiryapi");

// proxy.setPublishURL("https://www-3.ibm.com/services/" +
//

"uddi/protect/publishapi");
// Microsoft

// proxy.setlnquiryURL(
//
"http://test.uddi.microsoft.com/inquire");
// proxy.setPublishURL(

229

230

Web- Java
II

"https://test.uddi.microsoft.com/publish");
// Microsoft

// proxy.setlnquiryURL("http://uddi.microsoft.com/inquire");
// proxy.setPublishURL("https://uddi.microsoft.com/publish");
// Hewlett Packard
// proxy.setlnquiryURL("http://uddi.hp.com/inquire");
// proxy.setPublishURL("https://uddi.hp.com/publish");
// WSTK
// proxy.setlnquiryURL(
//

"http://localhost:8080/services/uddi/inquiryapi");

// proxy.setPublishURL(
//

"http://localhost:8080/services/uddi/publishapi");
// UDDI-.
AuthToken token = proxy.get_authToken(
"userid", "password");
I
System.out.println(
" : " + token.getAuthlnfoString());
System.out.println(" Web-");
Vector entities = new Vector();
// <businessEntity>.
// UUID .
BusinessEntity be = new BusinessEntity("", "SomeService");
entities.addElement(be);
// Web-
BusinessDetail bd =
proxy.save_business(token.getAuthlnfoString(), entities);
// UUID.

5. Web Services UDDI

231

Vector businessEntities = bd.getBusinessEntityVector();


BusinessEntity returnedBusinessEntity =
(BusinessEntity)(businessEntities.elementAt(0));
System.out.println(" UUID: " +
returnedBusinessEntity.getBusinessKey());
}catch(UDDIException e){
DispositionReport dr = e.getDispositionReport();
if (dr != null)(
System, out. println (
"UDDIException faultCode:" + e.getFaultCode() +
"\n operator:" + dr.getOperator() +
"\n generic:" + dr.getGeneric() +
"\n errno:"

+ dr.getErrno() +

"\n errCode:" + dr.getErrCode() +


"\n errlnfoText:" + dr.getErrlnfoText());
}
e.printStackTrace();
}catch(Exception e){
System.err.println("From proxy: " + e ) ;

5.8 Web-
UDDI Web-.
5.8. UDDI
import com.ibm.uddi.*;
import com.ibm.uddi.datatype.business.*;
import com.ibm.uddi.response.*;
import com.ibm.uddi.client.*;
import org.w3c.dom.Element;

Web- J

232

import Java.util.Vector;
import Java.util.Properties;
public class SaveSomeService{
public static void main (String[] args){
SaveSomeService app = new SaveSomeService();
UDDIProxy proxy = new UDDIProxyO;
try{
// UDDI-:
// IBM
proxy.setlnquiryURL("http://www-3.ibm.com/services/" +
"uddi/testregistry/inquiryapi");
proxy.setPublishURL("https://www-3.ibm.com/services/" +
"uddi/testregistry/protect/publishapi");
// IBM
// proxy.setlnquiryURL("http://www-3.ibm.com/services/" +
//

"uddi/inquiryapi");

// proxy.setPublishURL("https://www-3.ibm.com/services/" +
//

"uddi/protect/publishapi");
// Microsoft

// proxy.setlnquiryURL(
//

"http://test.uddi.microsoft.com/inquire");

// proxy.setPublishURL(
//

"https://test.uddi.microsoft.com/publish");
// Microsoft

// proxy.setlnquiryURL("http://uddi.microsoft.com/inquire");
// proxy.setPublishURL("https://uddi.microsoft.com/publish") ,
// Hewlett Packard

5. Web Services UDDI


II proxy.setlnquiryURLC'http://uddi.hp.com/inquire");
// proxy.setPublishURLC'https://uddi.hp.com/publish");
// WSTK
// proxy.setlnquiryURL(
//

"http://localhost:8080/services/uddi/inquiryapi");

// proxy.setPublishURL(
//
"http://localhost:8080/services/uddi/publishapi");
// UDDI-.
AuthToken token = proxy.get_authToken(
"userid", "password");
System.out.println(
" : " + token.getAuthlnfoString());
System.out.println(" Web-:");
//
// Web-, "S".
BusinessList bl = proxy.find_business("S", null, 0);
Vector businessInfoVector =
bl.getBusinessInfos().getBusinessInfoVector();
for (int i = 0; i < businessInfoVector.size(); i++){
Businesslnfo businesslnfo =
(Businesslnfo)businessInfoVector.elementAt(i) ;
System.out.println(businesslnfo.getNameString());

}catch(UDDIException e){
DispositionReport dr = e.getDispositionReport(),
if (dr != null){

233

234

Web- Java
System.out.println(
"UDDIException faultCode:" + e.getFaultCode() +
"\n operator:" + dr.getOperator() +
"\n generic:"

+ dr.getGeneric() +

"\n errno:"

+ dr.getErrno() +

"\n errCode:"

+ dr.getErrCode() +

"\n errlrifoText:" + dr.getErrlnfoText());


}
e.printStackTrace();
}catch(Exception e){
System.err.println("From proxy: " + e ) ;

JAXR
2 Web-: UDDI, ebXML, WS-Inspection. , .
.
,
Web-.
2, Sun Microsystems
JAXR. Sun WSDP
J2EE, 1.4. Sun WSDP
, JAXR. Registry Browser. .
$ jaxr-browser

2, WSDP , RegistryServerServlet. Web- Tomcat


Xindice (, , "--"
), Apache Software Foundation
WSDP.
Tomcat :

5. Web Services UDDI

235

$ cd $WSDP_HOME/bin
$ startup
$ xindice-start

, .
:
$ registry-server-test run-cli-request -Dxml/GetAuthToken.xml
Xindice WSDP
Indri. :
$ registry-server-test run-indri
JAXR , , (service provider) . UDDI ebXML, ,
JAXR. 2.4.

JAXR
JAXR Java- javax.xml. registry
javax.xmi.registry.infomodei.
, , .
connection.
-
ConnectionFactory. newinstance ()
, setProperties () , createConnectionO
connection. :
Properties props = new Properties();
props.setProperty("j avax.xml.registry.queryManagerURL",
queryURL);
ConnectionFactory fact = ConnectionFactory.newinstance();
fact.setProperties(props);
Connection conn = factory.createConnection();

236

Web- Java

,
getRegistryServi.ee () Connection
RegistryService:
RegistryService rs = conn.getRegistryService();
RegistryService JAXR.
getxxxo , .
,

getBusinessQueryManager()

BusinessQueryManager:
B u s i n e s s Q u e r y M a n a g e r bqm = r s . g e t B u s i n e s s Q u e r y M a n a g e r ( ) ;


BusinessQueryManager
findxxxo . ,
UDDI API, JAXR , UDDI.
:
public BulkResponse findServices(Key orgKey,
Collection findQualifiers,
Collection namePatterns,
Collection classifications,
Collection specifications);
orgKey Web-, UDDI.

findQualifiers,

<findQuaiifiers> UDDI, .
FindQuaiifier. ,

FindQuaiifier.SORT_BY_NAME_ASC.
namePatterns .
, SQL.
c l a s s i f i c a t i o n s
c l a s s i f i c a t i o n , Web-.
<categoryBag> UDDI API.
, , specifications,
, <tModeiBag> UDDI API. RegistryObject. RegistryObject
. service,
ServiceBinding, User, Organization.

5. Web Services UDDI

237

, findservices () ,
.
findservices BulkResponse,
Web- collection.
,
. g e t s t a t u s (),
STATUS_SUCCESS, STATUS_WARNING, STATUS_FAILURE,
STATUSJJNAVAILABLE.

, Web- :
BulkResponse resp = bqrn. findService (key, null, null, null, null);
if (resp.getstatus() = BulkResponse.STATUS_SUCCESS){
Collection coll = resp.getCollectionO;
}

Service, <businessService> UDDI.


:
Service serv =

(Service)coll.iterator().next();


Service RegistryObject: getKeyO,
getDescription() , getName(), getSubmittingOrganization() .
findXxx() BusinessQueryManager , , , ,
, , . findServiceBindings , findservices ().
, findServiceBindings ()
. findorganizationso
.
5.9 , JAXR.
5.9. JAXR
import javax.xml.registry.*;
import javax.xml.registry.infomodel.*;
import j ava.net.*;
import java.util.*;

235

Web- Java

public class JAXRClient{


public static void main(String[] args)(
// .
String queryURL =
"http://www-3.ibm.com/services/uddi/inquiryapi";
//"http://uddi.rte.microsoft.com/inquire";
//"http://localhost:8080/registry-server/RegistryServerServlet";
if (args.length < 1){
System.out.println("Usage: Java JAXRClient <name>");
System.exit(1);

JAXRClient jq = new JAXRClient();


String httpProxyHost = "localhost";
String httpProxyPort = "8080";
Properties props = new Properties();
props.setProperty("j avax.xml.registry.queryManagerURL",
queryURL);
props.setProperty("com.sun.xml.registry.http.proxyHost",
httpProxyHost);
props.setProperty("com.sun.xml.registry.http.proxyPort",
httpProxyPort);
Connection conn = null;
try{
ConnectionFactory fact =
ConnectionFactory.newInstance();
fact.setProperties(props);
conn = fact.createConnection();
System.out.println(" ");

5. Web Services UDDI


RegistryService rs = conn.getRegistryServi.ee();
BusinessQueryManager bqm = rs.getBusinessQueryManager();
Collection findQualifiers = new ArrayList();
findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
Collection namePatterns = new ArrayList();
namePatterns.add("%" + args[O] + " % " ) ;
// .
BulkResponse response =
bqm.findOrganizations(findQualifiers,
namePatterns, null, null, null, null);
Collection orgs = response.getCollection();
// .
Iterator orglter = orgs.iterator();
while (orglter.hasNext()){
Organization org = (Organization)orglter.next();
System.out.println(": " +
org.getName().getValue());
System.out.println(": " +
org.getDescription().getValue());
System.out.println(": " +
org.getKey().getld()) ;
//
User pc = org.getPrimaryContact();
if (pc != null){
PersonName pcName = pc.getPersonName();
System.out.println(": " +

239

240

Web- Java
pcName.getFullName());
Collection phNums =
pc.getTelephoneNumbers(null);
Iterator phlter = phNums.iterator();
while (phlter.hasNext()){
TelephoneNumber num =
(TelephoneNumber)phlter.next();
System.out.println(" : " +
num.getNumber());
}
Collection eAddrs = pc.getEmailAddresses();
Iterator ealter = eAddrs.iterator();
while (ealter.hasNext()){
EmailAddress eAd =
(EmailAddress) ealter.next();
System.out.println("E-mail: " +
eAd.getAddress());
}
}
//
Collection services = org.getServices();
Iterator svclter = services.iterator();
while (svclter.hasNext()){
Service svc = (Service) svclter.next();
System.out.println(" : " +
svc.getName().getValue());

5. Web Services UDDI

241

System.out.println(" : " +
svc.getDescription().getValueO);
Collection serviceBindings =
svc.getServiceBindings();
Iterator sblter = serviceBindings.iterator();
while (sblter.hasNextO ) {
ServiceBlnding sb =
(ServiceBinding)sblter.next();
System.out.println(" URI: " +
sb.getAccessURI());

System.out.println("
}
}catch(Exception e){
e.printStackTrace();
}finally{

")

if (connection != null)
try{
connection.close ();
}catch(JAXRException je){}


BusinessLifeCycleManager.


BusinessLifeCycleManager deleteXxxO
savexxxo, , . ,
LifeCycieManager,
createXxxO , .

242

Web- Java

BusinessLifeCycieManager RegistryService :
BusinessLifeCycieManager blcm = rs.getBusinessLifeCycleManager();
: createClassificationf), createEmailAddress{),
createKeyO, createPostalAddress(), createService(), createUserf)

.
, ,
deieteservices .
.
, , saveservices .

.
5.10 .
:

5,10.
import javax.xml.registry.*;
import javax.xml.registry.infomodel.*;
import j ava.net.*;
import Java.security.*;
import java.util.*;

public class JAXRPublishf


Connection connection = null;
public JAXRPublish(){}
public static void main(String[] args){
String queryURL =
"http://www-3.ibm.com/services/uddi/v2beta/inquiryapi";
//"http://uddi.rte.microsoft.com/inquire";
//"http://localhost:8080/registry-server/RegistryServerServlet";
String publishURL =
"https://www-3.ibm.com/services/uddi/v2beta/protect/publishapi";

5. Web Services UDDI


//"https://uddi.rte.microsoft.com/publish";
//"http://localhost:8080/registry-server/RegistryServerServlet";
String username = "testuser";
String password = "testuser";
String httpProxyHost = "localhost";
String httpProxyPort = "8080";
Properties props = new Properties();
props.setProperty("j avax.xml.registry.queryManagerURL",
queryURL);
props.setProperty("javax.xml.registry.lifeCycleManagerURL",
publishURL);
props.setProperty("com.sun.xml.registry.http.proxyHost",
httpProxyHost);
props.setProperty("com.sun.xml.registry.http.proxyPort",
httpProxyPort);
props.setProperty("com.sun.xml.registry.https.proxyHost",
httpsProxyHost);
props.setProperty("com.sun.xml.registry.https.proxyPort",
httpsProxyPort);
try{
ConnectionFactory fact =
ConnectionFactory.newInstance();
fact.setProperties(props);
conn = factory.createConnection();
System.out.println(" .");
RegistryService rs = connection.getRegistryService();
BusinessLifeCycleManager blcm =
rs.getBusinessLifeCycleManager();
BusinessQueryManager bqm = rs.getBusinessQueryManager();
PasswordAuthentication passwdAuth =

243

244

Web- Java
new PasswordAuthentication(username,
password.toCharArray());
Set creds = new HashSet();
creds.add(passwdAuth);
conn.setCredentials(creds);
// .
Organization org =
blcm.createOrganization(" ");
InternationalString s =
blcm.createlnternationalString(
" .");
org.setDescription(s);
// .
User primaryContact = blcm.createUser();
PersonName pName = blcm.createPersonName(". . ");
primaryContact.setPersonName(pName);
TelephoneNumber tNum = blcm.createTelephoneNumber();
tNum.setNumber("333-44-55");
Collection phoneNums = new ArrayListO;
phoneNums. add (tNum) ;
primaryContact.setTelephoneNumbers(phoneNums);
EmailAddress emailAddress =
blcm.createEmailAddress("bender@hornhoof.com");
Collection emailAddresses = new ArrayListO;
emailAddresses.add(emailAddress) ;
primaryContact.setEmailAddresses(emailAddresses);
org.setPrimaryContact(primaryContact);
ClassificationScheme cScheme =
bqm.findClassificationSchemeByName(
null, "ntis-gov:naics");
Classification classification = (Classification)

5. Web Services UDDI

245

blcm.createClassification(cScheme,
"Snack and Nonalcoholic Beverage Bars", "722213");
Collection classifications = new ArrayList();
classifications.add(classification);
org.addClassifications(classifications);
Collection services = new ArrayList();
Service service =
blcm.createService(" ");
InternationalString is =
blcm.createlnternationalString(" ");
service.setDescription(is);
Collection serviceBindings = new ArrayList();
ServiceBinding binding = blcm.createServiceBinding();
is = blcm.createlnternationalString("My Service Binding " +
"Description");
binding.setDescription(is) ;
// allow us to publish a bogus URL without an error
binding.setValidateURI(false);
binding.setAccessURI("http://TheCoffeeBreak.com:8080/sb/");
serviceBindings.add(binding);
// Add service bindings to service
service.addServiceBindings(serviceBindings);
// Add service to services, then add services to organization
services.add(service);
org.addServices(services) ;
// Add organization and submit to registry
// Retrieve key if successful
Collection orgs = new ArrayList();
orgs.add(org) ;
BulkResponse response = blcm.saveOrganizations(orgs);
Collection exceptions = response.getExceptions();
if (exceptions == null){
System.out.println("Organization saved");

246

Web- Java
Collection keys = response.getCollection();
Iterator keylter = keys.iterator();
if (keylter.hasNextO ) {
javax.xml.registry.infomodel.Key orgKey =
(javax.xml.registry.infomodel.Key) keylter.next();
String id = orgKey.getldO;
System.out.println("Organization key is " + id);
}
}else{
Iterator exciter = exceptions.iterator();
Exception exception = null;
while (exciter.hasNext()){
exception = (Exception) exciter.next();
System.err.println("Exception on save: " +
exception.toString());

}catch(Exception e){
e.printStackTrace();
}finally{
if (connection != null){
try{
connection.close();
}catch(JAXRException je){}

Web Services
3 Web- ,
, Web-, , Web. ,
Web-. Sun
Microsystems, SAAJ, JAXM, JAXR, JAX-RPC. .
Sun WSDP (Web
Services Developer Pack). WSDP , , Web Tomcat, JSP,
UDDI- Registry Server. JAXP XML JSP.
WSDP ,

Web-. Web-
WSDP J2EE, , 12-:
WebLogic, IBM WebSphere, Sun ONE Application Server, JBoss, Sybase
EAServer, Oracle Application Server, IONA Orbix E2A, Borland Enterprise
Server. 1.4 J2EE, WSDP .
, Web-, Java:
Q SAAJ, SOAP SOAP-, SOAP- ,
Java- j avax. xmi. soap;

248

Web- Java

JAXM,
SOAP- , Java-
javax.xml.messaging;
JAX-RPC, SOAP-, Java-: javax.xml. rpc, javax.xml.rpc. handler, soap,
javax.xml.rpc.encoding,
javax.xml.rpc.soap,
javax.xml.rpc.handler,
javax.xml.rpc.holders, javax.xml.rpc. server.
. SAAJ.

SOAP-
Java, javax.xml.soap, SOAP . XML, SOAP-, DOM (. 7). , , Node.

Node
Node :
public s t r i n g getvalue()
-, ;
null;
Q p u b l i c SOAPElement getParentElement () null, :
public void setParentElement(SOAPElement parent)
parent ;
public void detachNodeO .

SOAPElement
Node SOAPElement, XML, SOAP-.
addxxx () :
public SOAPElement addAttribute(Name name, String value) name value ; ;

6. Web Services

249

p u b l i c SOAPElement addChildElement(Name name) name, ,


;
public SOAPElement addChildElement(SOAPElement element).

element, , ;
public SOAPElement addChildElement(String localName) localName ,
, ;
public SOAPElement addChildElement(String localName, String
prefix)

prefix:localName, ,
;
Q public SOAPElement addChildElement(String localName, String
p r e f i x , s t r i n g u r i )
prefix:localName uri, , ;
Q public SOAPElement addNamespaceDeclaration(String prefix, String
uri) xmins u r i
;
public SOAPElement addTextNode(String t e x t ) t e x t ;
public void setEncodingStyle(String encStyle)
encodingstyle e n c s t y l e
.
getXxx () , removeXxx () SOAPElement

.

XML
Name, ,
XML

getLocalNameO,
getPrefixO,
getQuaiifiedName (), getURi () XML
s t r i n g .

SOAP-
SOAPElement ,
SOAP- <Enveiope>

250

Web- Java

<Header> <Body>. SOAPEnvelope, SOAPHeader, SOAPBody.


soAPHeaderElement,
SOAPBodyElement.
SOAPBodyElement soAPFauit, <Fault> ,
<Body> SOAP. ,
<Fault>, SOAPFaultElement, < d e t a i l > D e t a i l . , <detail>,
D e t a i l E n t r y .

. 6.1.
Nod

SOAPEnvelope
-SOAPHeader
-SOAPBody
-SOAPHeaderElement
-SOAPBodyElement SOAPFault
-SOAPFaultElement Detail
-DetailEntry
. 6 . 1 . SAAJ

SOAPEnvelope
SOAPEnvelope soAPEiement , SOAP-:
p u b l i c SOAPHeader addHeaderf) SOAP-
<Header> ;
p u b l i c SOAPHeader getHeaderO <Header> ;
p u b l i c SOAPBody addBodyO SOAP- <Body> ;
p u b l i c SOAPBody getBody ()
<Body>;
p u b l i c Name createName ( S t r i n g
localName ;

localName) XML

public Name createName(String localName, String prefix, String


u r i ) XML p r e f i x : l o c a l N a m e
u r i .

6. Web Services

251

SOAPHeader
SOAPHeader, ,
public SOAPHeaderElement addHeaderElement(Name name),
name.
public Iterator examineHeaderElements(String actor),
, actor,
public Iterator extractHeaderElements(String actor),
, actor, .

SOAPBody
SOAPBody
public SOAPBodyElement addBodyElement(Name name),
SOAP- ,

public SOAPFault addFault(),


public SOAPFault getFault(),
public boolean hasFault(),
<Fauit>, <Body> .
, , SAAJ,
SOAP-
.

SOAPMessage
SAAJ SOAP- ,
"SOAP ", 3. SOAPMessage,
, .
SOAP- ,
SOAP-, soAPPart, AttachmentPart.
MimeHeaders,
MimeHeader.

252

Web- Java

, SAAJ ,
. Sun WSDP , saaj-ri.jar. , SAAJ. ,
SAAJ, , . MessageFactory,
SOAPFactory SOAPConnectionFactory SAAJ.

SOAP-
SOAP-
SOAPMessage. createMessageO
MessageFactory, MessageFactory
newinstance ():
MessageFactory mf = MessageFactory.newinstance();
SOAPMessage smsg = mf.createMessage();
smsg, SOAP- ,
soapPart, SOAP:
SOAPPart soapPart = smsg.getSOAPPart();
SOAP-:
SOAPEnvelope env = soapPart.getEnvelope();
<Enveiope>:
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
</SOAP-ENV:Envelope>
, , SAAJ 1.1
SOAP- SOAP 1.1, http://schemas.xmlsoap.org/soap/envelope/.
<Header>:
SOAPHeader header = env.getHeader() ;

<SOAP-ENV:Header>
</SOAP-ENV:Header>
, <Enveiope>.
<Body>:
SOAPBody body = env.getBody();

6. Web Services

253


<SOAP-ENV:Body>
</SOAP-ENV:Body>
<Enveiope>.
<Header> , :
header.detachNode();
SOAP- .
,
public String getEcho(String request)
:
String response = echoService.getEcho("!").


<m: getEcho xmlns :m="http: //some, com/names"></m:getEcho>
createName():
Name element = env.createName("getEcho", "m",
"http://some.com/names");
<getEcho> <Body>:
SOAPBodyElement ge = body.addBodyElement(element);

<request>npBeT!</request>
<getEcho>.
:
Name name = env.createName("request");
SOAPElement req = ge.addChildElement(name);
req.addTextNode("! ") ;

, SOAP- :
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<m:getEcho xmlns:m="http://some.com/names">
!</request>

254

Web- Java
</m:getEcho>

</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

SOAP-
SOAP- smsg. SOAP-.
SOAPConnection:
SOAPConnectionFactory scf =
SOAPConnectionFactory.newInstance();
SOAPConnection con = scf.createConnection();
Web- URL
Endpoint, :
URL endpoint =
new URLC'http://some.com/services/EchoService");
. SOAP-
:
SOAPMessage response = con.call(smsg, endpoint);
:
con.close();
.
, c a l l , SOAP- , . , SAAJ
Web-. "point-to-point", "2".
SOAP- response,
. SOAP-.
:
SOAPPart sp = response.getSOAPPart();
SOAP-:
SOAPEnvelope respEnv = sp.getEnvelope();

6. Web Services

255

:
SOAPBody respBody = respEnv.getBody();
<Body>, respBody,
. :
Iterator

it

respBody.getChildElements();

, . :
SOAPBodyElement bodyElement = (SOAPBodyElement)it.next();
:
String echo = bodyElement.getValue();
:
System.out.println(" : " + echo);
, Web-. 6.1
Web-.
6.1. Web-, SAAJ
import javax.xml.soap.*;
import j ava.ut i1.*;
import java.net.URL;
public class ClientSAAJ{
public static void main(String!] args){
try{
MessageFactory mf =
MessageFactory.newInstanceO ;
SOAPMessage smsg = mf.createMessage();
SOAPPart soapPart = smsg.getSOAPPart();
SOAPEnvelope env = soapPart.getEnvelope();
SOAPHeader header = env.getHeader();
SOAPBody body = env.getBody();
header.detachNode();
Name element = env.createName(

256

Web- Java
"getEcho", "m", "http://some.com/names");
SOAPBodyElement ge =
body.addBodyElement(element);
Name name = env.createName("request");
SOAPElement req = ge.addChildElement(name);
req.addTextNode("!");
SOAPConnectionFactory scf =
SOAPConnectionFactory.newInstance();
SOAPConnection con = scf.createConnection();
URL endpoint =
new URLC'http://some.com/services/EchoService");
SOAPMessage response = con.call(smsg, endpoint);
con.close ();
SOAPPart sp = response.getSOAPPart();
SOAPEnvelope respEnv = sp.getEnvelope();
SOAPBody respBody = respEnv.getBody();
Iterator it = respBody.getChildElements();
SOAPBodyElement bodyElement =
(SOAPBodyElement)it.next();
String echo = bodyElement.getValue();
System.out.print(" : " + echo);
}catch(Exception e){
System.err.println(e) ;

6. Web Services

257

SOAP-
, soAPMessage SOAP-
.
soAPPart. .

AttachmentPart. SOAPMessage.

AttachmentPart = smsg.createAttachmentPart;
. ,
, AttachmentPart.
, ,
:
smsg.addAttachmentPart();
AttachmentPart:
public AttachmentPart createAttachmentPart(
Object content, String contentType);
, , content, MIME- ,
content-Type ,
contentType. :
AttachmentPart = smsg.createAttachmentPart(
" ASCII- ",
" t e x t / p l a i n ; charset=windows-1251");
smsg.addAttachmentPart();

public AttachmentPart createAttachmentPart(
javax.activation.DataHandler handler);
handler , URL Java Activation Framework [10]. :
URL url = new URL("http://some.com/images/myface.jpg");
AttachmentPart ap =
9 . 748

258

Web- Java
smsg.createAttachmentPart(new DataHandler(url));

smsg.addAttachmentPart(ap);

, , . , AttachmentPart
SOAP-.

AttachmentPart
, ,
"SOAP " (. 3),
-.
MIME-, , .
content-Type, MIME- .


AttachmentPart MIME-
SOAP-.
name MIME- value

public void addMimeHeader(String name, String value);
Content-Type,
public void setContentType(String value);
content-id content-Location
public void setContentld(String value);
public void setContentLocation(String value);

, setxxxo
. name
value
public void setMimeHeader(String name, String value);
, .
content
public void setContent(Object content. String contentType);

6. Web Services

259

, contentType ContentType.


SOAP- .

SOAPMessage
public I t e r a t o r getAttachments();

SOAPMessage, ,
.

public I t e r a t o r getAttachments(MimeHeaders headers);

, headers.
,
:
I t e r a t o r it = smsg.getAttachments();
while ( i t . h a s N e x t O ) {
AttachmentPart ap = (AttachmentPart)it.next();

//
}
, . AttachmentPart
getxxx (). .

public Object getContent();

public int getSize();
,
public I t e r a t o r getAHMimeHeaders () ;

name
public String[] getMimeHeader(String name);

260

Web- Java

public Iterator getMatchingMimeHeaders(String[] names);


,
names.

public Iterator getNonMatchingMimeHeaders(String[] names);


,
, names.
, : content-Type, Content-id
Content-Location
public String getContentType();
public String getContentld();
public String getContentLocation();



public void clearContent();


public void removeAHMimeHeaders () ;


public void removeMimeHeader(String name);
name.
6.2 SOAP-
HTML.
; 6.2.
import javax.xml.soap.*;
import javax.xml.messaging.*;
import javax.activation.*;
import java.util.*;
import java.net.URL;
public class ClientSAAJAttach{
public static void main(String[] args)(

6. Web Services
try{
MessageFactory mf = MessageFactory.newInstance();

SOAPMessage smsg = mf.createMessage();

SOAPPart soapPart = smsg.getSOAPPart();


SOAPEnvelope env = soapPart.getEnvelope();
SOAPHeader header = env.getHeader();
SOAPBody body = env.getBody();
header.detachNode();

Name element = env.createName(


"getEcho", "ra", "http://some.com/names");
SOAPBodyElement ge =
body.addBodyElement(element);

Name name = env.createName("request");


SOAPElement req = ge.addChildElement(name);

req.addTextNode("!");
URL url = new URL("http://localhost:8080/data/info.html");
AttachmentPart ap =
smsg.createAttachmentPart(new DataHandler(url));
ap.setContentType("text/html") ;
smsg.addAttachmentPart(ap);
SOAPConnectionFactory scf =
SOAPConnectionFactory.newInstance() ;
SOAPConnection con = scf.createConnectionO;
URLEndpoint endpoint =
new URLEndpoint("http://some.com/services/EchoService");

261

262

Web- Java
SOAPMessage response = con.call(smsg, endpoint);
con.close ();
SOAPPart sp = response.getSOAPPart();
SOAPEnvelope respEnv = sp.getEnvelope{);
SOAPBody respBody = respEnv.getBody();
Iterator it = respBody.getChildElements();
SOAPBodyElement bodyElement =
(SOAPBodyElement)it.next();
String echo = bodyElement.getValue();
System.out.print(" : " + echo);
}catch(Exception e){
System.err.println(e);


3, ,
SOAP- , SOAP <Fauit>, <Body>. SAAJ soAPFauit, <Fault>.

SOAPFault
, <Fauit> SOAP 1.1 <faultcode>, <faultstring>, <actor> <detail>. , soAPFauit:
public void setFaultCode(String faultCode);
public void setFaultString(String faultString);
public void setFaultActor(String faultActor);
public Detail addDetail() ;

6. Web Services

263

soAPFauit :
public String getFaultCode() ;
public String getFaultString();
public String getFaultActor();
public Detail getDetail();

, addDetaiio
<detail>. .
public DetailEntry addDetailEntry(Name name);

Detail.
<detail>
, Detail:
public Iterator getDetailEntries();
6.3.
* 6.3.
import j avax.xml.soap.*;
import java.util.*;
public class SOAPFaultTest{
public s t a t i c void main(String[] args)(
try{
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage smsg = mf.createMessage();
SOAPEnvelope env =
smsg.getSOAPPart().getEnvelope();
SOAPBody body = env.getBody();
SOAPFault fault = body.addFault();
fault.setFaultCode("Client");

264

Web- Java
fault.setFaultString(
" ");
fault.setFaultActor("http://some.com/SomeService");
Detail detail = fault.addDetail();
Name entryNamel = env.createName(
"comment", "nsl", "http://some.com/comments");
DetailEntry entry = detail.addDetailEntry(entryNamel);
entry.addTextNode("He ");
Name entryName2 = env.createName(
"confirmation", "ns2", "http://some.com/confirm");
DetailEntry entry2 = detail.addDetailEntry(entryName2);
entry2.addTextNode(" ");
smsg.saveChanges();
// .
if (body.hasFault()){
fault = body.getFault();
String code = fault.getFaultCode();
String s = fault.getFaultStringO;
String actor = fault.getFaultActor();
System.out.println(" : " + code);
System.out.println(": " + s ) ;
if (actor != null)
System.out.println(" " + actor);
detail = fault.getDetail();
if (detail != null){

6. Web Services
System.out.println(":

265

");

Iterator it = detail.getDetailEntries();
while (it.hasNext()){
entry = (DetailEntry)it.next ();
String value = entry.getValue();
System.out.println(value);

}catch(Exception e){
System.out.println(e);


SAAJ SOAP- 2 (point-to-point). - , . ,
. . Java SOAP-
JAXM, Java- javax.xmi.messaging.
, , ,
. (messaging provider)
, ,
, , . , . Java JMS (Java Message Service).
JMS , , [10], .
SOAP SOAP-, JAXM .

266

Web- Java


(acknowledgement) .
, . , , .

SOAP-. , "ebXML Message Service
Specification" ebXML- <MessageHeader>, <Service>, <SyncReply> .
(profile) SOAP-.
. ,
, "ebxml", "soaprp", URI. .
JAXM "" ebXML
Microsoft WS-Routing, "SOAP-RP".
EbXMLMessagelmpl SOAPRPMessagelmpl ,
com.sun.xml.messaging.jaxm.ebxml com. s u n . x m l . m e s s a g i n g . j a x m . s o a p r p .

SOAP- JAXM, .
WS-Routing, SOAP-RP.

WS-Routing
WS-Routing (Web Services Routing Protocol),
Microsoft 2001 (http://msdn.microsoft.com/library/enus/dnsrvspec/html/ws-routing.asp),
SOAP-, . , WS-Routing,
(actors), (forward message path).
SOAP-, WS-Routing, SOAP,
. . ,
(reverse message path)
.
, WS-Routing,
HTTP SMTP, TCP
UDP,
.

6. Web Services

267

, WS-Routing
SOAP- .
.
SOAP- <Header> <path>, <from> URI ,
<to> URI , <via> URI . <via> <fwd>
.
<via>.
, , <via>, <rev>.
http://schemas.xmlsoap.org/rp/.
. :
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<m:path xmlns:m="http://schemas.xmlsoap.org/rp/">
<m:action>http://some.com/update</m:action>
<m:to>soap://D.com/endpoint;up=udp</m:to>
<m:id>uuid:09233523-345b-4351-b623-5dsf35sgs5d6</m:id>
</m:path>
</env:Header>
<env:Body>
< ! ... >
</env:Body>
</env:Envelope>

SOAP-,
WS-Routing.
<action> URI - .

268

Web- Java

<id> URI, .
, . <reiatesTo>, :
<relatesTo>uuid:09233523-345b-4351-b623-5dsf35sgs5d6</relatesTo>

, <to> URI soap:. URI IETF, .


soap: h t t p : , up (underlying
protocol), . TCP.
, , .com .com,
<fwd> <via>:
<env:Envelope
xmlns:env="http://schemes.xmlsoap.org/soap/envelope/">
<env:Header>
<m:path xmlns:m="http://schemas.xmlsoap.org/rp/">
<m:action>http://some.com/update</m:action>
<m:to>soap://D.com/endpoint</m: to>
<m: fwd>
<m:via>soap://B.com</m:via>
<m:via>soap://C.com</m:via>
</m:fwd>
<m:id>uuid:09233523-345b-4351-b623-5dsf35sgs5d6</m:id>
</m:path>
</env:Header>
<env:Body>
<! ... >
</env:Body>
</env:Envelope>

6. Web Services

269

, ,
<from> <rev>:
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<m:path xmlns:m="http://schemas.xmlsoap.org/rp/">
<m:action>http://www.notification.org/update</m:action>
<m:to>soap://D.com/endpoint</m:to>
<m:fwd>
<m:via>soap://B.com</m:via>
<m:via>soap://C.com</m:via>
</m:fwd>
<m:rev>
<m:via/>
</m:rev>
<m:from>mailto:ivanov@some.com</m:from>
<m:id>uuid:09233523-345b-4351-b623-5dsf35sgs5d6</m:id>
</m:path>
</env:Header>
<env:Body>

<! ... >


</env:Body>
</env:Envelope>
<m:via/> ,
.
JAXM com. sun. xml. messaging,
jaxm.soaprp, SOAPRPMessageFactorylmpl

270

Web- Java

soAPRPMessageimpi WS-Routing
SOAP- , "SOAP-RP".
soAPRPMessageimpi soAPMessage, soAPMessage, createMessage , :
SoAPRPMessageimpi soaprpMsg =
(SOAPRPMessagelmpl)mf.createMessage();

, soAPRPMessageimpi ,
soAPMessage, SOAP- SOAP-RP.
soAPRPMessageimpi:
public void newMessageido <id> ;
Q public void setAction(Endpoint actor) <action>
actor;
Q public void setFrom (Endpoint from) <from> from;
public void setTo (Endpoint to) <to> to;
public void setRelatesTo (String id) <relatesTo>
id;
public void updateFwdMessagePath(Endpoint actor, int position)
<via> actor position
<fwd>;
U public void updateRevMessagePath(Endpoint actor) <via> actor <rev>.
:
public string getsoAPRPMessageid () <id> ;
public Endpoint getsoAPRPActionO <action>;
public Endpoint getFromO <from>
;
public Ebdpoint getToo <to>
;
public string
<relatesTo>;

getRelatesTo ()

6. Web Services

271

public Vector getSOAPRPFwdMessagePath{)


<fwd>;
public Vector getSOAPRPRevMessagePathO
<rev>.
/
public void saveChanges();
6.4.


.
, .
ProviderConnectionFactory:
ProviderConnectionFactory pcf = ProviderConnectionFactory.newlnstance();
ProviderConnection pc = pcf.createConnection();


JNDI (Java Naming and Directory Interface) (., , [10])
JNDI-:
Context ctx = new InitialContext();
ProviderConnectionFactory pcf =
(ProviderConnectionFactory)ctx.lookup("SomeProvider");
ProviderConnection pc = pcf.createConnection();

, JNDI . "SomeProvider".
, ProviderConnection.
ProviderConnection .
, ProviderConnection:
public ProviderMetaData getMetaData ();

ProviderMetaData. , "major.minor", ,
"1.2".

272

Web- Java

public String getName();


public i n t getMajorVersion();
public int getMinorVersion(};

, ProviderMetaData , .
public String[] getSupportedProfiles();

SOAP-
SOAP- MessageFactory
SAAJ, , ,
MessageFactory ProviderConnection
public MessageFactory createMessageFactory(String profile);
, , SOAP- , , . . 6.4
SOAP- SOAP-RP.

SOAP-

ProviderConnection:
public void send(SOAPMessage message);

, send () ,
, , . ,
ProviderConnection;
public void close ;

6.4 JAXM, SOAP SOAP-RP .


6.4. SOAP-
import j ava.net.*;
import javax.xml.messaging.*;
import javax.xml.soap.*;
import javax.activation.*;

6. Web Services
import com.sun.xml.messaging.jaxm.soaprp.*;
public class ClientJAXM{
public static void main(String[] args){
String from ="http://some.com/soaprp/sender";
String to = "http://another.com/soaprp/receiver";
try{
ProviderConnectionFactory pcf =
ProviderConnectionFactory.newlnstance();
ProviderConnection pc = pcf.createConnectionO;
ProviderMetaData metaData = pc.getMetaData();
String[] supportedProfiles =
metaData.getSupportedProfiles();
String profile = null;
for (int i=0; i < supportedProfiles.length; i++){
if (supportedProfiles[i].equals("soaprp")){
profile = supportedProfiles[i];
break;

MessageFactory mf = pc.createMessageFactory(profile);
SOAPRPMessagelmpl soaprpMsg =
(SOAPRPMessagelmpl)mf.createMessage();
soaprpMsg.setFrom(new Endpoint(from));
soaprpMsg.setTo(new Endpoint(to));
URL url =
new URL("http://127.0.0.1:8080/jaxm-soaprp/data.xml"
AttachmentPart ap =
soaprpMsg.createAttachmentPart(new DataHandler(url))

273

274

Web- Java
ap.setContentType("text/xml");
soaprpMsg.addAttachmentPart();
pc.send(soaprpMsg);
pc.close();
}catch(Exception e){
System.err.println(e);

, Web-
SAAJ JAXM. , SOAP-
.
Java SOAP- ,
. [10, 11].
, .

(servlet) , s e r v i e t javax.serviet. i n i t o , , destroy ,


, service ,
. ,
, Web-.
, Web-,
, Web-,
i n i t (), service (). i n i t () , ,
service .
, "".
service () , :
public void service(ServletRequest req, ServletResponse resp)
throws ServletException, IOException;

6. Web Services

275

req servietRequest, Web- , service . ,


getParameter(String name), getAttribute(String name).
ServietRequest
: Servietinputstream
Buf feredReader java. io.
resp
servletResponse, Web-. service , req,
ServietRequest, ,
resp ServletResponse.
ServletResponse

S e r v l e t O u t p u t S t r e a m P r i n t W r i t e r .

resp . Web-
resp, ,
Web-, Web-.
javax.serviet GenericServiet, Serviet service .
, , Web-, GenericServiet, service () .
6.5 , .
! 6.5.
import javax.serviet.*;
import j ava.io.*;
public class EchoServlet extends GenericServiet{
public void service(ServietRequest req,
ServletResponse resp)
throws ServletException, IOException{
Servietinputstream sis = req.getlnputStreamO;
ServletOutputStream sos = resp.getOutputStream();
int b = 0;
while ((b = sis.read()) != -1) sos.write(b);

276

Web- Java
sis.close();
sos.close();

EchoServiet
Web-. (deployment) , Web- "" , . . servietconfig,
getinitParameter (string). ServletConfig getServletContext() , Web-,
Servietcontext.
Web-. - Web-
. Web , , J2EE-cepeepa, J2EE, depioytooi.
serviet GenericServiet ,
. .
HTTP Web-, HTTP- HttpServiet GenericServiet. HttpServiet HTTP- :
protected void doDelete(HttpServletRequest req,
HttpservletResponse resp);
protected void doGet(HttpServletRequest req,
HttpservletResponse resp);
protected void doHead(HttpServletRequest req,
HttpservletResponse resp);
protected void doOptions(HttpServletRequest req,
HttpservletResponse resp);
protected void doPost(HttpServletRequest req,
HttpservletResponse resp);
protected void doPut(HttpServletRequest req,
HttpservletResponse resp);
protected void doTrace(HttpServletRequest req,
HttpservletResponse resp);

6. Web Services

277

, .
HttpServletRequest, ServletRequest,
getxxx() URL,
HTTP- cookie. HttpservietResponse, ServietResponse, setxxxt),
HTTP- cookie.
HttpServiet, Web-, ,
i n i t o service .
service HttpServiet . HTTP- doxxx () HTTP-. service (), doXxx (),
: doGet () doPost ().
6.6 , HTTP-
GET /servlet/HttpEchoServlet?name=MBaHOB&age=27 HTTP/1.1

GET POST,
HTML.
; 6.6. , HTTP
import javax.servlet .*;
import javax.servlet.http.*;
import j ava.io.*;
public class EchoHttpServlet extends HttpServiet{
public void doGet(HttpServletRequest req,
HttpservietResponse resp)
throws ServletException, IOException(
doPost(req, resp);

public void doPost(HttpServletRequest req,


HttpservietResponse resp)
throws ServletException, IOException(
req.setCharacterEncoding("windows-1251");
String name = req.getParameter("name");

278

Web- Java
String age =

req.getParameter("age");

resp.setContentType("text/html;charset=windows-1251");
PrintWriter pw = resp.getWriter();
pw.println("<htmlxhead><title>Echo</titlex/head>") ;
.11("<1><112>1 :</h2>");
pw.println("MMH: " + name + "<br/>");
pw.println(": " + age + "<br/>");
pw.println("</bodyx/html>") ;
pw.flush();
pw.close ();

HttpServiet

HttpServletRequest,
HttpServietResponse , j avax. s e r v l e t . http.
Java Web- .
Web- HTTP, , HttpServiet. Web- ,
GenericServlet Servlet.
,
SOAP-, XML.
HTML, ,
p r i n t in ().
, SOAP-, j avax. xmi. messaging HttpServiet. JAXMServiet.
, SOAP-,
JAXM.

JAXMServiet
JAXMServiet HttpServiet .

protected s t a t i c MimeHeaders getHeaders(HttpServletRequest req);

6. Web Services

279

HTTP- req MimeHeaders.



protected void putHeaders(MimeHeaders headers,
HttpServletResponse resp);

HTTP- resp
headers.


public void s t a t i c setMessageFactory(MessageFactory factory);

factory MessageFactory.
JAXMServlet MessageFactory.
(protected) . msgFactory.
, msgFactory, i n i t () JAXM :
msgFactory = MessageFactory.newlnstance();

i n i t (), msgFactory, JAXMServlet


doxxx(), doPosto. HTTP :
MimeHeaders headers = getHeaders(req);
InputStream is = req.getlnputStreamO ;

SOAP- soAPMessage,
m s g F a c t o r y :
SOAPMessage msg = m s g F a c t o r y . c r e a t e M e s s a g e ( h e a d e r s ,

is);

SOAP- msg onMessage().


.
, , doPost () , resp "204 No Content".
2, , resp
onMessage (). - SOAP- .
doPost .
, JAXMServlet SOAP-
doPost ,
onMessage ( ) , JAXMServlet. onMessage ()

, JAXMServlet,
do Post .

280

Web- Java

, , JAXMServiet, Web-, , Web-, . . Web-


,
OnewayListener, ReqRespListener.
.
onMessage () , .
OnewayListener onMessage ,
:
p u b l i c void onMessage(SOAPMessage msg);

RegRespListener SOAP:
public SOAPMessage onMessage(SOAPMessage msg);
null, .
, Web-, SAAJ, JAXMServiet
ReqRespListener, onMessage . :
import javax.xml.messaging.*;
public class SyncSAAJServlet extends JAXMServiet
implements ReqRespListener{
public SOAPMessage onMessage(SOAPMessage msg){
// msg, ...

Web-
JAXM, , JAXMServiet,
OnewayListener. :
import javax.xml.messaging.*;

public c l a s s AsyncJAXMServlet extends JAXMServiet


implements OnewayListener{

public void onMessage(SOAPMessage msg){


// msg...

6. Web Services

281

6.7 Web-,

. SAAJ
, AckJAXMServlet.
\ 6,7. ,

import javax.xml.messaging.*;
import javax.xml.soap.*;
public class AckJAXMServlet extends JAXMServlet
implements ReqRespListener{
public SOAPMessage onMessage(SOAPMessage msg){
try{
System.out.println(" :\");
msg.writeTo(System.out);
SOAPMessage reply = msgFactory.createMessage();
SOAPEnvelope env = reply.getSOAPPart().getEnvelope();
env.getBody().addChildElement(
env.createName("Response"))
.addTextNode(" .");
return reply;
}catch(Exception e){
System.err.println(e);
return null;


SOAP-,
, SOAP-, ,
Java JAX-RPC. ,
JAX-RPC SOAP-.

282

Web- Java

JAX-RPC
RMI (Remote Method Invocation), , , [10]. RMI
JAX-RPC, .
, ,
Remote java.rmi. (remote) (distributed) .
Remote , ,
. "extends Remote"
,
, .
, Web- JAX-RPC , Web- .
RMI , , , (stub). Java,
, Web, , SOAP-,
, SOAP-.
,
(tie). , SOAP-, Web- Web-.
Web- .
. , Web- . . 6.2.
, Java, , .
Web-
(Port)

(Endpoint)

(Stub)

(Tie)
->

JAX-RPC <
HTTP
. 6.2. JAX-RPC

JAX-RPC

6. Web Services

283

Web- JAX-RPC
, Web- , , ,
JAX-RPC "Service Endpoint Interface".
SEI- Web-. WSDL- Web-
<portType>. SEI-
(port) Web-.
Web- Web-.
:
(public);
Remote;
;
RemoteException;
, , (checked) ;
Remote.
SEI- Web- ,
6.8.
:

6.8. Web- ()

package bookinfo;
import j ava. rmi.*;
public interface BooklnfoPort extends Remote{
Book getlnf(String isbn) throws RemoteException;
void setInfo(Book book) throws RemoteException;
}

:
Java, char, boolean, byte,
short, int, long, float, double;

- Boolean, Byte, Short, Integer, Long,


Float, Double;

284

Web- Java

Q String, Date, Calendar,Biglnteger, BigDecimal,Object;


, ;
- collection, Map, set;
Java, JAX-RPC "value types".
, "value types" Java, .
Remote, (public) , (public) JAX-RPC . , Book, 6.8, :
package bookinfo;

public class Book{


private String isbn;
private String[] authors;
private String t i t l e ;

public Book(){}
public String getlsbn(){ return isbn; }
public void setlsbn(String isbn){ this.isbn = isbn; }
public String[] getAuthors (){ return authors; }
public void setAuthors(String[] authors)! this.authors = authors; }
public String getTitle()( return t i t l e ; }
public void setTitle(String title){ t h i s . t i t l e = t i t l e ;

,
XSD (. ). , i n t I n t e g e r x s d : i n t , B i g l n t e g e r
xsd: i n t e g e r , Date c a l e n d a r

xsd:dateTime,

byte[]

Byte [)

xsd:base64Binary. -
, XSD.
SEI- ,
Web-. JAX-RPC "Service Endpoint Class". (servant).

6. Web Services

285

- SEI-
"impi".
- :
(public), (abstract)
(final);
;
Q , , MH(finai) ( s t a t i c ) ;
finalize {).
6.9 , Web- Bookinfo
JAX-RPC.
6.9. Web- JAX-RPC
package bookinfo;
import
import
import
import

javax.xml.rpc.server.*;
j avax.servlet.ServletContext;
java.sql.*;
java.util.*;

public class Booklnfolmpl


implements BooklnfoPort, ServiceLifecycle{
private ArrayList books;
private Connection con;
public void init(Object context))
ServletContext sc =
((ServletEndpointContext)context).getServletContext();
String dbUrl =sc.getlnitParameter("dbUrl");
try{
con = DriverManager.getConnection(dbUrl);
}catch(Exception e){}

286

Web- Java

public void destroy(){


setToDB();
con = null;
}
public Booklnfolmpl(){
try{
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM book"
insertFromDB(rs);
rs.close 0;
st.close();
}catch(Exception e){}

public Book getlnfo(String isbn){


Book t = null;
for (int = 0; < books.size ; ++){
t = (Book)books.get(k);
if (isbn.equals(t.getlsbn())) break;
}
return t;

public void setInfo(Book book){


books.add(book);
}
private void insertFromDB(ResultSet rs){

6. Web Services

287

II books
}

p r i v a t e void setToDB(){
// books

, - .
Web- Web-, , . JAXRPCserviet, JAX-RPC.

Web-
6.9 ServiceLifecycie, Web-. :
public void init(Object context);
public void destroy();
Web- JAX-RPC
Web- .
i n i t () context,
Web-, Web-.
object, servietcontext ,
ServletEndpointContext.

Web-
ServletEndpointContext , , Web-.
public HttpSession getHttpSession() , Web-
null, ;
public MessageContext getMessageContext ()
;

288

Web- Java

public ServletContext getServletContext() -

Web-, Web-;
Q public Principal getUserPrincipal () ,
Web-.
MessageContext,
, SOAPMessageContext.
MessageContext , , , :
public void setProperty(String name, Object value);
public Iterator getPropertyNames();
public Object getProperty(String name);
public void removeProperty(String name);
public boolean containsProperty(String name);
SOAPMessageContext ,
SOAP-:
public SOAPMessage getMessage();
public void setMessage(SOAPMessage message);
public String [] getRolesO;
-, SOAP- Web-.
.


JAX-RPC SOAP: , , .
SOAP-, , .
Handler. , SOAP-, SOAP :
public boolean handleRequest(MessageContext context);
public boolean handleResponse(MessageContext context);
public boolean handleFault(MessageContext context);
MessageContext,
SOAPMessageContext.
SOAP-.

6. Web Services

289

, Handler
public QName[] getHeaders();
SOAP-.

public void init(Handlerlnfo config);
public void destroy();

. i n i t ()
,
,
.

Handle Handlerlnfo,
- SOAP-

, SOAP- -, .
HandierChain.
HandierChain List, , Handler. List Collection,
, ,
:
public
public
public
public
public
public
public

boolean handleRequest(MessageContext context);


boolean handleResponse(MessageContext context);
boolean handleFault(MessageContext context);
void init(Map config);
void destroy();
String[] getRoles();
void setRoles(string[] actorNames);

, Handler.
HandierChain , -.
"next" (actors), SOAP- (. 3).
handieXxx () , handleRequest ()
true, SOAP-
handleRequest , Web-, . handleRequest () false, , . 748

290

Web- Java

handieResponse () -
handieResponse .
handleRequest () SOAPFaultException, TO
nandieFauit () . , .
Handler, JAX-RPC
GenericHandler.
true,
, getHeaders .
, - :
public class MyHandler extends GenericHandler(
public MyHandler(){}
public boolean handleRequest(MessageContext context)!
try{
SOAPHeader sh = ((SOAPMessageContext)context)
.getMessage().getSOAPPart().getEnvelope().getHeader();
// sh
return true;
}catch(Exception ex){ }

- SOAP-
Web-.
HandierRegistry, :
public List getHandlerChain(QName portName);
public void setHandlerChain(QName portName, List chain);
HandierRegistry
public HandierRegistry getHandlerRegistry() ;
service, .
.
MyHandler:
QName serviceName = new QNarae("myservice");

6. Web Services

291

ServiceFactory sf = ServiceFactory.newInstance();
Service serv = sf.createService(serviceName);
HandlerRegistry reg = serv.getHandlerRegistry();
List chain = reg.getHandlerChain(serv.getServiceName());
chain.add(new Handlerlnf(MyHandler.class, null, null));
- ,
.
.

Web-
BookinfoPort Bookinfoimpi, Book,
j avac * . j ava
-, , Web- , RMI. , , , ,
. , Web-
WSDL.
, RMI, . Sun WSDP
JAX-RPC.
, , : wsdeploy, WSDL,
wscompile, .
.
:
$ -server config.xml
- c l i e n t . , , , both.
SEI -,
XML-, Web-.
config.xml. ,
,
.

292

Web- Java

wsdeploy
:
$ wsdeploy -tmpdir temp - deployable.war portable.war

deployable.war (
), , jaxrpc-ri.xml DD-
(Deployment Descriptor) Web- web.xml [10].
Web- ,
portable.war. , Web-.
-tmpdir , temp . -keep,
.
Web-,
( portable.war), Web- Web. , , , - (tie) Web-.

jaxrpc-ri.xml
jaxrpc-ri.xml wsdeploy XML <webServices>,
<endpoint> <endpointMapping>.
.
<webServices>, ximns version .
targetNamespaceBase typeNamespaceBase WSDL , urlPatternBase
Web-.
<endpoint> Web- :
name Web-,
WSDL Web-;
dispiayName Web-,
JAX-RPC Web-
;
description
Web-;
interface SEI-;

6. Web Services

implementation

293

model URI Web-.


<endpoint> <handlerchains>, -. - <chain>.
<endpointMapping> WSDL.
, :

endpointName WSDL;

u r l P a t t e r n .
jaxrpc-ri.xml:
<?xml version="1.0" encoding="UTF-8"?> '
<webServices
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/dd"
version=" xsd:string"
targetNamespaceBase=" xsd:string"
typeNamespaceBase=" xsd:string"
urlPatternBase=" xsd:string">
<endpoint
name="xsd:string"
displayName="xsd:string"
description="xsd:string"
interface=" xsd:string"
implementation^' xsd:string"
model="xsd:anyURI"> [*]
<handlerChains> [?]

<! - >
</handlerChains>
</endpoint>
<endpointMapping

294

Web- Java
endpointName=" xsd:string"
urlPattern=" xsd:string" /> [*]

</webServices>
6.10 jaxrpc-ri.xml wsdeploy Web- Bookinfo.
6.10. jaxrpc-ri.xml
<?xml v e r s i o n = " l . 0 " encoding="UTF-8"?>
<webServices
xmlns="http://Java.sun.com/xml/ns/jax-rpc/ri/dd"
version="l.0"
targetNamespaceBase="http://bookinfo.com/wsdl"
typeNamespaceBase="http://bookinfo.com/types"
urlPatternBase="/ws">
<endpoint
name="BookInfo"
displayName="BookInfo Service"

descriptio="Cee "
interface="bookinfo.BookInfoPort"
implementation="bookinfo.BookInfoImpl" />
<endpointMapping
endpointName="BookInfo"
urlPattern="/bookinfo" />
</webServices>
wsdeploy , portable.war Web-. Web-
Tomcat WSDP depioytool.
Tomcat
$ depioytool
.

6. Web Services

295

Web- Web-, ,

http://localhost:8080/services/bookinfo. Web-.
"services" , . . "/bookinfo"
u r l P a t t e r n
<endpointName>, jaxrpc-ri.xml.
, Web- , Web-, , . .

JAX-RPC
JAX-RPC .

(generated stubs). - c l i e n t ,
, :
$ -client -d bookclient config.xml

wscompile, :
$ wscompile -gen:client -d bookclient config.xml


config.xml ,
-d, bookclient. ,
SEI- Web-,
wscompile WSDL,

Web-

,
,
http://localhost:8080/
services/bookinfo?WSDL. Web- Web-, .
,
config.xml. .

config.xml
<configuration>
http://java.sun.com/xrnl/ns/jax-rpc/ri/config.
:
<service>, Web- SEI-;

296

Web- Java

<wsdi>, Web- WSDL-;


<modelf iie>, .
<service> .
name Web-.
packageName , .
targetNamespace
WSDL.
typeNamespace , WSDL.
<service>
<interface>, SEI- Web-. SEI name, - servantName.
soAPAction soAPActionBase MIME.
<wsdi> . location
URI WSDL, packageName
Web-.
. ,
.
<?xml version="1.0" encoding="UTF-8"?>
Configuration
xmlns="http://Java.sun.com/xml/ns/jax-rpc/ri/config">
<service name="xsd:string"
packageName="xsd:xtring"
targetNamespace="xsd:anyURI"
typeNamespace="xsd:anyURI">
<interface name="xsd:string"
servantName="xsd:string"

<! >
soapAction="xsd:string"

6. Web Services

297

soapActionBase="xsd:string">
<handlerChains>
<! - >
</handlerChains>
</interface>
<typeMappingRegistry>
<! >
</typeMappingRegistry>
<handle rCha ins >
<! - >
</handlerChains>
<namespaceMappingRegistry>
<! Java >
</namespaceMappingRegistry>
</service>
</configuration>
6.11 Web Bookinfo Web- SEI-.
6.11. SEl-
<?xml version="1.0" encoding="UTF-8"?>
^configuration
xmlns="http://Java.sun.com/xml/ns/jax-rpc/ri/config">
<service name="BookInfo"
packageName="book"
targetNamespace="http://book.org"
typeNamespace="http://book.org/types">
<interface name="BookInfoPort"

298

Web- Java
servantName="BookInfoImpl">
</interface>

</service>
</configuration>
BookInfoPort_Stub.class,
SEI- ,
WSDL- Web-, Booklnfo.wsdl,
Web-, BookInfo_Config.properties.
Web-, name <service> config.xml.
config.xml wscompile, Web- Bookinfo WSDL, 6.12.
6.12. WSDL-
<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns="http://Java.sun.com/xml/ns/jax-rpc/ri/config">
<wsdl location="http://localhost:8080/services/bookinfo?WSDL"
packageName="bookinfo"/>
</configuration>

,
stub
javax.xmi.rpc. .
public void _setProperty(String name, Object value);
public Object _getProperty(String name);
public Iterator _getPropertyNames();
:
USERNAME_PROPERTY s t r i n g Web;
PASSWORD_PROPERTY s t r i n g Web;

6. Web Services

299

ENDPOINT_ADDRESS_PROPERTY s t r i n g URI- Web;


SESSION_MAINTAIN_PROPERTY Boolean, , Web- . .
Bookinfo_stub
, . :
Stub stub = new Booklnfo_Stub();
BooklnfoPort info = (BooklnfoPort)stub;
Book book = info.getInfo("5-94157-041-4");
Bookinfo_impi, . getxxxPort , Web-, name <service> config.xml, .
, 6.13.
6.13. ,
import javax.xml.rpc.Stub;
import bookinfo.*;
public class BooklnfoStubClient{
public static void main(String[] args){
try{
Stub stub =
(Stub)(new Booklnfo_Impl().getBooklnfoPort());
stub._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY,
"http://localhost:8080/services/bookinfo");
BooklnfoPort bip = (BooklnfoPort)stub;
Book book = bip.getInfo("5-94157-041-4");
System.out.println(book.getTitle());

300

Web- Java
}catch(Exception e){
System.err.println(e);

, WSDL
Web- , WSDL. . , JAXRPC WSDL- Web-,
Service javax.xmi.rpc. service
SOAP- Web-.
service ServiceFactory:
S e r v i c e F a c t o r y sf = S e r v i c e F a c t o r y . n e w l n s t a n c e ( ) ;
Service s e r v = sf.createService(QName serviceName);
serv
serviceName. service

Web-

public Service createService(URL wsdl, QName serviceName);


wsdl WSDL- Web-.
service , getPort ().
serv wsdl WSDL SEI,
public Remote getPort(QName wsdlName, Class sei);
wsdlName SEI-.
,
public Remote getPort(Class sei);
6.14 Web- Bookinfo, WSDL.
. 6.14. , WSOL
import java.net.URL;
import javax.xml.rpc.*;

6. Web Services

301

import javax.xml.namespace.QName;
import bookinfo.*;
public class BookInfoProxyClient{
public s t a t i c void main(String[]

args){

try{
String ns = "http://bookinfo.com/wsdl/";
URL wsdl = new URL(
"http://localhost:8080/services/bookinfo?WSDL");
ServiceFactory sf = ServiceFactory.newInstance();
Service serv = sf.createService(wsdl,
new QName(ns, "Bookinfo"));
BooklnfoPort bip = (BooklnfoPort)serv.getPort(
new QName(ns, "BooklnfoPort"),
book.BooklnfoPort.class);
Book book = bip.getInfo("5-94157-041-4");
System.out.println(book.getTitle());
}catch(Exception ex)(
ex.printStackTrace();

, Web-
, WSDL Web-, Web-
, c a l l . c a l l
Web-, .
SEI- . Web-, SEI- Web-.

302

Web- Java

c a l l c r e a t e C a i i o
service. serv Service,
:
public
public
public
public

Call
Call
Call
Call

createCall();
createCall(QName portName);
createCall(QName portName, QName operationName);
createCall(QName portName, String operationName);

portName SEI- Web-,


QName. operationName ,
Web-.
c a l l ,
. Call
public void setOperationName(QName operationName);
public void setPortTypeName(QName portType);
public void setReturnType(QName xmltype);
public void setTargetEndpointAddress(String address);
, .
public void addParameter(String name, QName xmlType,
ParameterMode mode);
public void addParameter(String name, QName xmlType,
Class javaType, ParameterMode mode);
name, XSD xmlType, Java javaType,
XML Java.

ParameterMode:

mode

ED ParameterMode.IN ,
;
ParameterMode.OUT ,
;
ParameterMode.INOUT ,
.
, c a l l , , .
public void setProperty(String name, Object value);

6. Web Services

303

c a l l .
USERNAME_PROPERTY s t r i n g Web;
PASSWORD_PROPERTY s t r i n g Web;
ENCODINGSTYLE_URI_PROPERTY S t r i n g
;
SESSION_MAINTAIN_PROPERTY Boolean, , Web- . .
OPERATION_STYLE_PROPERTY " " " d o c u m e n t " , -

SOAP-;
SOAPACTION_USE_PROPERTY Boolean, , SOAP Act ion SOAP-; ;
SOAPACTIONJJRI_PROPERTY S t r i n g
soAPAction SOAP-.
Call , Web Web-
public Remote invoke(Object[] a r g s ) ;
public Remote invoke(QName operationNarae, Object[] args};
public void invokeOneWay(Object[] a r g s ) ;
6.15 Web-
Web- Bookinf .
6.15. ,
import j avax.xml..*;
import javax.xml.namespace.QName;
public class BookinfoDynamicClient{
private static String BODY_NAMESPACE_VALUE =
"http://bookinfo.com/wsdl/";
private static String ENCODING_STYLE_PROPERTY =
"j avax.xml.rpc.encodingstyle.namespace.uri";
private static String NS_XSD =
"http://www.w3.org/2001/XMLSchema";

304

Web- Java

private static String URI_ENCODING =


"http://schemas.xmlsoap.org/soap/encoding/";
public static void main(Stringf] args){
try{
ServiceFactory sf =
ServiceFactory.newInstance() ;
Service serv =
sf.createService(new QName("Booklnfo")) ;
QName port = new QName("BooklnfoPort");
Call call = serv.createCall(port);
call.setTargetEndpointAddress(
"http://localhost:8080/services/bookinfo");
call.setProperty(Call.SOAPACTION_USE_PROPERTY,
new Boolean(true));
call.setProperty(Call.SOAPACTION__URI_PROPERTY,
"");
call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
QName xsdString = new QName(NS_XSD, "string");
call.setReturnType(xsdString);
call.setOperationName(new QName(BODY_NAMESPACE_VALUE,
"getlnfo"));
call.addParameter("Stringl", xsdString,
ParameterMode.IN);
String[] params = { "5-94157-041-4" };
String title = (String)call.invoke(params) ,
System.out.println(title);
}catch(Exception e){
System.err.println(e);

Web Services J2EE


, Web-
JSP. JSP, Web-, , Web-.
Web- Tomcat, Apache Software
Foundation. Web- .
Web-
(application server), , ,
, , , ,
. BEA WebLogic, IBM WebSphere, JBoss, Sun ONE Application Server,
Oracle9i Application Server, Borland Enterprise Server.
, , EJB,

EJB-. , J2EE (Java 2 Enterprise
Edition), J2EE-cepeepoM. J2EE Sun http://java.sun.com/j2ee/.

J2EE, Web-, EJB, Web .
Web-, J2EE-cepeepe,
JSP, EJB.
[7, 10]. .

306

Web- Java

EJB
EJB, , , JavaBeans,
.
EJB 2-
EJB-. EJB
J2EE-cepeepoM.
EnterpriseBean . , , s e r i a i i z a b i e .
, EJB .
EnterpriseBean
, EJB. EJB,
EnterpriseBean SessionBean,
EntityBean MessageDrivenBean. EJB .
SessionBean EJB, , JSP, , EJB. session-.
session- (remote) (local). Java, . Java.
session-: ,
(Stateless Session
Beans), , ,
(Stateful Session Beans).
Web-, Web-
.
Web- .
EntityBean , , Java.
entity-. entity- . Entity-
. Web-, Web-
.
MessageDrivenBean ,

session- , .

7. Web Services J2EE

307

MDB-. Web- .
, Web- session , Web- MDB-.
EJB.

Session-
, session- , SessionBean. SessionBean
. EJB.

public void ejbActivate()


throws EJBException, RemoteException
EJB- , , , , .

public void ejbPassivate()


throws EJBException, RemoteException
EJB-, ,
session-.

ejbActivateO

ejbPassivate session- . Web- .



public void ejbRemoveO
throws EJBException, RemoteException

EJB- .
.

public void setSessionContext(SessionContext ctx)
throws EJBException, RemoteException
session- , ,
SessionContext.

308

Web- Java

, session . EJB-,
session- .
- EJB-. remote- home-.

Remote- session-
EJB-
EjBObject. Web-
, Web- Web-. , EJB-. EJBLocalobject.
EJBObject Remote, ,
. EJBObject
remote- session-. Web-,
remote-, RemoteException , .
EJBObject ,
EJB-. Web- ,
.

public EJBHome getEJBHome() throws RemoteException


EJBHome home-,
.

public Handle getHandle() throws RemoteException


Handle.
EJBObject,
getEjBObject (). , , t h i s
EJB .

public boolean isldentical(EJBObject obj)


throws RemoteException

7. Web Services J2EE

309

equals , , - , Java.

public void remove 0 throws RemoteException,


RemoveException
.
, , EJBObject
public Java.lang.Object getPrimaryKey()
throws RemoteException
entity- .
remote- EjBLocaiobject :
getHandie (),
public EJBLocalHome getEJBLocalHome() throws EJBException
home- .

Home- session-
EJBHome, Remote session .
EJBHome home-. EJBHome , EJ -. Web-
EJB-
.

public EJBMetaData getEJBMetaData()


throws RemoteException
EJBMetaData,
.

public HomeHandle getHomeHandle()


throws RemoteException
HomeHandle,
getEJBHome . t h i s .

public void remove(Handle handle) throws RemoteException,
RemoveException

310

Web- Java

public void remove(Object pk) throws RemoteException,


RemoveExcept i on

, .
home- EJBLocalHome
public void remove(java.lang.Object primaryKey)
throws RemoveException, EJBException

Web- EJBHome, / EJBLocalHome, , create .


create () home- ,
,
RemoteException. ,
CreateException. create ,
remote-,
EJBHome EJBLocalHome. EJB session-. ,
EJB- remote-
. Web, remote-.

Web-
session- , Web-. session remote- home-, Web- (Web Service Endpoint Interface).
WSEI- session-.
remote- home-, WSEI-
Remote, . JAX-RPC, 6,
SEI- . , JAX-RPC,
RemoteException. ,
EJBObject EJBLocaiObject. WSEI-, EJB-.
WSEI- session-
.
EJB-, WSEI-
ear-jar.xml <service-endpoint>,
<session>, WSDL-.

7. Web Services J2EE

311

session-, . session- name, sayHeiloo session-. :


", <name>!", .
HeiioEJB. Web, .
remote-, sayHeiloo.
7.1.
; 7.1. Remote- session-
package hello;
import j ava.rmi.*;
import javax.ejb.*;
public interface Hello extends EJBObject{
String sayHello(String name) throws RemoteException;

home-, create ,
7.2.
:

7.2. Home- session-

package hello;
import Java.rmi.*;
import

javax.ejb.*;

public interface HelloHome extends EJBHome{


Hello create() throws CreateException, RemoteException;

WSEI- session-. 7.3.


| 7.3. WSEI- session-
package hello;
import j ava.rmi.*;

312

Web- Java

public interface HelloPort extends Remote{


String sayHello(String name) throws RemoteException;
}
session-. 7.4.
| 7.4, session-

- j

package hello;
import j ava.rmi.*;
import javax.ejb.*;
public class HelloBean implements SessionBean{
private SessionContext ctx;
public HelloBean(){}
public String sayHello(String name) throws RemoteException{
return ", " + name + "!";

public void setSessionContext(SessionContext ctx)


this.ctx = ctx;

public void ejbCreate (){}


public void ejbActivate(){}
public void ejbPassivate(){}
public void ejbRemove(){}
}

7.4
SessionBean setSessionContext().
, EJB
(public) , . ejbCreate create home-,

7. Web Services J2EE

313

. create
. , , create () .
,
EJB. HelioEJB, remote- Hello, home- HeiioHome, HelloBean.
, (deploy) EJB-.
XML-
ear-jar.xml. - , EJB-. J2EE
deploytool, . [10]. JNDI [10],
java:comp/env/ejb/. Web- java:comp/env/service/.
session- HelioEJB JNDl-
hello. ,
7.5.
; 7.5. session-
package hello;
import j avax.naming.*;
import javax.rmi.*;
public class HelloClient{
public static void main(String[] args)f
try{
InitialContext ctx = new InitialContext();
HeiioHome home = (HeiioHome)PortableRemoteObject.narrow(
ctx.lookup("java:comp/env/ejb/hello"), HeiioHome .class);
Hello h = home.create();
System.out.println(h.sayHello(""));

Web- Java

314
}catch(Exception e){
System.err.println(e);

Web- JAX-RPC, 6.
session-, EJB-
class.newinstance
, . EJB- sessionContext setsessioncontext . EJB ejbCreate () .
,
SessionContext.

session-
sessionContext remote-
EJBObject EJBLocaiobject
public EJBObject getEJBObject();
public EJBLocalObject getEJBLocalObject() ;
EJB 2.1 ,
Web-:
public MessageContext getMessageContext();
MessageContext, . 6.
, SessionContext EJBContext ,
,
public EJBHome getEJBHome();
public EJBLocalHome getEJBLocalHome();
public UserTrasaction getUserTransaction();
public boolean getRollbackOnly();
public Principal getCallerPrincipal();
home-, ,
, .
.

7. Web Services J2EE

315

MDB-
MDB (Message Driven Beans)
EJB-. ,
, , , MDB- .
MDB-, , . .
MDB- remote- home-,
. MDB-
MessageDrivenBean.
MessageDrivenBean
public void setMessageDrivenContext(MessageDrivenContext ctx)
throws EJBException
public void ejbRemove() throws EJBException
EJB-.
MessageDrivenContext, EJBContext,
EJBContext.
MDB- ,
- . , EJBContext, remote- home-.
EJB- MDB- ,
session-,
e j b c r e a t e o . .
, MDB- - . MDB-
JMS (Java Message Service),
MessageListener. MDB-
JAXM, OnewayListener
RegRespListener. 6.
onMessageO,
MDB-.
MessageListener [7, 10].
:
public void onMessage(Message msg);
msg, , Message. Message

316

Web- Java


JMS. [10].
7.6 MDB-, .
7.6. MDB-
import

javax.ejb.*;

import javax.jms.*;
import

java.util.*;

public c l a s s DummyMDB
implements MessageDrivenBean, MessageListenerf
public void onMessage(Message msg){
try{
System.out.println("\ " +
msg.getJMSMessageID() +
" " + msg.getJMSDestinationO);
System.out.println(" " +
(msg.getJMSExpiration() > 0 ?
new Date(msg.getJMSExpiration()) :
" ."));
System.out.println("\ : " +
msg.getJMSReplyTo());
System.out.println("\ " +
msg.getJMSType());
if

(msg instanceof TextMessage)


System.out.println(" :\n" +
((TextMessage)msg).getTextf));

}catch(Exception e){
System.err.println(e);

7. Web Services J2EE

317

public void ejbCreate(){}


public void ejbRemove(){}
public void setMessageDrivenContext(
MessageDrivenContext mdc){}

EJB-
EJB ear-jar.xml,
META-INF EJB-. EJB .
session- remote-,
home- WSEI-. MDB- .
EJB .
ear-jar.xml . 7.7
,
HeiioEjB DummyMDB, .
; 7.7. ear-jar.xml EJB-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC
'-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN1
'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<display-name>Simple EJB</display-name>
<enterprise-beans>
<session>
<display-name>HelloEJB</display-name>
<ejb-name>HelloEJB</ejb-name>
<home>HelloHome</home>
<remote>Hello</remote>
<service-endpoint>HelloPort</service-endpoint>

318

Web- Java
<ejb-class>HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
<security-identity>
<descriptionx/description>
<use-caller-identity></use-caller-identity>
</security-identity>
</session>
<message-driven>
<display-name>DummyMDB</display-name>
<ejb-name>DummyMDB</ejb-name>
<ejb-class>DummyMDB</ejb-class>
<transaction-type>Bean</transaction-type>
<message-selector></message-selector>
<acknowledge-mode>Auto-acknowledge</acknowledge-mode>
<message-driven-destination>
<destination-type>javax.jms.Topic</destination-type>
<subscription-durability>Durable</subscription-durability>
</message-driven-destination>
<security-identity>
<description></description>
<run-as>
<description></description>
<role-name></role-name>
</run-as>
</security-identity>

</message-driven>
</enterprise-beans>
<assembly-descriptor>
<method-permission>
<unchecked />

7. Web Services J2EE


<method>
<ejb-name>HelloEJB</ejb-name>
<method-intf>Home</method-intf>
<method-name>remove</method-name>
<method-params>
<method-param>j ava.lang.Obj ect</method-param>
</method-params>
</method>

<method>
<ejb-name>HelloEJB</ejb-name>
<method-intf>Remote</method-intf>
<method-name>getHandle</method-name>
<method-params />
</method>

<method>
<ejb-name>HelloEJB</ejb-name>

<method-intf>HoitiK/method-intf>
<method-name>remove</method-name>
<me thod-pa rams >
<method-param>'j avax,ej b.Handle</method-param>
</method-params>
</method>

<method>
<ejb-name>HelloEJB</ejb-name>
<method-intf>Remote</method-intf>
<method-name>sayHello</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</method>

<method>
<ejb-name>HelloEJB</ejb-name>
<method-intf>Home</method-intf>

319

320

Web- Java
<method-name>getHomeHandle</method-name>
<method-params />
</method>
<method>
<ejb-name>HelloEJB</ejb-name>
<method-intf>Remote</method-intf>
<method-name>getPrimaryKey</method-name>
<method-params />
</method>
<method>
<ejb-name>HelloEJB</ejb-name>
<method-intf>Home</method-intf>
<method-name>getEJBMetaData</method-name>
<method-params />
</method>
<method>
<ejb-name>HelloEJB</ejb-name>
<method-intf>Remote</method-intf>
<method-name>remove</method-name>
<method-params />
</method>
<method>
<ejb-name>HelloEJB</ejb-name>
<method-intf>Home</method-intf>
<method-name>create</method-name>
<method-params />
</method>
<method>
<ejb-name>HelloEJB</ejb-name>
<method-intf>Remote</method-intf>
<method-name>isldentical</method-name>
<method-params>

7. Web Services J2EE

321

<method-param>j avax.ejb.EJBObj ect</method-param>


</method-params>
</method>
<method>
<ejb-name>HelloEJB</ejb-name>
<method-intf>Remote</method-intf>
<method-name>getEJBHome</method-name>
<method-params />
</method>
</method-permission>
</assembly-descriptor>
</ejb-jar>

Web- J2EE-cepeepe
Web-, J2EE-cepBepa, EJB.
. EJB , JSP.
. 7.1.

(Endpoint)
Web-

JSP

7 . 1 . EJB Web-

EJB
Web-, , . 7.2.

, EJB Web-
JSP.
11 . 748

322

Web- Java
J2EE-cepeep
EJB-
(Endpoint)
Web-
Entity Bear-'

7.2. Web- EJB

Web- 12- , . Web- , , EAR-,


J2EE-cepBepe . ,
,
Web- -.
, IBM "Web Services for J2EE". http://www106.ibm.coin/developerworks/webservices/. "WS4EE".
WS4EE
Web- J2EE-cepeepe, JAX-RPC.
. 7.3. Web-
, Web- EJB-.
JNDI ,
service JAX-RPC. Web , SEI- Web. JNDI, SEI- Web-.
Web-,
, JSP EJB.
Web-, WS4EE (port),
- (tie) JAXRPC, , JAXRPCServiet, session . Web-
Web-,
EJB-.

323

7. Web Services J2EE


J2EE-cepeep
(Web EJB)
Web-
SEI-

Service

()

. 7 . 3 . , "WS for J2EE"

"" WSDL (. 4). SEI-, WSDL- <wsdi:portType>,


-, <wsdi:binding>, .
URI, Web-.
- service,
<wsdl:service>. . WS4EE
WSDL Web-
.


WSDL , WS4EE .
JAX-RPC, 6. SEI, - Web.
EJB, session- , WSEI-.
EJB-.
WS4EE , , , , JAXM MDB. Web- . .
, WS4EE,
.
, , SEI- JAX-

324

Web- Java

RPC. WSDL- , <wsdl:portType> <wsdl:binding>.


, SEI-.
<wsdi:port> WSDL-.
- JAX-RPC, session-
- . WS4EE
"Service Implementation Bean". -.
SEI-, SEI-.
URI, <wsdi:port>.
, Web-.
WSDL-
, Web- web.xml EJB ear-jar.xml
EJB,
. WS4EE .

webservices.xml Web-.

webservicesclient.xml
Web-. Web-.
, ,
Java WSDL JAX-RPC.
JAX-RPC-.
.

Web-
Web- EJB- , Web-, . XML- webservices.xml <webservices>.
Web- web.xml
WEB-INF, EJB- ear-jar.xml
-INF.
<webservices> <webservice-description>, Web-.
<webservice-description-name>
Web-, , <wsdi-fiie>
WSDL-,

7. Web Services J2EE

325

Web- EJB-. <jaxrpc-mapping-fiie> JAX-RPC-.


<port-component>,
<webservice-description>, - Web. - <portcomponent-name>. WSDL-,
. <wsdi-port> <namespaceURi> <iocaipart>
(QName) XML-, WSDL-.
<service-endpoint-interface> SEI-,
<service-impi-bean> -.
- ,
<service-impi-bean>.
<serviet-iink>. ,
<serviet-ciass> web.xml. session- <ejb-iink> , <ejb-name>
ear-jar.xml.
, <handier> - JAX-RPC, Web-,
, , SOAP-, .
7.8 webservices.xml.
, , , . id ,
.
j 7.8. Web-
<webservices id="">
<description id=""> [?]
<display-name id=""> [?]
<small-icon id=""> [?]
<large-icon id=""> [?]
<webservlce-description> [+]
description id=""> [?]

326

Web- Java
<display-narae id=""> [?]
<small-icon id=""> [?]
<large-icon id=""> [?]
<webservice-description-name id="">
<wsdl-file id="">
<jaxrpc-mapping-file id="">
<port-component id=""> [+]
<description id=""> [?]
<display-name id=""> [?]
<small-icon id=""> [?]
<large-icon id=""> [?]
<port-component-name id="">
<wsdl-port id="">
<namespaceURI id="">
<localpart id="">
</wsdl-port>
<service-endpoint-interface id="">
<service-impl-bean id="">
<ejb-link id=""> I <servlet-link id="">
</service-impl-bean>
<handler id="">*
<description id=""> [?]
<display-name id=""> [?]
<small-icon id=""> [?]
<large-icon id=""> [?]
<handler-name id="">
<handler-class id="">
<init-param id=""> [*]

7. Web Services J2EE

327

<param-name id="">
<param-value id="">
description id=""> [?]
</init-param>
<soap-header id=""> [*]
<namespaceURI id="">
<localpart id="">
</soap-header>
<soap-role id=""> [*]
</handler>
</port-component>
</webservice-description>
</webservices>
7.9
"HelloService", 7.3, 7.4, 7.7.

Web-

* 7.9. Web- "HelloService"


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE webservices PUBLIC
"-//IBM Corporation, Inc.//DTD J2EE Web services 1.0//EN"
"http://WVJW.ibm.com/webservices/dtd/j2ee_web_services_l_0.dtd">
<webservices>
<webservice-description>
<webservice-description-name>
HelloService
</webservice-description-name>
<wsdl-file>META-INF/hello.wsdl</wsdl-file>

328

Web- Java

<jaxrpc-mapping-file>
META-INF/HelloMapping.xml
</j axrpc-mapping-file>
<port-component>
<port-component-name>
He1lo Po rtComponent
</port-component-name>
<wsdl-port>
<namespaceURI></namespaceURI>
<localpart>HelloPortComponent</localpart>
</wsdl-port>
<service-endpoint-interface>
hello.HelloPort
</service-endpoint-interface>
<service-impl-bean>
<ejb-link>HelloEJB</ejb-link>
</service-impl-bean>
</port-component>
</webservice-description>
</webservices>


webservicesclient.xml XML <webservicesciient>.
Web-, Web-.
Web- Web-,
.
.
<service-ref>.
,
ear-jar.xml web.xml, <service-ref> -

7. Web Services J2EE

329

<component-scoped-refs>,
<component-name> .

<service-ref>.
<service-ref-name> .
Web- lookup ()
JNDI. "service/".
<service-interface> ,
javax.xmi.rpc.Service .
, <service-ref>, .
<wsdi-fiie> <jaxrpc-mapping-fiie>
WSDL- JAX-RPC- .
<service-qname> (QName) XML WSDL-, Web-. , <wsdl-file>, WSDL- <wsdi:service>.
<port-component-ref> SEI-
-, <port-componentname> webservices.xml.
getPort .
, <handier> - SOAP. , ,
<port-name>. ,
.
7.10
webservicesclient.xml.

; 7.10.
<webservicesclient id="">
<component-scoped-refs id=""> [+] I <service-ref id=""> [+]
<component-name id="">
<service-ref id=""> [+]
<description id=""> [?]
<display-name id=""> [?]

330

Web- Java
<small-icon id=""> [?]
<large-icon id=""> [?]
<service-ref-name id="">
<service-interface id="">
<wsdl-file id="">?
<jaxrpc-mapping-file id=""> [?]
<service-qname id=""> [?]
<namespaceURI id="">
<localpart id="">
</service-qname>
<port-component-ref id=""> [*]
<service-endpoint-interface id="">
<port-component-link id=""> [?]
</port-component-ref>
<handler id=""> [*]
description id=""> [?]
<display-name id=""> [?]
<small-icon id=""> [?]
<large-icon id=""> [?]
<handler-name id="">
<handler-class id="">
<init-param id=""> [*]
<param-name id="">
<param-value id="">
<description id=""> [?]
</init-param>
<soap-header id=""> [*]
<namespaceURI id="">
<localpart id="">
</soap-header>

7. Web Services J2EE

331

<soap-role id=""> [*]


<port-name id=""> [*]
</handler>
</service-ref>
</component-scoped-refs>
</webservicesclient>
7.11 Web- "HelloService",
7.9.
' 7.11. Web- "HelloService"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE webservicesclient PUBLIC
"-//IBM Corporation, Inc.//DTD J2EE Web services client 1.0//EN"
"http://www.ibm.com/webservices/dtd/j2ee_web_services_client_l_0.dtd">
<webservicesclient>
<service-ref>
<service-ref-name>service/HelloService</service-ref-name>
<service-interface>j avax.xml.rpc.Service</service-interface>
<wsdl-file>META-INF/hello.wsdl</wsdl-fi
<jaxrpc-mapping-file>
META-INF/HelloMapping.xml
</jaxrpc-mapping-file>
<port-component-ref>
<service-endpoint-interface>
hello.HelloPort
</service-endpoint-interface>

332

Web- Java
<port-component-link>
HelloPortComponent
</port-component-link>
</port-component-ref>

</service-ref>
</webservicesclient>

JAX-RPC
, JAX-RPC, ,
"Mapping". WSDL, , WEB-INF META-INF.
, WSDL-
<wsdi:service> <wsdl:port>,
<wsdi:operation> <wsdl:input>
<wsdi:output>, WSDL
,
<java-wsdl-mapping> <package-mapping>.
<package-mapping> Java,
<package-type>, , WSDL-. <namespaceURI>.
<java-wsdi-mapping> <java-xmi-type-mapping>
, WSDL-, <exception-mapping>
WSDL- <wsdi:fauit> <serviceinterface-mapping> WSDL-
<wsdl:service>. , < s e r v i c e endpoint-interface-mapping> WSDL-
<wsdl:portType> <wsdl:binding>.

7.12 JAX-RPC-.
; 7.12. Java-WSDL-Mapping
<java-wsdl-mapping id="">
<package-mapping id=""> [+]

7. Web Services J2EE


<package-type id="">
<namespaceURI id="">
</package-mapping>
<java-xml-type-mapping id=""> [*]
<class-type id="">
<root-type-qname id="">
<namespaceURI id="">
<localpart id="">
</root-type-qname>
<qname-scope id="">
<variable-mapping id==""> [*]
<Java-variable-name id="">
<data-member id=""> [?]
<xml-element-name id="">
</variable-mapping>
</java-xml-type-mapping>
<exception-mapping id=""> [*]
<exception-type id="">
<wsdl-message id="">
<namespaceURI id="">
<localpart>
</wsdl-message>
<constructor-parameter-order> [?]
<element-name> [+]
</constructor-parameter-order>
</exception-mapping>
<service-interf-mapping id=""> [?]
<service-interface id="">
<wsdl-service-name id="">
<port-mapping id=""> [*]
<port-name id="">
<java-port-narae id="">
</port-mapping>
</service-interface-mapping>
<service-endpoint-interface-mapping id=""> [+]
<service-endpoint-interface id="">

333

334

Web- Java
<wsdl-port-type id="">
<namespaceURI id="">
<localpart id="">
</wsdl-port-type>
<wsdl-binding id="">
<namespaceURI id="">
<localpart>
</wsdl-binding>

<service-endpoint-method-mapping id=""> [*]


<Java-method-name id="">
<wsdl-operation id="">
<method-param-parts-mapping id=""> [*]
<param-position id="">
<param-type id="">
<wsdl-message-mapping id="">
<wsdl-message id="">
<wsdl-message-part-name id="">
<parameter-mode id="">
<soap-header id=""> [?]
</wsdl-message-mapping>
</method-param-parts-mapping>
<wsdl-return-value-mapping id="">
<method-return-value id="">
<wsdl-message id="">
<wsdl-message-part-name id="">
</wsdl-return-value-mapping>
</service-endpoint-method-mapping>
</service-endpoint-interface-mapping>
</j ava-wsdl-mapping>
7.13 JAX-RPC- Web- "HelloService".
HelloMapping.xml.
7.13. JAX-RPC- Web- "helloService"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE java-wsdl-mapping PUBLIC

7. Web Services J2EE

335

"-//IBM Corporation, Inc.//DTD J2EE JAX-RPC mapping 1.0//EN"


"http://www.ibm.com/webservices/dtd/j 2ee_j axrpc_mapping_l__O.dtd">
<j ava-wsdl-mapping>
<package-mapping>
<package-type>hello</package-type>
<namespaceURI>myservices.hello</namespaceURI>
</package-mapping>
</java-wsdl-mapping>

Web-
"Web Services for J2EE" Web- session-,
(deploy) Web- EJB- J2EE. RMI, ,
, . , , [10]. 12-
, . J2EE SDK depioytool,
,
,
.
Web-,
WS4EE, , Web- JAX-RPC, RMI. ,
:
WSDL-, web.xml ear-jar.xml,
Web- webservices.xml,
webservicesclient.xml JAX-RPC-. Web .
IBM (RI Reference
Implementation) "Web Services for J2EE"
http://www-106.ibm.com/developerworks/webservices/. ,
,
.

336

Web- Java

J2EE SDK, J2EE-cepBep Web-, .


Web-
svcgen (Web Service Generator), . : Web-
, Web WSDL.
:
$ svcgen [ - c l a s s p a t h <path> ] -sei <classname> \
-map <namespace> <pkg> -wsdl <WSDLfile>

-classpath Web-. -sei SEI-


.class. - WSDL- Java.
-wsdl WSDL-.
:
$ svcgen -wsdl <WSDLfile> -map <namespace> <pkg> [ - d i r <path> ]

-wsdl WSDL-. - Java. -dir , Java JAX-RPC-,


WSDL- ".deployment.xml". ,
$WS4EE_HOME/temp/svcgen/. , Web-
.
Web- application.ear J2EE-cepBepa, , deploytooi. webservices.xml,
webservicesclient.xml. wsdd.
Web-
wsdepioy. :
$ wsdepioy <input.ear> [ -coutput.jar> ]

<input.ear> . Enabled<input.ear>, deploytooi.


<output.jar>, ,
Web-. wsdepioy
deploytooi, .


Web- .
, ,
Web-, ,
, .
.
,
.
, , ,
. Web-
.

(confidentiality) . ,
Web- , ,
. .
(integrity) . Web- , . MD (Message Digest).
(authentication) . ,
Web- , ,
.
, ,
.
12 3. 748

338

Web- Java

(authorization) .
, . : , ACL (Access
Control Lists), .
(nonrepudiation) . , Web- ,
.
NR-.
,
. .
.


. , , (key) . .
: () , ( ) .



, . .
,
. ( .)
, .
DES (Data Encryption Standard) 56 .

.
2814789.
256- .

8.

339

DES . Triple-DES 3DES.


IDEA (International Data
Encryption Algorithm) 128- .
(Bruce Schneier) Blowftsh, 56-
, Twofish, 256 ,

http://www.counterpane.com/labs.html.

(Ronald Rivest) RC2, RC4, RC5, RC6. .
.
,
.
,
.


Web-
(public key), ,
(private key), .
, . Web . Web-,
. Web- ,
, ,
. , .
,
.
.
DSA (Digital Signature Algorithm)
. , DSS (Digital
Signature Standard) 512 1024
. , , .
RSA, (Rivest,
Shamir, Adleman), 1024 .

340

Web- Java

- DH (Diffie-Hellman) 4096 .
AlGamal - (Taher ElGamal) ,
.

. , , , . : , .

, .



MD (Message Digest), . ,
. ,
. . , .
.
MD5, RFC 1321.
128- .
SHA-1 (Secure Hash Algorithm) -
160- .
SHA-256, SHA-384, SHA-512 .
MAC (Message Authentication Code)
. .


,
.
-

8.

341

, . .
, .
.
,
. ,
.
, .
, ,
.



. , , , , , . , ,
(Certificate Authority).
, , ,
: , , .

ISO X.509.
.
VeriSign, http://www.verisign.com/,
.

Java
Java 2 SDK, Standard Edition Security
API, . Security API JCA (Java Cryptography Architecture)
JCE (Java Cryptography Extension). Java
java. security, javax. crypto ,
com.sun.security , ,
, . ,

342

Web- Java

Security API javax.security.auth , , Java, JAAS (Java Authentication and Authorization Service).
, Security API,
DES, IDEA, DSA, MD5, SHA-1, RSA , .509, Java Kerberos.
Security API.
[13] ,
Java. Security API

J2SE
SDK,

$JAVA_HOME/docs/guide/security/.


Web- . ,
, .
SSL (Secure Sockets Layer),
Netscape Communication. TCP/IP
IP-
. , , , . SSL 3.0
TLS (Transport Layer Secure),
RFC 2246. TLS SSL , .
SSL TLS ,
DES, RSA, SHA-1, MD5, RC2, RC4.
.
, , .
Java SSL 3.0 TLS JSSE (Java
Secure Socket Extension). Java j a v a x . n e t . s s i ,
j a v a x . s e c u r i t y . c e r t J2SE SDK. [13] J2SE SDK.
SSL TLS
, .
- .

8,

343

VPN
(Virtual Private Network) . ,
.
. , , ,

.
, , IPSec, IPv6 (Point-to-Point
Tunneling Protocol).

Web-,
. -, Web- : HTTPS, , SMTP, Web .
-, ,
SOAP-
SOAP- (actors).
, . ,
.

XML
SOAP-,
, XML XML, .
XML- W3C SOAP Web-,
.
,
XML, "XML Encryption
Syntax and Processing". "XML Encryption".
http://www.w3.org/TR/2002/xmlenc-core/.
, XML, http://www.w3.org/TR/xmldsig-core/, : RFC 3275

344

Web- Java

, a RFC 3076 XML


(Canonical XML).
.

XKMS
(XML
Key
Management
Specification) .
http://www.w3.org/TR/xlms2/.
.

XML
XML
. ,
.

"XML
Encryption"

XML-
<EncryptedData> .
http://www.w3.org/2001/04/xmlenc*.
,
. <EncryptedData>
XML-,
.
, XML-
<person>
<nuinb>XY-123456-27</nuinb>
</person>

<numb>,
. .
:
<person>
<numb>
<EncryptedData Type="http://www.w3.org/2001/04/xmlencttContent">
<! >
</EncryptedData>
</numb>
</person>
<numb>:
<person>
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element">

8.

345

<! >
</EncryptedData>
</person>
, , "content" "Element".
<EncryptedData> :
id <EncryptedData>, ;
URI;
MimeType MIME-
URI;
Encoding URI.
;
:
<EncryptedData
xmlns="http://www.w3.org/2001/04/xmlenctt"
xmlns:ds="http://www.w3.org/2000/09/xmldsigtt"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.w3.org/2001/04/xmlencttxenc-schema.xsd">
<EncryptedData> .
<EncryptionMethod Algorithm=""> Algorithm.
<KeySize>, .
, , RSA <OAEPparams>.
<EncryptionMethod> , .
<ds:Keyinfo> .
, http://www.w3.org/2000/09/xmldsigS.
, .
<EncryptedKey>,
, ,
<AgreementMethod>, .
<cipherData> .

346

Web- Java

<EncryptionProperties> <EncryptionProperty>.
<cipherData>. ,
<ciphervaiue>
. ,
Base64.
, <EncryptedData>
:
<EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#">
<CipherData>
<CipherValue>
BNjivf7gTOXRRhdgB5h4JSxHJ7dlZudnZBrg=
</CipherValue>
</CipherData>
</EncryptedData>
<CipherValue> <CipherData>
<cipherReference U R I = " " > , URI URI.
<CipherReference> <Transforms>,
<ds :Transform>,

. ,
Base64, :
<EncryptedData xmlns="http://www.w3.org/2001/04/xinlenct">
<CipherReference URI="http://www.some.com/CipherData.xml">
<Transforms>
<ds:Transform Algorithm=
"http://www.w3.org/2000/09/xmldsigttbase64"/>
</Transforms>

8.

347

</CipherReference>
</EncryptedData>
<EncryptedKey>, ,
<EncryptedData>
<ReferenceList>, <KeyReference URI="">
/ <DataReference U R I = " " > URI
( id) , .
<AgreementMethod>
. , ,
<originatorKeyinfo>, , <RecipientKeyinfo>.
<KA-Nonce>, .
8.1.
- 8.1.
<EncryptedData Id=""[?] Type=""[?] MimeType=""[?] Encoding=""[?]
xmlns="http://www.w3.org/2001/04/xmlenci"
xmlns:ds="http://www.w3.org/2000/09/xmldsigi"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/04/xmlencixenc-schema.xsd">

<EncryptionMethod Algorithm=""> [?]


<KeySize>

[?]

<OAEPparams> [?]
<ds:DigestMethod Algorithm="">

[?]

</EncryptionMethod>
<ds:KeyInfo>

[?]

<ds:KeyName> (? ]
<ds:RetrievalMethod URI="" Type=""> [?]
<EncryptedKey>

[?]

<EncryptionMethod Algorithm="">
<CipherData>

[?]

Web- Java

348

<CipherReference URI=""> | <CipherValue>


<Transforms>
<ds:Transform Algorithm="">
</Transforrns>
</CipherReference>
</CipherData>
<ReferenceList> [?]
<KeyReference URI=""> [*]
<DataReference URI=""> [*]
</ReferenceList>
</EncryptedKey>
<AgreementMethod Algorithm=""> [?]
<KA-Nonce> [?]
<ds:DigestMethod Algorithm="">
<OriginatorKeyInfo> [?]
<RecipientKeyInfo> [?]
</AgreementMethod>
</ds:KeyInfo>
<CipherData>
<CipherReference URI=""> I <CipherValue>
<Transforms>
<ds:Transform Algorithm="">
</Transforms>
</CipherReference>
</CipherData>
<EncryptionProperties> [?]

8.

349

<EncryptionProperty> [+]
</EncryptionProperties>
</EncryptedData>

XML
XML RFC 3275. ,
, <signedinfo>
. ,
. <signedinfo> RFC 3275.
<signature>,
RFC 3275.
<signature> <signedinfo>
<signaturevalue>, <Keyinfo>
<object>.
http://www.w3.org/2000/09/xmldsigft.
<signedinfo>, , . <CanonicalizationMethod> <SignatureMethod>.
, <signedinfo> ,
<Reference>.

<CanonicaiizationMethod> <signedinfo> XML. Algorithm. , .


<signatureMethod>
<SignedInfo>. Algorithm,
:
<SignatureMethod
Algorithm=http://www.w3.org/2000/09/xmldsigtdsa-shal />

DSA-SHA1.
<signatureMethod> , .

350

Web- Java

<Reference> , XML, HTML , , . ,


, <Reference>
URI , :
<Reference URI="http://www.some.com/pub/inv.xml#ident">
inv.xml. (detached signature) .

(enveloped signature). :
<Reference URI="#ident">
.
<Reference> <Transforms>, <Transform> , ,
XML. ,
<Reference> :
<DigestMethod> Algorithm, <Digestvalue> Base64. :
<Reference URI="file:/D:/sign.xml">
<Transforms>
<Transform Algorithm=
"http://www.w3.org/TR/2001/REC-xml-cl4n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#shal" />
<DigestValue>j61wx3rvEPO0vKtMup4NbeVu8nk=</DigestValue>
sign.xml SHA-1.
sign.xml XML.
<signatureVaiue> Base64.
<Keyinfo> ,
. . <Keyinfo> ,
. , . <KeyName>, <KeyVaiue>,
<RetrievalMethod>, <X509Data>, <PGPData>, <SPKIData>, <MgmtData>. .

8.

351

<object> , , , <signatureProperty>,
<Manifest> .
8.2 , .
8.2.
<Signature Id="" [?]>
<SignedInfo>
<CanonicalizationMethod Algorithm="">
<SignatureMethod Algorithm="">
<Reference URI="" [?] > [+]
<Transforms> [?]
<Transform Algorithm=""> [+]
</Transforms>
<DigestMethod Algorithm="">
<DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>
<KeyInfo> [?]
(<KeyName> I <KeyValue> I <RetrievalMethod> I <X509Data> I
<PGPData> I <SPKIData> I <MgmtData>) [+]
</KeyInfo>
<Object I d = " "

[?]> [*]

352

Web- Java
<SignatureProperties>
<SignatureProperty Target=""> [+]
</SignatureProperties>
<Manifest>
<Reference> [+]
</Manifest>

</Object>
</Signature>

XML
. .
, , , .

<CanonicalizationMethod>.

XML
RFC 3076, "Canonical XML".
RFC 3076 UTF-8, , , XML , ,
. , <canonicaiizationMethod> :
<CanonicalizationMethod
Algorithm="http://www.w3.org/TR/2001/REC-xml-cl4n-20010315" />

Java XML
IBM XSS4J (XML Security
Suite for Java), "XML Encryption", RFC 3275, RFC 3076, ,
. XSS4J
,
http://www-106.ibm.com/developerworks/webservices/library/xinlsecuritysuite/.

8.

353

XSS4J
xss4j.jar J2SE
SDK, , $JAVA_HOME/jre/lib/ext/,
CLASSPATH. XSS4J Java Security API, J2SE SDK.
, XML-, , Apache Xerces2, XSLT, , Apache Xalan-J. XSS4J
IBM WSTK IBM WebSphere Studio.
Apache Software Foundation "Apache XML
Security", http://xml.apache.org/security/.
, "XML Encryption",
RFC 3275
RFC 3076. XML. , ,
Web- Apache Axis, 3.
8.3 Web-, SOAP, , Web-, .
Java
.keystore. keytool J2SE SDK,
:
keytool -genkey

.
: 8.3. Web-, SOAP-
import org.apache.axis.*;
import org.apache.axis.client.*;
import org.apache.axis.message.*;
import org.apache.axis.utils.*;
import org.apache.axis.configuration.NullProvider;
import org.apache.axis.encoding.*;
import org.apache.xml.security.cl4n.Canonicalizer;
import org.apache.xml.security.signature.XMLSignature;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import j ava.io.*;

354

Web- Java

import j ava.security.*;
import Java.security.cert.X509Certificate;
public class ClientAxis{
static SOAPEnvelope env = new SOAPEnvelope();
public static void main(String[] args){
if (args.length != 3){
System.err.println("Usage: Java ClientAxis" +
" <keystorePassword> <privateKeyPassword>" +
" <distinguishedName>");
System.exit(0);
try{
Options opts = new Options(args);
Service service = new Service ();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(
new j ava.net.URL(opts.getURL()) ) ;
SOAPBodyElement sbe = new SOAPBodyElement(
XMLUtils.StringToElement(
"http://localhost:8080/EchoService",
"getName", ""));
env.addBodyElement(sbe);
sign(args[0], args[l], args[2]);
System.out.println("\nRequest:

");

XMLUtils.PrettyElementToStream(env.getAsDOMO, System.out);
call.invoke(env);
MessageContext me = call.getMessageContext();

8.
System.out.println("\nResponse:
");
XMLUtils.PrettyElementToStream(
me.getResponseMessage().getSOAPEnvelope().getAsDOM(),
System.out);
}catch(Exception e) {
e.printStackTrace ();

private static void sign(String keystorePassword,


String privateKeyPassword,
String certificateAlias){
try{
env.addMapping(new Mapping(
"http://schemas.xmlsoap.org/soap/security/2000-12",
"SOAP-SEC"));
env.addAttribute(Constants.URI_SOAP11_ENV,
"actor", "some-uri");
env.addAttribute(Constants.URI_SOAP11_ENV,
"mustUnderstand", "1");
SOAPHeaderElement header = new SOAPHeaderElement(
XMLUtils.StringToElement(
"http://schemas.xmlsoap.org/soap/security/2000-12",
"Signature", ""));
env.addHeader(header);
Document doc = soap2dom(env);
KeyStore ks = KeyStore.getlnstance("JKS");
FilelnputStream fis = new FileInputStream(".keystore") ;
ks.load(fis, keystorePassword.toCharArray());
PrivateKey privateKey = (PrivateKey)ks.getKey("mykey",

355

356

Web- Java
privateKeyPassword.toCharArray());
Element soapHeaderElement =
(Element)((Element)doc.getFirstChild()).
getElementsByTagNameNS("*", "Header").item(O);
Element soapSignatureElement =
(Element)soapHeaderElement.
getElementsByTagNameNS("*", "Signature").item(O);
XMLSignature sig = new XMLSignature(doc,
"http://xml-security",
XMLSignature.ALGO_ID_SIGNATURE_DSA);
soapSignatureElement.appendChild(sig.getElement());
sig.addDocument("#Body");

X509Certificate cert =
(X509Certificate)ks.getCertificate(certificateAlias);

sig.addKeylnfo(cert);
sig.addKeylnfo(cert.getPublicKey());
sig.sign(privateKey);
Canonicalizer cl4n = Canonicalizer.getlnstance(
Canonicalizer.ALGO_IDJ^4N_WITH_COMMENTS);
byte[] canonicalMessage = cl4n.canonicalizeSubtree(doc);
InputSource is = new InputSource(
new Java.io.ByteArraylnputStream(canonicalMessage));
DeserializationContextlmpl dser = null;
AxisClient tmpEngine =
new AxisClient(new NullProvider());

8.

357

MessageContext msgContext =
new MessageContext(tmpEngine);
dser = new DeserializationContextlmpl(is,
msgContext, Message.REQUEST);
dser.parse();
}catch(Exception e) {
e.printStackTrace() ;
throw new RuntimeException(e.toString());

private static Document soap2dom(S0APEnvelope env)


throws Exception{
StringWriter writer = new StringWriter();
SerializationContextlmpl ctx =
new SerializationContextlmpl(writer);
env.output(ctx);
writer.close();
Reader reader = new StringReader(writer.getBuffer().toString()
Document doc = XMLUtils.newDocument(new InputSource(reader));
if (doc == null) throw new Exception();
return doc;


XML. ,
, XML.

SOAP-
SOAP- XML, , -

358

Web- Java

.
, , ,
XML, . SOAP-
XML.
, SOAP- , Web-, .
SOAP-,
Web-.
SOAP.
SOAP, , IBM 2000 .
"SOAP Security Extensions"
http://www.trl.ibni.com/projects/xinl/soap/wp/wp.html. ,
XML <Encryption>, <Signature> <Authorization> http://schemas.xmlsoap.org/soap/security/.
<Header> SOAP-.
<Encription> <DecryptionInfo>,
"XML Encryption"
http://www.w3.org/2000/10/xmlenc. SOAP.
<signature> <ds:Signature>, "XML Signature" http://www.w3.org/2000/02/xmldsig*.
"SOAP Security Extensions" SOAP-.
<Authorization> ,
, .
SOAP, IBM Microsoft
2001 , . "SOAP Security Extensions: Digital Signature" -
http://www.w3.org/TR/SOAP-dsig/.

<signature>, "SOAP Security


Extensions". <signature>, http://schemas.xmlsoap.org/soap/security/2000-12,
<ds:Signature>,

http://www.w3.org/2000/09/xmldsig*.
, "SOAP Security Extensions: Digital Signature"
<Signature> <Header> SOAP-

8.

359

, Web.
, 2002 SOAP
"WS-Security", IBM, Microsoft
VeriSign. .

"WS-Security"
"Web Services Security", "WS-Security",
http://www-106.ibm.com/developerworks/webservices/
library/ws-secure/. , -
.
<security>
http://schemas.xmlsoap.org/ ws/2002/04/secext.
"WS-Security", 2002 , , "WS-Security Addendum".
http://msdn.microsoft.com/webservices/.
, http://schemas.xmlsoap.org/
ws/2002/07/secext. "WS-Security".
<security>, "WS-Security", . XML, <Encryption>, <Signature>,
<Authorization>, SOAP.
,
<EncryptedData>, <ds: signature>, "XML
Encryption" RFC 3275. ,
<Security>, SOAP-. "WS-Security" , , .

<UsernameToken> <0sername>
<Password>. <Password>
. :
"PasswordText" ,
"PasswordDigest"
Base64. SHA-1.

, : <Nonce>
16- , , -

360

Web- Java

<created> ,
. SOAP-
:
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
<soap:Header>
<wsse:Security>
<wsse:UsernameToken>
<wsse:Username>Ivan</wsse:Username>
<wsse:Password Type="wsse:PasswordDigest">
vb2zDRGHjopcDfXn4Beg6Unm4Hm=
</wsse:Password>
<wsse:Nonce>
5uW4ABku/m6/S5rnE+L7vg==
</wsse:Nonce>
<wsu:Created xmlns:wsu=
"http://schemas.xmlsoap.org/ws/2002/07/utility">
2002-11-13T09:00:OOZ
</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<! >

8.

361

</soap:Body>
</soap:Envelope>
, , ,
"WS-Security" <BinarySecurityToken>. , ,
, .509,
Base64:
<wsse:BinarySecurityToken
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext"
I d = " c e r t " ValueType="wsse:X509v3"
EncodingType="wsse:Base64Binary">
MIIEZzCCA9CgAwIBAgIQEmtJZcO...
</wsse:BinarySecurityToken>
, , , <BinarySecurityToken>,
<ds:KeyInfo>.

<security>, SOAP-,
. <security> <SecurityTokenReference>, <Reference> .
URI URI. :
<wsse:SecurityTokenReference
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
<wsse:Reference
URI="http://www.some.com/fl.xmltttokenl" />
<wsse:KeyIdentifier wsu:Id="akey"
ValueType="wsse:X509v3" EncodingType="wsse:Base64Binary">
MIIEZzCCA9CgAwIBAgIQEmtJZcO...
</wsse:KeyIdentifier>
</wsse:SecurityTokenReference>

362

Web- Java

<KeyIdentifier> <ds:KeyName>,
<ds:Keyinfo>
.
<SecurityTokenReference>
<security>, <ds:Keyinfo> .
<ds: Keyinfo>
<Security>, <ds: Signatures
SOAP-
, .
"WS-Security Addendum" <Timestamp>.
http://schemas.xmlsoap.org/ws/2002/07/utility.
<Timestamp> <Created>, <Expires>
<Received> , SOAP- .
dateTime XSD.
UTC, vaiueType, , XML. :
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
<soap:Header>
<wsu:Timestamp>
<wsu:Created>2002-ll-13T08:42:00Z</wsu:Created>
<wsu:Expires>2002-12-13T09:00:00Z</wsu:Expires>
<wsu:Received Actor="http://some.com/" Delay="60 000">
2002-ll-13T08:44:00Z
</wsu:Received>
</wsu:Timestamp>
</soap:Header>
<soap:Body>
</soap:Body>
</soap:Envelope>

8.

363

?
, "WS-Security"
SOAP-,
SOAP-. . IBM
Microsoft
Web-.
, "WS-Security":
"WS-Policy"
. ,
, ,
.
.
"WS-Trust" Web-, .
G "WS-Privacy", "WSSecurity", "WS-Policy" "WS-Trust", SOAP.
IBM Microsoft , "WS-Policy", "WS-Trust"
"WS-Privacy". .
"WS-Secure Conversation" , , .
"WS-Federation" .
"WS-Authorization"
.

, , . Web-. ,
Web-.

Web Services
, , ,
Web Services . XML , HTTP, .
. . Web Services .
Web Services, Web.
Web Services. , " ", Web- SOAP, WSDL UDDI.

SOAP
1.2 SOAP. ,
, .
, 3,
SOAP 1.2, 2002 . ,
,
(extensions) SOAP.
SOAP 1.2 :
encodingstyie <Enveiope>, actor

9. Web Services

365

role, mustunderstand
" t r u e " "false". , HTTP SOAPAction, MIME- application/soap+xml,
<Fauit>.
3.
SOAP 1.2, , SOAP, SOAP 1.1. , Apache Axis
SOAP 1.2. 1.2
,
.
SOAP, -, XML, "XMLP" (XML
Protocol). ,
. , Web-
SOAP 1.2.

http://www.w3.org/TR/xp/.

WSDL
1.1 Web WSDL, 2002 WSDL 1.2. http://www.w3.org/TR/wsdll2.
WSDL XML SOAP 1.2.
, , ,
Web-. WSDL, 4, WSDL 1.2.
WSDL 1.2,
. , ,
. ,
, WSDL- Web-
. WSDL 1.1.
.

http://www.w3.org/ws/desc/.

WSDL

366

Web- Java

UDDI
UDDI , UDDI 2.0, . 2002
3.0 UDDI.
"UDDI
Version 3.0
Published
Specification",

http://uddi.org/pubs/uddi_v3.htm.
, (affiliate)
. . , , . .
operationalinfo. .
UDDI 3.0 , , ,
.
UDDI Web-, WSDL.
UDDI API,
. 5,
UDDI 3.0.
UDDI 3.0
,
UDDI. 3.0 2.0, ,
.
, UDDI.
UDDI
http://www.uddi.org/.


Web-
SOAP, WSDL UDDI. Web
Services, 2, " ". HTTP.
Web- XML
WWW. Web, XML WWW. XML-RPC, DIME, WS-Routing, WS-

9. Web Services

367

Inspection, WS-Security.
IBM Microsoft OASIS. .
Web Services, , IBM. , , ,
-.

WSFL
WSFL (Web Services Flow Language)
IBM : Web-, - (flow
model), Web- (global
model). SEI- Web-. WSDL-
Web-.
WSFL http://www-4.ibm.com/
software/solutions/webservices/pdf/WSFL.pdf.
WSFL XML <definitions>,
<fiowModei>, ,
<giobaiModei>, Web-. ,
<import>
<serviceProviderType>.

- , <flowModei>.
<fiowsource>, <flowSink>. <serviceProvider> Web-,
, <activity> ,
Web-. , .
<controlLink>, <dataLink>.
Web- source
target .
Web- , <giobaiModei>. Web-
<serviceProvider>, <piugLink>, <source> <target>, Web, .
9.1 WSFL.

368

Web- Java

' 9.1. WSFL


d e f i n i t i o n s name="">
<import namespace="" location="" /> [*]
<serviceProviderType name="">

[*]

<portType name="" /> [*]


<import namespace="" location="" /> [*]
</serviceProviderType>
<serviceProvider name="">
<portType name="" />
</serviceProvider>
<flowModel name="" serviceProviderType=""> [*]
<flowSource name=""> [?]
<output name="" message="" />
</flowSource>
<flowSink name=""> [?]
<input name="" message="" />
</flowSink>
<serviceProvider name="" type="" /> [+]
<export lifecycleAction=""> [*]
<source portType="" operation=""> [?]
<target portType="" operation=""> [?]
<map

/>

</target>
<ref > [*]

9. Web Services

369

<plugLink> [?]
csource portType="" operation="" /> [?]
<target portType="" operation="" /> [?]
<map /> [?]
<locator> [?]
</plugLink>
</export>
<activity name=""> [*]
<input name="" message="" />
<output name="" message="" />
<performedBy serviceProvider="" />
<implement>
<internal> I <export>
<export portType="" operation="">
<map

/>

</export>
</implement>
<join condition="" />
<materialize>
<mapPolicy> I <construction>
</materialize>
</activity>
<datalink name="" source= "" target="" /> [*]
<controlLink name=""

source=""

target="" /> [*]

</flowModel>
<globalModel name="" serviceproviderType="">
OerviceProvider name="" serviceProviderType="">
. 748

370

Web- Java
<export>
<source portType="" operation="" />
<target portType="" operation="" />
</export>
<locator type="" service="" />
</serviceProvider>
<plugLink>
<source serviceProvider="" portType="" operation^"" />
<target serviceProvider="" portType="" operation="" />
</plugLink>

</globalModel>
</definitions>

, WSFL SOAP- Web-.


Microsoft -,
WSFL. XLANG BizTalk. XLANG
http://msdn.microsoft.com/library/.

- BPEL4WS
IBM XLANG BPEL4WS
(Business Process Execution Language for Web Services), WSFL XLANG. BPEL4WS
http://www-106.ibm.com/developerworks/library/ws-bpel/.
BPEL4WS Web-, , Web- <portType>
WSDL. BPEL4WS <process>. (activity). - Web Web- <invoke>, <wait>,
<receive>, <repiy>, <assign>.

9. Web Services

371

, <sequence>, <switch>, <while>, <flow>,


<pick>,
Web-, BPEL4WS.
<throw> <catch> , , <f auit> WSDL.
BPEL4WS , Web-,
WSDL,

<serviceLinkType>,
http://schemas.xmlsoap.org/ws/2002/07/service-link/. <definitions> WSDL-.
<roie>,
WSDL- Web-, , .
Web-, , <partner>, <partners>, ,
, <process>.
9.2 <process>.
9.2. <process> BPEL4WS
<process>
<partners> [?]
<partner name="" serviceLinkType="" myRole=""
</partners>
<containers> [?]
<container name="" messageType="" /> [+]
<message> [*]
</container>
</containers>
<faultHandlers> [?]
<catch faultName="" faultContainer="">
<reply partner="" portType="" operation=""

372

Web- Java
container="" faultName="" /> [*]
</catch>
<catchAll> [?]

</faultHandlers>
<correlationSets> [?]
ccorrelationSet name="" properties=""> [+]
</correlationSets>
<compensationHandler>
<compensate> | <>
</compensationHandler>
<flow>
<links>
<link name="" /> [*]
</links>
<pick> [*]
<onMessage> [+]
<onAlarm> [*]
</pick>
<sequence>

[*]

<assign>
<copy>
<from container="" part="" />
<to container=""
</copy>
</assign>

part="" />

9. Web Services
<invoke

partner="" portType="" operation=""


inputContainer="" outputContainer="">

<source linkName="" />


<correlations> [?]
<catch> [*]
<catchAll> [+]
<compensationHandler> [?]
</invoke>
<receive partner="" portType="" operation=""
container="">
<source linkName="" /> [*]
</receive>
<reply partner="" portType="" operation=""
container="">
<correlations> [?]
<target linkName="" /> [*]
</reply>
</sequence>
<switch> [*]
<case condition="" /> [+]
<otherwise> [?]
</switch>
<throw faultName="" faultContainer="" />
<wait for="" until="" />

373

374

Web- Java

<while condition=""> [*]


</flow>
</process>

IBM BPEL4WS
Web- -. BPWS4J,
BPEL4WS. , BPEL4WS,
BPEL4WS,
BPEL4WS, BPEL4WS. BPWS4J
http://www.alphaworks.ibm.cora/tech/bpws4j/.

WS-Coordination
WS-Coordination, IBM, Microsoft
BEA Systems,
, , .
http://www.ibm.com/developerworks/library/ws-coor/.
[10] ,
.
(coordination protocols).
.
Web- (coordination service).
. Web- .
Web- SOAP-
<createCoordinationContext>. ,
<Activationservice>.
<CoordinationType> <RequesterReference>

, .
, ,
http://schemas.xmlsoap.org/ws/2002/08/wscoor.
Web- SOAP <CreateCoordinationContextResponse>,

<RequesterReference>,

<coordinationcontext>, Web , , .

9. Web Sen/ices

375

SOAP-, Web- ,

<coordinationcontext>.

<CoordinationContext> <CoordinationType>, , <RegistrationService>,


, <Address>, URI-
Web- .
, Web- . Web- SOAP <Register>,
<Registrationservice> , Web- , <Protocoiidentifier>,

<ParticipantProtocoiservice>, Web-, , ,
<RequesterReference>.
Web- SOAP- <RegisterResponse>, <RequesterReference>
<coordinatorProtocoiservice>, Web, , Web-
.
Web-,
.
WS-Coordination Web- .
. WSTransaction, ,
.

WS-Transaction
WS-Translation, IBM, Microsoft
Systems, , WS-Coordination:

AT (Atomic Transaction)
(Business Activity).
http://www.ibm.com/developerworks/library/ws-transpec/.
AT " ".
WS-Coordination. <wscoor:CoordinationType>,
, http://schemas.xmlsoap.org/
ws/2002/08/wstx. -

376

Web- Java

, , [10] .

WS-Coordination, ,
SOAP- <Prepare>, <ReadOnly>, <Coimnit>, <Rollback>,
<OnePhaseCommit>, <phasezero>, http://schemas.xmlsoap.org/ws/2002/08/wstx. Web- SOAP- <Prepared>, <Aborted>,
<Coiranitted>, <Notified>, <PhaseZeroCompleted>, <Unknown>.
<sourceProtocolService>
<TargetProtocoiService>, Web-, . Web- , .
, , ,
-, , , BPEL4WS. , <wscoor:CoordinationType>,

http://schemas.xmlsoap.org/ws/2002/08/wstx.
- , .
WS-Transaction <compiete>,
<Close>, <Cancel>, <Compensate>, <Forget>, Web-
-,
<Completed>, <Closed>, <Compensated>, <Faulted>, <Exited>, <Unknown>, - . http://schemas.xmlsoap.org/
ws/2002/08/wsba. , Web- .

WS-I
Web Services . , Web-: SAML, WSXL, WSCL, WSCM, WSEL,
WSML, WSUI, WS-License, WS-Referral. ,
. . 2002 IBM
Microsoft , "Web Services Interoperability
Organization", WS-I.
,

9. Web Services

377

, , . WS-I

. http://www.ws-i.org/.
WS-I : , ,
, .
(interoperability profile)
/ ,
, . , Web-.
, WS-I,
XML Schema 1.0,
SOAP 1.1, WSDL 1.1 UDDI 1.2. "WS-Basic".

WS-Basic
WS-Basic Profile IBM, Microsoft BEA Systems.

http://www.wsi.org/Proffles/Basic/2002-lO/BasicProfile-l.O-WGD.htm. : SOAP-, WSDL,


UDDI . .

SOAP-
WS-1 WS-Basic :

SOAP 1.1;

XML 1.0 (Second Edition);

HTTP/1.1.

SOAP 1.1 <Fauit>. <Fauit> <fauitcode>,


<faultstring>, <faultactor> <detaii>. . <fauitcode> , SOAP 1.1.
encodingstyle SOAP- <Body> , http://schemas.xmlsoap.org/soap/envelope/.

378

Web- Java

SOAP- DTD,
<Body>.
, <Body>, . .
SOAP-
HTTP 1.1, POST.
HTTP-, "405 Method not
Allowed". <Fauit>
"500 Server Error", <Fauit> "200
" "202 Accepted".
"415 Unsupported Media Type",
content-Type MIME- text/xmi.
"307 Temporary Redirect",
.
HTTP, RFC 2774.
, SOAP 1.2.

WSDL
WS-Basic :
WSDL 1.1;
XML Schema 1.0.
Web, WSDL.
<import>
WSDL.
Web-.
<import> <definitions>
XSD. targetNamespace
.
namespace <import>. <import>
<types>.
<types> <definitions>
<import>. <types>
,
<import>.

9. Web Services

379

<message>
<part>, <Body>
SOAP-. element,
XSD- .

<part>, type
<part>. <part>,
, .
soiicit-response
notification.
(SOAP
binding) SOAP 1.1. <soap:binding> transport "http://schemas.xmlsoap.org/soap/http".
4.2. use "literal".
<soap:fault> <soap:headerfault>
part, <soap:fault> name.
.
WSDL 1.2.

UDDI
WS-Basic UDDI 2.0:
UDDI Version 2.04 API Published Specification;
UDDI Version 2.03 Data Structure Reference;
Version 2.0 UDDI XML Schema 2001;
UDDI Version 2.03 Replication Specification;
Published Specification, Version 2.03 Replication XML Schema 2001;
UDDI Version 2.03 XML Custody Schema;
UDDI Version 2.01 Operator's Specification, Published Specification.
WS-Basic
Web-, WSDL, UDDI.

<wsdi:port>
<uddi:bindingTempiate> UDDI.

380

Web- Java

l o c a t i o n <wsdi:port>
accessPoint <uddi:bindingTemplate>.
, <uddi:businessservice> WSBasic. <keyedReference>,
<categoryBag>, ws-i-org:conformsTo
"http://wwww.ws-i.Org/profiles/base/l .0".
<tModei> WSDL. <overviewURL>,
<tModei>, WSDL, 5.5. , <tModei>
WSDL. <categoryBag>
uddi-org: types "wsdlSpec".
WS-Basic UDDI 3.0.

WS-Basic
HTTPS, :
Q HTTP Over TLS ( RFC 2818);
TLS Protocol Version 1.0 ( RFC 2246);

SSL Protocol Version 3.0;

Internet X.509 Public Key Infrastructure Certificate and CRL Profile ( RFC 2459).
, . Web- .
, WS-Basic
Web-. Web Services.
. WS-I , . http://www.ws-i.org/.

?
. Web, -

9. Web Services

381

. , Web- . ,
.
,
. ,
Web Services. Web- .
, Web Services. !

1.

., . Java XML. .:
, 2002. 400 , .

2.

. . XSLT. .: -, 2002.
544 , .

3.

. JavaServer Pages. .: "", 2002. 464 , .

4.

., A. XML Java 2. .: , 2001. 384 ,


.

5.

. XSLT. . .: -,
2002. - 1016 , .

6.

- . Java XML. .: -, 2002. 544 , .

7.

- P. Enterprise JavaBeans. 3- . .: , 2002. 672 , .

8.

. . .: , 2001. 352 , .

9.

. . Java. .: -, 2001.
464 , .

10. . . Java 2.
.: -, 2002. - 704 , .
11. . JavaServer Pages. .: , 2001. 496 ,
.
12. . . Web-
, 2002. 336 , .

Microsoft.NET.

.:

13. ., . . Java.
. .: "", 2001. 528 , .
14. Bequet H. et al. Beginning Java Web Services. Wrox Press, 2002. 411 p.

383

15. Bequet H. Professional Java SOAP. Wrox Press, 2002. 400 p.


16. Cable S. et al. Professional Java Web Services. Wrox Press, 2002. 600 p.
17. Chappell D., Jewell T. Java Web Services. O'Reilly & Ass., 2002. 276 p.
18. Deitel H. M. et al. Java Web Services For Experiences Programmers.
Prentice Hall, 2002. 500 p.
19. Developing Java Web Services with Java APIs for XML using WSDP.
Syngress Media, 2002. 501 p.
20. Englander R. Java and SOAP. O'Reilly & Ass., 2002. 300 p.
21. Irani R., Basha S. J. AXIS: Next Generation Java SOAP. Wrox Press,
2002. - 250 p.
22. Jasnowski M. Java XML and Web Services Bible. John Wiley & Sons,
2002. - 1000 p.
23. Java Web Services Unleashed. SAMS Publ., 2002. 752 p.
24. Mogha R., Niit, Preetham V. V. Java Web Services Programming. John
Wiley & Sons, 2002. - 555 p.
25. Nagappan R. et al. Developing Java Web Services. John Wiley & Sons,
2002 - 800 p.
26. Simeonov G. et al. Building Web Services with Java: Making Sense of XML,
SOAP, USDL, and UDDI. - SAMS Publ., 2001. - 600 p.
27. Wesley A. A. Programming Web Services with Java. Manning Publ.,
2002. - 325 p.

3DES 339

AlGamal 340
Apache SOAP 97, 135, 166, 206
Application server 86, 305
Axis 98, 101, H I , 135, 166, 167, 203, 353

BES 99
Binding language 63
Blowfish 339
BPEL4WS 370

DD- 170
Default namespace 25
Deployment 276
DES 338
Deserialization 148
DH340
DIME 164
Document type declaration 17
DOM 65
DOM API 53
dom4j 74
DSA 339
DSS 339
DTD 15,21

Castor 65
Components 25
Coordination protocols 374
CPA 121
CPP 120
CSS 14, 77

EAServer 86, 247


EBXMIRR 122
ebXML 113, 119, 183,212
Eclipse 166
EIS64
EJ- 305
EJB- 86
Empty element 18
Entity- 306
EXML 75
EXML+ 75

Data binding 54
DCD51
DDML51

Facets 29
Frontier 88
Fundamental facets 30

385

G
Generated stubs 295
GLUE 75, 99, 166, 206
Grammar parsing 52

1 I

Home- 309
HTML 14

1
IDEA 166, 339
Indri 235
Inquiry API 225
Interoperability profile 377

J
J2EE-cepnep 305
JAAS 342
Java XML Pack 23
JAXB 63
JAXM 98, 167, 247, 265, 269, 280
JAXP 23, 53, 62, 65, 75, 247
JAXR 127, 128, 167, 234, 247
JAX-RPC 98, 167, 170, 247, 281
JBoss 64, 86, 247, 305
JBuilder 99, 166
JCA 341
JCE 341
JDeveloper 99
JDO 54, 64
JDOM 74
JMS98, 265, 315
JSSE 342
JWSDL 206

Kodo JDO 64

L
Lexical parsing 52
List 28

M
MAC 340
Mapping file 65

MD5 340
MDB315
MDB- 307
Message 92
Messaging provider 265
Microsoft SOAP Toolkit 99
Model group 35
MSXML 23

N
Namespace 23

OC4J 99
Open Fusion 64
Orbix E2A 86, 247

P
P2P 265, 279
Parser 52
Port 283, 322
Processing instructions 51
Publish API 226

Q
QName 24
Qualified name 28
Qualified Name 24

RC6 339
Relax 51
RELAX NG 51
Remote- 308
Restriction 28
Root element 17
RPC- 93
RSA 339

s
SAAJ 98, 167, 247, 252, 280
SAX 53, 62
SAX API 53
SAX2 53

386
Schematron 51
SEI- 283, 323
Serialization 148
Servant 284
Servlet 274
Session- 306
SGML 15
SHA-1 340
SMTP 97
SOAP 92, 97, 134
SOAP nodes 136
SOAP.rLite 135
SOAP4J 97
SOAP- 136
SOX 51
SSI 14
SSL 342
Stub 282
Sun ONE Studio 98

Target namespace 46
Tie 282
TLS 342
Token 52
Tomcat 112, 206, 247, 294, 305
TREX 51
Triple-DES 339
Twofish 339

UDDI 113, 183,212


UDDI Business Registry 113, 212
UDDI4J 116,228
Union 28
UUID213

Validating parser 23
VPN 343
w
Web Services 87
WebLogic 64, 86, 247, 305
WebSphere 23, 64, 86, 247, 305


WebSphere Studio 98, 166
Web- 305
Web- 274, 305
Web- 86
Web- 88
Web- 88
WS4EE 322, 323
WS-Basic 377
WS-Coordination 374
WSDL 176, 183
WSDL4J 112,206
WSDP 98, 234, 247, 252, 291
WSEI- 310
WSFL 367
WSIF 112, 206
WSIL 123
WSIL4J 125
WS-Inspection 113, 123
WS-Routing 136, 266
WSTK98, 111, 167,203, 228
WS-Translation 375

X.509 341
Xalan 75
XDR51
Xerces 23, 24, 50, 74
XHTML 25
Xindice 127, 234
XML 15
XML declaration 17
XML Schema 23, 25
XML schema instance 48
xml4j 23
XMLP 97
XML-RPC 88, 97
XML- 93
XP97
XPath 81
XSchema 51
XSD21, 39
XSL 75, 77
XSL FO 81
XSLT 75
XSS4J 352
XSV50

387

283
48
18

30
37
137

48
52

148
93

282
18

28
54
XML 17
17
18

52
283, 322
- 3247
92
265
23
26
26
23
25
377
93
18

24
UDDI , 212

XML 27
51
Web- 310
64

25
17

52

282
54
86, 305
274
148
26
26
284
374
28
28
22
21
XML 23, 25

35

18

388

276
24

29

1
46

48
XML 18

1600
- www.computerbook.ru
* UompulerBQOK-iu - Microsoft Internet Explore!

"-! "

- ' -P *

>)**

4!

I >>

cipaa

-
V


20


(S3

--
Computetbook .iu
16 .

Microsoft Office XP

: 1636
: 11
: 1

**

"-"

Web-. XML
: i

"-"

Copyright tompviieAook.iu.2001

1600
,

!
" - "

:
=> : (812) 541-85-51 ( " ")
=> : (812) 541-84-61 ( " ")
=> : 199397, -, / 194
=> E-mail: trade@bhv.spb.su
Internet , ,
-
( ),

, , .

, "-"

'.bhv.ru

: , 199397, -, / 194; Web-: www.bhv.ru

!
"-"
.
, ,
, ,
,


"-"
,
,
.



.: (812) 251 4244, 251 6501
e-mail: kat@bhv.ru
: (812) 2511295

Mc
i rosoft* =*=
Access

-: www.bhv.ru (812) 251-42-44


-: www.computerbook.ru
: trade@bhv.spb.su

5 . 2000 . :
, .
1 9
1 11 .

- .

I l l (11

({V

*1

\ * *

'lit inii*81 i

3W"'

!}.: "
^

14


" ( . .,
. )

.

.
,

, , .
,

.
4
- .

5 . 2000 . :
, .
1 9
1 11 .

S."
f!<{ f -ti\1i* ( 4*4,1*
1(()1"1

- < ^

56 7
8



.
,
QBasic. ,
,
.
, , ,
MS-DOS,
Windows, , , , .
, .
,
- .

"-"
:
" "
. . MS Windows XP: Home Edition Professional
. . Windows 2000 Professional.
. . Microsoft Windows 2000 Server.
. . Windows 2000
. . Microsoft Windows 2000 Server Professional.

P. Macromedia ColdFusion
. HTML 3.2 ( -)
. Java ( -)
. -
" ": "MS Office XP ", "MS Access 2002",
"MS Word 2002", "MS Excel 2002"
. Microsoft Word 2002
., A. Delphi 6
. MS Excel 2002
. .
., . PC,
4-
. MS SQL Server 2000
. . HTML 4.0
., . Microsoft Access 2000
., . Microsoft Access 2002
., A. Microsoft Office 2000
., A. Microsoft Office XP
., . Java 2
. Web-
P. Word 97
., . XML
. Adobe Illustrator 9.0
. Adobe Photoshop 6.0
. CorelDRAW 9
. Macromedia FreeHand 9
. WAP:
. PC ( )
P. Python ( -)
. ., A. A. Adobe PageMaker 7.0
. ., A. A. Adobe InDesign
. ., A. A. CorelDRAW 9:
. ., A. A. CorelDRAW 10:
. Microsoft SQL Server 7.0

848 .
700 .
960 .
576 .
1056 .
672 .
1040 .
1104 .
32 .

992
1152 .
1072
1008 .
1024 .
1280 .
672 .
1088 .
1040 .
728 .
928 .
1072 .
1024 .
1120 .
736 .
608 .
832 .
576 .
432 .
432 .
1248 .
768 .
784 .
704 .
1136 .
1136 .
720 .

. . Active Server Pages ( -)


. Microsoft Outlook 2002
. CorelDRAW ( -)

672 .
656 .
704 .

""
CD-ROM " MS Windows NT Server 4.0"
" Windows NT Server 4"
Microsoft Press. .
2- ( -)
Microsoft Press. Visual Basic 6.0
Microsoft Press. MS Windows NT Server 4.0
. Dynamic HTML ( -)
.
. Linux
. -: , ,

. Windows
. Windows 98 ( )
. .
. XSLT
. Internet 2000
. Novell GroupWise 5.5:

A. Microsoft Excel 2000:
A. Excel, VBA, Internet
., . Web- Java JavaScript
. Windows ( )
., . Delphi
. . Delphi 5 ( )
. JavaScript Web-
. . MS Excel
.
Excel 97/2000 ( )
. -
. Shareware:

. .
. Borland C++ 5
. Web-
. DirectX. Delphi ( -)
. Open GL Delphi ( )
.
Java
. 3ds max 4:
. MS Office Project
. . Motorola
. . , ,
.

368 .
992 .
752
496 .
384 .
496 .
256 .
250 .
496 .
320 .
432 .
448 .
480 .
576 .
816 .
1040 .
384 .
656 .
784 .
880 .
304 .
416 .
480 .
320 .
320 .
976 .
592 .
416 .
352 .
336 .
448
400
560
304
624

.
.
.
.
.

A. Maple 6.

., . "" PC ( )
., . Visual C++ MFC,
2- ( )
. Web- MS Office 2000
., .

., . Microsoft Access 2000:
. . Microsoft Office 2000:
. Access 97 ( -)
. .

., . IP-
. . -
Delphi ( )
. Visual LISP AutoCAD
. ActiveX Delphi
. Adobe InDesign:
. Windows Scripting Host
. 3D Studio MAX 3.0
( -)
.
., . PC: , ,
2-
. .
. SVGA- IBM
. Photoshop Plug-Ins
. MS SQL Server 2000:
. SQL Server 7.0:
.
Visual C++ ( )
. ATL 3.0 ( )
., . ADO Delphi ( -)
. , , Web Linux
A. Windows 2000 Active Directory
. Java ( -)
. Web-
. -
. Web-. XML
. C++
., .
. , , ( -)

528 .
720 .
1040 .
320 .
560 .
832 .
680 .
656 .
512 .
512 .
432 .
576 .
320 .
544 .
320 .
352 .
512 .
336 .
352 .
432 .
464 .
368 .
370 .
256 .
928 .
816 .
416 .
400 .
400 .
224 .
224 .
304 .
416 .
464 .

" BHV"
. Internet , 2-
A. Adobe Photoshop 5.0 ( )

752 .
448 .

""
., . Visual Basic 6.0
.
. VBA
. .
. JavaScript
. Excel 2000 ( )
. Macromedia Dreamweaver 4
. Macromedia Flash 5
., . : , ,
( )
. Adobe Premiere 6.0
. MathCAD 2001
. Microsoft Internet Explorer 6.0
. 4
. Object Pascal
Delphi 6 ( )
. .
Turbo Pascal 7.0 Delphi, 2- ( )
. UML
., . Perl
., . Microsoft FrontPage 2002
., . Windows 2000 Professional
., . Windows Millennium
. 3D Studio MAX 4.0
. AutoCad 2000 Visual LISP,
2-
. AutoCAD 2002
. Kylix
. Visual C++ 6 ( )
. #
. WML WMLScript
. ., . . Adobe Photoshop 6
( )
. ., . . CorelDRAW 10
. MFC ( )
. Java
. Microsoft Word 2002
. .
. HTML 4
. C++, 3- ( )

624 .
448 .
512 .
640 .
512 .
368 .
560 .
368 .
480 .
432 .
544 .
288 .
576 .
528 .
416 .
304 .
432 .
576 .
528 .
464 .
370 .
672 .
608 .
416 .
960 .
576 .
240 .
608 .
640 .
640 .
464 .
624 .
272 .
288 .
512 .

" "
. PC
. Web-
. Web-

352 .
512 .
288 .

.
., . PC
., . PC
., . PC. Cakewalk Pro Audio 9.

., . PC. Cakewalk.
""
., . .

., . PC

320
272
256
420

.
.
.
.

272 .
608 .
240 .

" "
.
( -)
.
. ,
2-
. C/C++
. Turbo Pascal
.
. Unix
.
. .
. .
MOTOROLA
.
.

464 .
240 .
512 .
288 .
256 .
432 .
528 .
224 .
464 .
512 .
528 .
592 .

""
.
.
. ,

304 .
288 .
304 .

" "

. .
., A. Delphi.
. JavaScript.
. Microsoft Excel.
., . . Microsoft Access.

480 .
288 .
336 .
208 .
304 .


5 . 2000 . :
, .

! t i ' M f i It |'

;1>.

Logo Logo,

.


. .
Logo . .,
. .
56 .

Вам также может понравиться