Java Mail Session Resource config in Play Framework Netty Server - java

I am trying to configure the Java Mail Sessions Resource in the Netty server Play config and loop up this resource using JNDI in my application. I couldnt find this in Play framework documentation nor any articles for this set up. I also looked up on the Play code, but no luck.
https://github.com/playframework/playframework/blob/master/framework/src/play-netty-server/src/main/resources/reference.conf
https://github.com/playframework/playframework/blob/master/framework/src/play-netty-server/src/main/scala/play/core/server/NettyServer.scala
Play Version: 2.4.6
HTTPmail.setMailSessionFromJNDI("java:comp/env/mail/myemailserver");
Could anyone guide me to some articles or share the knowledge?
We are deploying our play applications in tomcat environment and the resources are expected to looked up from server configurations through JNDI. As a first step, I am trying to make the application work in Netty during development and move to TOMCAT later. thank you for the guidence.

If you want to use the sessions in the same way as in Tomcat's HttpSession, you should forget it immediately. Play Framework can store only String instances. In additionally, session data can take only 4kb of data because data is stored in the cookie called PLAY_SESSION. This kind of constraint a little bit logical. If enhances stateless character of the application, so also its scalability. For more complex use of Play sessions (shopping carts), you should think about alternatives as NoSQL, file system or database.
Read this

Related

How would I implement an embedded SFTP Server on Openshift

Background Context:
Due to enterprise limitations, an uncooperative 3rd party vendor, and a lack of internal tools, this approach has been deemed most desirable. I am fully aware that there are easier ways to do this, but that decision is a couple of pay grades away from my hands, and I'm not about to fund new development efforts out of my own pocket.
Problem:
We need to send an internal file to an external vendor. The team responsible for these types of files only transfers with SFTP, while our vendor only accepts files via REST API calls. The idea we came up with (considering the above constraints) was to use our OpenShift environment to host a "middle-man" SFTP server (running from a jar file) that will hit the vendor's API after our team sends it the file.
I have learned that if we want to get SFTP to work with OpenShift we need to set up of our cluster and pods with an ingress/external IP. This looks promising, but due to enterprise bureaucracy, I'm waiting for the OpenShift admins to make the required changes before I can see if this works, and I'm running out of time.
Questions:
Is this approach even possible with the technologies involved? Am I on the right track?
Are there other configuration options I should be using instead of what I explained above?
Are there any clever ways in which an SFTP client can send a file via HTTP request? So instead of running an embedded SFTP server, we could just set up a web service instead (this is what our infrastructure supports and prefers).
References:
https://docs.openshift.com/container-platform/4.5/networking/configuring_ingress_cluster_traffic/configuring-externalip.html
https://docs.openshift.com/container-platform/4.5/networking/configuring_ingress_cluster_traffic/configuring-ingress-cluster-traffic-service-external-ip.html#configuring-ingress-cluster-traffic-service-external-ip
That's totally possible, I have done it in the past as well with OpenShift 3.10. The approach to use externalIPs is the right way.

what is the best usage Redis session for spring boot with external tomcat container

Folks.
I am using spring boot framework with tomcat containers, and because of several reasons for maintaining this service, I try to share sessions with Redis. Usually, I used spring-session-data-redis which is recommended by following the guide.
https://www.baeldung.com/spring-session
but, I have a question about session-sharing with Redis by using spring-session-data-redis. If I need to set and use multiple server clusters to reduce traffic stress (with load balancer), should I set also a Tomcat configuration to use Redis session? or is spring-session-data-redis enough to session-sharing for multiple server clusters?
if someone visited the wrong sub-path in the specific domain (for example somewheredomain.com/not_spring_project/some_path), I guess the spring session is not working to share session. if this guy visited A-tomcat server with the correct path and went to another tomcat server with the wrong-path, maybe another tomcat server which the someone visited the first time can generate(or re-write) jsessionid.
is there anyone able to explain the best usuage session sharing for spring boot with an external tomcat container?
A while i struggled to find the answer of this question. after making test-bed with multiple VMs on google cloud platform, finally I got the answer.
The answer is very simple, the session key of Spring-session is not jsession_id :P
so, developers don't need to worry The multiple tomcat servers issues new jsession_id.
just developers need to use spring-session-data with redis, then they can share session data on redis server.

How can I share session in two web application in different web servers?

I have the following problem. The customer have a Java EE web application running in EAServer 5.5.0 with a custom loggin. The loggin is very simple, when the application validates the credentials entered by the user through a web page, stores the user name and profile in a session variable. That way the application knows if the session is still alive. Now, the customer have another Java EE web application running in jboss server 7.1 and wants when the user log in the web application running on EAServer, at same time login in the application running in Jboss Server whitout any further steps.
My first idea was send the credentials via ajax call from EAServer to Jboss web application and stored the credentials in session, same way as the EAServer do. That seems to works fine on Internet Explorer, but in chrome or firefox the ajax call is done and the session variables are created in jboss, but when the user tries to see any view on the Jboss Application the session variables just gone.
Can somebody please tell me what is the best way or practice to do this? or what kind of problem I'm facing whit chrome and firefox that doesn't keep the session variables after ajax call?
One way you can do is the single sign-on that Leonardo Luiz suggested in the comment.
But I have another suggestion. Just install Redis and use it as a session store. This is very standard nowadays and it's broadly used in Ruby on Rails, NodeJs and Java as well.
Some libraries that might get you going:
Spring Session
Tomcat Redis Session Manager (I know you are using different servlet server, but still you can take a look to get the idea)
Or you might opt to use memcached. In that case you might use:
memcached-session-manager
The feature you need is called Single sign-on. I believe it's better to integrate an existing solution on your environment than create a custom one.
I already used two solutions for that:
http://picketlink.org/federation/ (Deprecated)
https://www.apereo.org/projects/cas
It will not be a ease task and requires some knowledge of security concerns.
If you really wanna to create a custom solution there is some information here: http://merbist.com/2012/04/04/building-and-implementing-a-single-sign-on-solution/

How to load existing http sessions from an existing server to another server?

I would like to know if Servlet specifications provides a way to load http sessions into my web application.
The idea is simple : every time a new http client is connected, a new session is created... and I will send this session and its values into a database (for the time being this step is easy to do).
If this "master server" dies, another machine will take its IP address, so http clients will now send their requests to this new machine (lets call it "slave server").
Here I would like my slave server retrieve sessions from the old server... but I don't know which method from Servlet specifications can "add" session ! Is there a way to do it ?
PS: it's for an university project, so I cannot use already existing modules like Tomcat's mod_jk for this homemade load-balancer.
EDIT:
I think that a lot of people think I am crazy to not use already existing tools. It's an university project, and I have to make it with my bare hands in order to show to my professors the low level mecanisms that I have used. I already know it would be crazy to use what I am doing in production, when this project will be finished, it will be thrown in the trash.
For the moment, I didn't find a "standard way" to make it with the Servlet specifications, but I can maybe do it with Manager and Session from Tomcat native classes... How can I get the instances for those interfaces ?
This isn't exactly a new idea and is called session replication. There are a couple of ways to do this. The easiest ones imho are (in ascending order of preference):
Jetty's Session clustering with a database
Tomcat's Session clustering. I personally prefer the BackupManager, which makes sure that a session lives on 2 servers in a cluster at any given point in time and forwards clients accordingly. This reduces the network traffic for session replication to a bare minimum.
Session replication with a distributed cache like hazelnuts or ehcache. There are plugins for both jetty and Tomcat to do this. Since most often a cache is used anyway, this is to be the best solution for me. What I tend to do is to put 2 round robin balanced varnish servers in front of such a cluster, which serve the dual purpose role of load balancing the cluster and serving static content from in memory cache.
As for your university project, I'd turn in an embedded jetty with automatic session replication which connects to other servers via broadcast using hazelcast. Useful, not overcomplicated (iirc, you need to implement 2 relatively simple interfaces), yet powerful. Put a varnish in front of your test machines and you should be good to go.
This feature is supported by all major Java EE application server vendors out of the box, so you shouldn't implement anything by yourself. As Markus wrote it is referred as session replication or session persistence. You can take a look at WebSphere Liberty which is available for free for development. It supports it out of the box, without need to implement anything. You just need to:
install Liberty Download just the Liberty profile runtime
configure session replication Configuring session persistence for the Liberty profile
install and configure IBM Http Server for load balancing Configuring a web server plug-in for the Liberty profile

Pass Database Connection from GWT App to Java Program

I have a web app built in GWT running in tomcat that accesses the database. On the same server, I have some server-side Java applications running that need to use the same database connection. These applications will be deployed as a war file alongside the GWT app.
Is there a way I can send the connection from the GWT app to these server-side apps?
This isn't a whole lot of information, I understand. To me, the problem is easy enough to understand, though I haven't found a solution yet. If you need anymore information, I'll be happy to provide.
Do you mean, that the applications have to use the same jdbc connection string or is it more like a shared connection pool.
Is it a solution for you to have a datasource in the local jndi and use this in your applications as well as in the servlets?
Actually this has nothing to do with GWT.
Have a look at this answer
ServletContext provides a way of sharing objects among different servlets and even among diffrenet webapps
this.getServletConfig().getServletContext().setAttribute("sharedObject", shared);
this.getServletConfig().getServletContext().getAttribute("sharedObject");
You cannot use the same connection in two different web apps. But if you mean to use same connection pool form which both the GWT and the other web app will fetch connections, then you need to configure the datasource at the application server level using JNDI
There are lots of JNDI tutorials using servlet in the internet.
Following is a link I found on using JNDI in GWT
http://humblecode.blogspot.in/2009/05/gwt-16-using-jndi-datasource.html

Categories

Resources