Sunday, March 13, 2011

How to Deploy WSO2 ESB 3.2.x and above in Apache Tomcat

All WSO2 products are recommended to be deployed as stand alone servers and  we have stop supporting deploying on other 3rd party appservers from the latest releases.

In this blog post I will walk through on how you deploy Apache Tomcat 6.x.x with the new ESB which could be downloaded here. Also note that this blog will be valid from ESB 3.2.x.

Step 1
Extract the downloaded ESB to a desired location. The home directory will now be known as $ESB_HOME from here onwards.

Step 2
Extract Apache Tomcat 6.x.x to the required location which now will be known as $CATALINA_HOME. Downloadable here.

Step 3
Create a 'esb' folder within $CATALINA_HOME/webapps and copy WEB_INF folder which exists in $ESB_HOME/lib/core. You may also copy log4j.properties in $ESB_HOME/lib in to $CATALINA_HOME/webapps/esb/WEB-INF/classes to facilitate logging.

Step 4
Also copy repository and resources folders from $ESB_HOME and create a separate folder 'esb_repo' and copy them in.

From here onwards there requires some configuration tuning for them to work together.

Step 5
Edit $CATALINA_HOME/conf/server.xml to entertain https ports. Note that path of the esb_repo should be as for your location.

<connector port="8443" maxhttpheadersize="8192" maxthreads="150" minsparethreads="25" maxsparethreads="75" enablelookups="false" disableuploadtimeout="true" acceptcount="100" scheme="https" secure="true" sslenabled="true" clientauth="false" sslprotocol="TLS" keystorefile="/esb_repo/repository/resources/security/wso2carbon.jks" keystorepass="wso2carbon">

Step 6
Now we have to complete necessary changes in 'esb_repo' to start successfully
axis2.xml (esb_repo/repository/conf)

Go to the TransportListener and TransportSender section which uses org.apache.synapse.transport.nhttp.HttpCoreNIOSSLListener and change the keystore and truststore absolute paths as per accordingly. Remeber to change this in both TransportListener and TransportSender.

<parameter name="keystore" locked="false">
</parameter></connector>
/esb_repo/repository/resources/security/wso2carbon.jks<connector port="8443" maxhttpheadersize="8192" maxthreads="150" minsparethreads="25" maxsparethreads="75" enablelookups="false" disableuploadtimeout="true" acceptcount="100" scheme="https" secure="true" sslenabled="true" clientauth="false" sslprotocol="TLS" keystorefile="/esb_repo/repository/resources/security/wso2carbon.jks" keystorepass="wso2carbon"><parameter name="keystore" locked="false"><keystore><location></location>
<type>JKS</type>
<password>wso2carbon</password>
<keypassword>wso2carbon</keypassword>
</keystore>
</parameter>
<parameter name="truststore" locked="false">
<truststore>
<location>/esb_repo/repository/resources/security/client-truststore.jks</location>
<type>JKS</type>
<password>wso2carbon</password>
</truststore>
</parameter>

Also change the synapse_config directory absolute path accordingly.
<parameter name="SynapseConfig.ConfigurationFile" locked="false">/esb_repo/repository/deployment/server/synapse-configs</parameter>

Carbon.xml
You may find this file in the same location as per axis2.xml.
Change the Server_URL, WebContextRoot and RegistryHttpPort configurations as per follows

<serverurl>https://localhost:8443/esb/services/</serverurl>

<webcontextroot>/esb</webcontextroot>

<registryhttpport>8080</registryhttpport>

registry.xml
Change the necessary db url to absolute paths as per follows;
<url>jdbc:h2:/esb_repo/repository/database/WSO2CARBON_DB;DB_CLOSE_ON_EXIT=FALSE</url>

user-mgt.xml
Change the necessary db url property to absolute paths as per follows;
<property name="url">jdbc:h2:/esb_repo/repository/database/WSO2CARBON_DB;DB_CLOSE_ON_EXIT=FALSE</property>

Now we are done with the configurations :)

- Go ahead and declare the CARBON_HOME in a console;

export CARBON_HOME=/esb_repo

Start apache tomcat by cd'ng to $CATALINA_HOME/bin and using
./catalina.sh run

Upon starting the WSo2 ESB you can access the console with the server URL https://localhost:8443/esb/services/

Post in any comments if there are problems if you find any in deploying. Best of Luck!

4 comments:

  1. Hi Ishani

    This is a great post which is very clear. I followed the guideline as it is and when i start the esb it gave me the following exception.

    i'm doing this in a window environment and using ESB_4.0.0

    HTTP Status 500 -

    --------------------------------------------------------------------------------

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    javax.servlet.ServletException: Servlet.init() for servlet bridgeservlet threw exception
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:556)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:401)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:267)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:245)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:260)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    java.lang.Thread.run(Thread.java:619)


    root cause

    java.lang.IllegalStateException: instance already set
    org.wso2.carbon.bridge.BridgeServlet.setInstance(BridgeServlet.java:218)
    org.wso2.carbon.bridge.BridgeServlet.init(BridgeServlet.java:56)
    javax.servlet.GenericServlet.init(GenericServlet.java:151)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:556)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:401)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:267)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:245)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:260)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    java.lang.Thread.run(Thread.java:619)

    ReplyDelete
  2. Hi Harshi,

    Thank you for your feedback.

    With ESB 4.0.0 and above we have to do the following changes.
    You have to copy the jars (xalan-*.jar, xercesImpl-*.jar and xml-apis-*.jar) under the Java/jre/lib/ext of your JDK.

    Let me knw if it doesnt work out. And also both registry.xml and usermgt.xml are located at repository/conf directory.

    Regards,
    Ishani

    ReplyDelete
  3. Hi Ishani,

    That didn't work. But was able to make it worktable by copying all the jars under /wso2esb-4.0.0/lib/api to CATALINA_HOME\webapps\esb\WEB-INF\lib.

    ReplyDelete
  4. Hi Ishani,

    I get an exception thrown -
    java.lang.IllegalStateException: instance already set

    from Servlet.init() when trying to run wso2greg 4.5.1 inside my tomcat server. any ideas?

    ReplyDelete