/
ch07.txt
1741 lines (1386 loc) · 50 KB
/
ch07.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
chapter: Providing SOAP-Based Web Services
==================
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
<endpoint name="HelloService"
implementation="com.soacookbook.ch04.HelloServer" url-pattern="/hello" />
</endpoints>
====================================
<wsdl:definitions targetNamespace="http://example.org/ns";
xmlns:apachesoap="http://xml.apache.org/xml-soap";
//...
<element name="anImage">
<complexType>
<sequence>
<element name="image" type="apachesoap:Image">
<sequence>
<complexType>
</element>
====================================
@WebService
(endpointInterface="com.soacookbook.MyGeneratedInterface",
wsdlLocation="/META-INF/wsdl/MyWsdl.wsdl")
public class MyService implements MyGeneratedInterface { ... }
====================================
<binding name="CartEJBPortBinding" type="tns:CartEJB">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="getVersion">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
====================================
<message name="authorSearch">
<part name="parameters" element="tns:authorSearch"></part>
</message>
<message name="authorSearchResponse">
<part name="parameters" element="tns:authorSearchResponse"></part>
</message>
<portType name="Catalog">...</portType>
====================================
[ERROR] Non unique body parts! In a port, as per BP 1.1 R2710 operations must have unique operation signaure on the wire for successful dispatch. In port CatalogPort, Operations "authorSearch" and "add" have the same request body block {http://ns.soacookbook.com/catalog}author. Try running wsimport with -extension switch, runtime will try to dispatch using SOAPAction
line 70 of http://localhost:8080/CatalogService/Catalog?wsdl
====================================
Testcase: searchByAuthorTest(com.soacookbook.catalog.test.CatalogTest):
Caused an ERROR
Cannot find dispatch method for Request=[SOAPAction="",Payload={http://ns.soacookbook.com/catalog}author]
javax.xml.ws.soap.SOAPFaultException: Cannot find dispatch method for Request=[SOAPAction="",Payload={http://ns.soacookbook.com/catalog}author]
====================================
<xs:schema xmlns:tns="http://ns.soacookbook.com/catalog" ...>
<xs:element name="searchAuthor" nillable="true" type="tns:Author"></xs:element>
<xs:element name="addAuthor" nillable="true" type="tns:Author"></xs:element>
<xs:complexType name="Author">
<xs:sequence>
<xs:element name="firstName" type="xs:string"></xs:element>
...
</xs:sequence>
</xs:complexType>
====================================
<message name="authorSearch">
<part xmlns:ns4="http://ns.soacookbook.com/catalog" name="author" element="ns4:author"></part>
</message>
<message name="authorSearchResponse">
<part xmlns:ns5="http://ns.soacookbook.com/catalog" name="searchResults" element="ns5:searchResults"></part>
</message>
<portType name="Catalog">...</portType>
====================================
$ wsgen [options] service-implementation-class
====================================
package com.soacookbook;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
/**
* Used to manually run the wsgen tool against.
*/
@WebService(targetNamespace="http://ns.soacookbook.com",
name="GenCatalog", serviceName="GenCatalog")
public class CatalogToGen {
@WebMethod
@WebResult(name="title")
public String getTitle(
@WebParam(name="id") String id) {
return "King Lear";
}
}
====================================
javac com/soacookbook/CatalogToGen.java
====================================
$ wsgen -verbose -cp . -wsdl -servicename {http://ns.com/}Catalog \
-keep -r gen -s gen com.soacookbook.CatalogToGen
Note: ap round: 1
[ProcessedMethods Class: com.soacookbook.CatalogToGen]
[should process method: getTitle hasWebMethods: true ]
[endpointReferencesInterface: false]
[declaring class has WebSevice: true]
[returning: true]
[WrapperGen - method: getTitle(java.lang.String)]
[method.getDeclaringType(): com.soacookbook.CatalogToGen]
[requestWrapper: com.soacookbook.jaxws.GetTitle]
[ProcessedMethods Class: java.lang.Object]
com\soacookbook\jaxws\GetTitle.java
com\soacookbook\jaxws\GetTitleResponse.java
Note: ap round: 2
====================================
<definitions targetNamespace="http://ns.soacookbook.com"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://ns.soacookbook.com"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<types>
<xsd:schema>
<xsd:import namespace="http://ns.soacookbook.com"
schemaLocation="GenCatalog_schema1.xsd"/>
</xsd:schema>
</types>
<message name="getTitle">
<part name="parameters" element="tns:getTitle"/>
</message>
<message name="getTitleResponse">
<part name="parameters" element="tns:getTitleResponse"/>
</message>
<portType name="GenCatalog">
<operation name="getTitle">
<input message="tns:getTitle"/>
<output message="tns:getTitleResponse"/>
</operation>
</portType>
</definitions>
====================================
<definitions targetNamespace="http://ns.com/" name="Catalog"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://ns.com/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<import namespace="http://ns.soacookbook.com" location="GenCatalog.wsdl"/>
<binding name="GenCatalogPortBinding"
type="ns1:GenCatalog" xmlns:ns1="http://ns.soacookbook.com">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document"/>
<operation name="getTitle">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="Catalog">
<port name="GenCatalogPort" binding="tns:GenCatalogPortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
</definitions>
====================================
<wsgen
sei="..."
destdir="directory for generated class files"
classpath="classpath" | cp="classpath"
resourcedestdir="directory for generated resource files such as WSDLs"
sourcedestdir="directory for generated source files"
keep="true|false"
verbose="true|false"
genwsdl="true|false"
protocol="soap1.1|Xsoap1.2"
servicename="..."
portname="...">
extension="true|false"
<classpath refid="..."/>
</wsgen>
====================================
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen">
<classpath path="jaxws.classpath"/>
</taskdef>
====================================
package com.soacookbook.catalog.ejb;
import com.soacookbook.ns.catalog.*;
import javax.ejb.*;
import javax.jws.*;
/**
* Basic Web Service does shopping cart operations.
*/
@WebService
@Stateless
@Local
public class CartEJB {
public Double getVersion() {
return 5.0;
}
}
====================================
<types>
<xsd:schema>
<xsd:import namespace="http://ejb.catalog.soacookbook.com/"
schemaLocation="http://localhost:8080/CartEJBService/CartEJB?xsd=1">
</xsd:import>
</xsd:schema>
</types>
====================================
<xs:schema xmlns:tns="http://ejb.catalog.soacookbook.com/"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
targetNamespace="http://ejb.catalog.soacookbook.com/">
<xs:element name="getVersion" type="tns:getVersion">
</xs:element>
<xs:element name="getVersionResponse" type="tns:getVersionResponse">
</xs:element>
<xs:complexType name="getVersion">
<xs:sequence></xs:sequence>
</xs:complexType>
<xs:complexType name="getVersionResponse">
<xs:sequence>
<xs:element name="return" type="xs:double" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
====================================
<service name="CartEJBService">
<port name="CartEJBPort" binding="tns:CartEJBPortBinding">
<soap:address location="http://localhost:8080/CartEJBService/CartEJB"></soap:address>
</port>
</service>
====================================
<portType name="CartEJB">
<operation name="getVersion">
<input message="tns:getVersion"/>
<output message="tns:getVersionResponse"/>
</operation>
</portType>
====================================
<binding name="CartEJBPortBinding" type="tns:CartEJB">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document">
</soap:binding>
<operation name="getVersion">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
====================================
@WebMethod(operationName = "add")
public int add(@WebParam(name = "i", partName="iPart")
====================================
@WebMethod
public @WebResult(name="doItOne") int
doIt(int x) {
return 1;
}
====================================
<message name="doItResponse">
<part name="parameters" element="tns:doItResponse"></part>
</message>
<portType name="Worker">
<operation name="doIt">
<input message="tns:doIt"></input>
<output message="tns:doItResponse"></output>
</operation>
</portType>
====================================
<xs:complexType name="doItResponse">
<xs:sequence>
<xs:element name="doItOne" type="xs:int"></xs:element>
</xs:sequence>
</xs:complexType>
====================================
@WebMethod
public boolean startBatch(){
return true;
}
====================================
<xs:schema xmlns:tns="urn:myNs"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0" targetNamespace="urn:myNs">
<xs:element name="startBatch" type="tns:startBatch" />
<xs:element name="startBatchResponse" type="tns:startBatchResponse" />
<xs:complexType name="startBatch">
<xs:sequence />
</xs:complexType>
<xs:complexType name="startBatchResponse">
<xs:sequence>
<xs:element name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
====================================
@WebMethod(operationName="update")
public void update(int status) {
System.out.println("The new status is: " + status);
}
====================================
<operation name="update">
<input message="tns:update" />
<output message="tns:updateResponse" />
</operation>
====================================
//Remember WebServiceRef only works in managed environment
@WebServiceRef(wsdlLocation="http://localhost:8080/CalculatorApp/CalculatorWSService?wsdl")
public CalculatorWSService service;
service.getCalculatorWSPort();
port.update(200);
====================================
<xs:element name="updateResponse" type="tns:updateResponse" />
<xs:complexType name="updateResponse">
<xs:sequence />
</xs:complexType>
====================================
@Oneway
@WebMethod(operationName="update")
public void update(int status) {
System.out.println("The new status is: " + status);
}
====================================
<message name="update">
<part name="parameters" element="tns:update" />
</message>
====================================
<operation name="update">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
</operation>
====================================
Example: Credit.xsd Credit Card Schema
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
version="1.0"
targetNamespace="http://ns.soacookbook.com/credit"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://ns.soacookbook.com/credit"
elementFormDefault="qualified">
<xs:element name="creditCard" type="tns:CreditCard" />
<xs:element name="authorization" type="tns:Authorization" />
<xs:annotation>
<xs:documentation xml:lang="en">
A Credit Card contains a number, a cardholder name,
and an expiry date. The date is just an XSD date,
and the others are custom types with constraints.
</xs:documentation>
</xs:annotation>
<xs:complexType name="CreditCard">
<xs:sequence>
<xs:element id="cardNumber" name="cardNumber"
type="tns:CardNumber"
minOccurs="1" maxOccurs="1"/>
<xs:element id="name" name="name" type="tns:Name" />
<xs:element id="expirationDate" name="expirationDate"
type="xs:date" nillable="true" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Name">
<xs:sequence>
<xs:element name="firstName" type="tns:NameString"/>
<xs:element name="middleInitial" type="tns:InitialString"
nillable="true"/>
<xs:element name="lastName" type="tns:NameString"/>
</xs:sequence>
</xs:complexType>
<!-- Names must be at least 2 characters, no more than 35
characters, and consist of alphabetic characters, hyphens,
single quotes, periods and spaces -->
<xs:simpleType name="NameString">
<xs:restriction base="xs:string">
<xs:minLength value="2" />
<xs:maxLength value="35" />
<xs:pattern value="[A-Za-z\-. ]{2,35}" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="InitialString">
<xs:restriction base="xs:string">
<xs:minLength value="0" />
<xs:maxLength value="1" />
<xs:pattern value="[A-Za-z]?" />
</xs:restriction>
</xs:simpleType>
<!--Just simple constraint to keep it this short.
Not good enough for real world.-->
<xs:simpleType name="CardNumber">
<xs:restriction base="xs:string">
<xs:pattern value="\^(\d{4}[- ]){3}\d{4}|\d{16}$" />
<xs:minLength value="10" />
<xs:maxLength value="16" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Authorization">
<xs:sequence>
<xs:element name="amount" type="xs:double"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
====================================
Example: Credit.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://ns.soacookbook.com/credit"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://ns.soacookbook.com/credit"
name="CreditService">
<types>
<xsd:schema>
<xsd:import namespace="http://ns.soacookbook.com/credit"
schemaLocation="Credit.xsd"/>
</xsd:schema>
</types>
<message name="authorizeRequest">
<part name="creditCard" element="tns:creditCard" />
</message>
<message name="authorizeResponse">
<part name="authorization" element="tns:authorization" />
</message>
<portType name="CreditAuthorizer">
<operation name="authorize">
<input message="tns:authorizeRequest" />
<output message="tns:authorizeResponse" />
</operation>
</portType>
<binding name="CreditAuthorizerPortBinding"
type="tns:CreditAuthorizer">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document" />
<operation name="authorize">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
<service name="CreditService">
<port name="CreditAuthorizerPort"
binding="tns:CreditAuthorizerPortBinding">
<soap:address
location="http://localhost:8080/soaCookbookWS/CreditService" />
</port>
</service>
</definitions>
====================================
Example: CreditService.java
package com.soacookbook.ch03.validate;
import com.soacookbook.ns.credit.*;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import org.apache.log4j.Logger;
/**
* Demonstrates a service that uses JAXB-generated types as
* parameters for a start-from-schema-and-java method.
* Uses Credit.wsdl and Credit.xsd.
*/
@WebService(
name="CreditAuthorizer",
serviceName="CreditService",
targetNamespace="http://ns.soacookbook.com/credit",
wsdlLocation="WEB-INF/wsdl/ch03/Credit.wsdl")
public class CreditService {
private static final Logger LOGGER =
Logger.getLogger(CreditService.class);
/** Creates an instance of CreditService.
*/
public CreditService() {
LOGGER.debug("Created provider instance.");
}
//business method
@WebMethod(operationName="authorize")
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,
use=SOAPBinding.Use.LITERAL,
parameterStyle=SOAPBinding.ParameterStyle.BARE)
public @WebResult(name="authorization",
targetNamespace="http://ns.soacookbook.com/credit")
Authorization
authorize(
@WebParam(name="creditCard",
mode=WebParam.Mode.IN,
targetNamespace="http://ns.soacookbook.com/credit")
CreditCard creditCard) {
LOGGER.debug("Authorizing.");
LOGGER.debug("Card Number: " + creditCard.getCardNumber());
//get data from compound type
String cardNumber = creditCard.getCardNumber();
//create custom type for return
Authorization auth = new Authorization();
//business logic here
if (cardNumber.startsWith("4")) {
auth.setAmount(2500.0);
} else {
auth.setAmount(0.0);
}
LOGGER.debug("Returning auth for amt: " + auth.getAmount());
return auth;
}
}
====================================
Example: SOAP Message Credit Card Request
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<creditCard xmlns="http://ns.soacookbook.com/credit">
<cardNumber>4011111111111111</cardNumber>
<name>
<firstName>Phineas</firstName>
<middleInitial>J</middleInitial>
<lastName>Fogg</lastName>
</name>
<expirationDate>2015-04-27-07:00</expirationDate>
</creditCard></S:Body></S:Envelope>
====================================
Example: SOAP Message XML for Authorization Return
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<authorization xmlns="http://ns.soacookbook.com/credit">
<amount>2500.0</amount>
</authorization>
</S:Body>
</S:Envelope>
====================================
Example: CreditCard.java
package com.soacookbook.ns.credit;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;
/**
* Java class for CreditCard complex type. Comments ommitted.
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CreditCard", propOrder = {
"cardNumber",
"name",
"expirationDate"
})
public class CreditCard {
@XmlElement(required = true)
protected String cardNumber;
@XmlElement(required = true)
protected Name name;
@XmlElement(required = true, nillable = true)
@XmlSchemaType(name = "date")
protected XMLGregorianCalendar expirationDate;
//getters and setters for each field ommitted.
====================================
<project name="soacookbookServer" default="all">
<property file="soacookbookServer.properties"/>
<!-- PATHS -->
<path id="cp">
<pathelement location="${classes.dir}"/>
<pathelement location="${gen.classes.dir}"/>
<pathelement location="${javaee.jar}"/>
<pathelement location="${common.jar}"/>
<pathelement location="${config.dir}"/>
<pathelement location="${commons.lang.jar}"/>
<pathelement location="${service.schemas.classes.dir}"/>
<pathelement location="${sun.ws.rt.jar}"/>
<pathelement location="${log4j.jar}"/>
<pathelement location="${client.jar}"/>
</path>
<path id="cp.test">
<!-- Added src.test.dir to allow a specific log4j.xml
file just for the tests -->
<pathelement location="${src.test.dir}"/>
<pathelement location="${test.classes.dir}"/>
<pathelement location="${junit.jar}"/>
<path refid="cp" />
</path>
<path id="srcs.path">
<pathelement path="${src.dir}" />
<pathelement path="${src.gen.dir}" />
</path>
<!-- BUILD TARGETS -->
<target name="all" depends="init,clean,prepare,
schema-class-gen,compile,build-war,deploy" />
<!-- INIT & TASK DEFS -->
<target name="init">
<echo message="Testing for glassfish root directory"/>
<fail>
<condition>
<not>
<available file="${javaee.jar}"/>
</not>
</condition>
Please open the user.properties file and set the
gf.root property to point
to your glassfish install directory.
(default /opt/glassfish on Linux and
c:/glassfish-v2 on windows)
</fail>
<echo message="Testing for gf.password.file setting in user.properties"/>
<fail>
<condition>
<not>
<available file="${gf.password.file}"/>
</not>
</condition>
Please open the user.properties file and set the gf.password.file property to point
to the absolute path on your machine of this file. This is required for the
glassfish deploy task (which does not work on relative paths).
</fail>
<echo message="Using Path Separator: ${path.separator}"/>
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
<classpath path="${junit.task.path}" />
<classpath path="${junit.jar}" />
</taskdef>
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath path="${xjc.task.path}"/>
</taskdef>
<taskdef name="gf-deploy"
classname="org.apache.tools.ant.taskdefs.optional.sun.appserv.DeployTask"
classpath="${deploy.cp}" />
</target>
<!-- END INIT -->
<!-- CLEAN -->
<target name="clean">
<echo message="-----Cleaning-----" />
<delete dir="${dist.dir}"/>
<delete dir="${build.dir}"/>
<delete dir="${test.dir}"/>
<delete dir="${src.gen.dir}" />
</target>
<!-- PREPARE -->
<target name="prepare">
<mkdir dir="${dist.dir}"/>
<mkdir dir="${build.dir}"/>
<mkdir dir="${ear.lib.dir}"/>
<mkdir dir="${src.gen.dir}"/>
<mkdir dir="${classes.dir}"/>
<mkdir dir="${gen.classes.dir}"/>
<mkdir dir="${ejb.dependencies.classes.dir}"/>
<mkdir dir="${test.dir}"/>
<mkdir dir="${test.classes.dir}"/>
<mkdir dir="${test.report.dir}"/>
</target>
<!-- RUN JAXB TO GENERATE JAVA FROM SCHEMA-->
<target name="schema-class-gen">
<echo message="---Generating Java src from Schema---" />
<xjc destdir="${src.gen.dir}"
extension="false">
<schema dir="${schemas.dir}"
includes="**/*.schemalet,
${schemas.includes.pattern}"/>
</xjc>
</target>
<!-- COMPILE CLASSES-->
<target name="compile">
<echo message="-----Compiling-----" />
<javac compiler="modern" debug="${debug}" fork="true"
source="${source.java.version}"
target="${target.java.version}"
excludes="**/client/**"
destdir="${classes.dir}">
<src path="${src.gen.dir}"/>
<src path="${src.dir}"/>
<classpath refid="cp"/>
</javac>
</target>
<!-- BUILD WAR -->
<target name="build-war">
<echo message="-----Building WAR-----" />
<war destfile="${build.dir}/${war.name}"
webxml="${webinf.dir}/web.xml">
<manifest>
<attribute name="Manifest-Version" value="1.0"/>
<attribute name="Built-By" value="${user.name}"/>
</manifest>
<webinf dir="${config.meta.inf.dir}"
includes="**/*.wsdl,**/*.xsd"/>
<lib file="${client.jar}" />
<classes dir="${build.dir}/classes"
excludes="**/ejb/**"/>
<fileset dir="${root.dir}/jsp" includes="*.jsp" />
</war>
</target>
<!-- DEPLOY TO GLASSFISH-->
<!-- Undeploy happens automatically on a new deploy so it
does not need to be called explicitly -->
<target name="deploy">
<echo message="Deploying ${war.name}"/>
<gf-deploy user="${gf.username}"
passwordfile="${gf.password.file}"
host="${gf.server.address}"
port="${gf.adminport}"
file="${build.dir}/${war.name}"
asinstalldir="${gf.root}"/>
<property name="artifact.deployed" value="true" />
</target>
</project>
====================================
Example: soacookbookServer.properties
project.name=soaCookbookWS
#USER PROPERTIES: LINUX
#gf.password.file=/home/ehewitt/soacookbook/repository/code/chapters/ws/soacookbookServer.properties
#gf.root=/opt/glassfish91u1
#USER PROPERTIES: WINDOWS
gf.password.file=C:\\oreilly/soacookbook/code/chapters/ws/soacookbookServer.properties
gf.root=C:\\programs/glassfishv2ur1
#GENERAL JAVA
source.java.version=1.6
target.java.version=1.6
debug=on
#DIRS
root.dir=.
build.dir=./build
classes.dir=${build.dir}/classes
gen.classes.dir=${build.dir}/gen-classes
dist.dir=dist
docs.dir=./docs
src.dir=./src/java
src.gen.dir=./src/gen
src.xml.dir=./src/xml
src.test.dir=./src/test
test.dir=./test
test.classes.dir=${test.dir}/classes
test.report.dir=${test.dir}/report
tmp.dir=${build.dir}/tmp
config.dir=./config
webinf.dir=${config.dir}/WEB-INF
config.meta.inf.dir=${config.dir}/META-INF
ear.lib.dir=${build.dir}/lib
schemas.dir=${config.meta.inf.dir}/wsdl/ch03
ejb.dependencies.classes.dir=${build.dir}/ejb-dependency-classes
#location of the .class files for classes generated from schemas used by the service and the client
service.schemas.classes.dir=${root.dir}/../ws/build/classes
#generated classes from wsimport go here
gen.client.package.name=com.dte.soa.soacookbook.wsclient
#PATTERNS
ejb.dir.pattern=**/ejb/**
spi.includes.pattern=**/*.spi.*
schemas.dir=config/META-INF/wsdl/ch03
schemas.includes.pattern=**/*.xsd
#DEPENDENCIES: LIB DIR
lib.dir=../../lib
commons.lang.jar=${lib.dir}/commons-lang-2.3.jar
javaee.jar=${lib.dir}/javaee.jar
junit.jar=${lib.dir}/junit-4.4.jar
log4j.jar=${lib.dir}/log4j-1.2.9.jar
webservices-rt.jar=${lib.dir}/webservices-rt.jar
#From the Client project, to be included in WAR
client.jar=../client/dist/soaCookbookClient.jar
#ARTIFACT NAMES
client.classes.jar=${project.name}-client.jar
ejb-jar.name=${project.name}-ejb.jar
ear.name=${project.name}.ear
log4j.xml=${config.dir}/log4j.xml
log4j.props.jar=log4jProps.jar
war.name=${project.name}.war
war.name=${project.name}.war
svc.common.jar.name=svc-common.jar
#GLASSFISH DEPLOYMENT
deploy.target=glassfish
gf.server.address=localhost
gf.domain.name=soacookbookdomain
#You may need to modify these for your system
# GlassFish requires the AS_ADMIN_PASSWORD to be in a file.
# The task requires an absolute path. We are pointing directly
# to this file.
gf.username=admin
gf.adminport=5050
gf.port=8080
gf.esb.port=18181
AS_ADMIN_PASSWORD=adminadmin
deploy.cp=${sun.app.ant.jar}${path.separator}${gf.root}/lib/admin-cli.jar${path.separator}${gf.root}/lib/appserv-rt.jar${path.separator}${gf.root}/lib/appserv-admin.jar
server.location=http://${gf.server.address}:${gf.port}
#2.1
sun.app.ant.jar=${lib.dir}/sun-appserv-ant.jar
sun.ws.tools.jar=${lib.dir}/webservices-tools.jar
sun.ws.rt.jar=${lib.dir}/webservices-rt.jar
#TASKS
junit.task.path=${lib.dir}/ant-junit.jar
xjc.task.path=${sun.app.ant.jar}${path.separator}${sun.ws.tools.jar}${path.separator}${sun.ws.rt.jar}
====================================
@WebMethod
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,
use=SOAPBinding.Use.LITERAL,
parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)
public @WebResult(name="searchResults",
targetNamespace="http://ns.soacookbook.com/catalog") SearchResults
authorSearch(
@WebParam(name="author", mode=WebParam.Mode.IN,
targetNamespace="http://ns.soacookbook.com/catalog") Author author) {
//...
====================================
Response<T> invokeAsync(T msg)
Future<?> invokeAsync(T msg, AsyncHandler<T> handler)
====================================
Example: Standalone File with JAX-WS Binding Customizations
<jaxws:bindings wsdlLocation="http://ns.soacookbook.com/Calculator.wsdl">
<jaxws:packageName="com.soacookbook.calc">
<jaxws:javadoc>The 'add' operations in this package will be
available asynchronously.
</jaxws:javadoc>