03/05/2006

Java: Web Service

2006/05/03 使用 Eclipse Web Standard Tools 開發 Web Service

一直想要找一個方法,可以讓我直接將 JavaBean 轉換成 Web Service,而不需要太大的 coding effort。之前試過 SpringFramework 對 Web Service 的支援,基本上它也是要你自己去編一大堆的組態檔,好像也沒輕鬆到哪去。而 JAX-RPC 2.0 則是借用 JDK 5.0 對 Annotation 的支援,用起來跟 .NET web service 的寫法很像。但我仍在思考,是否存一種更乾淨的作法,可以不用 Annotation…

今天心想我已經為 Eclipse 裝上 Web Standard Tools,何不就試試它的 web service 開發能力呢。一試之下驚為天人,怎麼可以這麼好用。基本上它為 server 端的 web service 的開發提供兩種支援:

  1. 給定一個 Java 類別,它可以為你產生合適的 WSDL 檔
  2. 給定一個 WSDL 端點,它為你產生 Java 樣版

然後包含 web.xml、server-config.wsdd 的產生或修改、它都幫你做到好。其實它還有許多好用的功能,像是直接在 WSDL 上新增方法,甚至 refactor WSDL 等,絕對值得一試。

Eclipse Web Standard Tools WSDL Graph Editor

Eclipse WST 的WSDL 圖形編輯器

想了解更多 Eclipse WST 如何開發 web service,可參考:Developing Web Services Eclipse Web Tools Project

Web Service 測試小技巧

寫起來免得自己忘記。如果你有個 web service 叫 HelloMath,其中有個 method 為 add(int a, int b),你可以不用寫程式,直接瀏覽 http://some.url.to/services/HelloMath?method=add&a=1&b=2 進行測試。

這個方法在以 Axis 為服務套件的 web service 上行得通。.NET 預設也有類似用法。至於其他的 web service 套件,就請自行測試了。

----***----

2004/02/10 Java Web Service 簡介

談到對於 Web Service 的支援,多數專家會認定 .NET 平台比 Java 好。個人認為就易用性而言,這可能是真的(只是可能);不過若就支援的標準來說,Java 肯定是贏家。

這個領域的重要成員包括:

  • 來自 Sun 的 Java Web Services Developer Pack (Java WSDP),含括以下幾個套件:
    • JavaServer Pages Standard Tag Library (JSTL)
    • Java WSDP Registry Server
    • Web Application Deployment Tool
    • Ant
    • Tomcat
  • 另外一個要角則是來自 Apache 的 Axis(Apache eXtensible Interaction System,據說是 IBM donate 的)。Axis 有許多特異功能。例如只要把一般的 Java Class 的副檔名由 .java 改為 .jws,就可以立刻變身為 web service,可作為獨立的 web server 等

其他專案

The Simple Messaging Framework: "The Simple Messaging Framework provides an elegant way to create robust and flexible Web services. It is based on the document-style Web services paradigm that uses the full power of XML Schema. This approach enables you to expose arbitrarily complex business objects and services with ease."