2010年5月30日 星期日

[Web Service]-NetBeans開發Web Service

Getting Started with JAX-WS Web Services
                                                          from NetBeans Web Service tutorials
Java API for XML Web Services (JAX-WS) 2.0/2.1, JSR 224, is an important part of the Java EE 5 platform. A follow-up to the release of Java API for XML-based RPC 1.1(JAX-RPC), JAX-WS simplifies the task of developing web services using Java technology. It addresses some of the issues in JAX-RPC 1.1 by providing support for multiple protocols such as SOAP 1.1, SOAP 1.2, XML, and by providing a facility for supporting additional protocols along with HTTP. JAX-WS uses JAXB 2.0 for data binding and supports customizations to control generated service endpoint interfaces. With its support for annotations, JAX-WS simplifies web service development and reduces the size of runtime JAR files.

Creating a Web Service
Choosing a Container
You can either deploy your web service in a web container or in an EJB container. This depends on your choice of implementation. If you are creating a Java EE 6 application, use a web container in any case, because you can put EJBs directly in a web application. For example, if you plan to deploy to the Tomcat Web Server, which only has a web container, create a web application, not an EJB module.
  1. Choose File > New Project (Ctrl-Shift-N). Select Web Application from the Java Web category or EJB Module from the Java EE category.
  2. Name the project CalculatorWSApplication.
  3. Click through the remaining pages and click Finish.
Creating a Web Service from a Java Class
  1. Right-click the CalculatorWSApplication node and choose New > Web Service.
  2. Name the web service CalculatorWS and type org.me.calculator in Package.
  3. If you are creating a Java EE 6 project, leave Create Web Service from Scratch selected, and select Implement Web Service as a Stateless Session Bean.
  4. Click Finish. The Projects window displays the structure of the new web service and the source code is shown in the editor area.
Designing the Web Service
Adding an Operation to the Web Service
  1. Change to the Design view. (Note: The Preview view in NetBeans 6.5.1 is disabled.)
  2. Click Add Operation in the visual designer. A dialog box appears where you can define the new operation.
  3. In the upper part of the Add Operation dialog box, type add in Name and type int in the Return Type drop-down list. In the lower part of the Add Operation dialog box, click Add and create a parameter of type int named i. Then click Add again and create a parameter of type int called j. You now see the following:
  4. Click OK at the bottom of the Add Operation dialog box. The visual designer now displays the following:
  5. Click Source and view the code that you generated in the previous steps. It differs whether you created the service as an EE6 stateless bean or not. Can you see the difference in the screenshots below?
  6. In the editor, extend the skeleton add operation to the following (changes are in bold):
@WebMethod
public int add(@WebParam(name = "i") int i, 
@WebParam(name = "j") int j) {
int k = i + j;
return k;
} 
Deploying and Testing the Web Service
To test successful deployment to a web container:
  1. Right-click the project and choose Deploy. The IDE starts the application server, builds the application, and deploys the application to the server. You can follow the progress of these operations in the CalculatorWSApplication (run-deploy) and GlassFish or Tomcat tabs in the Output view.
  2. If you deployed to the Tomcat Web Server, you will see the following instead, which indicates that you have successfully deployed your web service:

Consuming the Web Service
Client : Java Class in Java SE Application
  1. Choose File > New Project (Ctrl-Shift-N). Select Java Application from the Java category. Name the project CalculatorWS_Client_Application. Leave Create Main Class selected and accept all other default settings. Click Finish.
  2. Right-click the CalculatorWS_Client_Application node and choose New > Web Service Client.
  3. In Project, click Browse. Browse to the web service that you want to consume. When you have selected the web service, click OK.
  4. Leave the other settings at default and click Finish. The Projects window displays the new web service client, with a node for the add method that you created:
  5. Double-click Main.java so that it opens in the Source Editor. Delete the TODO comment and then drag the add node above into the empty line. You now see the following:
public static void main(String[] args) {
try {
// Call Web Service Operation
org.me.calculator.CalculatorWSService service = 
new org.me.calculator.CalculatorWSService();
org.me.calculator.CalculatorWS port = 
service.getCalculatorWSPort();
// TODO initialize WS operation arguments here
int i = 0;
int j = 0;
// TODO process result here
int result = port.add(i, j);
System.out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
}

2010年5月29日 星期六

[Web Service]-淺談Web Service

Introduction to Web Services
                                                                      from NetBeans Web Service tutorials
Web services are distributed application components that are externally available. You can use them to integrate computer applications that are written in different languages and run on different platforms. Web services are language and platform independent because vendors have agreed on common web service standards.
Several programing models are available to web service developers. These models fall into two categories, both supported by the IDE:
  • REST-based. REpresentational State Transfer is a new way to create and communicate with web services. In REST, resources have URIs and are manipulated through HTTP header operations.
  • SOAP/WSDL-based. In traditional web service models, web service interfaces are exposed through WSDL documents (a type of XML), which have URLs. Subsequent message exchange is in SOAP, another type of XML document.
RESTful Web Services
REST-based ("RESTful") web services are collections of web resources identified by URIs. Every document and every process is modeled as a web resource with a unique URI. These web resources are manipulated by the actions that can be specified in an HTTP header. Neither SOAP, nor WSDL, nor WS-* standards are used. Instead, message exchange can be conducted in any format—XML, JSON, HTML, etc. In many cases a web browser can serve as the client.

HTTP is the protocol in REST. Only four methods are available: GET, PUT, POST, and DELETE. Requests can be bookmarked and responses can be cached. A network administrator can easily follow what is going on with a RESTful service just by looking at the HTTP headers.

REST is a suitable technology for applications that do not require security beyond what is available in the HTTP infrastructure and where HTTP is the appropriate protocol. REST services can still deliver sophisticated functionality. Flickr, Google Maps and Amazon all provide RESTful web services. NetBeans IDE Software as a Service (SaaS) functionality lets you use Facebook, Zillow, and other third-party-provided services in your own applications.

SOAP-based Web Services
In SOAP-based web services, Java utilites create a WSDL file based on the Java code in the web service. The WSDL is exposed on the net. Parties interested in using the web service create a Java client based on the WSDL. Messages are exchanged in SOAP format. The range of operations that can be passed in SOAP is much broader than what is available in REST, especially in security.

SOAP-based web services are suitable for heavyweight applications using complicated operations and for applications requiring sophisticated security, reliability or other WS-* standards-supported features. They are also suitable when a transport protocol other than HTTP has to be used. Many of Amazon's web services, particularly those involving commercial transactions, and the web services used by banks and government agencies are SOAP-based.

The Java API for XML Web Services (JAX-WS) is the current model for SOAP-based web services in Metro. JAX-WS is built on the earlier JAX-RPC model but uses specific Java EE 5 features, such as annotations, to simplify the task of developing web services. Because it uses SOAP for messaging, JAX-WS is transport neutral. It also supports a wide range of modular WS-* specifications, such as WS-Security and WS-ReliableMessaging.

2010年5月10日 星期一

巴里島蜜月之旅-第3天

第三天:
第三天的行程主要集中在烏布市區,由於行程相當密集也滿趕的
所以這天是唯一自助行中唯一有包車+隨車導遊的,以便增加機動性
(因為第三天住的是庫塔的葉子,離烏布有點距離,所以只有今天能逛囉)
第一站就是蠟染村,其實蠟染村就是一棟建築
裡面是販售現成的商品,外面則是有一區是現場幫人蠟染的區域
每一攤都會展示他們的圖案,你可以選你喜歡圖案的那一攤幫你蠟染


其實在出發前網站資訊就有說白T要從台灣帶比較便宜
可是偏偏就是不信邪,想說那裡的衣服能賣多貴
結果單買白T居然要四百多台幣,重點是布料也不是挺優…
人果然是不能夠嘴硬滴(下面是我跟太座選的圖案)


下一站銀飾村其實就在蠟染村的旁邊
裡面就是一個很大的銀飾賣場,也有賣少許的金飾
裡面的銀飾真的是貴呀~~太座買了一個小項鍊居然要台幣六千多!!嗚噗~


再來就到了午餐時間~
今天的午餐也是網路上大家極力推薦的nuri's豬肋排
由於第一天本來要送的水明漾按摩導遊居然忘了訂
所以今天的豬肋排大餐是免費送的喲~,不瞞各位… 真的是好吃到棒棒聲呀~
不只豬排好吃,連飯跟炒青菜也是讚,至於他們的沙嗲我只能說soso而已




接下來是一個小時的烏布市場自由晃,老實說不太建議大家來烏布市場
雖然網路上說可以在這挖寶,但是這裡的東西品質真的是太差了
當伴手禮的話實在沒什麼東西可以搬的上臺面,而且環境滿髒亂的
重點是為了品質不怎樣的東西還要跟店家殺價老半天,何苦來哉咧~


烏布皇宮就在烏布市場的旁邊,本來的行程有考慮過晚上看表演的
不過因為行程有點趕,也有人說表演不怎樣,所以就放棄了


接下來是前往德布拉朗的teras padi梯田下午茶(距烏布傳統市場約15分車程)
簡直就是趕趕趕呀~這個點其實滿不錯的,梯田頗壯觀
坐在這吃下午茶有一種悠閒的感覺,不過這裡有蚊子,來之前要記得擦防蚊液




下午行程又由梯田回到了烏布,因為離晚上訂位的餐廳還有一個多小時
所以臨時追加了四手spa,這間spa是我們的隨車導遊小林推薦的
也許跟店家有合作吧~誰知道呢,不過這間用的是若梨泥耶~還滿妙的
主要是按摩後把若梨泥塗在身上,然後等泥乾乾後再搓掉它
整個流程結束後還可以泡澡捏,連浴缸都是愛心型狀的@@



結束spa後整個人神清氣爽不少,接下來就是今天晚上的重頭戲了
特地早早就訂位的mozaic法式晚餐,太座從網路上找來,聽說是米其林3星
排行世界50大美食餐廳內(有沒有這麼誇張…)
大廳非常的美輪美煥,但只是用來招待客人用的


真正的用餐地點別有洞天,是後面的樹林耶~


在出餐前服務生會來介紹今天菜色,的佐料是用那些材料做成的


中間用餐內容省略,老實說個人是覺得沒有比陶板屋之流的好吃
可能是我們這種貧窮嘴吃不慣吧 哈哈~~
今天這餐一個人大概花了台幣2700左右…
離開前門口拍一張


吃完mozaic下一站就是第三天的住宿地點DE DAUN VILLA(葉子)
房間配備下一篇再報給客倌們知道,因為我們有加訂蜜月配套
(2人各一次2小時Dala Essential Spa療程及
Villa內1次燭光晚餐(泳池灑滿花瓣+VILLA蠟燭佈置))
進來房間首先映入眼簾的就是一整個騷包到不行的排場



不過這個佈置並沒有維持太久,因為今天行程實在太密集了
所以胡亂收拾洗完澡後就倒頭大睡了 哈哈~~

2010年4月8日 星期四

巴里島蜜月之旅-第1天~第2天

距離去年十月底的蜜月旅行已經過五個月了
現在才稍稍有力提起筆來~噢不~
是打開從開通帳號來從未使用過的Bloger

感覺從規畫到確定行程好像只花了不到一個月的時間
雖然結婚的事已經忙到不行了
但是跟老婆兩個人硬是又要搞個自由行出來
只能說乖乖跟團這種fu不太適合我們兩個

下面是我們排出來的行程經旅行社的人稍微修改過後的定案
除了第三天烏布的行程較密集有跟旅行社加訂一天的一車一導遊外
其餘的時間都是搭計程車的自由行程哞~
第一天: 換匯(庫塔) => 超市買補及品 => 水明漾JOJO按摩 1 hour(贈送)
            => 金巴蘭海鮮(金巴蘭cafe')、看夕陽 => 日航check in
            => 日航熱石能spa
第二天: 9點早餐 => 游泳、逛日航(教堂、設施) => 沙灘騎駱駝
            =>日航club下午茶(15:00~16:00) => 看夕陽
            => 日航Mandala四手精油按摩 2 hours => 日航吃晚餐
第三天: 8點早餐 => 蠟染村、銀飾工廠 => nuri's吃午餐
            => 烏布傳統市場shopping、附近逛逛
            => 德布拉朗的teras padi梯田下午茶(距烏布傳統市場15分車程)
            => 回烏布的zen spa做spa(有時間的話) => mozaic吃晚餐
            => 葉子check in(迎賓按摩)
第四天: 9點早餐 => 2 hours Dala Essential spa(贈送)
            => 庫塔街上晃晃shopping => 神鷹廣場
            => 回葉子休息一下 => 游個泳
            => 到太陽百貨逛逛 => 葉子燭光晚餐
第五天: 9點早餐還有check out => 黃金咖啡工廠 => 名產店
            => 酥骨雞 => 機場go home
除了機票和住宿費用還有下面這些額外加訂的部份:
日航升級Club Beachfront + 葉子選擇1Bed Pool Villa並加購蜜月配套
+ nuri's和mozaic的費用 + 日航熱石能spa和Mandala四手精油按摩
總費用是 1人:44500元

第一天:
第一站就是直奔換匯店,這是我家太座堅持要去的換匯店
從網路上收集來的消息


第一天的隨車導遊,滿活潑親切的,可惜她只負責到日航check in而已
(抽號碼牌等待換匯中)


換完匯後先到超市買些補給品
峇里島的超市規模大概就跟全聯差不多,裡面有很多微妙的水果跟餅乾
(峇里島的山竹好吃到棒棒聲呀~)
這裡我們買了礦泉水、山竹和泡麵



峇里島的幣值太大了,所以找的零錢通常變成了…糖果?
不過它的糖果還滿好吃的~哈哈~


買完補給品後趕在黃昏前來到了金巴蘭海灘
這裡的特色就是可以在沙灘上邊吃海鮮邊看海景
我們在網路上找了一家評價不錯的金巴蘭cafe'吃海鮮
雖然裡面的活海鮮上頭還有一些蒼蠅在飛
不過看來這裡每一家都差不多是降
還好海鮮真是不錯吃,我們點了龍蝦大餐,好險吃完也沒拉肚子~哈



吃完好吃的海鮮大餐後,再來就是到日航check in準備好好休息了
等待check in時還有招待免費飲料捏



日航的房間算是寬敞舒適,淋浴間還是透明的@@



第一天晚上的重頭戲就是額外加購的熱石能spa
所謂的熱石名附其實就是拿用熱水泡過的小石頭來按摩…
不過也不是全程都用熱石啦,因為石頭的熱度沒法維持很久
過程中還是有用雙手按摩的~,一個人要台幣2510! 真是貴森森呀
雖然熱石的感覺滿新鮮的,但我還是覺得傳統的指壓按摩比較能夠盡興點 哈


第二天:
一起床當然要見識一下傳聞中的無敵海景,果然有Club Beachfront 的價值呀~TT…


club的早餐空間也是跟一般級別的有所區隔
除了自助式也有五到六種中西式的套餐可以點
套餐部份也是免費的喲,簡直整個飽到爆炸



早上沒安排額外的行程,計畫把日航裡裡外外都設施都逛熟再說
基本上這裡還是以水上設施居多囉,一群朋友來這玩水上排球真有fu



升級club的另一個誘人的地方是
隨時可以到club享用免費的果汁
空間比較有私密性,還有下午茶時間喲!!一樣是免費的~



千呼萬喚始出來的沙灘騎駱駝,當初就是為了騎駱駝才特地訂日航的
費用好像是30分鐘七百多台幣
一開始還滿有趣的,不過其實過程中的風景都差不多
30分鐘的路程原本以為是繞日航一圈,結果是15分鐘去,15分原路折返
原路折返的15分就覺得滿無聊的了,因為景色都一樣,一邊是海一邊是草叢



騎完駱駝開始找尋傳聞中日航裡面的海邊教堂
教堂大部份是落地窗,很有fu,不過可惜的是下午剛舉辦過婚禮
正在打掃中所以無法進入,只能遠遠的拍照囉