可以清楚的看到,对Order类添加@XmlRootElement注解。Java Architecture for XML Binding (JAXB) 规范中注解库包含了@XmlRootElement。JAXB提供了快速而简便的方法将XML模式绑定到Java表示。JAXB隐含了SOAP消息和Java代码的转换细节,节XML和SOAP的解析,开发者不用知道这一过程。CXF默认使用JAXB作为数据绑定工具。
/**
* Validates the order and returns the order ID
**/
privateString validate(Order order) {
StringcustID = order.getCustomerID();
StringitemID = order.getItemID();
intqty = order.getQty();
doubleprice = order.getPrice();
“Spring is a first class citizen with Apache CXF. CXF supports theSpring 2.0 XML syntax, making it trivial to declare endpoints which are backedby Spring and inject clients into your application.”
OrderProcess client = (OrderProcess)context.getBean("orderClient");
Order order = new Order();
order.setCustomerID("C001");
order.setItemID("I001");
order.setQty(100);
order.setPrice(200.00);
String orderID = client.processOrder(order);
String message = (orderID == null) ?"Order not approved" : "Order approved; order ID is " +orderID;
System.out.println(message);
cd orderapp
#启动jetty
mvnjett:run
#执行client
mvn test -Pclient
执行client可以直接在IDE (Netbeanor Eclipse)中运行。
名词解释:
ApacheCXF = Celtix + XFire,ApacheCXF 的前身叫 Apache CeltiXfire,现在已经正式更名为 Apache CXF 了,以下简称为 CXF。CXF 继承了 Celtix 和 XFire 两大开源项目的精华,提供了对 JAX-WS 全面的支持,并且提供了多种 Binding 、DataBinding、Transport 以及各种 Format 的支持,并且可以根据实际项目的需要,采用代码优先(Code First)或者 WSDL 优先(WSDL First)来轻松地实现 Web Services 的发布和使用。Apache CXF已经是一个正式的Apache顶级项目。
Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来构建和开发 Services ,像 JAX-WS 。这些 Services 可以支持多种协议,比如:SOAP、XML/HTTP、RESTful HTTP 或者 CORBA ,并且可以在多种传输协议上运行,比如:HTTP、JMS 或者 JBI,CXF 大大简化了 Services 的创建,同时它继承了 XFire 传统,一样可以天然地和 Spring 进行无缝集成。
JCP(JavaCommunity Process) 是一个开放的国际组织,主要由Java开发者以及被授权者组成,职能是发展和更新。
CXF frontendsare programming APIs that can be used to develop and publish web services. CXFsupports two types of frontends, JAX-WS and simple frontend.
JAX-WS规范是一组XML web services的JAVAAPI,JAX-WS允许开发者可以选择RPC-oriented或者message-oriented来实现自己的web services。
java.lang.annotation,接口Annotation。对于Annotation,是Java5的新特性,JDK5引入了Metedata(元数据)很容易的就能够调用Annotations.Annotations提供一些本来不属于程序的数据,比如:一段代码的作者或者告诉编译器禁止一些特殊的错误。An annotation 对代码的执行没有什么影响。Annotations使用@annotation的形势应用于代码:类(class),属性(field),方法(method)等等。一个Annotation出现在上面提到的开始位置,而且一般只有一行,也可以包含有任意的参数。
Java annotation: An annotation, in the Java computer programming language, is a form of syntactic metadata that can be added to Java source code.[1] Classes, methods, variables, parameters and packages may beannotated. Unlike Javadoc tags, Java annotations can be reflective in that they can be embedded in class files generated by the compiler and may be retained by the Java VMto be made retrievable at run-time.[2] It is possible to create meta-annotations out of the existingones in Java, which makes this concept more sophisticated than in otherlanguages like C#
POJO(Plain OldJava Objects)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创造的简称。
Web Services Description Language的缩写,是一个用来描述Web服务和说明如何与Web服务通信的XML语言。为用户提供详细的接口说明书。
JAXB(JavaArchitecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术。该过程中,JAXB也提供了将XML实例文档反向生成Java对象树的方法,并能将Java对象树的内容重新写到XML实例文档。从另一方面来讲,JAXB提供了快速而简便的方法将XML模式绑定到Java表示,从而使得Java开发者在Java应用程序中能方便地结合XML数据和处理函数。
SOAP:简单对象访问协议,简单对象访问协议(SOAP)是一种轻量的、简单的、基于 XML 的协议,它被设计成在 WEB 上交换结构化的和固化的信息。 SOAP 可以和现存的许多因特网协议和格式结合使用,包括超文本传输协议( HTTP),简单邮件传输协议(SMTP),多用途网际邮件扩充协议(MIME)。它还支持从消息系统到远程过程调用(RPC)等大量的应用程序。