Skip to content

Commit be5ac40

Browse files
author
Xiong Neng
committed
cxf客户端代码生成
1 parent 26e4227 commit be5ac40

File tree

11 files changed

+668
-6
lines changed

11 files changed

+668
-6
lines changed

springboot-cxf/README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,44 @@
66

77
## 客户端动态代理调用
88

9-
这个在单元测试类ApplicationTests中有演示
9+
这个在单元测试类ApplicationTests中有演示,这里要注意的是model类的包名一定要放到指定的路径下。
10+
也就是targetNamespace的倒叙包名中。
1011

11-
## 生产客户端代码
12+
## 客户端代码生成
1213

13-
apache的wsdl2java工具,使用`-autoNameResolution`自动处理
14+
有两种方式生成客户端调用代码
15+
16+
**Apache的wsdl2java工具**
1417

1518
```
1619
wsdl2java -autoNameResolution http://xxx?wsdl
1720
```
1821

19-
JDK自带的工具
22+
**JDK自带的工具(推荐)**
23+
24+
```
25+
wsimport -encoding utf-8 -p com.xncoding.webservice.client -keep http://xxx?wsdl -s d:/ws -B-XautoNameResolution
26+
```
27+
28+
其中:
2029

2130
```
22-
wsimport -p com.enzhico.land.client -keep http://xxx?wsdl -s d:/ws -B-XautoNameResolution
31+
-encoding :指定编码格式(此处是utf-8的指定格式)
32+
-keep:是否生成Java源文件
33+
-s:指定.java文件的输出目录
34+
-d:指定.class文件的输出目录
35+
-p:定义生成类的包名,不定义的话有默认包名
36+
-verbose:在控制台显示输出信息
37+
-b:指定jaxws/jaxb绑定文件或额外的schemas
38+
-extension:使用扩展来支持SOAP1.2
39+
```
40+
41+
生成的客户端代码不能改包名
42+
43+
``` java
44+
CommonService_Service c = new CommonService_Service();
45+
com.xncoding.webservice.client.User user = c.getCommonServiceImplPort().getUser("Tom");
46+
assertThat(user.getName(), is("Tom"));
2347
```
2448

2549
## 许可证
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
package com.xncoding.webservice.client;
3+
4+
import javax.jws.WebMethod;
5+
import javax.jws.WebParam;
6+
import javax.jws.WebResult;
7+
import javax.jws.WebService;
8+
import javax.xml.bind.annotation.XmlSeeAlso;
9+
import javax.xml.ws.RequestWrapper;
10+
import javax.xml.ws.ResponseWrapper;
11+
12+
13+
/**
14+
* This class was generated by the JAX-WS RI.
15+
* JAX-WS RI 2.2.9-b130926.1035
16+
* Generated source version: 2.2
17+
*
18+
*/
19+
@WebService(name = "CommonService", targetNamespace = "http://model.webservice.xncoding.com/")
20+
@XmlSeeAlso({
21+
ObjectFactory.class
22+
})
23+
public interface CommonService {
24+
25+
26+
/**
27+
*
28+
* @param userName
29+
* @return
30+
* returns com.xncoding.webservice.client.User
31+
*/
32+
@WebMethod
33+
@WebResult(targetNamespace = "")
34+
@RequestWrapper(localName = "getUser", targetNamespace = "http://model.webservice.xncoding.com/", className = "com.xncoding.webservice.client.GetUser")
35+
@ResponseWrapper(localName = "getUserResponse", targetNamespace = "http://model.webservice.xncoding.com/", className = "com.xncoding.webservice.client.GetUserResponse")
36+
public User getUser(
37+
@WebParam(name = "userName", targetNamespace = "")
38+
String userName);
39+
40+
/**
41+
*
42+
* @param userName
43+
* @return
44+
* returns java.lang.String
45+
*/
46+
@WebMethod
47+
@WebResult(targetNamespace = "")
48+
@RequestWrapper(localName = "sayHello", targetNamespace = "http://model.webservice.xncoding.com/", className = "com.xncoding.webservice.client.SayHello")
49+
@ResponseWrapper(localName = "sayHelloResponse", targetNamespace = "http://model.webservice.xncoding.com/", className = "com.xncoding.webservice.client.SayHelloResponse")
50+
public String sayHello(
51+
@WebParam(name = "userName", targetNamespace = "")
52+
String userName);
53+
54+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
2+
package com.xncoding.webservice.client;
3+
4+
import java.net.MalformedURLException;
5+
import java.net.URL;
6+
import javax.xml.namespace.QName;
7+
import javax.xml.ws.Service;
8+
import javax.xml.ws.WebEndpoint;
9+
import javax.xml.ws.WebServiceClient;
10+
import javax.xml.ws.WebServiceException;
11+
import javax.xml.ws.WebServiceFeature;
12+
13+
14+
/**
15+
* This class was generated by the JAX-WS RI.
16+
* JAX-WS RI 2.2.9-b130926.1035
17+
* Generated source version: 2.2
18+
*
19+
*/
20+
@WebServiceClient(name = "CommonService", targetNamespace = "http://model.webservice.xncoding.com/", wsdlLocation = "http://localhost:8092/services/CommonService?wsdl")
21+
public class CommonService_Service
22+
extends Service
23+
{
24+
25+
private final static URL COMMONSERVICE_WSDL_LOCATION;
26+
private final static WebServiceException COMMONSERVICE_EXCEPTION;
27+
private final static QName COMMONSERVICE_QNAME = new QName("http://model.webservice.xncoding.com/", "CommonService");
28+
29+
static {
30+
URL url = null;
31+
WebServiceException e = null;
32+
try {
33+
url = new URL("http://localhost:8092/services/CommonService?wsdl");
34+
} catch (MalformedURLException ex) {
35+
e = new WebServiceException(ex);
36+
}
37+
COMMONSERVICE_WSDL_LOCATION = url;
38+
COMMONSERVICE_EXCEPTION = e;
39+
}
40+
41+
public CommonService_Service() {
42+
super(__getWsdlLocation(), COMMONSERVICE_QNAME);
43+
}
44+
45+
public CommonService_Service(WebServiceFeature... features) {
46+
super(__getWsdlLocation(), COMMONSERVICE_QNAME, features);
47+
}
48+
49+
public CommonService_Service(URL wsdlLocation) {
50+
super(wsdlLocation, COMMONSERVICE_QNAME);
51+
}
52+
53+
public CommonService_Service(URL wsdlLocation, WebServiceFeature... features) {
54+
super(wsdlLocation, COMMONSERVICE_QNAME, features);
55+
}
56+
57+
public CommonService_Service(URL wsdlLocation, QName serviceName) {
58+
super(wsdlLocation, serviceName);
59+
}
60+
61+
public CommonService_Service(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
62+
super(wsdlLocation, serviceName, features);
63+
}
64+
65+
/**
66+
*
67+
* @return
68+
* returns CommonService
69+
*/
70+
@WebEndpoint(name = "CommonServiceImplPort")
71+
public CommonService getCommonServiceImplPort() {
72+
return super.getPort(new QName("http://model.webservice.xncoding.com/", "CommonServiceImplPort"), CommonService.class);
73+
}
74+
75+
/**
76+
*
77+
* @param features
78+
* A list of {@link WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
79+
* @return
80+
* returns CommonService
81+
*/
82+
@WebEndpoint(name = "CommonServiceImplPort")
83+
public CommonService getCommonServiceImplPort(WebServiceFeature... features) {
84+
return super.getPort(new QName("http://model.webservice.xncoding.com/", "CommonServiceImplPort"), CommonService.class, features);
85+
}
86+
87+
private static URL __getWsdlLocation() {
88+
if (COMMONSERVICE_EXCEPTION!= null) {
89+
throw COMMONSERVICE_EXCEPTION;
90+
}
91+
return COMMONSERVICE_WSDL_LOCATION;
92+
}
93+
94+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
package com.xncoding.webservice.client;
3+
4+
import javax.xml.bind.annotation.XmlAccessType;
5+
import javax.xml.bind.annotation.XmlAccessorType;
6+
import javax.xml.bind.annotation.XmlType;
7+
8+
9+
/**
10+
* <p>getUser complex type的 Java 类。
11+
*
12+
* <p>以下模式片段指定包含在此类中的预期内容。
13+
*
14+
* <pre>
15+
* &lt;complexType name="getUser">
16+
* &lt;complexContent>
17+
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
18+
* &lt;sequence>
19+
* &lt;element name="userName" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
20+
* &lt;/sequence>
21+
* &lt;/restriction>
22+
* &lt;/complexContent>
23+
* &lt;/complexType>
24+
* </pre>
25+
*
26+
*
27+
*/
28+
@XmlAccessorType(XmlAccessType.FIELD)
29+
@XmlType(name = "getUser", propOrder = {
30+
"userName"
31+
})
32+
public class GetUser {
33+
34+
protected String userName;
35+
36+
/**
37+
* 获取userName属性的值。
38+
*
39+
* @return
40+
* possible object is
41+
* {@link String }
42+
*
43+
*/
44+
public String getUserName() {
45+
return userName;
46+
}
47+
48+
/**
49+
* 设置userName属性的值。
50+
*
51+
* @param value
52+
* allowed object is
53+
* {@link String }
54+
*
55+
*/
56+
public void setUserName(String value) {
57+
this.userName = value;
58+
}
59+
60+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
package com.xncoding.webservice.client;
3+
4+
import javax.xml.bind.annotation.XmlAccessType;
5+
import javax.xml.bind.annotation.XmlAccessorType;
6+
import javax.xml.bind.annotation.XmlElement;
7+
import javax.xml.bind.annotation.XmlType;
8+
9+
10+
/**
11+
* <p>getUserResponse complex type的 Java 类。
12+
*
13+
* <p>以下模式片段指定包含在此类中的预期内容。
14+
*
15+
* <pre>
16+
* &lt;complexType name="getUserResponse">
17+
* &lt;complexContent>
18+
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
19+
* &lt;sequence>
20+
* &lt;element name="return" type="{http://model.webservice.xncoding.com/}user" minOccurs="0"/>
21+
* &lt;/sequence>
22+
* &lt;/restriction>
23+
* &lt;/complexContent>
24+
* &lt;/complexType>
25+
* </pre>
26+
*
27+
*
28+
*/
29+
@XmlAccessorType(XmlAccessType.FIELD)
30+
@XmlType(name = "getUserResponse", propOrder = {
31+
"_return"
32+
})
33+
public class GetUserResponse {
34+
35+
@XmlElement(name = "return")
36+
protected User _return;
37+
38+
/**
39+
* 获取return属性的值。
40+
*
41+
* @return
42+
* possible object is
43+
* {@link User }
44+
*
45+
*/
46+
public User getReturn() {
47+
return _return;
48+
}
49+
50+
/**
51+
* 设置return属性的值。
52+
*
53+
* @param value
54+
* allowed object is
55+
* {@link User }
56+
*
57+
*/
58+
public void setReturn(User value) {
59+
this._return = value;
60+
}
61+
62+
}

0 commit comments

Comments
 (0)