Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
I
iSignatureSever
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
邓砥奕
iSignatureSever
Commits
42c146a8
提交
42c146a8
authored
7月 20, 2020
作者:
邓砥奕
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新代码
上级
6a89b31f
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
187 行增加
和
58 行删除
+187
-58
pom.xml
pom.xml
+40
-0
WebSevice.java
src/main/java/com/example/demo/WebSevice.java
+0
-10
CxfConfig.java
...main/java/com/example/demo/WebSeviceConfig/CxfConfig.java
+39
-0
CxfClient.java
src/main/java/com/example/demo/client/CxfClient.java
+41
-0
WebSevice.java
src/main/java/com/example/demo/service/WebSevice.java
+12
-0
Test.java
src/main/java/com/example/demo/service/impl/Test.java
+51
-44
NewTest.java
src/test/java/com/example/demo/NewTest.java
+4
-4
没有找到文件。
pom.xml
浏览文件 @
42c146a8
...
@@ -24,6 +24,46 @@
...
@@ -24,6 +24,46 @@
<artifactId>
spring-boot-starter
</artifactId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
javax.xml.bind
</groupId>
<artifactId>
jaxb-api
</artifactId>
<version>
2.3.1
</version>
</dependency>
<dependency>
<groupId>
com.sun.xml.bind
</groupId>
<artifactId>
jaxb-impl
</artifactId>
<version>
2.2.11
</version>
</dependency>
<dependency>
<groupId>
com.sun.xml.bind
</groupId>
<artifactId>
jaxb-core
</artifactId>
<version>
2.2.11
</version>
</dependency>
<dependency>
<groupId>
javax.xml.bind
</groupId>
<artifactId>
jaxb-api
</artifactId>
<version>
2.3.1
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web-services
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.cxf
</groupId>
<artifactId>
cxf-rt-frontend-jaxws
</artifactId>
<version>
3.1.6
</version>
</dependency>
<dependency>
<groupId>
org.apache.cxf
</groupId>
<artifactId>
cxf-rt-transports-http
</artifactId>
<version>
3.1.6
</version>
</dependency>
<dependency>
<groupId>
jakarta.jws
</groupId>
<artifactId>
jakarta.jws-api
</artifactId>
<version>
2.1.0
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<artifactId>
spring-boot-starter-test
</artifactId>
...
...
src/main/java/com/example/demo/WebSevice.java
deleted
100644 → 0
浏览文件 @
6a89b31f
package
com
.
example
.
demo
;
import
org.springframework.stereotype.Repository
;
import
java.io.IOException
;
@Repository
public
interface
WebSevice
{
String
setUser
(
String
keySn
,
String
userCode
,
String
userName
,
String
overDate
,
String
password
)
throws
IOException
;
}
src/main/java/com/example/demo/WebSeviceConfig/CxfConfig.java
0 → 100644
浏览文件 @
42c146a8
package
com
.
example
.
demo
.
WebSeviceConfig
;
import
com.example.demo.service.impl.Test
;
import
org.apache.cxf.Bus
;
import
org.apache.cxf.bus.spring.SpringBus
;
import
org.apache.cxf.jaxws.EndpointImpl
;
import
org.apache.cxf.transport.servlet.CXFServlet
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.web.servlet.ServletRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
com.example.demo.service.WebSevice
;
import
javax.jws.WebService
;
import
javax.xml.ws.Endpoint
;
@Configuration
public
class
CxfConfig
{
@Autowired
private
WebSevice
webSevice
;
@Bean
public
ServletRegistrationBean
disServlet
()
{
return
new
ServletRegistrationBean
(
new
CXFServlet
(),
"/demo/*"
);
}
@Bean
(
name
=
Bus
.
DEFAULT_BUS_ID
)
public
SpringBus
springBus
()
{
return
new
SpringBus
();
}
@Bean
public
Endpoint
endpoint
()
{
EndpointImpl
endpoint
=
new
EndpointImpl
(
springBus
(),
webSevice
);
endpoint
.
publish
(
"/api"
);
return
endpoint
;
}
}
src/main/java/com/example/demo/client/CxfClient.java
0 → 100644
浏览文件 @
42c146a8
package
com
.
example
.
demo
.
client
;
import
com.example.demo.service.WebSevice
;
import
com.example.demo.service.impl.Test
;
import
com.sun.xml.bind.v2.runtime.output.C14nXmlOutput
;
import
org.apache.cxf.endpoint.Client
;
import
org.apache.cxf.jaxws.JaxWsProxyFactoryBean
;
import
org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory
;
public
class
CxfClient
{
public
static
void
main
(
String
[]
args
)
{
CxfClient
.
main1
();
}
public
static
void
main1
()
{
try
{
// 接口地址
String
address
=
"http://localhost:8080/demo/api?wsdl"
;
// 代理工厂
JaxWsProxyFactoryBean
jaxWsProxyFactoryBean
=
new
JaxWsProxyFactoryBean
();
// 设置代理地址
jaxWsProxyFactoryBean
.
setAddress
(
address
);
// 设置接口类型
jaxWsProxyFactoryBean
.
setServiceClass
(
WebSevice
.
class
);
// 创建一个代理接口实现
WebSevice
us
=
(
WebSevice
)
jaxWsProxyFactoryBean
.
create
();
// 数据准备
String
keySn
=
"123456"
;
String
userCode
=
"1"
;
String
userName
=
"dengdiyi"
;
String
overDate
=
"2025-10-10"
;
String
password
=
"123456"
;
// 调用代理接口的方法调用并返回结果
String
result
=
us
.
setUser
(
keySn
,
userCode
,
userName
,
overDate
,
password
);
System
.
out
.
println
(
"返回结果:"
+
result
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
src/main/java/com/example/demo/service/WebSevice.java
0 → 100644
浏览文件 @
42c146a8
package
com
.
example
.
demo
.
service
;
import
javax.jws.WebMethod
;
import
javax.jws.WebParam
;
import
javax.jws.WebService
;
import
java.io.IOException
;
@WebService
(
targetNamespace
=
"http://service.demo.example.com"
)
public
interface
WebSevice
{
@WebMethod
String
setUser
(
String
keySn
,
String
userCode
,
String
userName
,
String
overDate
,
String
password
)
throws
IOException
;
}
src/main/java/com/example/demo/
TestApi
/Test.java
→
src/main/java/com/example/demo/
service/impl
/Test.java
浏览文件 @
42c146a8
package
com
.
example
.
demo
.
TestApi
;
package
com
.
example
.
demo
.
service
.
impl
;
import
com.example.demo.WebSevice
;
import
com.example.demo.service.WebSevice
;
import
org.springframework.stereotype.Component
;
import
javax.jws.WebService
;
import
javax.xml.ws.Endpoint
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
@@ -10,50 +13,53 @@ import java.io.OutputStream;
...
@@ -10,50 +13,53 @@ import java.io.OutputStream;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URL
;
@WebService
(
serviceName
=
"MyService"
,
targetNamespace
=
"http://service.demo.example.com"
,
endpointInterface
=
"com.example.demo.service.WebSevice"
)
@Component
public
class
Test
implements
WebSevice
{
public
class
Test
implements
WebSevice
{
@Override
@Override
public
String
setUser
(
String
keySn
,
String
userCode
,
String
userName
,
String
overDate
,
String
password
)
throws
IOException
{
public
String
setUser
(
String
keySn
,
String
userCode
,
String
userName
,
String
overDate
,
String
password
)
throws
IOException
{
//第一步:创建服务地址
// //第一步:创建服务地址
URL
url
=
new
URL
(
"http://127.0.0.1:8080/iSignatureServer/services/KeyInfoService?wsdl"
);
// URL url = new URL("http://127.0.0.1:8080/iSignatureServer/services/KeyInfoService?wsdl");
//第二步:打开一个通向服务地址的连接
// //第二步:打开一个通向服务地址的连接
HttpURLConnection
connection
=
(
HttpURLConnection
)
url
.
openConnection
();
// HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//第三步:设置参数
// //第三步:设置参数
//3.1发送方式设置:POST必须大写
// //3.1发送方式设置:POST必须大写
connection
.
setRequestMethod
(
"POST"
);
// connection.setRequestMethod("POST");
//3.2设置数据格式:content-type
// //3.2设置数据格式:content-type
connection
.
setRequestProperty
(
"content-type"
,
"text/xml;charset=utf-8"
);
// connection.setRequestProperty("content-type", "text/xml;charset=utf-8");
//3.3设置输入输出,因为默认新创建的connection没有读写权限,
// //3.3设置输入输出,因为默认新创建的connection没有读写权限,
connection
.
setDoInput
(
true
);
// connection.setDoInput(true);
connection
.
setDoOutput
(
true
);
// connection.setDoOutput(true);
String
outPut
=
null
;
// String outPut = null;
//
//第四步:组织SOAP数据,发送请求
// //第四步:组织SOAP数据,发送请求
String
soapXML
=
getXML
(
keySn
,
userCode
,
userName
,
overDate
,
password
);
// String soapXML = getXML(keySn,userCode,userName,overDate,password);
OutputStream
os
=
connection
.
getOutputStream
();
// OutputStream os = connection.getOutputStream();
os
.
write
(
soapXML
.
getBytes
());
// os.write(soapXML.getBytes());
//第五步:接收服务端响应,打印
// //第五步:接收服务端响应,打印
int
responseCode
=
connection
.
getResponseCode
();
// int responseCode = connection.getResponseCode();
if
(
200
==
responseCode
)
{
// if (200 == responseCode) {
InputStream
is
=
connection
.
getInputStream
();
// InputStream is = connection.getInputStream();
InputStreamReader
isr
=
new
InputStreamReader
(
is
);
// InputStreamReader isr = new InputStreamReader(is);
BufferedReader
br
=
new
BufferedReader
(
isr
);
// BufferedReader br = new BufferedReader(isr);
//
StringBuilder
sb
=
new
StringBuilder
();
// StringBuilder sb = new StringBuilder();
String
temp
=
null
;
// String temp = null;
while
(
null
!=
(
temp
=
br
.
readLine
()))
{
// while (null != (temp = br.readLine())) {
sb
.
append
(
temp
);
// sb.append(temp);
}
// }
outPut
=
sb
.
toString
();
// outPut = sb.toString();
/**
// /**
* 打印结果
// * 打印结果
*/
// */
// System.out.println(sb.toString());
//// System.out.println(sb.toString());
is
.
close
();
// is.close();
isr
.
close
();
// isr.close();
br
.
close
();
// br.close();
}
// }
os
.
close
();
// os.close();
return
outPut
;
// return outPut;
return
"Hello World!"
;
}
}
...
@@ -76,4 +82,5 @@ public class Test implements WebSevice {
...
@@ -76,4 +82,5 @@ public class Test implements WebSevice {
+
"</soap:Envelope>"
;
+
"</soap:Envelope>"
;
return
soapXML
;
return
soapXML
;
}
}
}
}
src/test/java/com/example/demo/NewTest.java
浏览文件 @
42c146a8
...
@@ -3,15 +3,15 @@ package com.example.demo;
...
@@ -3,15 +3,15 @@ package com.example.demo;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
com.example.demo.service.WebSevice
;
import
java.io.IOException
;
import
java.io.IOException
;
@SpringBootTest
@SpringBootTest
public
class
NewTest
{
public
class
NewTest
{
@Autowired
private
WebSevice
webSevice
;
@Test
@Test
public
void
test1
()
throws
IOException
{
public
void
test1
()
throws
IOException
{
com
.
example
.
demo
.
TestApi
.
Test
test
=
new
com
.
example
.
demo
.
TestApi
.
Test
();
System
.
out
.
println
(
webSevice
.
setUser
(
"12345678"
,
"1"
,
"dengdiyi"
,
"2025-10-10"
,
"123456"
));
System
.
out
.
println
(
test
.
setUser
(
"12345678"
,
"1"
,
"dengdiyi"
,
"2025-10-10"
,
"123456"
));
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论