Archive

Archive for the ‘CXF’ Category

Apache CXF Web Service Development book.

February 20, 2010 Leave a comment

I was invited to review the new book about Apache CXF from packtpub, it is called《Apache CXF Web Service Development》by Naveen Balani and Rajeev Hathi. From the table of content, it covers both web service and restful service in CXF, also had three chapters for the CXF’s frontend, transport, interceptors, invoke etc, which are the essential concepts of CXF’s architecture. So it definitely seems interesting to me. I will post more detailed review once I finished the book.

Categories: CXF, SOA

IMS rolled out its 0.1 version

November 13, 2007 Leave a comment

I created a little project at Google Code, it rolled out its 0.1 version in 5 Nov 2007.. In this release, it demonstrates below functionalities (copied from release note)..

ims-core module

  1. Using JAXWS + JAXB (CXF runtime) to publish web service.
  2. Using Spring acegi as web service authorization.
  3. Using ws-security (plain password) as authentication.
  4. Using Spring AOP transaction.
  5. Using DBUnit to do the dao unit test.
  6. Using easymock to do the service layer unit test.
  7. Using cxf local transport to do the web service unit test.

ims-web module

  1. Using CXF wsdl2java (codegen tool) to generate the stub.
  2. Using JAXWS customization to use the java.util.Date instead of XMLGregorianCalendar.
  3. Using JAXWS + JAXB (CXF runtime) to access the web service.
  4. Using Spring acegi web application filter and Jcaptcha as security implementation.
  5. Using div + css as layout design implementation.

You can download the source code from here, since its war size is about 20M, I don’t provide it in the website, you need to refer to the README.txt in the source code to build it, it is quite straightforward to get it working.. (actually you just need to set up database manually, and then update the database connection config file appropriately).

I’ve also created some tasks for 0.2 release or future in the issue page, if you want to join this project, drop me a mail, (or add a comment here), I would add you as a commiter.

Categories: CXF, Java, Spring

CXF ServiceInfo Model diagram

September 6, 2007 1 comment

If you want to know the CXF code, you need to now the CXF ServiceInfo Model. what is that model about? We can think the ServiceInfo as a JAVA model to the WSDL. so all the runtime code are all dealing with ServiceInfo instead of WSDL.

Categories: CXF

[CXF]CXF中的两个概念:Invoker & PhaseInterceptor

August 26, 2007 Leave a comment
在读CXF代码中,其中有个Invoker的概念,在CXF的WIKI上有对为什么有这个概念的解释,写得很清楚: 参考[1]

另外,在CXF当中的Interceptor概念中,引入PhaseInterceptor,就是说从一个endpoint发送message到另外一个endpoint的时候,它所要经历的Phases,那么这些Phases是哪些呢?而且分别代码什么呢? 参考[2]

[1] http://cwiki.apache.org/CXF20DOC/invokers.html
[2] http://cwiki.apache.org/CXF20DOC/interceptors.html

Categories: CXF

[CXF]CXF当中的Configuration — Spring2.0可扩展XML配置

August 23, 2007 Leave a comment
还是忍不住,昨天看完了CXF中Bus后,就一直想着CXF的Configuration的实现问题.可以说,CXF中的configuration是依赖于spring2.0中所提供的可扩展XML.

如果你使用CXF的话,如果你是通过xml文件来部署endpoint的话,那么下面的这段,你肯定不陌生:

    <jaxws:endpoint
        id="hello_world"
        implementor="demo.hw.server.GreeterImpl"
        wsdlLocation="WEB-INF/wsdl/hello_world.wsdl"
        address="/hello_world">
                <jaxws:features>
             <bean class="org.apache.cxf.feature.LoggingFeature"/>
                </jaxws:features>
    </jaxws:endpoint>

在Spring当中,本来没有endpoint这样的tag,这属于我们自定义的tag. 那么在spring2.0当中,我们可以很容易的扩展他原有的标签.

到底怎么来实现Spring的可扩展XML配置呢. 可以参考以下几篇文章: (当然了,你也可以从CXF的源代码中看到大量这样的实现).

http://www.javaeye.com/topic/102450
http://www.javaeye.com/topic/30963
http://www.javaeye.com/topic/30964
http://www.memestorm.com/blog/spring-components-xml-configuration-on-steroids/

Categories: CXF

[CXF]CXF中重要概念Bus

August 22, 2007 1 comment
记得我刚看CXF代码的时候,对其中的BUS这个概念很不清楚..因为提到Bus,好像就总跟传说中的ESB相关联. 问题在于是这个ESB的概念巨模糊,特别是对于刚跨入SOA或者Web service世界里的人来说,那就更不好理解了.

对于企业应用程序开发人员,我们可以把Bus看作是Spring框架中的BeanFactory. BeanFactory是负责管理Bean的,采用的是IOC的模式. 而在CXF中,Bus是管理那些全局配置的.比如你给我一个Namespace是http://schemas.xmlsoap.org/soap/,那么我就知道你需要的是一个SoapBinding. 还比如说我给你一个Transport的Namespace是:http://apache.org/cxf/binding/http,那么我就知道你需要的是一个Http传输. 所以这里的Bus,实质上也就是个资源管理器,你在这里可以注册或者删除一个资源.

Bus同时也是管理着接口和实现的连接.比如说,你的BindingFactory具体的实现是:org.apache.cxf.binding.http.HttpBindingFactory. 所以从某种意义上来说,Bus就是Spring当中的BeanFactory,如果你把BindingFactory等东西看作是一个普通的Bean的话.

在CXF当中,提供了三种方式对Bus的配置:
1.通过bus-extension.xml
2.通过API.
3.通过cxf-extension-*.xml

这里,对于Bus的配置,采取了跟Spring当中类似的做法,也就是采取了IOC的模式.
其中前2种方法是CXF内部的,也就是说不对spring的东西进行依赖. 第1,2种的方案其实是一样的,只不过一个是通过API,一个是通过xml配置文件而已.

这里我们以Http Binding这个来举例: 看下面这个bus-extension.xml:
<extensions xmlns="http://cxf.apache.org/bus/extension"&gt;
    <extension class="org.apache.cxf.binding.http.HttpBindingFactory"
      interface="org.apache.cxf.binding.BindingFactory" deferred="true">
        <namespace>http://apache.org/cxf/binding/http</namespace&gt;
    </extension>
</extensions>

其中,CXF当中存在了一系列的类,来负责解析,来配置这个Bus. 参与的类有:
Extension: 也就是Model
ExtensionManager: 负责取某个具体的Extension.
ExtensionFragmentParser: 负责解析bus-extension.xml的文件.
ExtensionManagerBus: CXF中bus-extension配置的Bus.其实也就是负责从bus-extension.xml文件中构建成Bus.注意,这里他也支持lazy-initialization的配置. 可以从deferred="true"看出.

在CXF当中,有两种方式来初始化Bus,一是通过CXF自带的bus-extension.xml,另外一个是通过跟spring相关的cxf-extension-*.xml. 那么这里呢,有个两个类: 一是CXFBusFactory是负责从bus-extension.xml来初始化Bus;二是SpringBusFactory负责从cxf-extension-*.xml来初始化Bus.在这里稍微一提的是,通过Spring来配置Bus的时候,一般是有个META-INF/cxf/cxf.extension,然后在cxf.extension第一行来指定是在哪个位置存放你的xml配置文件.

其实,在CXF中,跟spring的整合是很好的,比如说,如果你要通过xml文件来配置endpoint,他本身就是依赖于spring2.0的xml语法.在基于spring2.0 xml语法上做的.  当然了,你可以使用CXF让他不依赖于spring,但那样的话,你就丧失了可以用xml来配置endpoint的一个功能.

Categories: CXF

[CXF]CXF中ServiceInfo的结构图

August 16, 2007 Leave a comment
CXF中内部的ServiceModel,负责存放所有从WSDL或者从Java code中读取到的meta data.

Categories: CXF

[CXF]一句话概括Apache CXF

July 16, 2007 Leave a comment
我觉得用一句话来概括CXF就是:
Apache CXF就是帮助你如果把你的Service,一般来说就是Business Interface的服务转成Web Service的形式,这样可以供其它应用程序通过web service的方式来调用.
Categories: CXF

[CXF]CXF中DynamicProxy模式的应用

July 15, 2007 Leave a comment
在讲Dynamic Proxy模式之前,可能需要理解下Proxy模式, 经典的Proxy模式里,我们一般需要建立个Proxy的类来包含真正的实现类,而Client端调用的时候,则是去调用Proxy的类,这样Proxy类里就可以控制权限等问题.
在CXF当中用的是JDK自带的Dynamic Proxy,为什么叫Dynamic Proxy呢,因为他在编译的时候,并没有那个Proxy类,而是在运行时期生成一个Proxy类.
在看CXF代码应用Dynamic Proxy之前,来看一个简单的实现.

Interface类:
public interface HelloInterface {
public void sayHi(String name) throws Exception;
}

Impl类:
public class HelloInterfaceImpl implements HelloInterface {
public void sayHi(String name) throws Exception {
System.out.println("This is real HelloInterfaceImpl");
System.out.println("You Inovke sayHi with name : [" + name +"]");
}
}

Proxy的实现..
public class HelloInterfaceProxy implements InvocationHandler {
private Object object;
public static Object getInstance(Object o) {
return Proxy.newProxyInstance(o.getClass().getClassLoader(), o.getClass().getInterfaces(), new HelloInterfaceProxy(o));
}
private HelloInterfaceProxy(Object o) {
object = o;
}
public Object invoke(Object arg0, Method method, Object[] arg2) throws Throwable {
System.out.println("It was interceptored by the HelloInterfaceProxy class firstly");
return method.invoke(object, arg2);
}
}

Client端的调用:
HelloInterfaceImpl impl = new HelloInterfaceImpl();
HelloInterface hello = (HelloInterface)HelloInterfaceProxy.getInstance(impl);
hello.sayHi("Jeff");
运行结果:
It was interceptored by the HelloInterfaceProxy class firstly
This is real HelloInterfaceImpl
You Inovke sayHi with name : [Jeff]

在Client端的调用程序中,我们所获得的hello是一个HelloInterfaceProxy的类,并不是指到真正的HelloInterfaceImpl类.
这里,我们并没有一个真正的HelloInterfaceProxy的类,因为他是在运行时期产生的,所以我们把这个模式叫做Dynamic Proxy.

在CXF当中,实现InvocationHandler的类是: ClientProxy
Interface呢,就是SEI: 比如说是: Greeter.
真正的实现类,是GreeterImpl.
我们在客户端所获取到的Greeter实现,实际上是个GreeterProxy对象.

下面这是获取到客户端实现:
SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);
Greeter port = ss.getSoapPort();

Categories: CXF

[CXF]CXF中Collection Parameter模式的应用

July 14, 2007 Leave a comment
在CXF当中,ErrorVisitor就是一个典型的Collection Parameter模式的应用.
其实,Collection Parameter模式很简单,就是有个类,负责到各个对象去收集结果.比如Struts中的ActionErrors类.
我刚开始看到ErrorVisitor的时候,我以为是跟Visitor模式有关系,其实是没关系的.如果有可能,我希望能改个名字,比如叫:ErrorCollector.

参考资料:
——————–
http://c2.com/cgi/wiki?CollectingParameter

Categories: CXF