Skip to content

Commit 26e4227

Browse files
author
Xiong Neng
committed
增加一个cxf
1 parent f8e958f commit 26e4227

File tree

15 files changed

+655
-0
lines changed

15 files changed

+655
-0
lines changed

springboot-cxf/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 此为注释– 将被Git 忽略
2+
# /结尾表示是目录,忽略目录和目录下的所有件
3+
# /开头表示根目录,否则是.gitignore的相对目录
4+
# !开头表示反选
5+
.idea/
6+
target/
7+
*.iml
8+
*.ipr
9+
*.iws
10+
*.log
11+
.svn/
12+
.project
13+
rebel.xml
14+
.rebel-remote.xml.*

springboot-cxf/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2018 Xiong Neng
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

springboot-cxf/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## 实现WebService
2+
3+
利用Apache CXF实现WebService
4+
5+
启动之后,wsdl访问链接:<http://localhost:8092/services/CommonService?wsdl>
6+
7+
## 客户端动态代理调用
8+
9+
这个在单元测试类ApplicationTests中有演示
10+
11+
## 生产客户端代码
12+
13+
apache的wsdl2java工具,使用`-autoNameResolution`自动处理
14+
15+
```
16+
wsdl2java -autoNameResolution http://xxx?wsdl
17+
```
18+
19+
JDK自带的工具
20+
21+
```
22+
wsimport -p com.enzhico.land.client -keep http://xxx?wsdl -s d:/ws -B-XautoNameResolution
23+
```
24+
25+
## 许可证
26+
27+
Copyright (c) 2018 Xiong Neng
28+
29+
基于 MIT 协议发布: <http://www.opensource.org/licenses/MIT>

springboot-cxf/pom.xml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.xncoding</groupId>
8+
<artifactId>springboot-cxf</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>springboot-restful</name>
13+
<description>CXF实现WebService</description>
14+
15+
<parent>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-starter-parent</artifactId>
18+
<version>1.5.10.RELEASE</version>
19+
<relativePath/>
20+
</parent>
21+
22+
<properties>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
25+
<java.version>1.8</java.version>
26+
</properties>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-web</artifactId>
32+
<exclusions>
33+
<exclusion>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-tomcat</artifactId>
36+
</exclusion>
37+
</exclusions>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-jetty</artifactId>
42+
</dependency>
43+
44+
<!-- CXF webservice -->
45+
<dependency>
46+
<groupId>org.apache.cxf</groupId>
47+
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
48+
<version>3.2.4</version>
49+
</dependency>
50+
<!-- CXF webservice -->
51+
52+
<dependency>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-starter-test</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.hamcrest</groupId>
59+
<artifactId>hamcrest-all</artifactId>
60+
<version>1.3</version>
61+
<scope>test</scope>
62+
</dependency>
63+
</dependencies>
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<groupId>org.apache.maven.plugins</groupId>
69+
<artifactId>maven-compiler-plugin</artifactId>
70+
<version>3.6.1</version>
71+
<configuration>
72+
<!--<proc>none</proc>-->
73+
<source>1.8</source>
74+
<target>1.8</target>
75+
</configuration>
76+
</plugin>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-surefire-plugin</artifactId>
80+
<version>2.20</version>
81+
<configuration>
82+
<skip>true</skip>
83+
</configuration>
84+
</plugin>
85+
<plugin>
86+
<groupId>org.springframework.boot</groupId>
87+
<artifactId>spring-boot-maven-plugin</artifactId>
88+
<executions>
89+
</executions>
90+
</plugin>
91+
</plugins>
92+
93+
<resources>
94+
<resource>
95+
<directory>src/main/resources</directory>
96+
</resource>
97+
<resource>
98+
<directory>src/main/java</directory>
99+
<includes>
100+
<include>**/*.xml</include>
101+
</includes>
102+
</resource>
103+
</resources>
104+
</build>
105+
106+
</project>

springboot-cxf/run.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
# 项目自动更新脚本
3+
# 先clone相应的分支下来:
4+
# git clone ssh://[email protected]:7999/xxx.git
5+
# 远程调试启动:
6+
# nohup java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -Xms512m -Xmx1024m -jar -Dspring.profiles.active=${profile} ${jarfile} >/dev/null 2>&1 &
7+
8+
function start {
9+
profile="$1"
10+
echo "启动环境profile=${profile}"
11+
jarfile=$(ls target/*.jar)
12+
if [[ "$?" == "0" ]]; then
13+
stop $profile $jarfile
14+
fi
15+
branch=$(git branch |awk '{print $2}')
16+
git pull origin ${branch}
17+
echo "更新完代码开始重新打包"
18+
mvn clean && mvn clean && mvn package -DskipTests=true
19+
if [[ "$?" != "0" ]]; then
20+
echo "编译出错,退出!"
21+
exit 1
22+
fi
23+
echo "nohup java -Xms512m -Xmx1024m -jar -Dspring.profiles.active=${profile} ${jarfile} >/dev/null 2>&1 &"
24+
nohup java -Xms512m -Xmx1024m -jar -Dspring.profiles.active=${profile} ${jarfile} >/dev/null 2>&1 &
25+
echo "启动应用中,请查看日志文件..."
26+
}
27+
28+
function stop {
29+
profile="$1"
30+
jarfile="$2"
31+
ps aux | grep "${jarfile}" | grep "spring.profiles.active=${profile}" | grep -v grep > /dev/null
32+
if [[ "$?" == "0" ]]; then
33+
echo "该应用还在跑,我先停了它"
34+
pid=$(ps aux | grep "${jarfile}" | grep "spring.profiles.active=${profile}" | grep -v grep |awk '{print $2}')
35+
if [[ "$pid" != "" ]]; then
36+
kill -9 $pid
37+
fi
38+
echo "停止应用成功..."
39+
fi
40+
}
41+
42+
if [[ "$1" == "start" ]]; then
43+
if [[ "$#" < 2 ]]; then
44+
echo "请输入正确参数:./epay.sh start {profile}"
45+
exit 1
46+
fi
47+
profile="$2"
48+
if [[ "$profile" != "dev" && "$profile" != "test" && "$profile" != "show" && "$profile" != "production" ]]; then
49+
echo "参数错误,请输入正确的profile参数,使用方法:"
50+
echo "./epay.sh start {profile} ==> 启动应用,{profile}取值:dev|test|show|production"
51+
exit 1
52+
fi
53+
start "${profile}"
54+
elif [[ "$1" == "stop" ]]; then
55+
if [[ "$#" < 2 ]]; then
56+
echo "请输入正确参数:./epay.sh stop {profile}"
57+
exit 1
58+
fi
59+
profile="$2"
60+
if [[ "$profile" != "dev" && "$profile" != "test" && "$profile" != "show" && "$profile" != "production" ]]; then
61+
echo "参数错误,请输入正确的profile参数,使用方法:"
62+
echo "./epay.sh stop {profile} ==> 停止应用,{profile}取值:dev|test|show|production"
63+
exit 1
64+
fi
65+
jarfile=$(ls target/*.jar)
66+
stop $profile $jarfile
67+
else
68+
echo "参数错误,使用方法:{}参数是必填的,[]参数可选"
69+
echo "./epay.sh start {profile} ==> 启动应用,{profile}取值:dev|test|show|production"
70+
echo "./epay.sh stop {profile} ==> 停止应用,{profile}取值:dev|test|show|production"
71+
exit 1
72+
fi
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.xncoding.webservice;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
public static void main(String[] args) {
9+
SpringApplication.run(Application.class, args);
10+
}
11+
12+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.xncoding.webservice.config;
2+
3+
import javax.xml.ws.Endpoint;
4+
5+
import org.apache.cxf.Bus;
6+
import org.apache.cxf.jaxws.EndpointImpl;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.context.annotation.Bean;
9+
import com.xncoding.webservice.service.ICommonService;
10+
import org.springframework.context.annotation.Configuration;
11+
12+
/**
13+
* 默认服务在 Host:port/services/*** 路径下
14+
* 这里相当于把Commonservice接口发布在了路径/services/CommonService下
15+
* wsdl文档路径为http://localhost:8080/services/CommonService?wsdl
16+
*
17+
* @author XiongNeng
18+
* @version 1.0
19+
* @since 2018/6/15
20+
*/
21+
@Configuration
22+
public class CxfConfig {
23+
@Autowired
24+
private Bus bus;
25+
26+
@Autowired
27+
ICommonService commonService;
28+
29+
/**
30+
* JAX-WS
31+
**/
32+
@Bean
33+
public Endpoint endpoint() {
34+
EndpointImpl endpoint = new EndpointImpl(bus, commonService);
35+
endpoint.publish("/CommonService");
36+
return endpoint;
37+
}
38+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.xncoding.webservice.model;
2+
3+
/**
4+
* 基础返回类
5+
*
6+
* @author XiongNeng
7+
* @version 1.0
8+
* @since 2018/1/7
9+
*/
10+
public class BaseResponse<T> {
11+
/**
12+
* 是否成功
13+
*/
14+
private boolean success;
15+
16+
/**
17+
* 说明
18+
*/
19+
private String msg;
20+
21+
/**
22+
* 返回数据
23+
*/
24+
private T data;
25+
26+
public BaseResponse() {
27+
28+
}
29+
30+
public BaseResponse(boolean success, String msg, T data) {
31+
this.success = success;
32+
this.msg = msg;
33+
this.data = data;
34+
}
35+
36+
public boolean isSuccess() {
37+
return success;
38+
}
39+
40+
public void setSuccess(boolean success) {
41+
this.success = success;
42+
}
43+
44+
public String getMsg() {
45+
return msg;
46+
}
47+
48+
public void setMsg(String msg) {
49+
this.msg = msg;
50+
}
51+
52+
public T getData() {
53+
return data;
54+
}
55+
56+
public void setData(T data) {
57+
this.data = data;
58+
}
59+
60+
}

0 commit comments

Comments
 (0)