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蠟燭佈置))
進來房間首先映入眼簾的就是一整個騷包到不行的排場



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