Step by Step
develop WSDL-First Simple Request-Response Webservice
based on CXF+SPRING+MAVEN
(图片太多,稍后再传)
一、创建一个简单的基于cxf+spring的maven project
a) Create a Maven Project
b) Select an simple Cxf-spring archetype(cxf-http-basic): include snapshot archetypes
c) Specify Archetype parameters
完成后,maven就开始构建project了。如果没有设置你自己的maven local repository,那需要download plugin jar一段时间
d) 一个以groupId为名称的project生成了:
e) 有些包的错误,由于maven自动生成了一个helloWorld的webservice而有些路径错误导致,直接删掉有错误的java类,这些都不是我们需要的
二、修改POM 文件
1. Add properties:
i.
2. Add dependencies:
三、添加,修改wsdl
a)
b) Add yours wsdl,define wsdl namespace(targetNamespace [distinguish with other wsdl file]and xmlns:tns[used for current file])
c)
d) Add Types
就是些对象(这些对象可以在后面当做接口的输入输出参数,也可当做错误信息对象)便于jxb自动生成java类
e) Add xsd file to define your types(也可以定义在wsdl文件中)
Modify your xsd to follow a sensible style:
Define your BO and exception Object:
f)
四、添加,修改jxb binding.xml
a) Add jaxb ‘bindings.xml’ to bind your xsd file, jxb will automatically generate POJOs:
Modify binding configuration(define xsd location and pojo package name):
b) Import your xsd into your types:
c) Define your messages, which is your input and output info referring to your types as well as fault info(Do not forget import your xsd namespace into your wsdl head):
d) Input
e) Output:
f) Exception handling object:
g) Next, define your interface in portType:
h) Define your method intended to be invoked, Each operation is just the method to be deployed publicly:
i. Define your methodName
ii. add input, output and fault object defined above related to the method
iii. Continue, bind your service (refer to the interface defined above) to a protocol u choose in ‘<binding/>’:
iv. Add binding service method as well as encoding style of the transport message:
i) Last define your service with binding protocol referred above facilitating transporting messages
j) Whole wsdl:
k) Then, continue to define into POM file:
i. Define execution to run wsdl2java goal:
l) Add jetty plugin:
m)
n) Run maven generate-source
o) Run mvn clean install
p) Run mvn install eclipse:eclipse or click “Update Project Configuration”,alternatively, u want to add new auto-generated file into buildpath manually
五、实现web service
a) After that, Implement your serviceImpl to auto-generated Server interface
b) Add your business logic
c)
六、注册endpoint
Finally, Register endpoint to spring bean context:
Beans.xml:对于不熟悉spring的,短期完成作业可就学习IOC的部分即可(个人建议,仅供参考)
Define your implement class here and address (webapp root path):
七、Run and deploy web service
Run: mvn jetty:run
deploy web service successfully!!
八、SOUPUI测试web service
Test your webservice via SOUPUI:
1. New soapUI Project
a)
b) Add wsdl:
c)
d)
e) Now You can test:
f)