Showing posts with label Apache Tomcat. Show all posts
Showing posts with label Apache Tomcat. Show all posts

Monday, February 25, 2013

Error with starting OpenMRS - "Unable to get a connection to the database"

This blog post will be about a very primary error on starting and running OpenMRS medical record system, in which i did my gsoc project and where i am still contributing whenever i get a time (yes i still love openmrs!). This is more like a note to myself.

I recently started to use a new laptop, therefore i moved all my openmrs repositories, .m2 repository and .OpenMRS directories into the new machine, as my intention was saving the time that will be taken to build everything from scratch again. However when i tried to run OpenMRS in the new machine, after installing and setting up mysql server, it returned the following error.

java.lang.RuntimeException: Error occurred while trying to get the updates needed for the database.
Unable to get a connection to the database.  Please check your openmrs 
runtime properties file and make sure you have the correct 
connection.username and
connection.password set ...
.................................................................................
.................................................................................
Caused by: java.sql.SQLException: Access denied for user 'openmrs_user'@'localhost' (using password: YES)


 Although i have worked with the project over an year now, i was also first confused on why the webapp can not be started. But then i realized the fix.

This is simply because when we start the web app from a previous implementation it still uses some of the configuration from its past installation. 
If you go to "webapp" folder in the 'openmrs_home' repository, there is a file called "openmrs-runtime.properties" where there is previous configuration data (usernames, passwords etc.) still present. Now simply delete this file from /home/USER_NAME/.OpenMRS folder if it is present there. Then delete this file from the 'webapp' folder and start again using 'mvn jetty:run'. No more errors, You are good to go now  :) :)


Sunday, September 4, 2011

Remote Debugging Apache ODE with Apache Tomcat Server in IntelliJ Idea


Apache ODE (Orchestration Director Engine) can be deployed and run in three different environments. One of them is deploying ODE as a web service in Axis 2, by deploying the ode war distribution inside an application server like Apache tomcat. Once it is deployed and started you may need to debug ODE, to understand what is going inside the engine. The following is a short guide on how to debug Apache ODE with tomcat in both Windows and Linux environments.
If you don't know how to deploy ODE and run with Apache tomcat first visit and read the this previous blog post.

Applicable with:

Apache Tomcat : 7.0.11    Download 

Apache ODE: 1.3.5           Download


Debug ODE in Ubuntu 10.04

Apache Tomcat can be debugged with JPDA debugger by starting tomcat with catalina script. To do this start go to Tomcat_Home/bin folder and enter the following command.


apache-tomcat-7/bin$ sh catalina.sh jpda run  

This will start catalina server in debug mode and you can see it displays the message, "Listening for transport dt_socket at address: 8000" in terminal as shown in Figure 1.

Figure 1: Starting tomcat in debug mode


Another method would be setting the JAVA_OPTS to start up java for listening to debugger connections by giving,
apache-tomcat-7/bin$  export JAVA_OPTS=
"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"

When it is set start the catalina server in the usual manner as 'sh catalina.sh  run' and tomcat will be started in debug mode.   

Now we can create a remote debug configuration by giving Host: localhost and Port: 8000 in our IDE which we have used to open the ode source code, and debug ODE by using that. Remember to use the same port used as JPDA_ADDRESS in tomcat as your IDE's remote debug port. The default port address is 8000.
Creating a Remote Debug Configuration in Idea 10.0.3
This is how to create a remote debug with IntelliJ Idea 10.
  • Go to Run --> Edit Configurations in the IDE
Figure 2: Creating a Remote Debug Configuration


  • When it is selected the Run/Debug Configuration window will pop up.  Click the  icon there and select 'remote' from 'Add New configuration' menu.




Figure 3: Created New Remote Debug
  • This will create a new remote debug configuration for us. Let's name it as 'ode' and fill the Host field with 'localhost' and Port field with '8000'. Then click OK.
Figure 4: Setting up Host and Port for remote debugging
  • The new remote debug is successfully created now. After the tomcat server is started, select 'ode' remote debug and start it by clicking icon in Idea. It will connect to the server via the defined port and you can start debug ODE now.

Figure 5: Debugging ODE

Note: port 8000 is the default port address used in tomcat for JPDA debugging, however if port 8000 is busy(due to some other application running there), you can change it into another port. 
  • Open catalina.sh script in the Tomcat_Home/bin folder and search for JPDA_ADDRESS, you will see JPDA_ADDRESS="8000" defined there. Change it to any available port and restart tomcat under JPDA debugger. The server will listen from the new address now.
Figure 6: Edit the JPDA_PORT in catalina script


         You can also change this port (let's say to 8010) by giving,

         apache-tomcat-7/bin$ export JPDA_ADDRESS=8010 in terminal.


  • Now go back to the 'ode' remote debug and select 'Edit Configurations' to edit its configurations.

Figure 7: Edit the remote debug configuration in Idea 10.0.3


  • When Debug Configuration window appears set the Port address into the modified port,8010. Once it is set ODE can be debugged using the new port again.


Debug ODE in Windows
Debugging in Windows is also very similar to in Linux, except the commands that should be used. All the following demonstrations are performed in Windows 7 version.

  • To start tomcat, go to the tomcat home's bin folder and start catalina.bat file under jpda debugger as follows.

C:\Apache-Tomcat-7\bin> catalina.bat jpda start


Now catalina will start in remote debugging mode under JPDA debugger using its default port 8000. When it is started you will see tomcat starts a new debug console as shown below in Figure 8.
Figure 8: tomcat Debugger Console in Windows 

This can be also done by setting an environment variable  JAVA_OPTS, and starting the tomcat server with usual command.

C:\ Apache-Tomcat-7\bin>  set JAVA_OPTS=
"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"

C:\Apache-Tomcat-7\bin> catalina.bat run


When it is started create a new remote debug configuration as described in the previous section by configuring the correct Port address and Host. Once the remote debug configuration is connected to the server, you can debug ODE successfully.


Note: To change the port address from 8000 to another port 'set' command can be used in Windows. Go to Apache-Tomcat-7\bin and enter;


C:\ Apache-Tomcat-7\bin> set JPDA_ADDRESS="8010"

Figure 9: Change JPDA_ADDRESS in tomcat

When tomcat is started again you will see that it has changed the listening port into '8010' as we changed. Change the Port address in the remote debug into this new address and start debugging again. 
Figure 10: Debugging tomcat in Different Port
JPDA_ADDRESS can be also changed from the catalina.bat file in Windows. Right click catalina.bat file and select 'Edit' option from the menu. Then the file will be opened using Notepad or some other text document opening application in Windows. Search for JPDA_ADDRESS and change its value into a new one. Save the file back and start tomcat again.























Getting Started With Apache ODE 1.3.5

Apache ODE stands for Orchestration Director Engine which is an open source project designed to  execute business processes written using WS-BPEL. If you don't understand what BPEL is WS-BPEL (Business Process Execution Language) is an XML-based language which is defined  to write standard business processes.

There are three main ways to deploy ODE in our computer and run BPEL process. In this post i am going to describe about how to deploy the ODE war distribution as a simple service in Axis 2 and, run ODE in Apache Tomcat Server.

First we need to download Apache ODE 1.3.5 war distribution from the ODE website. If you still haven't downloaded ODE visit here to get ODE now.
Download the  apache-ode-war-1.3.5.zip archive into the local hard drive and extract it there by giving an identifiable name. I have renamed it into  'ode-1.3.5' directory in this case.

When you open the  'ode-1.3.5' directory ODE war archive can be seen inside the directory as 'ode.war'. Now we have to copy this and deploy it in Tomcat server in order to start Apache ODE in Tomcat.

To do this we need to have Apache Tomcat downloaded and installed in our computer. Download Tomcat 7 from here if you still haven't done it.Download and extract tomcat and i have renamed it as apache-tomcat-7. 

Starting ODE in Ubuntu 10.04 


Before start the tomcat server in Ubuntu, path to the TOMCAT_HOME directory  should be defined in our .bashrc script. Therefore go to your 'user' directory inside 'home' directory and open .bashrc file by giving,
home/user_1 $ gedit .bashrc
This will open the .bashrc script as a text document and enter the following lines into the end of file.

export TOMCAT_HOME=/home/PATH_TO_TOMCAT_DIRECTORY/apache-tomcat-7
export PATH=$PATH:$TOMCAT_HOME/bin

You can replace the PATH_TO_TOMCAT_DIRECTORY section with the filepath where the Tomcat directory is located at. Export the path to CATALINA_HOME as well in the .bashrc file since we will need it too at the future.


export CATALINA_HOME= /home/PATH_TO_TOMCAT_DIRECTORY/apache-tomcat-7
export PATH=$PATH:$CATALINA_HOME/bin

Now tomcat is set and ready to go. To start Apache ODE with tomcat copy the ode.war archive into the apache-tomcat-7/webapps directory. Then go to the apache-tomcat-7/bin from the console and start tomcat by using catalina.sh script.

apache-tomcat-7/bin$ sh catalina.sh run

Figure 1: Tomcat started in Ubuntu 10.04
This will start tomcat server and if you visit the webapps directory back you will see that tomcat has extracted ode.war distribution into a new 'ode' directory. Hence Apache ODE is successfully deployed.  Goto http://localhost:8080/ode/ in your browser and Apache ODE home page will be visible as shown in Figure 2. 

Figure 2: Apache ODE home



Starting ODE in Windows 7


Download ODE and Tomcat as given in above instructions.Copy the ode.war archive into the apache-tomcat-7/webapps directory. Tomcat server is started with catalina.bat in Windows. To do this go to the apache-tomcat-7/bin from the command prompt and enter the following command.
C:\Apache-Tomcat-7\bin> catalina.bat run

When you start tomcat for the first time it will show up the following error if file path to the JRE_Home is not saved.
Figure 3: Set JRE_HOME for Tomcat
Therefore let's set this path now from the console by entering;
C:\Apache-Tomcat-7\bin> set JRE_HOME=C:\Program Files\Java\jre6

Once this is set go back and start the tomcat server now. When the server is started, ODE will be deployed in the server. Go to http://localhost:8080/ode/ in browser and visit the ODE home page.