日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Eclipse Apache Axis2集成

系統(tǒng) 1997 0

?

???轉(zhuǎn)載自? http://bldmickey.blog.sohu.com/59887565.html

二. 安裝Apache Axis2

詳細(xì)見《Apache Axis2安裝》 http://bldmickey.blog.sohu.com/56486087.html

?

三. 開發(fā)環(huán)境描述

軟件

版本

Eclipse SDK Version

3.3.0

STP(SOA Tools Platform)

0.6.0

WST(Web Standard Tools)

2.0.0

DTP(Data Tools Platform)

1.5.0

JST(J2EE Standard Tools)

2.0.0

Apache Axis2

1.3

Apache Tomcat

5.5.20

?

四. 下載Apache Axis2 Tools

  • ???????? Code Generator Wizard - Eclipse Plug-in 版本1.3

包括Java2WSDL和WSDL2Java。其中Java2WSDL從java class開始創(chuàng)建WSDL文件;WSDL2Java從WSDL文件開始創(chuàng)建java class。下載地址:

http://apache.mirror.phpchina.com/ws/axis2/tools/1_3/axis2-eclipse-codegen-wizard.zip

  • ??????? Service Archive Wizard - Eclipse Plug-in版本1.3

?????? 用來創(chuàng)建web服務(wù)的軟件包(aar文件或者jar文件)。下載地址:

http://apache.mirror.phpchina.com/ws/axis2/tools/1_3/axis2-eclipse-service-archiver-wizard.zip

?

五. Apache Axis2 Tools的安裝

  • ???????? 解壓下載的文件
  • ???????? 拷貝解壓的內(nèi)容到eclipse安裝目錄下的plugins目錄下

?

六. Eclipse+Axis2集成例子

6.1 Eclipse Axis2參數(shù)設(shè)置

  • ???????? 菜單選擇:Window->Preference…->Web Service->Axis2 Preferences
  • ???????? 設(shè)置Axis Runtime Location,也就是Axis2 Runtime安裝的位置,例如:C:\Program Files\axis2

Eclipse Apache Axis2集成

  • ?????????? 設(shè)置Axis2 Preferences

?

6.2 創(chuàng)建Web Project

  • ???????? 菜單選擇:File->New Project…->Web(Dynamic Web Project)選擇Next, 在項(xiàng)目名稱中輸入SayHi

  • ???????? 選擇“Finish”完成

6.3 添加Axis2 Library

在項(xiàng)目屬性中->Java Build Path->Library中添加一個自定義的Axis2_Library的庫,將axis2 web應(yīng)用WEB-INF/lib目錄中所有jar添加到新定義的庫中。添加后項(xiàng)目的情況:

Eclipse Apache Axis2集成

?

6.4 創(chuàng)建WSDL文件

  • ???????? 菜單選擇:File->New Other…->Web Service WSDL->next
  • ???????? 選中指定路徑SayHi/src,指定WSDL的文件名:SayHi.wsdl,選擇Next
  • ???????? Target namespace:修改成 http://www.wsexample.org/SayHi ,選擇Finish

  • ?? 在WSDL design的tab中修改WSDL的設(shè)計(jì)。例如修改:Operation的名稱為:SayHiOper,具體有關(guān)WSDL的信息請查看《Web Service WSDL.doc》和《Web Service XML.doc》

?

  • ??????? 例如:本例中采用的types定義如下:

<wsdl:types>

??? <xsd:schema targetNamespace="http://www.example.org/SayHi/">

????? <xsd:element name="SayHiOper">

??????? <xsd:complexType>

????????? <xsd:sequence>

??????????? <xsd:element name="in" type="xsd:string"/>

????????? </xsd:sequence>

??????? </xsd:complexType>

????? </xsd:element>

????? <xsd:element name="SayHiOperResponse">

??????? <xsd:complexType>

????????? <xsd:sequence>

??????????? <xsd:element name="out" type="xsd:string"/>

????????? </xsd:sequence>

??????? </xsd:complexType>

????? </xsd:element>

??? </xsd:schema>

? </wsdl:types>

?

6.5從WSDL文件生成Java Server代碼

  • ? 選擇File->New->Other,從對話框中選取Axis2 Wizards->Axis2 Code Generator,選擇Next

Eclipse Apache Axis2集成

  • ?????? 選擇“Generate java source code from WSDL file”,點(diǎn)擊“Next”進(jìn)入下一步
  • ?????? 選擇WSDL文件所在的路徑:選中SayHi.wsdl文件
  • ?????? Axis2 Codegen Wizard對話框中選擇:(完成后選擇Next繼續(xù))
  • ?????? Codegen Option為custom
  • ???????Databinding Name為缺省的ADB(還有xmlbeans、jibx)
  • ? ?????先創(chuàng)建服務(wù)器端代碼

Eclipse Apache Axis2集成

  • ????????確定java服務(wù)器端程序的輸出位置,例如:SayHi\(不包括src目錄)。生成的代碼輸出的位置。注意:在程序的目錄中,不需要指定到src目錄下。
  • ??????? 項(xiàng)目程序結(jié)果:

Eclipse Apache Axis2集成

?

6.6 修改Service代碼

在SayHiSkeleton.java程序中添加處理代碼(藍(lán)色部分),實(shí)現(xiàn)了SayHiOper函數(shù)接口,獲取web請求“sayHiOper.getIn() ”,然后添加相關(guān)問候信息“"Hi," request ".How are you? ”

package org.example.www.sayhi;

public class SayHiSkeleton{

?? public org.example.www.sayhi.SayHiOperResponse SayHiOper

??????????? ( org.example.www.sayhi.SayHiOper sayHiOper )

?? ??{

??????? ? try {

??????????????? SayHiOperResponse response = new SayHiOperResponse();

??????????????? response.setOut("Hi,"+sayHiOper.getIn()+". How are you?");

??????????????? return response;

?????????????? }

catch (UnsupportedOperationException e)

?????????? ????{ throw e;}

??????? //throw new? java.lang.UnsupportedOperationException("Please implement " + this.getClass().getName() + "#SayHiOper");

??????? }

??? }

?

6.7 創(chuàng)建發(fā)布Package

  • ??? 菜單選擇:File->New->Other…->Axis2 Wizards中選擇Axis2 Service Archive,選擇Next

Eclipse Apache Axis2集成

  • ??? 選擇classes的路徑,例如:SayHi\build\classes,選擇Next
  • ??? 選擇WSDL文件,選擇Next,在選擇Next
  • ??? 設(shè)置Service XML文件,例如:SayHi\resources\services.xml
  • ??? 設(shè)置輸出的文件和目錄,例如tomcat下的部署目錄:webapps\axis2\WEB-INF\services,輸出文件名:SayHi.aar,直接可以輸出到tomcat對應(yīng)的axis2 services的目錄中。

6.8 瀏覽器測試

<ns1:SayHiOperResponse xmlns:ns1=” http://www.example.org/SayHi/ ">

? <out> Hi,bldmickey. How are you? </out>

</ns1:SayHiOperResponse>

?????? 其中SayHiOper是對應(yīng)的Web Service的Operation,in對應(yīng)的是函數(shù)對應(yīng)的輸入值。詳細(xì)對應(yīng)在wsdl文件中。輸入?yún)?shù)的值是:bldmickey,輸出的結(jié)果是: Hi,bldmickey. How are you?

?

6.9 從WSDL生成Java Client代碼

  • ?? 選擇File->New->Other,從對話框中選取Axis2 Wizards->Axis2 Code Generator,選擇Next
  • ?? 具體的操作和6.5中創(chuàng)建Server端代碼類似,只是選擇輸出客戶端代碼,具體見下圖:

?

  • ? 確定java客戶端程序的輸出位置,例如:SayHi
  • ? 增加JUNIT庫(測試代碼需要JUNIT庫)
  • ? 項(xiàng)目屬性->Java Build Path->Libraries中Add Library…->選擇JUnit, Next繼續(xù),缺省選擇JUnit3完成
  • ? 創(chuàng)建的文件包括:SayHi\src\org\example\www\sayhi\SayHiStub.java(Stub程序)和SayHi\test\org\example\www\sayhi\SayHiTest.java(測試程序)?

6.10 修改客戶端代碼和測試

  • ?? 修改test代碼的路徑問題,將SayHiTest.java從test\org\example\www\sayhi目錄移動到src\org\example\www\sayhi\目錄
  • ?? 修改代碼

package org.example.www.sayhi;

public class SayHiTest extends junit.framework.TestCase{

??????? public? void testSayHiOper() throws java.lang.Exception{

??????? String url="http://localhost:8081/axis2/services/SayHi";

??????? org.example.www.sayhi.SayHiStub stub =

??????? ?????? ?????????? new org.example.www.sayhi.SayHiStub(url);

??????? //org.example.www.sayhi.SayHiStub stub =

??????? //????????? ???new org.example.www.sayhi.SayHiStub();

??????? org.example.www.sayhi.SayHiStub.SayHiOper sayHiOper2=

?????????????????? (org.example.www.sayhi.SayHiStub.SayHiOper)getTestObject(org.example.www.sayhi.SayHiStub.SayHiOper.class);

??????? sayHiOper2.setIn("Client bldmickey");

??????? System.out.println(stub.SayHiOper(sayHiOper2).getOut());

??????? assertNotNull(stub.SayHiOper(sayHiOper2));

??????? //? assertNotNull(stub.SayHiOper(sayHiOper2));

? ?????}

??????? //Create an ADBBean and provide it as the test object

??????? public org.apache.axis2.databinding.ADBBean getTestObject(java.lang.Class type) throws Exception{

?????????? return (org.apache.axis2.databinding.ADBBean) type.newInstance();

??????? }

??? }

?}

???

  • ???????? 執(zhí)行Run As->JUnit Test

Eclipse Apache Axis2集成

  • Console 中輸出: Hi,Client bldmickey. How are you?

?

6.11 TCP Monitor監(jiān)控Web Service

運(yùn)行tcpmon.bat

添加監(jiān)聽8888端口,定向到127.0.0.1端口8081

瀏覽器中訪問 http://localhost:8888/axis2/services/SayHi/SayHiOper?in=bldmickey

輸入:

GET /axis2/services/SayHi/SayHiOper?in=bldmickey HTTP/1.1

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*

Accept-Language: en-us

UA-CPU: x86

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.1; .NET CLR 2.0.50727)

Host: 127.0.0.1:8888

Connection: Keep-Alive

輸出

HTTP/1.1 200 OK

Server: Apache-Coyote/1.1

Content-Type: application/xml;charset=UTF-8

Transfer-Encoding: chunked

Date: Wed, 15 Aug 2007 06:03:12 GMT

7e

<ns1:SayHiOperResponse xmlns:ns1="http://www.example.org/SayHi/"><out>Hi,bldmickey. How are you?</out></ns1:SayHiOperResponse>

0

?

?

6.12 代碼分析

Axis2的新架構(gòu),寫一個服務(wù),會有很多種不同的方法,可以用pojo結(jié)合rpc模式來寫,也可以用Axis2自己的Axiom API從底層寫,也可以從WSDL生成相應(yīng)框架,然后填寫相應(yīng)邏輯。

對于WSDL生成框架代碼這種形式,又有不同的數(shù)據(jù)綁定可以使用。Axis2.1.1 可以使用adb(axis2自己的data binding)、xmlbeans、jibx、jaxme、jaxbri。其中常用的還是前兩種,axis2官方是極力推薦自己的data binding的,因?yàn)樗俣瓤欤軜?gòu)相對簡單,而且有一些獨(dú)有的特性。xmlbeans,是對模式支持最好的data binding,一些特別復(fù)雜的模式只能在xmlbeans下才能正確生成框架代碼。其他幾種代碼wsdl2java目前都不是支持得很好,都還在實(shí)驗(yàn)改進(jìn)階段。

面對這么多數(shù)據(jù)綁定模式,很多人都無從選擇。官方maillist上也有好多人問該用哪個。查了一些資料,據(jù)說,adb很好用,而且速度快,如果只是簡單的模式,那么使用這種數(shù)據(jù)綁定就可以了。xmlbeans的強(qiáng)力模式支持,可以支持足夠負(fù)責(zé)的模式,速度上也只是比adb低5%左右。而jibx很多人沒用過,因?yàn)槭褂脹]有前兩種方便,不過jibx支持unwrapping代碼生成(普通代碼生成的服務(wù)方法,一般只有一個參數(shù),而unwrapping可以生成多個參數(shù)的方法,相當(dāng)直觀。)

Eclipse Apache Axis2集成


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 鄂伦春自治旗| 新野县| 都昌县| 区。| 宁陵县| 新泰市| 五莲县| 望都县| 台北市| 三台县| 胶南市| 台中县| 南木林县| 岳阳市| 响水县| 彰化市| 长岛县| 普兰店市| 阳泉市| 涟源市| 滦南县| 神木县| 林口县| 九龙坡区| 宁德市| 喀什市| 青浦区| 格尔木市| 历史| 于都县| 孝昌县| 湟中县| 南和县| 宁蒗| 宽城| 临夏县| 永寿县| 平昌县| 寿光市| 彩票| 永春县|