Monday, January 19, 2015

WSO2 Carbon : Remote debug wso2 carbon components using Intellij Idea IDE






In this brief tutorial I'll explain how to remote debug a carbon component. Since all wso2 products are based on  carbon components, this simple tutorial will help you to debug any wso2 product.

Please note that first section explains how to install carbon component using p2 repository as a feature. You can skip first section if you have a component already installed.

Prerequisites :

WSO2 carbon binary [download] [1]
Sample carbon component [git repo] [2]
Intllij Idea IDE

Install Carbon Component

First we have to install carbon component to a carbon instance. This step is needed since we are going to remote debug installed component. If you have already installed/build the component you wants to debug skip this section and start with 'Remote Debugging'.

1. Download and extract wso2 carbon zip file.
Run wso2server.sh in {wso2_carbon_base}/wso2carbon-4.2.0/bin directory using CLI as follows.
sh wso2server.sh

If carbon instance successfully initiated it should promote a url for carbon console in CLI.
pumudus-MacBook-Pro:bin pumudu$ sh wso2server.sh
JAVA_HOME environment variable is set to /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
CARBON_HOME environment variable is set to /Users/pumudu/Documents/carbon/wso2carbon-4.2.0
[2015-01-19 13:28:03,617]  INFO {org.wso2.carbon.core.internal.CarbonCoreActivator} -  Starting WSO2 Carbon...
[2015-01-19 13:28:03,620]  INFO {org.wso2.carbon.core.internal.CarbonCoreActivator} -  Operating System : Mac OS X 10.9.4, x86_64
[2015-01-19 13:28:03,620]  INFO {org.wso2.carbon.core.internal.CarbonCoreActivator} -  Java Home        : /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
[2015-01-19 13:28:03,620]  INFO {org.wso2.carbon.core.internal.CarbonCoreActivator} -  Java Version     : 1.6.0_65
[2015-01-19 13:28:03,620]  INFO {org.wso2.carbon.core.internal.CarbonCoreActivator} -  Java VM          : Java HotSpot(TM) 64-Bit Server VM 20.65-b04-462,Apple Inc.
[2015-01-19 13:28:03,620]  INFO {org.wso2.carbon.core.internal.CarbonCoreActivator} -  Carbon Home      : /Users/pumudu/Documents/carbon/wso2carbon-4.2.0
[2015-01-19 13:28:03,621]  INFO {org.wso2.carbon.core.internal.CarbonCoreActivator} -  Java Temp Dir    : /Users/pumudu/Documents/carbon/wso2carbon-4.2.0/tmp
[2015-01-19 13:28:03,621]  INFO {org.wso2.carbon.core.internal.CarbonCoreActivator} -  User             : pumudu, en-US, Asia/Colombo
[2015-01-19 13:28:03,670]  WARN {org.wso2.carbon.core.bootup.validator.util.ValidationResultPrinter} -  The default keystore (wso2carbon.jks) is currently being used. To maximize security when deploying to a production environment, configure a new keystore with a unique password in the production server profile.
[2015-01-19 13:28:04,568]  INFO {org.wso2.carbon.registry.core.jdbc.EmbeddedRegistryService} -  Configured Registry in 50ms
[2015-01-19 13:28:04,660]  INFO {org.wso2.carbon.registry.core.internal.RegistryCoreServiceComponent} -  Registry Mode    : READ-WRITE
[2015-01-19 13:28:04,718]  INFO {org.wso2.carbon.user.core.internal.UserStoreMgtDSComponent} -  Carbon UserStoreMgtDSComponent activated successfully.
[2015-01-19 13:28:07,726]  INFO {org.apache.catalina.startup.TaglibUriRule} -  TLD skipped. URI: http://tiles.apache.org/tags-tiles is already defined
[2015-01-19 13:28:08,704]  INFO {org.wso2.carbon.core.deployment.DeploymentInterceptor} -  Deploying Axis2 service: echo {super-tenant}
[2015-01-19 13:28:08,872]  INFO {org.wso2.carbon.core.deployment.DeploymentInterceptor} -  Deploying Axis2 service: Version {super-tenant}
[2015-01-19 13:28:08,964]  INFO {org.wso2.carbon.core.deployment.DeploymentInterceptor} -  Deploying Axis2 service: echo {super-tenant}
[2015-01-19 13:28:09,022]  INFO {org.wso2.carbon.core.deployment.DeploymentInterceptor} -  Deploying Axis2 service: Version {super-tenant}
[2015-01-19 13:28:09,503]  INFO {org.wso2.carbon.core.init.CarbonServerManager} -  Repository       : /Users/pumudu/Documents/carbon/wso2carbon-4.2.0/repository/deployment/server/
[2015-01-19 13:28:09,518]  INFO {org.wso2.carbon.core.internal.permission.update.PermissionUpdater} -  Permission cache updated for tenant -1234
[2015-01-19 13:28:09,537]  INFO {org.wso2.carbon.core.transports.http.HttpsTransportListener} -  HTTPS port       : 9443
[2015-01-19 13:28:09,537]  INFO {org.wso2.carbon.core.transports.http.HttpTransportListener} -  HTTP port        : 9763
[2015-01-19 13:28:09,548]  INFO {org.apache.tomcat.util.net.NioSelectorPool} -  Using a shared selector for servlet write/read
[2015-01-19 13:28:09,669]  INFO {org.apache.tomcat.util.net.NioSelectorPool} -  Using a shared selector for servlet write/read
[2015-01-19 13:28:09,878]  INFO {org.wso2.carbon.core.init.JMXServerManager} -  JMX Service URL  : service:jmx:rmi://localhost:11111/jndi/rmi://localhost:9999/jmxrmi
[2015-01-19 13:28:09,879]  INFO {org.wso2.carbon.core.internal.StartupFinalizerServiceComponent} -  Server           :  WSO2 Carbon-4.2.0
[2015-01-19 13:28:09,879]  INFO {org.wso2.carbon.core.internal.StartupFinalizerServiceComponent} -  WSO2 Carbon started in 8 sec
[2015-01-19 13:28:10,004]  INFO {org.wso2.carbon.ui.internal.CarbonUIServiceComponent} -  Mgt Console URL  : https://10.106.3.125:9443/carbon/

2. Log into carbon management console using Mgt console URL : https://10.106.3.125:9443/carbon/
Default credentials username : admin Password : admin

3. From given simple carbon component git repository[2] get the source code of carbon component.

4. After logged into carbon management console goto
Configure -> Features -> Feature Management -> Repository Management -> Add Repository.
Then copy paste P-2 repository path from target directory.
{base_carbon_component}/order-manager/order-manager-repository/target/p2-repo/



5. Install "Order Manager Aggregate" carbon component using Available Features tab.



6. If everything went smoothly it'll ask you to restart the server. Using CLI or using web console restart the wso2 server.



7. Once restarted the server and logged into management console order management ui should appear  under main tab.
  


It's a very simple CRUD system. Feel free to add few entries and understand the functionality of this component. Now we can start debug this order management component using intellij IDE.

Remote Debugging


1. Start carbon server with debug enabled using following command.
sh wso2server.sh -debug 5005


2. Open carbon component project[2] using Intellij IDE. We'll debug addOrder and deleteOrder methods in back end. Similarly we can debug front end as well.
Add two break points in line number 49 and 79 in OrderService.java as follows.
order-manager/order-manager-components/org.wso2.carbon.order.mgt/src/main/java/org/wso2/carbon/order/mgt/OrderService.java 


3. Goto Run-> Debug.. It'll open debug dialog box. first select Remote and then click on plus sign on upper left corner.



4. Give appropriate name for debug session instead of "unnamed" and click on debug. Make sure Host is localhost and Port has set to 5005.

5. Once carbon server successfully boot up log in as admin in carbon management console and try to add a new order entry.


Click on resume program in debugger panel or press F9 to resume. Make sure you resume once you done with a break point before interacting with the management console again.

6. Similarly try to delete a record and it'll trigger the break point in line number 79.



This is how you can remote debug any carbon related product / component by intellij idea.
Happy debugging..!!! good luck..!!!




Reference :
[1] http://wso2.com/products/carbon/
[2] https://github.com/pumudu88/SimpleCarbonComponent


1 comment:

  1. Remote debugging is for me as a developer not the most comfortable way. I would like to see a IDE integration like with Wildfly with the Maven Wildfly plugin. Start, auto deploy and debug from IDE with hot code swap. And deploy directly in production from IDE.

    ReplyDelete