Concept
Modification to the service
On WSO2 carbon platform front end and back-end of a particular component is decoupled using service and stub concept.
In the core of a component backend is written and certain functionality is exposed as service using WSDL (Web Service Definition Language).
Using Java2WSDL tool, WSDL is generated during maven installation.
The front-end of the component should use a stub instance which is made according to the above WSDL. Then it can call the methods in the stub to access the back-end functionality.
Here I will explain how front-end of carbon/components/messagebox component can be modified to access the backend functionality of carbon/components/qpid in order to demonstrate the above scenario. As all the components are written in a consistent way same can be applied to other components as well.
Modification to the service
- Open the qpid component using idea (or preferred IDE). For example to create an idea project using that component cd to carbon/components/qpid and type mvn idea:idea. Then mevan will create an idea project (.ipr) for you. Or else newer versions of idea can build the project using pom file in that component (just open the pom file or .ipr file).
- Uder org.wso2.carbon.qpid/service/ws there is a file called qpidAdminService.
- In that file you can access the backend functionality of the component and expose only relevant information.
Public String getDetails();
Getting the WSDL
- Cd to qpid component and type "mvn clean install". This will build the component.
- In the same way build the features which use qpid component out of the features that are installed to the product you wish to run (example: carbon/features/qpid)
- Build the product (example: carbon/products/mb)
- After successful build unzip the product/module/distribution/product/target/
SNAPSHOT.zip - Copy /carbon/components/qpid/
/target/ to unzipFolder/repository/components/plugins replacing the existing file in the same name. - Open unzipFolder/repository/conf/carbon.xml file and set HideAdminServiceWSDLs to false
- Then cd to bin folder there and run WSO2Sever.sh script.
- After starting the server successfully open the client in the browser (using MGT console URL displayed in command prt).
For example
https://10.216.157.167:9443/carbon/services/QpidAdminService
Now the WSDL of the specified service will appear on the browser.
Generating the new stub
- Right click and get the source and copy the entire code and paste it replacing all he code in the relevant stub under carbon/service-stubs/
/src/main/resources. (example: carbon/service stubs/org.wso2.carbon.qpid.stub/src/main/resources/QpidAdminService.wsdl) - Now cd to carbon/service-stubs/
and build using "mvn clean install". Then the new stun class would be generated.
The Front-end
- Open carbon/components/
(example: carbon/components/messageBox) - Under /carbon/components/messagebox/org.wso2.carbon.messagebox.ui JSP (Java Server Pages) are located.
- In JSP pages you can create an instance of the stub (example: qpidAdminServiceStub) and access the methods you have exposed in the backend of the other (example: qpid) component. You will need to import it as well.
<%@ page import="org.wso2.carbon.qpid.stub.service.QpidAdminServiceStub" %>
QpidAdminServiceStub qpidAdminServiceStub = UIUtils.getQpidAdminServiceStub(config, session, request);
String detail = qpidAdminServiceStub.getDetails();
Note that phases in <> should be replaced with relevant terms according to your scenario
No comments:
Post a Comment