package cxf.client;
import javax.xml.namespace.QName;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import cxf.HelloWorld;
import cxf.impl.HelloWorldImpl;
public class WsClient {
public static void JaxWsClient(String address) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress(address);
factory.setServiceClass(HelloWorld.class);
HelloWorld helloService = factory.create(HelloWorld.class);
String result = helloService.sayHi("JaxWsClient", "123", "123");
System.out.println(result);
}
/*private static ApplicationContext context;
public static void main(String[] args) {
String address = "http://localhost:8080/CXF/spring/hello";
// JaxWsClient(address);
// DynamicClient(address);
SpringClient();
}
*//**
* 静态代理客户端
*//*
/**
* 通用动态代理客户端
*/
public static void DynamicClient(String address) {
//CXF发布用的是业务类(HelloWorldImpl.java),那么默认的命名空间就会是业务类所在包(路径),
//而对外界暴露的则是接口类(HelloWorld.java),那么对于客户端(第三方)调用访问时,需要按照接口类所在包(路径)进行命名空间的定义
QName opName = new QName("http://cxf/", "sayHi"); // 指定到接口类所在包
address = address+"?wsdl";
DynamicClientFactory factory = DynamicClientFactory.newInstance();
Client client = factory.createClient(address);
try {
Object[] results = client.invoke(opName, "DynamicClient","1","2");
System.out.println(results[0]);
} catch (Exception e) {
e.printStackTrace();
}
//如果接口和实现在同一路径下,就使用下面的代码.
// address = address+"?wsdl";
// DynamicClientFactory factory = DynamicClientFactory.newInstance();
// Client client = factory.createClient(address);
// try {
// Object[] results = client.invoke("sayHi", "DynamicClient");
// System.out.println(results[0]);
// } catch (Exception e) {
// e.printStackTrace();
// }
}
/**
* spring客户端
*/
/*public static void SpringClient() {
context = new ClassPathXmlApplicationContext("spring-client.xml");
HelloWorld helloService = context.getBean("helloWorld", HelloWorld.class);
String result = helloService.sayHi("123456");
System.out.println(result);
}*/
private static String webserviceUrl="http://localhost:8080/demo/spring/hello?wsdl";
public static void main(String[] args) {
String address = "http://localhost:8080/demo/spring/hello";
JaxWsClient(address);
//DynamicClient(address);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
demo-Maven-Webapp.rar_DEMO
共73个文件
xml:22个
class:10个
java:7个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 192 浏览量
2022-09-21
20:14:56
上传
评论
收藏 5.48MB RAR 举报
温馨提示
maven构建的spring继承CXF的简单示例,新手可以参考
资源推荐
资源详情
资源评论
收起资源包目录
demo-Maven-Webapp.rar (73个子文件)
demo Maven Webapp
pom.xml 2KB
target
test-classes
m2e-jee
web-resources
META-INF
maven
CXF
demo
pom.xml 2KB
pom.properties 241B
MANIFEST.MF 114B
classes
cn
dcwriter
ListItem.class 3KB
ListItemCollection.class 954B
DCWriter.class 668B
impl
DCWriterImpl.class 2KB
cxf
client
WsClient.class 3KB
spring-client.xml 560B
HelloWorld.class 263B
impl
HelloWorldImpl.class 1KB
emr
.settings
com.genuitec.eclipse.j2eedt.core.prefs 93B
org.eclipse.m2e.core.prefs 127B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.wst.common.component 591B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 508B
org.eclipse.jdt.core.prefs 467B
src
main
webapp
dt.jsp 190KB
META-INF
MANIFEST.MF 39B
WEB-INF
spring-client.xml 672B
web.xml 962B
classes
pom.xml 2KB
target
m2e-jee
web-resources
META-INF
maven
CXF
demo
pom.xml 2KB
pom.properties 241B
MANIFEST.MF 114B
classes
.settings
com.genuitec.eclipse.j2eedt.core.prefs 93B
org.eclipse.m2e.core.prefs 127B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.wst.common.component 662B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 508B
org.eclipse.jdt.core.prefs 467B
src
main
webapp
META-INF
MANIFEST.MF 39B
WEB-INF
spring-client.xml 551B
web.xml 955B
classes
target
m2e-jee
web-resources
META-INF
maven
CXF
demo
src
main
webapp
cxf
client
impl
emr
spring.xml 578B
lib
spring-cxf.xml 539B
index.jsp 52B
.project 2KB
.mymetadata 319B
.classpath 667B
cxf
client
WsClient.class 1KB
HelloWorld.class 263B
impl
HelloWorldImpl.class 1KB
emr
spring.xml 578B
lib
spring-cxf.xml 644B
dt2.jsp 387KB
index.jsp 145B
mydl.jsp 29KB
DCLib
demo1.xml 4KB
DCWriterWeb.cab 5.4MB
record.xml 85KB
zsk.xml 1KB
test.xml 5KB
myeclipse.lnk 671B
aa.xml 10KB
test1.xml 50KB
dcw.jsp 6KB
resources
java
cn
dcwriter
DCWriter.java 534B
ListItemCollection.java 1KB
ListItem.java 3KB
impl
DCWriterImpl.java 892B
cxf
client
WsClient.java 3KB
spring-client.xml 560B
HelloWorld.java 176B
impl
HelloWorldImpl.java 430B
emr
.project 2KB
.mymetadata 319B
.classpath 657B
共 73 条
- 1
资源评论
局外狗
- 粉丝: 65
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功