Tuesday, May 23, 2017

How Messages are Flow Inside the WSO2 ESB (ESB Story - 3)

WSO2 ESB is an open source middleware application which developed on top of the WSO2 carbon. ESB mainly underlying with Apache Axis2 and synapse.

If you are already ESB user, you know ESB received the message from external client or the user and of various transformation and send back to the separate endpoint or the back end. Then same way ESB, will get the response from endpoint or the backed and forward to the end user with transformation or without transformation. 

In this blog post I am trying to explain how the message flows inside the ESB specifically inside the mediation engine.

Mediation engine logics are written inside the Synapse-Core carbon component. Please find the Git location for checkout the code. I am specifically using ESB 5.0.0 for demonstrate this flow. Please note that ESB 5.0.0 uses synapse-core_2.1.7.wso2v7 version.

Message Flow
Message flow are separated to two main paths. 

1. Request path - In sequence flow
2. Response path - Out sequence flow


Request path - In sequence flow
In Axis2 level having "MessageReceiver" interface. Synapse core having implementation of "MessageReceiver" interface and it was implemented as a "SynapseMessageReceiver". This is the default message receiver which is configured in the Axis2. It will handle the incoming message through the synapse message mediation. 
If the ESB having proxy service, There is another implementation called "ProxyServiceMessageReceiver" do the same aforementioned task only for the proxy services. 

1. Once ESB received request to proxy service it will arrive to "receive" method.
 
org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive()



2. When message comes to the Axis2 level it will create axis2 message context. But mediation engine uses different message context to do the mediation. Because of that, "MessageContextCreatorForAxis2" class will convert into synapse message context in "
org.apache.synapse.core.axis2.MessageContextCreatorForAxis2.getSynapseMessageContext()" method. This method will call via the "ProxyServiceMessageReceiver" class.



3. After create synapse message context, it will forward to the message mediation. Main sequence also considered as a one specific mediator.Therefore it will trigger the "mediate"method in "sequence mediator"class. 



org.apache.synapse.core.axis2.ProxyServiceMessageReceiver





org.apache.synapse.mediators.base.SequenceMediator.mediate()


4. Inside the "mediate" method in "org.apache.synapse.mediators.base.SequenceMediator" class, calls the "org.apache.synapse.mediators.AbstractListMediator.mediate()" method. 


org.apache.synapse.mediators.base.SequenceMediator



org.apache.synapse.mediators.AbstractListMediator

5. Inside the "AbstractListMediator" class will go through the entire mediation flow and verifies the content aware mediators are exists. 

6. Then it trigger the  "org.apache.synapse.endpoints.send()" method to send request to the endpoint.

7. Now it will be trigger the "org.apache.synapse.core.axis2.Axis2SynapseEnvironment.send()" method to send it from the the axis2 level.


8. After that it will send to "sendOn" method in "org.apache.synapse.core.axis2.Axis2Sender" class. Here, it will retrieve all handlers associate with that.

 9. After above task, "org.apache.synapse.core.axis2.Axis2Sender.sendOn()" method will be called. this is the class send message out from the ESB engine. 


10. Finally It will be send to the "org.apache.synapse.core.axis2.Axis2FlexibleMEPClient.send()" method.





Response path - Out sequence flow
 
11. Once message received from the endpoint, It will arrive to the "org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive()" Method. 




12.Here, It reads all the information from the Message context and move forward to the "org.apache.synapse.mediators.base.SequenceMediator.mediate()" method as explained in aforementioned 3rd point. Out sequece also working as same way which is works in workflow.

13. After above, It will move to the "AbstractListMediator" as in above 4th point and then it will trigger the "org.apache.axis2.engine.AxisEngine.receive()" method.



I hope this will give you the brief idea how the message mediation happen inside the WSO2 ESB.






Friday, May 19, 2017

How to view Admin Services given WSO2 product

WSO2 products are uses SOAP services to communicate internally in-between UI and the back end. Sometime you may want to do direct invocation on particular admin service to do several task.

As a example if you want to add new users without using admin service, It can be achived by invoking the UserManagementAdminServie. Likewise you can use inbuilt admin services to do such kind of operations.

Some people does not know what are the admin services available in running WSO2 instance. Please find the easiest way to find the admin services and it's endpoints.

I am using WSO2 API Manager.

1. Please download WSO2 API Manager from above location.
2. Start API Manager with following property.
    Ex : wso2server.sh -DosgiConsole 

You will notice server is starting as below

Chamaras-MacBook-Pro:wso2am-2.0.0 chamara$ ./bin/wso2server.sh -DosgiConsole
JAVA_HOME environment variable is set to /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
CARBON_HOME environment variable is set to /Users/chamara/wso2/products/apim/wso2am-2.0.0
Using Java memory options: -Xms256m -Xmx1024m
OSGi console has been enabled with options: -console



3. By pressing "Enter" in terminal (after start server) you will landed to the OSGI console.


4. Now add below command and it will show all the admin services available in server.
"listAdminServices"








Tuesday, February 28, 2017

How to operate P2 repositories through the admin service

Even the WSO2 product comes with the default set of features, Anybody can install additional features based on their requirements. During the product release, WSO2 release feature repository aligns with the product release. It contains all the features can be installed in each product. Feature repository we called as a P2 repository and it's hosted on location again the to the product release version.

P2 repository can be installed via the "features" menu in each product UI console.

But some users may want to automate this process without logging to the management console UI. Following are the way It's can automate.

WSO2 product having set of admin services (SOAP service) which id do various operations.  For the P2 repository operations, there is an admin service called "RepositoryAdminService" and it's having all the operation which are doing through the admin console UI. you can call these admin service operation from the external client (soap client or java client) according to your requirement.
Please find the sample way to call these operations. In here I am using SOAP UI tool to call admin service operations.

1. Open PRODUCT_HOME/repository/conf/carbon.xml

2. Find proipertuy and change the value to false. 

ex :  false

In this way you can see the all admin service WSDL's from the browser.



 3. Start WSO2 prodcut with "-DosgiConsole" option.

ex :  Chamaras-MacBook-Pro:wso2greg-5.2.0 chamara$ ./bin/wso2server.sh -DosgiConsole

 4. Once server start, press enter button and it will direct you to the osgi console. Then type "listAdminServices" command. It will list down all admin services available in the product.


5. In here you will find the repository management admin service.

ex: https://10.100.1.36:9443/services/RepositoryAdminService

6. you can see the RepositoryAdminService wsdl with below URL.

"https://10.100.1.36:9443/services/RepositoryAdminService?wsdl"

7. Import above wsdl url  as a SOAP UI project.


















8. Now you can call admin service operation based on the requires functionality. 

Add Repository




Delete Repository


Enable Repository

Disable Repository



Update existing repository
This way you can do the repository operations from the outside.


Friday, July 1, 2016

Enable solr indexing debug log of WSO2 servers.

Most of the WSO2 products come with the embedded registry which is stored in several types of service artifacts. Each artifact stored as a registry artifacts. Registry artifacts are stored in an underline database as a blob content.
In practical scenario WSO2 products (ESB,Governance Registry, API Manager etc) having millions of registry resources. If WSO2 product want to search specific registry resource, It should search it from the millions of records and it will huge time consuming task and it will affected to the overall product performance.
Registry indexing comes to overcome this problem in WSO2 products. It uses embedded Solr indexing to index all of registry resources.

If anybody wants to verify how the indexing done on WSO2 products, There are indexing components you can enable debug logs. To enable it open,

1. CARBON_HOME/repository/conf/log4j.properties file.

2. Add below lines to log4j.properties file.

 log4j.logger.org.wso2.carbon.registry.indexing.solr.SolrClient=DEBUG
 log4j.logger.org.wso2.carbon.registry.indexing.ResourceSubmitter=DEBUG

3. Start Server. You will see below debug log printed in console while registry resources are indexing. 


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{org.wso2.carbon.core.internal.StartupFinalizerServiceComponent} -  Server           :  WSO2 Governance Registry-5.1.0

[2016-07-01 13:57:14,819]  INFO {org.wso2.carbon.core.internal.StartupFinalizerServiceComponent} -  WSO2 Carbon started in 33 sec

[2016-07-01 13:57:15,077]  INFO {org.wso2.carbon.ui.internal.CarbonUIServiceComponent} -  Mgt Console URL  : https://10.100.1.36:9445/carbon/

[2016-07-01 13:57:15,077]  INFO {org.wso2.carbon.ui.internal.CarbonUIServiceComponent} -  Governance Center Store Default Context : http://10.100.1.36:9765/store

[2016-07-01 13:57:15,078]  INFO {org.wso2.carbon.ui.internal.CarbonUIServiceComponent} -  Governance Center Publisher Default Context : https://10.100.1.36:9445/publisher

[2016-07-01 13:57:25,505] DEBUG {org.wso2.carbon.registry.indexing.ResourceSubmitter} -  Resource Updated: Resource at /_system/governance/repository/components/org.wso2.carbon.all-themes/Default/images/warn.png has been submitted to the Indexing Server

[2016-07-01 13:57:25,507] DEBUG {org.wso2.carbon.registry.indexing.ResourceSubmitter} -  Resource Updated: Resource at /_system/governance/repository/components/org.wso2.carbon.all-themes/Default/images/view.gif has been submitted to the Indexing Server

[2016-07-01 13:57:25,508] DEBUG {org.wso2.carbon.registry.indexing.ResourceSubmitter} -  Resource Updated: Resource at /_system/governance/repository/components/org.wso2.carbon.all-themes/Default/images/trace.png has been submitted to the Indexing Server

[2016-07-01 13:57:25,509] DEBUG {org.wso2.carbon.registry.indexing.ResourceSubmitter} -  Resource Updated: Resource at /_system/governance/repository/components/org.wso2.carbon.all-themes/Default/images/test.gif has been submitted to the Indexing Server 

Friday, April 15, 2016

How to generate random strings or number from Jmeter

While testing soap services, most of the time we may need jmeter scripts to generate random string or numbers as a service parameters.
I had a soap service to send the name (string value) and age (integer value) contentiously and each value should not be repeatable need to be random unique values. I used Random and RandomString functions to generate these values. Following Jmeter scrips may help you to do that.

Please find the SOAP/XML RPC request which I used here.

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice">  
   <soapenv:Header/>  
   <soapenv:Body>  
    <dat:inputOP>  
      <dat:age>${__RandomString(5,ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,)}</dat:age>  
      <dat:name>${__Random(5,0123456789,)}</dat:name>  
    </dat:inputOP>  
   </soapenv:Body>  
 </soapenv:Envelope>  


It will send SOAP request as below.

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice">  
   <soapenv:Header/>  
   <soapenv:Body>  
    <dat:inputOP>  
      <dat:age>X7NQH</dat:age>  
      <dat:name>97593961</dat:name>  
    </dat:inputOP>  
   </soapenv:Body>  
 </soapenv:Envelope>