Wednesday, February 18, 2009

Deploying WSO2 ESB 2.0 on Apache Tomcat

As you all know WSO2 ESB can be deployed on different application servers such as IBM WebSphere, BEA WebLogic Server, JBoss and Apache Tomcat. I have written a blog previously on how one can deploy WSO2 ESB on Apache Tomcat. Unfortunately this does not work with the new Carbon based WSO2 ESB. Therefore for anyone who is interested on deploying WSO2 ESB on Apache Tomcat the following guide will be useful.

Step 1 - Downloading and installing Apache Tomcat

You can download the latest version of Apache Tomcat from here (I will be using Apache Tomcat 5.5.20 to demonstrate this scenario).
Extract the downloaded distribution to a specific location and define the environment variables properly. (Assume you extracted the downloaded Tomcat into the folder C:\apache-tomcat-5.5.20)

E.g.: -
CATALINA_HOME=C:\apache-tomcat-5.5.20

Next you will need to enable HTTPS on Apache Tomcat since WSO2 ESB runs over HTTPS. To do this, access the server.xml file located at %CATALINA_HOME%/conf and uncomment the following.

<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"/>

Then you will need to provide the keystore file location along with it's password as below.

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="C:\Carbon\ESB\tomcat_repo\resources\security\wso2carbon.jks"
keystorePass="wso2carbon"/>


Step 2 - Downloading and installing WSO2 ESB

Download the latest WSO2 ESB distribution from here and extract to a specific location. (E.g.:- C:\Carbon\ESB\tomcat\wso2esb-SNAPSHOT). From this folder copy the folders,

- conf
- database
- resources
- repository

to a separate folder. (E.g.:- C:\Carbon\ESB\tomcat\esb_home)

Step 3 - Setting environmental variables

You will have to set an environment variable with the name CARBON_HOME pointing it to the directory which you copied the above files to.
E.g.:-
CARBON_HOME=C:\Carbon\ESB\tomcat\esb_home

Step 4 - Copying required files to Apache Tomcat

Now create a folder inside the webapps folder of Tomcat.
E.g.:-
C:\apache-tomcat-5.5.20\webapps\esb

Next, you need to copy the WEB-INF folder, which is in the folder which you extracted the downloaded ESB distribution. Then copy it into the esb folder which you created above.
E.g.:-
Copy
C:\Carbon\ESB\tomcat\wso2esb-SNAPSHOT\webapps\ROOT\WEB-INF
to
C:\WSO2\Installations\apache-tomcat-5.5.20\webapps\esb


Step 5 - Changing necessary files of the WSO2 ESB distribution

a) Open the carbon.xml file which is in the CARBON_HOME\conf folder and specify the following URL as the ServerURL
E.g.:-
https://localhost:8443/esb/services/

b) Next open the axis2.xml which is located inside the CARBON_HOME\conf and change the http port from 8280 to 8080 (the default http port of Tomcat) and the https port from 8243 to 8443.
Note that you do not have to do this in the Carbon based WSO2 ESB distribution. Just leave the ports as they are.

c) In addition to the above, you need to specify the correct paths for the two .jks files wso2carbon.jks and client-truststore.jks specified in the axis2.xml and also the wso2carbon.jks file specified in the carbon.xml file.

d) Then you also have to change the contextRoot parameter value to /esb of the axis2.xml file
Instead of the above, in the Carbon based ESB you need to change the WebContextRoot parameter in the carbon.xml

e) Then you need to specify the absolute paths of the WSO2CARBON_DB of the two files registry.xml and user-mgt.xml
E.g.:- Change
jdbc:derby:database/WSO2CARBON_DB;create=true
to
jdbc:derby:C:\Carbon\ESB\tomcat\esb_home\WSO2CARBON_DB;create=true


f) Next you will have to specify the absolute path of the synapse.xml which is in the axis2.xml file located at CARBON_HOME\conf

E.g.:-
Change
conf/synapse.xml
to
C:\Carbon\ESB\tomcat\esb_home\conf\synapse.xml

Step 6 - Starting the Apache Tomcat Server

Now you can start the Apache Tomcat server by giving the following command.
catalina.bat run

Step 7 - Login to the WSO2 ESB Administration Console

Now you should be able to login to the WSO2 ESB Administration Console as, https://localhost:8443/esb/carbon

9 comments:

rajika said...

good post..

Hiranya Jayathilaka said...

Great post. It works on ESB 2.0.2 as well. However it seems setting the http/https ports in the Carbon axis2.xml to Tomcat http/https ports is wrong. They should be left unchanged. Otherwise you'll get AddressAlreadyInUse exceptions at the startup when NIO listeners of Synapse try to initialize themselves.

metabyte said...

Hello,

Nice and clear post!
What if I wanted to use Apache server as a front-end over SSL? How should I change the configs (keystores...etc.) to use only Apache keystore?

Thanks

Evanthika said...

Hi Fredric,

Hope this helps.

http://wso2.org/library/knowledge-base/install-wso2-esb-ibm-websphere-application-server

Thanks,
Evanthika

hbagchi said...

Hi,

Nice post!
I am looking for ways to deploy WSO2 ESB on the JBoss 5.1 app server in embeddable mode. Can you point me to an article on that.
Thanks

Evanthika said...

Hi,

Information on how to deploy WSO2 ESB on JBoss is available here.
http://wso2.org/blog/ramanathan/5318

Madumm said...

Hi I treid to deploy ESB 4.0.0 into apache tomcat and ended up with following exception wnen trying to access the esb\carbon

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)


Any Idea?
Thanks in Advance
Madumm

Madumm said...

Hi

I was trying to deploy WSO2 ESB 4.0.0 inot apache tomcat and once i was going to start the admin console esb/carbon, ended up with the following exceptions Any idea?

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)



thanks in Advance
madumm

Evanthika said...

Hi Madumm,

Could you please verify whether you have followed the correct steps in deploying the latest WSO2 ESB version on Tomcat by going through [1]? The steps given in this post will not be applicable for the latest WSO2 ESB release.


[1] - http://wso2.org/project/esb/java/4.0.0/docs/webapp_deployment_guide.html

Regards,
Evanthika