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

Friday, October 30, 2015

How to configure sticky sessions between Apache web server and Tomcat application server

Why sticky sessions?

Imagine you have a Apache server which load balances between two tomcat servers(tomcat1 and tomcat2) in the backend, With the use of sticky sessions, When the user sends the first request, If apache routes it to tomcat1, It will keep on sending the other requests made by the same user to the same server. If the tomcat1 is down, Then the user will be forwared to tomcat2 and will be asked to login again as the session information is lost in the tomcat1.

When you use sticky session with session replication, This issue will be solved. Considering the above scenario, When the tomcat1 is down, The session will be carried over to the tomcat2 and the user will still be able to continue the work with out any disruption.

Implementation :

Sticky sessions can be implemented in many ways, out of which I am listing the configuration with proxy and configuration with worker.properties.

Configuration with mod_proxy:

After the installation of apache, Open the http.conf file, Enable the mod_proxy.so, mod_proxy_http.so and proxy_balancer_module.

LoadModule proxy_module mod_proxy.so
LoadModule proxy_http_module mod_proxy_http.so
LoadModule proxy_balancer_module 

<IfModule mod_proxy_balancer.c>
    ProxyPass /context balancer://tomcatcluster/context stickysession=JSESSIONID|jsessionid
    <Proxy balancer://tomcatcluster>
        BalancerMember http://tomcatlocalhost:9080 route=tomcatroute1
        BalancerMember http://tomcatlocalhost:9081 route=tomcatroute2
    </Proxy>
</IfModule>


Once this configuration is done in apache, Save the httpd.conf and restart the server.

After tomcat server installation, open the server.xml and ensure http connector port is same as the port that is defined in the cluster properties of apache configuration file. For sticky sessions, Ensure that the jvm route value is same as the route value in the httpd.conf file.


tomcatroute1 worker:


<Engine defaultHost="localhost" name="Catalina" jvmRoute="tomcatroute1">
</Engine>
<Connector port="9080" protocol="org.apache.coyote.http11.Http11Protocol" ... />

tomcatroute2 worker:


<Engine defaultHost="localhost" name="Catalina" jvmRoute="tomcatroute2">

</Engine>
<Connector port="9081" protocol="org.apache.coyote.http11.Http11Protocol" ... />


Save the configuration, Now the sticky sessions are configured.

Configuration with worker.properties:

The tomcat configuration will be same as above, Only the apache configuration would differ.

add the following configuration in httpd.conf.

LoadModule jk_module mod_jk.so
<IfModule mod_jk.c>
JkLogFile logs/mod_jk.log
JkLogLevel debug
JkShmFile logs/jk-runtime-status
JkWorkersFile conf/workers.properties

JkMount /context loadbalancer
JkMount /context/* loadbalancer
</IfModule>

In the worker.properties file, Add the following configuration:

worker.list=loadbalancerworker.tomcatroute1.port=9080worker.tomcatroute1.host=localhostworker.tomcatroute1.type=ajp13worker.tomcatroute1.lbfactor=1worker.tomcatroute2.port=9081worker.tomcatroute2.host=localhostworker.tomcatroute2.type=ajp13worker.tomcatroute2.lbfactor=1worker.loadbalancer.type=lbworker.loadbalancer.balanced_workers=tomcatroute1,tomcatroute2

Thursday, September 24, 2015

Caused by: java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String;

Issue:

This error is seen when the JAX-WS libraries are missing.

Solution:

When deploying webservice project to the tomcat server, Tomcat do not implement the entire java EE sepcifications and it needs the JAX-WS libraries deployed to support the project.

add the jars in the endorsed directory.

By default the endorsed directory will be taken as $CATALINA_HOME/endorsed.

If you want to force use a different path, Use the following in the setenv.sh or the catalina.sh file.

-Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS

Monday, August 10, 2015

ORA-12505, TNS:listener does not currently know of SID given in connect descriptor

Following error is seen when trying to configure a new jdbc pool with the back-end.

ERROR : 

FATAL DataSourcePool getDataSourceConnection Can't create a new connection for name on java:comp/env/jdbc/SID3 exception: java.sql.SQLException: Listener refused the connection with the following error:

ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
 code: 12505 ^?java.sql.SQLException: Listener refused the connection with the following error:^?
ORA-12505, TNS: listener does not currently know of SID given in connect descriptor^? ^?       at oracle.jdbc.driver.logon(java:419)^?     at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)^?  at oracle.jdbc.driver.<init>(T4CConnection.java:228)^?    at oracle.jdbc.driver.getConnection (T4CDriverExtension.java:32)^?    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)^?     at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:218)^?

Solution:

Solution for this particular issue resides in the error itself.

If the url mentioned during the pool configuration is as following from the server.xml. <resource tab>

url="jdbc:db2://dbhostname:portnumber/SID3"

The last parameter will be the SID. Recheck the sid value, Above error is seen when the SID value is specified incorrectly. Change the SID3 with the correct SID and the issue will be resolved.

Friday, June 26, 2015

javax.naming.NameNotFoundException after configuring the JDBC pools

ERROR:    [Date & Time] 0 FATAL DataSourcePool initialize Can't create a new connection for Nkdi1r_POOL on java:comp/env/jdbc/Nkdi1r exception: javax.naming.NameNotFoundException: Name Nkdi1r is not bound in this Context ^?java.lang.Throwable^?

Solution: This error will be seen when the datasource value defined in the pools.xml property doesn't match with the Resource details in server.xml

                <datasource>                       
                        <prod value="java:comp/env/jdbc/Nkdilr" />   ---pools.xml---
                </datasource>

Hence check the Nkdilr is defined correctly in both pools.xml and the server.xml, This is case sensitive.

pools.xml path: /jvm/webapps/appname/WEB-INF/classes
server.xml path: /jvm/conf/server.xml

Monday, May 25, 2015

JDBC configuration in tomcat application server - TeraData

This summary is not available. Please click here to view the post.

FATAL DataSourcePool getDataSourceConnection Can't create a new connection for tera

Error:

FATAL DataSourcePool getDataSourceConnection Can't create a new connection for tera on java:/jdbc/XXXX exception: java.sql.SQLException: com.teradata.jdbc.TeraDriver code: 0 java.sql.SQLException: com.teradata.jdbc.TeraDriver at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:208)at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:157) at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:617)  at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:561)     at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:166) at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:106)        at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:78) at cat.cis.tuf.server.connector.jdbc.DataSourcePool.getConnection(DataSourcePool.java:268)    at cat.cis.tuf.server.connector.jdbc.DataSourcePool.getDataSourceConnection(DataSourcePool.java:165

Scenario:

After configuring the Tomcat connection pool as the resource, i.e, You add the jdbc connection pool details to the server.xml. Once the restart is done, The following error will pop up if the jar files path or the files are missing.

Solution:

if the jar files exist in the libraries path, The probable cause for the error would be the missing jar files. Since it is for the tera database connection the following jar files have to be added to the common.loader in catalina.properties file seperated with a ,.

In my case the common.loader looks like the following.

common.loader=${catalina.home}/../Libraries/teradata, ${catalina.home}/../Libraries/teradata/*.jar

A quick restart after the above change would resolve the issue.

In case, If the jar files are not present. You have to download and add them to the libraries and configure the path in the common.loader.

Thursday, October 30, 2014

%1 is not a valid Win32 application - Tomcat 7 on Windows OS

Unable to Start Tomcat 7 on windows with the error "%1 is not a valid Win32 application"

Issue: 

Tomcat 7 service fails to start as a service in windows environment. The following error is logged in the tomcat logs.

Error:

Running 'Tomcat7' Service...
[Date N Time] [info] [ 6132] Starting service...
[Date N Time] [error] [ 6132] %1 is not a valid Win32 application.
[Date N Time] [error] [ 6132] Failed creating java C:\<PATH>
[Date N Time] [error] [ 6132] %1 is not a valid Win32 application.
[Date N Time] [error] [ 6132] ServiceStart returned 1
[Date N Time] [error] [ 6132] %1 is not a valid Win32 application.
[Date N Time] [info] [ 8084] Run service finished.  

Solution:

Main pointer to resolve this type of issues is the JAVA_HOME variable. JAVA in windows is typically installed in two paths. One is the (C:\Program Files (x86)) 32 bit path and the other is 64 bit path (C:\Program Files). 

--> Check the JAVA_HOME setting : 

Run the following command from the tomcat bin folder :  

tomcat7w.exe //ES//tomcat.

This command will launch the UI tool that will let you append the java options.

In case if the jvm.dll is chosen from the 32 bit path and the above error is seen in the logs. Change the jvm.dll path to the java path that is installed in 64 bit.

Issue will be resolved and the tomcat service will be started.

                                                                                    (: Happy Learning :)

The Digital Signature of a message is invalid - application deployed in tomcat

One of the form in application shows the error "The Digital signature of a message is invalid"

Issue: 

Above mentioned error message is displayed in the browser. However, Errors are not logged in the logs.

Solution:

Check the Java path of the application. In some cases, When there is a OS reboot performed, The JAVA_HOME and JRE_HOME will be nullified. Due to this the JAVA_HOME will be taken as default OS path.

Change the JAVA_HOME path to the one that is compatible with the tomcat service that is currently running.


                                          (: Happy Learning :)

Easy steps to Install and configure JAVA Melody in tomcat - Solaris

This summary is not available. Please click here to view the post.