session replication without loadbalancer - java

I am trying to set up session replication between two tomcat servers(server1,server2) in two different machines.
I am using StaticMembershipInterceptor and StaticMember instead of Multicast. I am not using any loadbalancer.
Below is the site mainly I have followed. I referred this configuration as this is the exact requirement I have.
http://khaidoan.wikidot.com/tomcat-cluster-session-replication-without-multicasting
I am using Tomcat9.
What I am expecting is after the above configuration is:
Server1: Tomcat A
Server2: Tomcat B
Exected Result :
Firststep:
I start the Tomcat A. Load the webpage.(http://server1:8080) Login to application by entering username and password and session is created.
Secondstep:
I start the Tomcat B. Load the webpage.(http://server2:8080). It should automcatically login to the application without entering username and password. No login page should be available.
Actual Result after the above configuration:
In Secondstep: Login page is available. the reason why login page appears is it creates different session.
When I tested the same configuration in the two nodes of same machine, it works fine. But in different machine, it does not work.
What I tried so far:
Checked the log file of two tomcats - I can see the connection is
established.
Made sure has distributable tag
Also added the same in context.xml
Tried adding inside the tag as I saw it in couple of forum.
Checked netstat -ano I could see ports are listening at 4100 in both
the machines
Am I missing any other configuration? Not sure why it does not work.

I'm assuming you are using cookie-based session-tracking, because it is enabled by default and is preferred over URL-based session-tracking in Tomcat if the client is willing to send JSESSIONID cookies.
Cookies are scoped to a particular hostname and path. So, when you login to Tomcat A (http://server1:8080), you get a cookie scoped to server1/path. Wen you visit Tomcat B (http://server2:8080), your cookie for server1 isn't sent and you are challenged to login.
If you want this to work, you will need to choose one of the following options:
Use a reverse-proxy / load-balancer
Use multiple-IP DNS to resolve server (not server or server2) to multiple IP addresses, each pointing to a separate Tomcat instance
Disable cookie-based session tracking
But the way you are testing things cannot work due to the rules browsers follow for HTTP cookie handling.

Related

How to configure Wildfly 9 to failover HTTP sessions

I'm really struggling to configure Wildfly 9 to cluster/failover its sessions...
I keep reading that wildfly in standalone-ha mode will automatically discover peers and automatically share sessions, but it's clearly not working for me.
I have setup 3 AWS EC2 servers which all have the same configuration. They all run the same versions of everything and have the same webapp .war file deployed to each of them. This webapp works fine, I can log in to the app which maintains a simple session variable to verify that I am logged in. I've launched each server with standalone-ha.xml configuration files but logging into one doesn't allow be to access the session in any of the others.
I've tried all the things I can think of, but don't know how to diagnose the issue as I don't know how the servers identify each other.
I've manually deployed the war file on each server but placing the file into .../standalone/deployments/
Each has a fully open firewall...
Oh - I set the muticast address on the command line to 230.0.0.4 (That number came from a guide, and I have literally no understanding of it) and each is bound (-b) to the internal IP of the server...
Any help appreciated...
First you must consider that in AWS EC2 multicast traffic is not allowed and thus MPING will not work.
See http://developer.jboss.org/wiki/JGroupsS3PING
An example how to implement S3Ping http://aws.typepad.com/awsaktuell/2013/10/elastic-jboss-as-7-clustering-in-aws-using-ec2-s3-elb-and-chef.html

Tomcat Request.getPort() stripping port number

Problem:
I am using Java HttpServeltResponse to call sendRedirect but on a particular deployment the URL port number is not included in the HTTP 302 response message.
Details:
I have an application, which uses spring security to authenticate and redirect on success. The redirection URL provided by me is a relative path.
On redirection the spring framework calls sendRedirect on HttpServletResponse passing in the context path along with the relative URL. For example:
HttpServletResponse.sendRedirect("/MyApp/index.html");
This all works fine when we deploy to tomcat instances on various platforms (Windows/Ubuntu etc). However one of our clients is finding that in their deployment, the redirection port is stripped, for example, if the entry point is:
http://server:8082/MyApp/authenticate
The redirection they get is:
http://server/MyApp/index.html - this page does not exist, as it is missing port 8082
Stepping through the code, I can see that the port is determined by asking the Java Request Object, which seems to be supplied by the Web Application Container (i.e Jetty/Tomcat?). In my dev environment it is org.eclipse.jetty.server.Request.
So is this a tomcat configuration issue? We could replicate the same behaviour using Apache2 ProxyPassReverse, but they assure me they are not running Apache2, and their connection is a direct connection to tomcat.
As I can not replicate this issue anywhere, I am really stuck for an answer. Any help would be very much appreciated.

GlassFish 4.1 - simultaneous access to web admin console of two domains of the same GF

I use GlassFish 4.1 - final release (downloaded from java.net). I have two domains - domain1 and domain2
The problem is that I can't work simultaneously with web admin console of two domains of the same GF server. I open admin of domain1 - everything is ok, at the same browser (firefox) but different tab I open admin console of domain2 - at this time server closes my access for the admin of domain1. What is the reason? How can it be fixed?
That is simply because you're accessing the two domains via URLs with the same host.
192.168.1.10:X
192.168.1.10:Y
Recall that the host portion is 192.168.1.10 and as with many other web-app, glassfish admin console use session cookies, which is unique per host. So what happen when you login to the second domain is, the session info from the first domain is lost / overwritten.
Easiest solution for this is use a different browser for each domain (eg: firefox for domain 1 and IE for domain 2) or open another window in incognito mode (if using google chrome)

Tomcat create always new session

I created some web application, on Tomcat 6. When I am accessing via localhost to these machine everything work good - server create one session. But when I connect to this application via Internet, Tomcat creates each time 3 new sessions. Do anyone knows why? The clue could be, that Tomcat server is in DMZ zone, so when i connect via proxy, or from localhost everything is good, but when I access via Internet, the problem occure.
I fixed the problem, the session time out was caused by the network settings. There were 2 problems: 1) mess up with ports connection between tomcat, apache and DNS server (different ports were set up for one application on each machines)
2) When I was connecting via LAN to app, tomcat was creating 1 session and everything was ok. But when I was connecting via Internet tomcat created as I said 3 different session - the first one was exactly like in LAN connection case (session was containing SESIONID for application), but 2,3 was created in the same time and their were empty sessions. My internet adress for application was like: www.example.com/application. In tomcat documentation I read that in this case I should set up emptySessionPath in server access configuration.
When I done everything that I wrote before, my application started to work properly. :)

Flex accessing https service of the same domain that swf is loaded

I am developing a flex application with flex 4.1 sdk and java backend (runs on Glassfish 3.1 via http). For security reasons I decided to move my authentication process to https until a session id is obtained. Therefore I changed the filter settings to use ssl for login and logout pages(just two pages due to performance reasons. The data-size sent to client is large and I do not want to slow down the system). Glassfish forwarded these pages to 8181 port (which is HTTPS port). Everything is ok for the java part. However flex defines the 8181 port as a different domain and then problems arise. Due to flash's same-origin policy it cannot load the secured content. Normally a crossdomain.xml is the solution but I am accessing content of the same domain through a different port. What will be the solution ?
Probably not the best solution but create a subdomain that maps to 8181 and put a crossdomain.xml that will allow access from root domain.

Categories