Thursday, October 6, 2011

Debugging your OSGi Application using OSGi console commands

This blog post is mainly targeted at the WSO2 Carbon developers who make use of OSGi console to debug their bundles/components during the runtime. I'm here assuming that you have the basic shell which you would find in equinox environment.
You can start any of the WSO2 server products (that is based on Carbon) with OSGi console enabled, by passing the system property 'osgiConsole' during the startup. To do so, start the carbon server with,
./wso2server.sh -DosgiConsole
After full server startup pressing enter in the command shell will give you the OSGi shell command prompt, which looks like;
osgi>

After that you can valid OSGi command using this shell. Let us explore some of those,
The below commands will help you while debugging bundles in 'Module Layer':


Command    Use-Case
install file:/<filePath of bundle jar>  Install bundle jar in to runtime
ss To simply list down the bundles along with the life-cycle state we can use this command.
start <bundleId found using ‘ss’ command>  starting the bundle given by bundle ID.
b <bundleId> Prints all the details attached with bundle including  importing packages, exporting packages, etc.
diag <bundleId> If the bundle is still in installed state we can use this command to find the missing constraints which are stopping bundle going in to next lifecycle stage
p <packageName> List all the bundles that import/export the given package name within the runtime.
stop <bundleId> stopping the bundle given by bundle ID
uninstall <bundleId> uninstalling the bundle



To debug OSGi services(Service Components) layer you can use the following commands.

Command    Use-Case
ls list down all the service components found in this runtime along with their component ID and life-cycle status
enable <componentID> enabling service components
comp <componentID> Use this command to find unsatisfied services of the given component, which prevent it from going it to satisfied state.
ls  -c <bundleID> same as the above command, but you can retrieve the information on your service components using the bundle ID instead of component ID
services list down all the services in the runtime including services provided by the system bundle. You can use simple filters to narrow down your list.

eg: To find out the bundles/serviceComponents that expose the OSGi service ‘ org.foo.bar’

you can use the command:
>services (objectclass=org.foo.bar)    or
>services (objectclass=*foo.bar)
disable <componentID>  disabling component  given by the component ID

You don’t have to memorize these commands; all the commands along with their documentation can be found using the OSGi console command ‘help’. This is just a quick reference guide. You can extend the available set of commands by writing your own command provider. Hope this helps.

Monday, May 30, 2011

POST variables get dropped while going through the WSO2 ESB proxy ... ?

This is more of a small note in case I forget what i did while trying things out. First of all I created a ESB proxy for a back-end service that accepts post request and does some manipulation on the received request.

Once you create a ESB proxy by giving the above REST service as the service endpoint , the InSequence element of the proxy.xml will look like this.

<inSequence>
         <send>
            <endpoint name="endpoint_urn_uuid_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
               <address uri="http://localhost/restServiceEndPoint" format="rest" />
            </endpoint>
         </send>
      </inSequence>

The problem is the configuration drops the POST variables while building the SOAP envelope. Some debugging in to the Axis2 code revealed that the transport is attaching the incoming variable list to the Axis2MessageContext, but the attached data structure is MultipleEntryHashMap(It removes the value from the data-structure once you access it) which is a Axis2 implementation. However I couldnot access the the stored variables in the data structure within a Custom mediator, (the data has been already consumed at that point, may be by once of the dispatchers.)

So the other option was to use binary relay. It worked fine for me. Here are the steps I followed to get it working. First you have to enable the binary relay builder / Formatter for the relevant application-content type (In my case XForm-URL-encoded).

Then remove the format="rest"  attribute from the address element (InSequence of proxy.xml)

Thats it, the binary relay builder wraps your request as it is and expand it back when it sends back to to actual service.

Friday, April 15, 2011

Delete a set of elements in a xml file

Recently I wanted to delete a certain search pattern in an XML file. Within the XML file I had a XML snippet;























and i wanted to delete the commented out part. I was able to do it with this, search replace command in vim.

:%s/<!--moved to nexus\_.\{-}-->

I got this to working by looking at the mail[1]
[1] http://osdir.com/ml/editors.vim/2002-06/msg00468.html
its a handy command once you couple it with a vim macro.