Web Services using AXIS2 - 01

0

No comments posted yet

Comments

Slide 3

http://en.wikipedia.org/wiki/Web_service Universal Description, Discovery and Integration (UDDI) Simple Object Access Protocol (SOAP) Web Services Description Language (WSDL) REpresentational State Transfer (REST) More recently, REpresentational State Transfer (REST) (RESTful web services are those conforming to the REST constraints) the REST web services have been regaining popularity, particularly with Internet companies. By using the PUT, GET and DELETE HTTP methods, alongside POST, these are often better integrated with HTTP and web browsers than SOAP-based services. They do not require XML messages or WSDL service-API definitions. JavaScript Object Notation (JSON)

Slide 7

http://en.wikipedia.org/wiki/Representational_State_Transfer http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm Representational State Transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web. The term Representational State Transfer (REST) was introduced and defined in 2000 by Roy Fielding[1][2] in his doctoral dissertation. Fielding is one of the principal authors of the Hypertext Transfer Protocol (HTTP) specification versions 1.0 and 1.1. Conforming to the REST constraints is referred to as being “RESTful” Architectural Elements Components (ex: server) A component is an abstract unit of software instructions and internal state that provides a transformation of data via its interface. Connectors (ex: dns)A connector is an abstract mechanism that mediates communication, coordination, or cooperation among components. Data Elements (ex: html) A datum is an element of information that is transferred from a component, or received by a component, via a connector.

Slide 1

Web Services using apache axis2 報告人:高明權 DATE :2010/04/11 Released V1.00 BLOG:http://tommykao.blogspot.com EMAIL : MCK6214@gmail.com

Slide 2

Web Services Agenda Background Case 01: Say Hello, pojo Case 02: File Upload & Download Case 03: Using the SoapMonitor module Case 04: SSL Transport Security Case 05: Message Level Security Case 06: Customized Module Case 07: Stateful Case 08: Clustering 2 著作人:高明權

Slide 3

Web Services Universal Description, Discovery and Integration (UDDI) Simple Object Access Protocol (SOAP) Web Services Description Language (WSDL) Source From: http://en.wikipedia.org/wiki/Web_service 3 著作人:高明權

Slide 4

Sequence of Web Services 4 著作人:高明權

Slide 5

Web Services in a SOA Source From: http://en.wikipedia.org/wiki/File:SOA_Detailed_Diagram.png 5 著作人:高明權

Slide 6

Web Services Specifications WS-Addressing WS-Policy WS-Security WS-Reliability WS-Transaction 6 著作人:高明權

Slide 7

RESTful Web Services REpresentational State Transfer (REST) Client-Server Stateless in nature Cache Uniform Interface between components Layered System constraints Code-On-Demand Architectural Elements Components (ex: server) Connectors (ex: router) Data Elements (ex: html) Source From: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm 7 著作人:高明權

Slide 8

Case 01: Say hello, pojo Sample code: webservices_workspace_01.zip 8 著作人:高明權

Slide 9

環境配置 – Apache Tomcat JDK 5.0 (or above) & JAVA_HOME 下載並安裝 Apache Tomcat v6.0 (above v5.5 would be fine) 從 TOMCAT 官方網站下載 網址: http://tomcat.apache.org/ 解壓縮至 <<Tomcat 安裝路徑 >> 從 Eclipse 設定 TOMCAT 伺服器 啟動 ECLIPSE 選單[Window]/[References] 選擇[Server]/[Runtime Environments]/[Add] 選定 [Apache Tomcat v6.0]/[Next] 確認<<Tomcat 安裝路徑>>點選 [Finish] 完成設定 從 Eclipse 啟動 TOMCAT 伺服器 從 Servers 視景找到 Tomcat v6.0 滑鼠右鍵 [Start] 連線並確認 Tomcat 安裝成功 網址: http://localhost:8080 著作人:高明權 9

Slide 10

環境配置 – Apache Axis2 下載並安裝 Apache AXIS2 從 AXIS2 官方網站下載 網址: http://ws.apache.org/axis2/ 將 axis2.war 檔案解壓縮至 <<Tomcat 安裝路徑 >>\webapps\ 從 Eclipse 重新啟動 TOMCAT 從 Servers 視景找到 Tomcat v6.0 滑鼠右鍵 [Restart] 連線並確認AXIS2 安裝成功 網址: http://localhost:8080/axis2/ 使用預設帳號登入 AXIS2 預設帳號/密碼為 admin/axis2 可編輯 axis2.xml 檔案,修改帳號密碼 檔案路徑: <<Tomcat 安裝路徑 >>\ webapps\axis2\WEB-INF\conf\axis2.xml 著作人:高明權 10

Slide 11

環境配置 – Tomcat 異常處理 指定 Apache Tomcat 的配置方式 從 Servers 視景找到 Tomcat v6.0 滑鼠快速點兩下 指定 Server Locations 相關配置 將 Deploy path 重新指定到 <<Tomcat 安裝路徑 >>\webapps\ 從 Eclipse 重新啟動 TOMCAT 從 Servers 視景找到 Tomcat v6.0 滑鼠右鍵 [Restart] 連線並確認 Tomcat 安裝成功 網址: http://localhost:8080 連線並確認AXIS2 安裝成功 網址: http://localhost:8080/axis2/ 著作人:高明權 11

Slide 12

1st Web Service Project 建立 Java 專案 選單[File]/[New]/[Other…] 選擇[Java Project]/[Next] 輸入專案名稱後點選[Finish] 專案名稱: WebServicesTutorial 滑鼠右鍵[New]/[Folder] 建立 META-INF 目錄 著作人:高明權 12

Slide 13

Write POJO Classes IHelloPOJOService.class package sample.webservice.pojo; public interface IHelloPOJOService { /** * Say Hello method, will return "Hello, " + name * @param name * @return */ public String sayHello(String name); } HelloPOJOService.class package sample.webservice.pojo; public class HelloPOJOService implements IHelloPOJOService { /** * Default constructor. */ public HelloPOJOService() { } public String sayHello(String name) { return "Hello, " + name; } } 著作人:高明權 13

Slide 14

declare the POJO Classes as a Web Service META-INF\Services.xml <serviceGroup> <!-- defines the name of the service. Axis2 uses the name of the service to create the endpoint address of the service as http://localhost:<port>/axis2/services/<nameofservice> So for the HelloPOJOService, the service endpoint will be http://localhost:8080/axis2/services/HelloPOJOService --> <service name="HelloPOJOService" scope="application"> <description>POJO Service : Say Hello</description> <!-- ServiceClass parameter specifies the service implementation class. --> <parameter name="ServiceClass">sample.webservice.pojo.HelloPOJOService</parameter> <!-- The messageReceiver element defines the message receiver to be used for handling this operation. Axis2 provides two built-in MessageReceivers for In-Only and In-Out operations without data binding; org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver for the In-Only operation and org.apache.axis2.receivers.RawXMLINOutMessageReceiver for the In-Out operation. --> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /> </messageReceivers> </service> </serviceGroup> 著作人:高明權 14

Slide 15

Pack the POJO Web Service 打包 POJO Web Service 滑鼠右鍵[Export] 選定 [JAR file]/[Next] 指定檔案輸出路徑 AXIS2路徑: <<Tomcat 安裝路徑 >>\ \webapps\axis2\WEB-INF\services\HelloPOJOService.aar 注意: 包名必須以 .aar 結尾 須含 META-INF\services.xml 著作人:高明權 15

Slide 16

Deploy the POJO Web Service 佈署 POJO Web Service 連線到 AXIS2 管理介面 網址: http://localhost:8080/axis2/axis2-admin/ 上傳 Web Service 檔案包 (*.aar ),選擇[Tools]/[Upload Service] 指定檔案並點選[Upload] 連線並確認 POJO 服務已開放 網址: http://localhost:8080/axis2/services/listServices 查看 POJO Web Service 取得該 Web Service 的描述 (WSDL) http://<host>:<port>/axis2/services/<ServiceName>?wsdl 本例為: http://localhost:8080/axis2/services/HelloPOJOService?wsdl 著作人:高明權 16

Slide 17

Test the POJO Web Service 1/3 直接連線測試 經由瀏覽器連線測試,連線方式為 http://<host>:<port>/axis2/services/<ServiceName>/<OperationName>?<parameters_key_pair> 本例為: http://localhost:8080/axis2/services/HelloPOJOService/sayHello?name=Tommy 著作人:高明權 17

Slide 18

Test the POJO Web Service 2/3 下載並安裝 soapUI 工具 網址: http://www.soapui.org 用 SoapUI 連線測試 建立新專案,選擇 [File]/[New soapUI Project] 專案名稱 : HelloPOJOService WSDL路徑 : http://localhost:8080/axis2/services/HelloPOJOService?wsdl 展開服務項目並著手編輯 soap request message 送出 soap request message,並檢視回傳結果 著作人:高明權 18

Slide 19

Test the POJO Web Service 3/3 執行 wsdl2java 產生 Client 端程式 指令:%AXIS2_HOME%\bin\wsdl2java.bat -p sample.webservice.pojo.client -o client -uri http://localhost:8080/axis2/services/HelloPOJOService?wsdl 撰寫並執行測試程式 著作人:高明權 19

Slide 20

以上為基礎,務必照表操課 Know-How, ExAct, Knowledge

URL: