Several WebService technology implementation schemes often used in Java development

Reprinted from: http://blog.csdn.net/zolalad/article/details/25158995

Several WebService technology implementation schemes often used in Java development

      With the increasing demand for interconnection of heterogeneous systems, the importance of WebService has become increasingly prominent. With webservice, we can realize the interconnection of projects based on different programming languages. Furthermore, the developed program interface can be released in the form of service for users to call. Webservice is also the cornerstone of SOA, so the demand for webservice developers by major enterprises is also increasing day by day.

      What can Web Services do?
      The main advantages of Web Servcie are: Communication between different systems across languages ​​and platforms. Nowadays, many systems are integrated within the enterprise, and the problem of system integration between enterprises and enterprises. Web Services are the main solution. (Service reuse, reduce development costs, and only open services that you are willing to open).
       At present, there are two main development modes for webservice development: one is the traditional SOAP-based webservice development; the other is the rest-based webservice development.

One, SOAP-based WebService solution

1. SOAP protocol

       Simple Object Access Protocol is a protocol specification for exchanging data. It is a lightweight, simple, XML-based (a subset of the standard general markup language) protocol, which is designed to exchange structured data on the WEB. and solidified information.

2. The relationship between SOAP and JAX-WS

      JAX  -WS ( introduced in Java 6) is a Java implementation specification of the SOAP protocol. This new specification is designed to simplify SOAP-based Java development . The JAX-WS specification is actually a set of JAVA APIs for XML web services. JAX-WS allows developers to choose RPC-oriented or message-oriented to implement their own web services . Designing and developing Web services using the Java™ API for XMLWeb Services (JAX-WS) technology brings many benefits, simplifying the development and deployment of Web services, and accelerating the development of Web services.
        In JAX-WS, a remote call can be converted to an XML-based protocol, such as SOAP. In the process of using JAX-WS, developers do not need to write any code to generate and process SOAP messages. The runtime implementation of JAX-WS translates these API calls into corresponding SOAP messages.

        2.1 Implement a JWS-based webservice project (implemented directly using JWS api, without any webservice framework)
        (1)On the server side, users only need to define the interfaceSEI (service endpoint interface), and Provide the relevantimplementation class SIB (Service implementation Bean).

         (2) By calling the service publishing interface of JAX-WS, it can be published as a WebService interface
         (3) On the client side , users can create a proxy (replacing remote services with local objects) through the JAX-WS API to achieve this For remote server-side calls. The wsimport command is used to generate local proxies (ie local objects).

       The design process is as follows:

        Of course, JAX-WS also provides a set of API calls that operate on the underlying messages. You can directly use SOAP messages or XML messages to send requests through Dispatch, or use Provider to process SOAP or XML messages.
       Through the interoperability environment provided by web service, we can use JAX-WS to easily realize the interoperability between the JAVA platform and other programming environments (.net, php, etc.).

      JAX-WS supports both SOAP-based web services and REST-style web services.

      Example reference: webservice implements a JWS-based webservice project

3. The relationship between JAX-WS and JAX-RPC:

        JAX-WS is often abbreviated as JWS . The current version of JWS is 2.x. JAX-WS is the new technology successor to JAX-RPC, which is becoming more and more popular. Sun's early implementation of web services is JAX-RPC 1.1 (JSR 101), which is based on Java RPC, does not fully support the schema specification, and does not define standard implementations for Binding and Parsing.
       JAX-WS2.0(JSR 224)是Sun新的webservices协议栈,是一个完全基于标准的实现。在binding层,使用的是theJava Architecture for XML Binding (JAXB, JSR 222),在parsing层,使用的是theStreaming API for XML (StAX, JSR 173),同时它还完全支持schema规范。

4、基于JAX-WS规范的webservice 开发框架:Apache Axis2Apache CXF

       4.1  利用Apache Axis2实现基于SOAP的Web Service技术
       4.2  利用Apache CXF实现基于SOAP的Web Service 技术

       注:也可以不使用框架,直接使用JAX-WS提供的接口编写webservice程序,但这样就会很复杂(参考13)。

       Apache AxisApache CXF均是是JAX-WS规范的一个开源实现框架。并且这两个框架同时也支持JAX-RS规范。

       Apache Axis2是是新一代的SOAP引擎。支持各种数据绑定技术,包括官方 Java™标准 JAXB 2.x。Axis2 还支持针对 Web 服务配置的 Java 标准JAX-WS 2.x,作为其自有的配置技术的替代选择。另外,它还支持REST (Representational State Transfer)。

       Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来构建和开发 Services ,像 JAX-WS 。这些 Services 可以支持多种协议,比如:SOAP、XML/HTTP、RESTful HTTP 或者 CORBA ,并且可以在多种传输协议上运行,比如:HTTP、JMS 或者 JBI,CXF 大大简化了 Services 的创建,同时它继承了 XFire 传统,一样可以天然地和 Spring 进行无缝集成。

       Apache CXF是在Java项目中使用的比较多的webservice开源框架,其也提供了对spring的良好支支持。

二、基于Rest的Web Service解决方案

1、Rest

       REST(Representational State Transfer)是一种轻量级的Web Service架构风格,其实现和操作明显比基于SOAPXML-RPC技术的webservice更为简洁,可以完全通过HTTP协议实现,还可以利用缓存Cache来提高响应速度,性能、效率和易用性上都优于SOAP协议。REST架构让人们真正理解我们的网络协议HTTP本来面貌,对资源的操作包括获取、创建、修改和删除资源的操作正好对应HTTP协议提供的GET、POST、PUT和DELETE方法,因此REST把HTTP对一个URL资源的操作限制在GET、POST、PUT和DELETE这四个之内。这种针对网络应用的设计和开发方式,可以降低开发的复杂性,提高系统的可伸缩性。

2、Rest和JAX-RS的关系

      JAX-RS (JavaAPI for RESTful Web Services)是Rest技术的一个Java实现规范,这个新规范提供了基于REST的webservice开发的应用程序接口。它主要关注使用Java注释和普通旧式Java对象(POJO)实现RESTful服务。尽管总是可以使用servlet实现RESTful服务,但是以这种方式实现业务逻辑需要太多HTTP GET请求。
       JAX-RS 隐藏所有 HTTP 并把servlet 绑定到 Java 类中的各个方法。注释还可以动态地提取 HTTP 请求中的信息,以及把应用程序生成的异常映射到 HTTP 响应码。由于这些原因,JAX-RS 是一种实现RESTful Java Web 服务的有效方法。

       JAX-RS提供了一些标注将一个资源类,一个POJO Java类,封装为Web资源。

       标注包括:

        @Path,标注资源类或者方法的相对路径
        @GET,@PUT,@POST,@DELETE,标注方法是HTTP请求的类型。
        @Produces,标注返回的MIME媒体类型
        @Consumes,标注可接受请求的MIME媒体类型
        @PathParam,@QueryParam,@HeaderParam,@CookieParam,@MatrixParam,@FormParam,分别标注方法的参数来自于HTTP请求的不同位置,例如        @PathParam来自于URL的路径,@QueryParam来自于URL的查询参数,@HeaderParam来自于HTTP请求的头信息,@CookieParam来自于HTTP请求的Cookie。

3、利用Apache Wink实现基于REST的Web Service技术

       Apache WinkJAX-RS规范的一个开源实现的框架,用于创建RESTfulweb services应用程序。Wink包括了一个服务器端模块和一个客户端模块,用于帮助开发者快速高效的开发RESTful Web services应用。

       其它基于JAX-RS实现的框架还有Jersey(详见参考17),RestEasy,Apache Wink,Spring REST都可以完成REST的搭建和使用,各有特点,看自己的项目关注的是哪一方面,性能、集成、抑或出身。框架或者组件能让我们开发REST更简单和容易,但也需要要深入的了解为什么使用REST.

       总的来说,基于SOAP的Web Service解决方案虽然较为成熟,且安全性较好,但是使用门槛较高,在大并发情况下会有性能问题,在互联网上使用不太普及,因此并不太适合Web 2.0网站服务使用,目前大量的Web 2.0网站使用另外一种解决方案——基于RESTWeb Service技术

注:webservice是RPC远程过程调用的一种。

参考资料:

1  ApacheWink使用介绍:http://blog.csdn.net/kimylrong/article/details/7687593

2  用ApacheWink+Eclipse+Maven2实现RESTful WebService:

http://blog.fangjian.me/posts/2010/10/02/use-eclipse-maven2-apache-wink-for-restful-web-service/

3. 使用 Apache Wink、Eclipse 和 Maven2 开发 基于RESTful 的Webservice:

参考: http://www.ibm.com/developerworks/cn/web/wa-useapachewink/?ca=drs-tp4608 

4 RESTful Web 服务和 ApacheWink,第 3 部分: ApacheWink 和 REST

http://www.ibm.com/developerworks/cn/web/wa-apachewink3/

5 Rest风格的web服务开发-入门篇1

参考:http://www.tuicool.com/articles/7bq6ju

6 REST类型Web服务的优势

http://blog.sina.com.cn/s/blog_5572d4d30100mn5a.html

7 基于 REST 的 Web 服务:http://www.ibm.com/developerworks/cn/webservices/ws-restful/

8 构建REST风格的Web Service

http://zhangjunhd.blog.51cto.com/113473/47283/

9 使用apache CXF和maven开发基于SOAP的WebService

参考:http://www.cnblogs.com/holbrook/archive/2012/12/12/2814821.html

10关于Web Service和Rest  Service理解

参考:http://my.oschina.net/lilw/blog/170518

11  REST和SOAP WebService的区别比较

参考:http://hi.baidu.com/itaolei/item/dd8e5f0fa6f1663bf3eafc99

http://www.360doc.com/content/09/0918/23/11553_6152605.shtml

12  JWS入门

参考:  http://blog.csdn.net/ylchou/article/details/7727337

13 JWS-webservice 与Axis2-webservice的基于SOAP的快速实现

参考: http://blog.csdn.net/a1314517love/article/details/24849759

14  webServices教程(JWS-Java)(图文介绍)

考: http://wenku.baidu.com/link?url=afnra_BuxObgfW5LR_cbMM55-kLSjSnBnwAthNeTIItiITxUC51xDXZj7xicMLkpmF-KiIxKxrAj8_TWLICx-WqqVOCetHeCRaI6yz96uLy

15.远程通信的几种选择(RPCRMIWebservice,JMS的区别)

16. webservice的概念,webservice可以做什么?webservice什么时候用?

参考:http://blog.csdn.net/weiguolee/article/details/6881411

17  WebService之基于REST机制的的实现实例(Java版)

http://blog.csdn.net/zolalad/article/details/31424831

 参考: http://www.tuicool.com/articles/2qAzqq

转自:http://blog.csdn.net/zolalad/article/details/25158995

Java开发中经常使用到的几种WebService技术实现方案

      随着异构系统互联需求的不断增加,WebService的重要性也日益彰显出来。凭借webservice,我们可以实现基于不同程序语言的项目的互联互通。更可以将开发好的程序接口以服务的形式发布出去供使用者调用。webservice也是SOA的基石,因此目前各大企业对于webservice开发者的需求量也是与日俱增。

      Web Service可以做什么?
      Web Servcie最主要的优点是: 即跨语言,跨平台的不同系统之间的通信。 现在企业内部的很多系统集成,企业和企业之间的系统集成的问题。Web Service是主要的解决方案。(服务重用,降低开发成本,只开放自己愿意开放的服务)。
       目前webservice开发主要有以下两种开发模式:一是传统基于SOAP模式的webservice开发;二是基于rest模式的webservice开发。

一、基于SOAP的WebService解决方案

1 、SOAP协议

       简单对象访问协议是交换数据的一种协议规范,是一种轻量的、简单的、基于XML(标准通用标记语言下的一个子集)的协议,它被设计成在WEB上交换结构化的和固化的信息。

2、SOAP与JAX-WS的关系

       JAX-WS(Java6引进) 是SOAP协议的一个Java的实现规范这个新规范是为了简化基于SOAP的Java开发。JAX-WS规范其实就是一组XMLweb services的JAVA API,JAX-WS允许开发者可以选择RPC-oriented或者message-oriented来实现自己的web services通过使用 Java™ API for XMLWeb Services (JAX-WS) 技术设计和开发 Web 服务,可以带来很多好处,能简化 Web 服务的开发和部署,并能加速 Web 服务的开发。
        在 JAX-WS中,一个远程调用可以转换为一个基于XML的协议,比如SOAP。在使用JAX-WS过程中,开发者不需要编写任何生成和处理SOAP消息的代码。JAX-WS的运行时实现会将这些API的调用转换成为对应的SOAP消息。

        2.1 实现一个基于JWS的webservice项目(直接使用JWS api 实现,不借助任何webservice框架)
        (1)在服务器端,用户只需要通过Java语言定义远程调用所需要实现的接口SEI(service endpoint interface),并提供相关的实现类SIB(Service implementation Bean)

         (2)通过调用JAX-WS的服务发布接口就可以将其发布为WebService接口
         (3)在客户端,用户可以通过JAX-WS的API创建一个代理(用本地对象来替代远程的服务)来实现对于远程服务器端的调用。wsimport命令用于生成本地代理(即本地对象)。

       设计流程如下:

        当然 JAX-WS 也提供了一组针对底层消息进行操作的API调用,你可以通过Dispatch 直接使用SOAP消息或XML消息发送请求或者使用Provider处理SOAP或XML消息。
       通过web service所提供的互操作环境,我们可以用JAX-WS轻松实现JAVA平台与其他编程环境(.net、php等)的互操作。

      JAX-WS同时支持基于SOAP的Web服务和REST风格的Web服务。

      示例参考:webservice之实现一个基于JWS的webservice项目

3、JAX-WS与JAX-RPC之间的关系:

        JAX-WS通常可简写为JWS。当前JWS的版本为2.x。JAX-WS是JAX-RPC的后继新技术,日渐流行。Sun早期的web services的实现是JAX-RPC 1.1 (JSR 101),这个实现是基于Java的RPC,并不完全支持schema规范,同时没有对Binding和Parsing定义标准的实现。
       JAX-WS2.0(JSR 224)是Sun新的webservices协议栈,是一个完全基于标准的实现。在binding层,使用的是theJava Architecture for XML Binding (JAXB, JSR 222),在parsing层,使用的是theStreaming API for XML (StAX, JSR 173),同时它还完全支持schema规范。

4、基于JAX-WS规范的webservice 开发框架:Apache Axis2Apache CXF

       4.1  利用Apache Axis2实现基于SOAP的Web Service技术
       4.2  利用Apache CXF实现基于SOAP的Web Service 技术

       注:也可以不使用框架,直接使用JAX-WS提供的接口编写webservice程序,但这样就会很复杂(参考13)。

       Apache AxisApache CXF均是是JAX-WS规范的一个开源实现框架。并且这两个框架同时也支持JAX-RS规范。

       Apache Axis2是是新一代的SOAP引擎。支持各种数据绑定技术,包括官方 Java™标准 JAXB 2.x。Axis2 还支持针对 Web 服务配置的 Java 标准JAX-WS 2.x,作为其自有的配置技术的替代选择。另外,它还支持REST (Representational State Transfer)。

       Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来构建和开发 Services ,像 JAX-WS 。这些 Services 可以支持多种协议,比如:SOAP、XML/HTTP、RESTful HTTP 或者 CORBA ,并且可以在多种传输协议上运行,比如:HTTP、JMS 或者 JBI,CXF 大大简化了 Services 的创建,同时它继承了 XFire 传统,一样可以天然地和 Spring 进行无缝集成。

       Apache CXF是在Java项目中使用的比较多的webservice开源框架,其也提供了对spring的良好支支持。

二、基于Rest的Web Service解决方案

1、Rest

       REST(Representational State Transfer)是一种轻量级的Web Service架构风格,其实现和操作明显比基于SOAPXML-RPC技术的webservice更为简洁,可以完全通过HTTP协议实现,还可以利用缓存Cache来提高响应速度,性能、效率和易用性上都优于SOAP协议。REST架构让人们真正理解我们的网络协议HTTP本来面貌,对资源的操作包括获取、创建、修改和删除资源的操作正好对应HTTP协议提供的GET、POST、PUT和DELETE方法,因此REST把HTTP对一个URL资源的操作限制在GET、POST、PUT和DELETE这四个之内。这种针对网络应用的设计和开发方式,可以降低开发的复杂性,提高系统的可伸缩性。

2、Rest和JAX-RS的关系

      JAX-RS (JavaAPI for RESTful Web Services)是Rest技术的一个Java实现规范,这个新规范提供了基于REST的webservice开发的应用程序接口。它主要关注使用Java注释和普通旧式Java对象(POJO)实现RESTful服务。尽管总是可以使用servlet实现RESTful服务,但是以这种方式实现业务逻辑需要太多HTTP GET请求。
       JAX-RS 隐藏所有 HTTP 并把servlet 绑定到 Java 类中的各个方法。注释还可以动态地提取 HTTP 请求中的信息,以及把应用程序生成的异常映射到 HTTP 响应码。由于这些原因,JAX-RS 是一种实现RESTful Java Web 服务的有效方法。

       JAX-RS提供了一些标注将一个资源类,一个POJO Java类,封装为Web资源。

       标注包括:

        @Path,标注资源类或者方法的相对路径
        @GET,@PUT,@POST,@DELETE,标注方法是HTTP请求的类型。
        @Produces,标注返回的MIME媒体类型
        @Consumes,标注可接受请求的MIME媒体类型
        @PathParam,@QueryParam,@HeaderParam,@CookieParam,@MatrixParam,@FormParam,分别标注方法的参数来自于HTTP请求的不同位置,例如        @PathParam来自于URL的路径,@QueryParam来自于URL的查询参数,@HeaderParam来自于HTTP请求的头信息,@CookieParam来自于HTTP请求的Cookie。

3、利用Apache Wink实现基于REST的Web Service技术

       Apache WinkJAX-RS规范的一个开源实现的框架,用于创建RESTfulweb services应用程序。Wink包括了一个服务器端模块和一个客户端模块,用于帮助开发者快速高效的开发RESTful Web services应用。

       其它基于JAX-RS实现的框架还有Jersey(详见参考17),RestEasy,Apache Wink,Spring REST都可以完成REST的搭建和使用,各有特点,看自己的项目关注的是哪一方面,性能、集成、抑或出身。框架或者组件能让我们开发REST更简单和容易,但也需要要深入的了解为什么使用REST.

       总的来说,基于SOAP的Web Service解决方案虽然较为成熟,且安全性较好,但是使用门槛较高,在大并发情况下会有性能问题,在互联网上使用不太普及,因此并不太适合Web 2.0网站服务使用,目前大量的Web 2.0网站使用另外一种解决方案——基于RESTWeb Service技术

注:webservice是RPC远程过程调用的一种。

参考资料:

1  ApacheWink使用介绍:http://blog.csdn.net/kimylrong/article/details/7687593

2  用ApacheWink+Eclipse+Maven2实现RESTful WebService:

http://blog.fangjian.me/posts/2010/10/02/use-eclipse-maven2-apache-wink-for-restful-web-service/

3. 使用 Apache Wink、Eclipse 和 Maven2 开发 基于RESTful 的Webservice:

参考: http://www.ibm.com/developerworks/cn/web/wa-useapachewink/?ca=drs-tp4608 

4 RESTful Web 服务和 ApacheWink,第 3 部分: ApacheWink 和 REST

http://www.ibm.com/developerworks/cn/web/wa-apachewink3/

5 Rest风格的web服务开发-入门篇1

参考:http://www.tuicool.com/articles/7bq6ju

6 REST类型Web服务的优势

http://blog.sina.com.cn/s/blog_5572d4d30100mn5a.html

7 基于 REST 的 Web 服务:http://www.ibm.com/developerworks/cn/webservices/ws-restful/

8 构建REST风格的Web Service

http://zhangjunhd.blog.51cto.com/113473/47283/

9 使用apache CXF和maven开发基于SOAP的WebService

参考:http://www.cnblogs.com/holbrook/archive/2012/12/12/2814821.html

10关于Web Service和Rest  Service理解

参考:http://my.oschina.net/lilw/blog/170518

11  REST和SOAP WebService的区别比较

参考:http://hi.baidu.com/itaolei/item/dd8e5f0fa6f1663bf3eafc99

http://www.360doc.com/content/09/0918/23/11553_6152605.shtml

12  JWS入门

参考:  http://blog.csdn.net/ylchou/article/details/7727337

13 JWS-webservice 与Axis2-webservice的基于SOAP的快速实现

参考: http://blog.csdn.net/a1314517love/article/details/24849759

14  webServices教程(JWS-Java)(图文介绍)

考: http://wenku.baidu.com/link?url=afnra_BuxObgfW5LR_cbMM55-kLSjSnBnwAthNeTIItiITxUC51xDXZj7xicMLkpmF-KiIxKxrAj8_TWLICx-WqqVOCetHeCRaI6yz96uLy

15.远程通信的几种选择(RPCRMIWebservice,JMS的区别)

16. webservice的概念,webservice可以做什么?webservice什么时候用?

参考:http://blog.csdn.net/weiguolee/article/details/6881411

17  WebService之基于REST机制的的实现实例(Java版)

http://blog.csdn.net/zolalad/article/details/31424831

 参考: http://www.tuicool.com/articles/2qAzqq

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325822317&siteId=291194637