首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

CXF客户端起动过程

2012-11-03 
CXF客户端启动过程最近,在研究CXF,在用JaxWsProxyFactoryBean 完成调用服务端虽然成功,但是不明白道理,所

CXF客户端启动过程

最近,在研究CXF,在用JaxWsProxyFactoryBean 完成调用服务端虽然成功,但是不明白道理,所以DEBUG+源代码了哈

客户端代码:
public final class Client {

    private Client() {
    }

    public static void main(String args[]) throws Exception {
        JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
        factoryBean.setServiceClass(demo.spring.HelloWorld.class);
        factoryBean.setAddress("http://localhost:8080/HelloWorld");

        HelloWorld client = (HelloWorld) factoryBean.create();

        String response = client.sayHi("Joe");
        System.out.println("Response: " + response);
        System.exit(0);

    }
}
服务器端代码:CXF包的SAMPLE,我们要看的是客户端代码:
这个DEMO非常简单!
package demo.spring;

import javax.jws.WebService;

@WebService
public interface HelloWorld {
    String sayHi(String text);
}

package demo.spring;

import javax.jws.WebService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@WebService(endpointInterface = "demo.spring.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
private final static Log log = LogFactory.getLog(HelloWorldImpl.class);

public String sayHi(String text) {
log.info("@WebService Hello support service");
return "Hello " + text;
}
}
bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- START SNIPPET: beans -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
             http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<jaxws:endpoint id="helloWorld"
implementor="demo.spring.HelloWorldImpl" address="/HelloWorld" />

</beans>
<!-- END SNIPPET: beans -->

分析:
   在把服务器端DEPLOY到TOMCAT然后启动
   运行客户端,发现SPRING LOAD很多XCF.JAR下面的META-INF下的XML文件,怎么LOAD,一定那里有配置或者约定!

   结果果然是:
         JaxWsProxyFactoryBean.java
         ClientProxyFactoryBean.java
         ClientFactoryBean.java
         AbstractWSDLBasedEndpointFactory.java
         AbstractEndpointFactory.java
         BusFactory.java
         SpringBusFactory.java
         BusApplicationContext.java[哈哈上下文....]
BusFactory.java 内部去找JAR包下面的配置文件了哈找到SpringBusFactory 
String serviceId = "META-INF/services/" + BusFactory.BUS_FACTORY_PROPERTY_NAME;

SpringBusFactory  搞定BusApplicationContext
BusApplicationContext内部
private static final String DEFAULT_CXF_CFG_FILE = "META-INF/cxf/cxf.xml";
    private static final String DEFAULT_CXF_EXT_CFG_FILE = "classpath*:META-INF/cxf/cxf.extension";
一切就搞定
附件有代码:和PPT[截图]

希望大家分享,CXF资料不多哈
努力!!
         
1 楼 teamlet 2008-09-28   非常好!
请问ppt中的图像是使用什么工具产生的?

热点排行