wso2Carbon組件開發(fā)教程V100_第1頁
wso2Carbon組件開發(fā)教程V100_第2頁
wso2Carbon組件開發(fā)教程V100_第3頁
wso2Carbon組件開發(fā)教程V100_第4頁
wso2Carbon組件開發(fā)教程V100_第5頁
已閱讀5頁,還剩50頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Carbon組件開發(fā)教程Carbon組件開發(fā)教程基礎(chǔ)平臺(tái)組2014年09月目錄52第1章 總體說明11.1 修訂歷史11.2 內(nèi)容簡(jiǎn)介11.3 用戶范圍1第2章 CARBON組件開發(fā)示例22.1 Best practices22.2 創(chuàng)建maven父項(xiàng)目(stu-manager)22.3 創(chuàng)建maven子項(xiàng)目42.3.1 stu-manager-components42.3.2 stu-manager-features62.3.3 stu-manager-repository62.3.4 創(chuàng)建服務(wù)端組件子項(xiàng)目(org.dhcc.carbon.student.mgt)72.4 項(xiàng)目概覽92.4.

2、1 目錄結(jié)構(gòu)92.4.2 student-manager-components項(xiàng)目pom.xml92.4.3 student-manager-features項(xiàng)目pom.xml102.4.4 student-manager-repository項(xiàng)目pom.xml102.4.5 student-manager項(xiàng)目pom.xml102.5 編寫服務(wù)端組件(org.dhcc.carbon.student.mgt)112.5.1 轉(zhuǎn)換項(xiàng)目為java項(xiàng)目112.5.2 設(shè)置編譯路徑122.5.3 編寫代碼142.5.4 編寫services.xml152.5.5 Maven install162.6 編

3、寫Service Stub172.6.1 org.dhcc.carbon.student.mgt.stub項(xiàng)目pom.xml182.7 編寫UI Component212.7.1 org.dhcc.carbon.student.mgt.ui項(xiàng)目pom.xml212.7.2 轉(zhuǎn)換項(xiàng)目為java項(xiàng)目222.7.3 編寫代碼222.7.4 編寫頁面242.8 部署運(yùn)行282.9 由Carbon Component創(chuàng)建feature282.9.1 在stu-manager-features項(xiàng)目下創(chuàng)建3個(gè)子項(xiàng)目292.9.2 項(xiàng)目概覽292.9.3 更新student-manager-repositor

4、y的pom文件352.9.4 安裝feature37第3章 編譯CARBON KERNEL源碼393.1 SVN地址393.2 使用jdk1.6393.3 Pom文件修改393.3.1 dependenciesaxis21.6.1-wso2v10modulesparent393.3.2 dependencieswss4j1.5.11-wso2v640第4章 CARBON源碼DEBUG414.1 Carbon在eclipse上運(yùn)行414.1.1 拷貝必要的文件414.1.2 修改數(shù)據(jù)庫配置414.1.3 入口函數(shù)424.1.4 引入相關(guān)jar包424.1.5 設(shè)置運(yùn)行參數(shù)434.1.6 運(yùn)行45

5、4.2 wso2esb在eclipse上運(yùn)行464.2.1 拷貝必要的文件464.2.2 修改axis2配置464.2.3 修改數(shù)據(jù)庫配置474.2.4 入口函數(shù)474.2.5 引入相關(guān)jar包474.2.6 設(shè)置運(yùn)行參數(shù)474.2.7 運(yùn)行474.3 wso2esb在eclipse上debug474.3.1 進(jìn)入組件頁面474.3.2 導(dǎo)入組件代碼到eclipse484.3.3 找到相關(guān)執(zhí)行函數(shù),打斷點(diǎn)49第5章 FAQ(常見問題解答)50第6章 附錄516.1 maven拷貝文件到指定目錄516.2 Carbon代碼編譯順序516.3 perties52第1章 總體說

6、明1.1 修訂歷史版本日期狀態(tài)修訂人摘要V1.02014-09-28C于鴻第一版本狀態(tài)標(biāo)識(shí):C Created A- Added M - Modified D Deleted1.2 內(nèi)容簡(jiǎn)介第2章用于指導(dǎo)用戶開發(fā)carbon組件。第3、4章用于指導(dǎo)用戶Debug Carbon組件。附錄為對(duì)本文部分內(nèi)容的補(bǔ)充。1.3 用戶范圍需要開發(fā)Carbon組件的開發(fā)人員。第2章 Carbon組件開發(fā)示例2.1 Best practicesl Always create the pom from scratch. This will prevent adding unnecessary dependenci

7、esl If there are any common dependencies for all the sub maven projects, add them to the parent poml Maintain the versions in parent pom as parameters and use them in sub projects to define the versions. Then, whenever theres an update on the versions, it will be easy to updatel Do not copy/paste th

8、e code, re-use the code through OSGI, Util methods, etcl Write tests for your code. This will gain a good percentage of code coverage. Otherwise developers will not know whether changes will break functionality or not until it is too latel Understand Multi Tenancy and design for Multi Tenancy. Makin

9、g code work for multiple tenants needs some careful designing. It may not be straightforward in some casesl Click here for more information on best practices2.2 創(chuàng)建maven父項(xiàng)目(stu-manager)相關(guān)屬性如下:l groupId - org.dhcc.carbonl artifactId - stu-managerl version - 1.0.0l packaging - poml name - DHCC Carbon -

10、 Student ManagerIDE會(huì)自動(dòng)創(chuàng)建src文件夾,由于這是父項(xiàng)目,我們可以刪掉src文件夾。后面會(huì)修改pom文件,添加倉(cāng)庫地址指向wso2的maven倉(cāng)庫,以檢出依賴包。2.3 創(chuàng)建maven子項(xiàng)目2.3.1 stu-manager-components相關(guān)屬性如下:l artifactId - stu-manager-componentsl packaging - poml name - DHCC Carbon - Student Manager ComponentsIDE會(huì)自動(dòng)創(chuàng)建src文件夾,由于這是子項(xiàng)目,我們可以刪掉src文件夾。2.3.2 stu-manager-fea

11、tures相關(guān)屬性如下:l artifactId - stu-manager-featuresl packaging - poml name - DHCC Carbon - Student Manager Features創(chuàng)建過程參考stu-manager-components項(xiàng)目的創(chuàng)建過程。2.3.3 stu-manager-repository相關(guān)屬性如下:l artifactId - stu-manager-repositoryl packaging - poml name - DHCC Carbon - Student Manager Repository創(chuàng)建過程參考stu-manag

12、er-components項(xiàng)目的創(chuàng)建過程。2.3.4 創(chuàng)建服務(wù)端組件子項(xiàng)目(org.dhcc.carbon.student.mgt)在stu-manager-components 項(xiàng)目下創(chuàng)建服務(wù)端組件。因?yàn)檫@將成為一個(gè)osgi bundle,所以需要配置Apache Felix插件來設(shè)置配置。相關(guān)屬性如下:l artifactId - org.dhcc.carbon.student.mgtl packaging - bundlel name - DHCC Carbon - Student Manager Server Componentl plugin - maven-bundle-plugi

13、n 建立maven項(xiàng)目 修改pom文件Pom.xml文件修改為如下所示:org.dhcc.carbon.student.mgt pom.xml<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/mave

14、n-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.dhcc.carbon</groupId> <artifactId>stu-manager-components</artifactId> <version>1.0.0</version> </parent> <artifactId>org.dhcc.carbon.student.mgt</artifa

15、ctId> <packaging>bundle</packaging> <name>DHCC Carbon - Student Manager Server Component</name> <build> <plugins> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</

16、extensions> <configuration> <instructions> <Bundle-SymbolicName>$pom.artifactId</Bundle-SymbolicName> <Bundle-Name>$pom.artifactId</Bundle-Name> <Export-Package>org.dhcc.carbon.student.mgt.*</Export-Package> </instructions> </configuration&

17、gt; </plugin> </plugins> </build></project>Note: When you export packages for the OSGI bundle, remember that if you are using any API classes or any other dependency in a separate package you have to export them as well. In this example, we will have our data classes in the&#

18、160;org.dhcc.carbon.student.mgt.data package. Exporting the parent mgt package will export everything needed.2.4 項(xiàng)目概覽2.4.1 目錄結(jié)構(gòu)2.4.2 student-manager-components項(xiàng)目pom.xmlstudent-manager-components pom.xml<project xmlns="/POM/4.0.0" xmlns:xsi="/20

19、01/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.dhcc.carbon</groupId> <artifactId>stu-manager</artifactId> <

20、;version>1.0.0</version> </parent> <artifactId>stu-manager-components</artifactId> <packaging>pom</packaging> <name>DHCC Carbon - Student Manager Components</name> <modules> <module>org.dhcc.carbon.student.mgt</module> <!- There

21、 are 2 more projects to be added here later in this tutorial stub, ui -> </modules></project>2.4.3 student-manager-features項(xiàng)目pom.xmlstudent-manager-features pom.xml<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance&q

22、uot; xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.dhcc.carbon</groupId> <artifactId>stu-manager</artifactId> <version>1.0.0</v

23、ersion> </parent> <artifactId>stu-manager-features</artifactId> <packaging>pom</packaging> <name>DHCC Carbon - Student Manager Features</name></project><!- We will be again updating this pom later in this tutorial ->2.4.4 student-manager-repos

24、itory項(xiàng)目pom.xmlstudent-manager-repository pom.xml<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"> <modelVersio

25、n>4.0.0</modelVersion> <parent> <groupId>org.dhcc.carbon</groupId> <artifactId>stu-manager</artifactId> <version>1.0.0</version> </parent> <artifactId>stu-manager-repository</artifactId> <packaging>pom</packaging> <n

26、ame>DHCC Carbon - Student Manager Repository</name></project><!- We will be again updating this pom later in this tutorial ->2.4.5 student-manager項(xiàng)目pom.xmlstudent-manager pom.xml<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/

27、XMLSchema-instance" xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.dhcc.carbon</groupId> <artifactId>stu-manager</artifactId> <version>1.0.0&

28、lt;/version> <packaging>pom</packaging> <name>DHCC Carbon - Student Manager</name> <modules> <module>stu-manager-components</module> <module>stu-manager-features</module> <module>stu-manager-repository</module> </modules> <

29、;repositories> <repository> <id>wso2-nexus</id> <name>WSO2 internal Repository</name> <url>/nexus/content/groups/wso2-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>

30、;false</enabled> </snapshots> <layout>default</layout> </repository> </repositories> </project>2.5 編寫服務(wù)端組件(org.dhcc.carbon.student.mgt)為了使用IDE工具方便的編寫代碼,先將org.dhcc.carbon.student.mgt項(xiàng)目轉(zhuǎn)換成java項(xiàng)目。2.5.1 轉(zhuǎn)換項(xiàng)目為java項(xiàng)目2.5.2 設(shè)置編譯路徑 轉(zhuǎn)換后的目錄結(jié)構(gòu) 修改文件夾屬性將src.

31、main.java,src.main.resources,src.test.java,src.test.resources設(shè)置為資源路徑 修改后的目錄結(jié)構(gòu)2.5.3 編寫代碼在org.dhcc.carbon.student.mgt項(xiàng)目下添加2個(gè)java類: Student.javapackage org.dhcc.carbon.student.mgt.data;public class Student private int ID;private String firstName;private String lastName;public Student(int

32、ID, String firstName, String lastName) this.ID = ID; this.firstName = firstName; this.lastName = lastName;public int getID() return ID;public void setID(int ID) this.ID = ID;public String getFirstName() return firstName;public void setFirstName(String firstName) this.firstName = firstName;public Str

33、ing getLastName() return lastName;public void setLastName(String lastName) this.lastName = lastName; StudentManager.javapackage org.dhcc.carbon.student.mgt;import org.dhcc.carbon.student.mgt.data.Student;public class StudentManager private Student students;public StudentManager() students = n

34、ew Student2; students0 = new Student(1234,"Amal", "Gunatilake"); students1 = new Student(4321, "John", "Carter");public Student getStudents() return students;2.5.4 編寫services.xml 創(chuàng)建services.xml文件在src/main/resources目錄下創(chuàng)建META-INF文件夾,在文件夾下創(chuàng)建services.xml文件,

35、如下圖所示: services.xml內(nèi)容services.xml文件的作用是導(dǎo)出名稱為StudentManager的服務(wù)。<serviceGroup><service name="StudentManager" scope="transportsession"> <transports> <transport>https</transport> </transports> <parameter name="ServiceClass">o

36、rg.dhcc.carbon.student.mgt.StudentManager</parameter></service><parameter name="adminService" locked="true">true</parameter><parameter name="hiddenService" locked="true">true</parameter><parameter name="Authorization

37、Action" locked="true">/permission/protected/manage</parameter></serviceGroup>Note: Here we have exposed StudentManager as our ServiceClass. This will make all the public methods in the StudentManager class as service operations (getStudents).· <transport>http

38、s</transport> - makes the service secure.· parameter name="adminService" - makes the service an admin service.· parameter name="hiddenService" - makes the service hidden to public.· parameter name="AuthorizationAction" - makes the service authorized

39、.2.5.5 Maven install設(shè)置goals參數(shù)為clean install。2.6 編寫Service Stub為了創(chuàng)建stub,我們需要?jiǎng)偛艅?chuàng)建的ws的wsdl。由于設(shè)置了安全訪問,所以不能直接從瀏覽器訪問剛才創(chuàng)建的ws的wsdl。需要修改CARBON_HOME/repository/conf/carbon.xml文件,將<HideAdminServiceWSDLs>標(biāo)簽的值由true改為false。Maven build剛才的org.dhcc.carbon.student.mgt項(xiàng)目,拷貝在target目錄下生成的org.dhcc.carbon.student.mg

40、t-1.0.0.jar文件到CARBON_HOME/repository/components/dropins/文件夾下。啟動(dòng)carbon服務(wù),訪問https:/localhost:9443/services/StudentManager?wsdl保存此wsdl,名稱為StudentManager.wsdl,之后在stub中使用。將<HideAdminServiceWSDLs>標(biāo)簽的值改回默認(rèn)值。在student-manager-components項(xiàng)目下創(chuàng)建名稱為org.dhcc.carbon.student.mgt.stub的maven項(xiàng)目相關(guān)屬性如下:l artifactId

41、 - org.dhcc.carbon.student.mgt.stubl packaging - bundlel name - DHCC Carbon - Student Manager Stubl dependency - axis2l dependency - axioml dependency - wsdl4jl plugin - maven-antrun-pluginl plugin - build-helper-maven-pluginl plugin - maven-bundle-plugin使用wsdl2java與maven-antrun-plugin,能夠從wsdl文件生成ja

42、va類??截?StudentManager.wsdl 到org.dhcc.carbon.student.mgt.stub項(xiàng)目的 src/main/resources/ 文件夾下。2.6.1 org.dhcc.carbon.student.mgt.stub項(xiàng)目pom.xmlorg.dhcc.carbon.student.mgt.stub pom.xml<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"

43、; xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.dhcc.carbon</groupId> <artifactId>stu-manager-components</artifactId> <version>1.0

44、.0</version> </parent> <artifactId>org.dhcc.carbon.student.mgt.stub</artifactId> <packaging>bundle</packaging> <name>DHCC Carbon - Student Manager Stub</name> <dependencies> <dependency> <groupId>org.apache.axis2.wso2</groupId>

45、<artifactId>axis2</artifactId> <version>1.6.1.wso2v10</version> </dependency> <dependency> <groupId>mons.axiom.wso2</groupId> <artifactId>axiom</artifactId> <version>1.2.11.wso2v4</version> </dependency> <dependency>

46、 <groupId>wsdl4j.wso2</groupId> <artifactId>wsdl4j</artifactId> <version>1.6.2.wso2v4</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-a

47、ntrun-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>source-code-generation</id> <phase>process-resources</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <path id=&

48、quot;wsdl2java.classpath"> <pathelement location="$settings.localRepository/org/apache/ws/commons/axiom/wso2/axiom/1.2.11.wso2v4/axiom-1.2.11.wso2v4.jar"/> <pathelement location="$settings.localRepository/org/apache/axis2/wso2/axis2-client/1.6.1.wso2v10/axis2-client-1

49、.6.1.wso2v10.jar" /> <pathelement location="$settings.localRepository/org/apache/axis2/wso2/axis2/1.6.1.wso2v10/axis2-1.6.1.wso2v10.jar" /> </path> <java classname="org.apache.axis2.wsdl.WSDL2Java" fork="true"> <classpath refid="wsdl2ja

50、va.classpath" /> <arg line="-uri src/main/resources/StudentManager.wsdl -u -uw -o target/generated-code -p org.dhcc.carbon.student.mgt.stub"/> </java> </tasks> </configuration> </execution> </executions> </plugin> <plugin> <groupId

51、>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration>

52、 <sources> <source>target/generated-code/src</source> </sources> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extension

53、s>true</extensions> <configuration> <instructions> <Bundle-SymbolicName>$project.artifactId</Bundle-SymbolicName> <Bundle-Name>$project.artifactId</Bundle-Name> <Private-Package> </Private-Package> <Export-Package> org.dhcc.carbon.studen

54、t.mgt.* </Export-Package> <Import-Package> !org.dhcc.carbon.student.mgt.* </Import-Package> <DynamicImport-Package>*</DynamicImport-Package> </instructions> </configuration> </plugin> </plugins></build></project>Note:l Axis2 dependenc

55、y has been used as the SOAP stackl The Apache Axiom library provides an XML Infoset compliant object model implementation, which supports on-demand building of the object treel wsdl4j dependency has been used to generate the Java classes from the existing WSDL document using the wsdl2javal wsdl2java

56、.classpath has been configured in the maven-antrun-plugin with the 3 dependencies as path elements.Maven build后會(huì)在target文件夾下生成org.dhcc.carbon.student.mgt.stub-1.0.0.jar bundle文件。2.7 編寫UI Component在student-manager-components項(xiàng)目下創(chuàng)建名稱為org.dhcc.carbon.student.mgt.ui的maven項(xiàng)目相關(guān)屬性如下:l artifactId - org.dhcc.c

57、arbon.student.mgt.uil packaging - bundle l name - DHCC Carbon - Student Manager UI Componentl dependency - org.dhcc.carbon.student.mgt.stubl plugin - maven-bundle-plugin2.7.1 org.dhcc.carbon.student.mgt.ui項(xiàng)目pom.xmlorg.dhcc.carbon.student.mgt.ui pom.xml<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-in

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論