Java httpSession is not maintained - java

I just migrated the application from an aged Tomcat server (6.x) to Tomcat 8.
Master: Apache http server
Slave: Apache Tomcat application server
I use the ProxyPass setting to connect the Apache http server to the Tomcat server.
Works well, except the Tomcat server does not maintain httpSession between two httpServletRequests. The second request is suppost to pick-up some values from the httpSession, but the session is new.
Using the Tomcat server on it's own (port 8080) session is maintained between two requests.
I know there is a trick to this, but I'm unable to find it, regardless how many times I'm reading up and down the Apache manual.
httpd-ajp.conf: ProxyPass /MY_APP ajp://127.0.0.1:8009/MY_APP
Any help would be appreciated.

Related

How to retrieve port number from a tomcat server sitting behind a load-balancer

Situation:
My client has a Java web application deployed on a JBoss server, it is accessed both via HTTPS and HTTP
The JBoss server is sitting behind a load-balancer that handles the SSL, in other words this load-balancer terminates SSL and sends requests to JBoss as plain HTTP
Problem I need to solve:
The web application deployed on JBoss needs to know what port the load-balancer is using for HTTPS, so that it can direct users to certain HTTPS urls correctly. This cannot be hard-coded because the application will be deployed on multiple clients, each of them have different configurations for the load-balancer.
My approach (which didn't work):
I am defining the port from a jspx page, via ${pageContext.request.serverPort}, but this always returns the port for HTTP because JBoss always gets the request via HTTP.
Thanks in advance. I've looked at this question but was not helpful.
There isn't really a way to determine the port if tomcat is sitting behind a load balancer. As suggested in the comments, exposing the port configuration to your clients would be the best for now.

How to redirect the request from tomcat server to another tomcat server

Assume that there is 2 tomcat server running say tomcat 1(ip address:101.155.55.15) and tomcat 2(ip address:101.155.55.16) User will be accessing some resource in tomcat 1,Tomcat 1 should redirect the request to tomcat 2 and tomcat 2 should send back the response to tomcat 1 i dont no how can i approach this issue.
You have following two choices :
Either purchase as many public address
Put one server front and delegate these request.
Applying second approach we put Apache httpd web server in front of all others ip of servers. so only one public IP is enough. Apache httpd webserver communicate to Tomcat sever through AJP (Apache JServ Protocol) protocol.
Reference Link : Reference

Configuring Tomcat to communicate through proxy in Localhost - Fiddler

Tomcat is running in my localhost on standard 8080 port. When tomcat calls a service (soap/rest) running in the same server, I would like to capture it through fiddler.
Basically, any request that tomcat sends out, should be captured through Fiddler. Currently, it sends out request to another service running the same machine and that service in turn calls Amazon AWS, which I would like to capture as well.
Can anyone help? Note that this is opposite of traditional web request through proxy to the server.
I am open to any other alternatives as well.
Please have a look at How to capture SOAP messages from a Tomcat Java app to an external server? for information on setting the proxy for Tomcat.
The correct JVM parameters should look like: -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8888 -DproxySet=true -DproxyHost=127.0.0.1 -DproxyPort=8888

Can a single Apache server handle both Tomcat and PHP?

I have a requirement as to have a single server with both a Java application and a PHP application, running on the same Apache. Is this possible?
This question may be very silly but I have no clue about java requirements or installation procedures.
Can I do such a thing that as to have the java application running on one port and the PHP application on another port, both on the same Apache?
Yes you can do that. Essentially you have to run the Apache (+ PHP) server on one port and the Tomcat server on a different port.
You can expose the 2nd port to the outside world, and have your URLs use either port 80 for Apache / PHP or (say) 8080 for the Java server. This simple, but you may find that upstream firewalls prevent a remote web browser from connecting to any port other than 80.
You can configure your Apache server as a reverse proxy for the Java server. So for instance, the Apache server might recognize that http://site.com/javaapp/foo.html is for the Java server, and relay requests for that URL to http://localhost:8080/javaapp/foo.html.
There is a whole chapter of the Apache documentation about configuring forward and reverse proxies using mod_proxy.
Yes.
Apache HTTPd can delegate to Apache Tomcat using ModProxy or ModAJP, and can be configured to do so based on the domain, path or file extension requested. Your Apache HTTPd configuration of PHP would remain the same.
You would need to configure Apache Tomcat to not listen on port 80, and then configure the Apache HTTPd proxying solution of your choice to talk to Tomcat on a different port.
Here's a starting point for more information: Apache + Tomcat: Using mod_proxy instead of AJP
This is possible using Apache Reverse Proxy,
I configured one Apache virtual host that serves one PHP website (Drupal) and one java (tomcat, for business logic) that are stored in the same server using a reverse proxy with 2 locations, the advantage of this configuration is that it doesn't expose the port that Tomcat is using on the URL which was mandatory for me for security reasons.
This is how I achieved this:
<VirtualHost *:80>
ProxyPreserveHost On
DocumentRoot "/srv/www/htdocs/"
ErrorLog /var/log/httpd/app_error_log.log
CustomLog /var/log/httpd/app_log.log combined
ServerName myapp.com
#Drupal PHP Content, stored at / as the main front end website.
<Location />
ProxyPass http://localhost/
ProxyPassReverse http://localhost
Order allow,deny
Allow from all
</Location>
#Tomcat/java content, secondary site used to process payments and business logic:
<Location /javaApp>
ProxyPass http://localhost:8080/javaApp/
ProxyPassReverse http://localhost:8080/javaApp/
Order allow,deny
Allow from all
</Location>
</VirtualHost>
Restart Apache:
service httpd restart;
Test your reverse proxies:
PHP/Drupal (In my case i'm using drupal but can be any PHP code):
http://yourserverip/ or http://localhost/
Java:
http://yourserverip/javaApp or http://localhost/javaApp
I hope someone can find this useful.
I had a hard time trying to figure this out. :)
Regards.
Can a sinle apache server handle both tomcat and php?
Yes, you need both apache and tomcat installed, but you can configure apache to redirect (transparently for the user) all JSP requests to tomcat using AJP protocol.
See more here:
http://www.datadisk.co.uk/html_docs/java_app/tomcat6/tomcat6_apache_server.htm

WebSocket connection interrupted when Apache HTTPD in front of Tomcat

I try to use Tomcat implementation of WebSockets on local machine.
When I use only tomcat everything works fine, but when I start use bundle Apache + mod_jk + Tomcat browser show me 'The connection to ws://example.com/test/echoMessage was interrupted while the page was loading' after couple of seconds of work. WebSocket connection is closed after this.
Can anyone tell me how to fix it?
I have: Apache HTTPD 2.2.18, mod_jk 1.2.37, Tomcat 7.0.28
Here is server side code that I use: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/ and client side: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/websocket/
Browsers: Firefox 12, Chrome 19
I would research whether Apache mod_proxy is able to transparently forward traffic at the TCP level at all. Since that is likely needed for WebSocket to pass through. IOW: is mod_proxy able to transparently reverse proxy WebSocket traffic?
But why would you want to bring Apache in the line anyway? It doesn't add any value, only more parts which can break. That is for WebSocket of course ..

Categories

Resources