Apr 21, 2009

Servicemix - HttpConnectorDemo – Example

This post explains how to create a servicemix httpconnector component using spring so if you are not using spring don’t waste your time.

(1) First of all create one configuration file containing component declaration. Put this file in your configuration folder (e.g. WEB-INF).
<sm:activationspec componentname=" HttpConnectorDemo" service="foo:MobileHttpBinding">
        <bean class="com.component.pollar.MobileHttpBinding">
            <property name="defaultInOut" value="false">

(2) Map the configuration file from your web.xml file so that your component takes part in web application.

Then after to load this component whenever container starts, add following snippet of code to your web.xml.


(3) Now make a class file containing implementation of HttpConnector class of servicemix. Add your actual logic to processInOnly method as we have defined that <property name="defaultInOut" value="false"> so a call to this class will go to processInOnly method. Yet for safety define processInOut method and call processInOnly method from there.
public class HttpConnectorDemo extends HttpConnector {
    public void processInOnly(HttpServletRequest request, HttpServletResponse response){
        // Your actual logic.
    public void processInOut(HttpServletRequest request, HttpServletResponse response){
        processInOnly(request, response);

(4) Now this class can act as a servlet. All we have to do is define a servlet in web.xml and map it to this class.
E. g.

(5) Now the part left is most easy part just make a war file and deploy it in your server. Start your browser, hit the URL and see the picture, your job is done. Just include necessary jar files in lib folder so that server can load your component properly.

Now start making components and Enjoy Servicemix ESB.