Spring 3 Web MVC with JMX client and remote service not running - java

The problem is relatively simple:
I have a web based application, that, among other things, needs to check for status of a remote service. This remote service has JMX based mbeans exposed. However, the remote service might be not running all the time. What I need is:
Setup Spring to connect to remote JMX server
When the remote is not running, present this information in the web ui
The problem with this is that if I setup the JMX client bean in springContext.xml and the service is not running, the webapp won't even start with exceptions like ConnectionRefused and so on.
So the question is: is there a way I can tell spring to ignore the fact that it cannot connect to remote mbean server and try it later?

I am assuming you are using the MBeanServerConnectionFactoryBean? Set the connectOnStartup property to false.

Related

setup proxy to docker containers from java application

Need help with technical solution.
I have java (spring boot) application which may start docker container. Application assign ID and port to each container. That port is used as separate UI. ID is used to stop container.
For now, application work with 443 secured port, while each container open it own port in a range 19000-19100.
Is it possible to setup something like proxy server in application, verify request and then forward it to container?
Let's say, instead of myhost.com:19000 I want to use myhost.com/container/{containerId}?
I'm thinking about rest template or feign client, but not sure how it will behave with websockets. Any thoughts? Existing tools or libraries?
Take a look at Spring Cloud Netflix Zuul.
I am working on a project where we use this to proxy requests from frontend to a service which handles persistence processes.
Maybe it will help you achieve what you are looking for.

How do I automatically restart tomcat in linux

I have created a Spring Boot microservice and hosted inside a Tomcat on a Linux machine.
Everything is inside the container and the container is inside the IBM cloud private platform.
Now the microservice should be running continuously.
But suppose for any reasons the microservice got stop or tomcat got crashed.
Is there any way we could restart the Tomcat server or microservice automatically without manual intervention?
Why are you deploying a Spring boot app in your local tomcat? By default Springboot comes with embedded Tomcat server in it, so if you just build and run the jar, a tomcat will be started with the service itself.You can also , configure the server type(tomcat or jetty) and other server properties in the application.yml file. More details here - https://www.springboottutorial.com/spring-boot-with-embedded-servers-tomcat-jetty
Coming to the second part, of the question,about how to make sure , that if one service crashes, a new instance should be started automatically, for this you might be needing to do some reading on container managers like dockerswarm or kubernetes, which support auto-scaling, and can take care of restarting services (pods) as and when required,they can even scale up, meaning increase the number of instances of a service if existing containers reach a resource usage threshold and then load balancing requests to that service through some discovery and registry client.I think this would be helpful to you - https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy

Spring MVC Apache Server integration

I have developed a Spring MVC app that can detect Ajax requests sent into my local environment 'localhost:8000/examplePath' with a json body being received as a mapped parameter. So, until here, all is fine.
My question is: Do i still need to deploy my application on a container 'Apache Tomcat/ HTTP Server for example' for my application to be accessible externally on a possible production environment, and if so why?
I want to better understand the necessity of such, if my backend 'Spring MVC app' can already receive and respond to ajax requests
Spring MVC creates a Web application that must be deployed to a Web Application Server to run. The server handles the low level stuff such as raw sockets and the HTTP protocol.
This is because you can't access from internet to your local environment, you need a public adress to access your application from everywhere only if you want to access it over internet otherwise can do it with a local network connection to access it.
If you want any container, you can do it easy with Pivotal. This a container platform for Spring apps.

How to call Clustered EJB application in weblogic server from a client application

I have created a cluster in weblogic server with two managed servers. My admin server is listing on 192.168.25.30:7001 and other two managed servers are listing on 192.168.25.30:7003 and 192.168.25.30:7005 . As i want to call the EJB application deploy on this cluster I have developed a client application. I used the 192.168.25.30:7003 address as the remote address to call from the client. When the both managed servers up and running my application works fine. But I want to run the application server if one manage server is down. When the 192.168.25.30:7005 is down it works fine. But when 192.168.25.30:7003 is down client requests doesn't forward to other server.
Please advice me is my approach correct for set up the weblogic cluster. And can i used one of the managed server address to call from the client application?
You have to do the look-up for the cluster, not only for a server.
Here is an example on how to do this on WebLogic.
Problem in your approach is that you are looking up a specific managed server instance instead of the cluster/Load balancer, so you always hit the same managed instance every time.
As already answered, you need to lookup on the WL cluster.

Running a java application on a remote server

I want to run a standalone java application on a remote server. It would not be accessible to clients, but would do background calculations and interact with a database and Secure Socket connection to a third party site. It would also interact with a php site.
Do I have to deploy this with JSP, or can I write a standalone application? If so, how would I deploy a standalone java application (jar file) on a remote server? I understand that I must have them install a jvm on the server (not a problem) but then how would I deploy it (if possible). Would I start it with a command line?
I know I have much to learn, but I am not sure how I would access the command line on a remote server. Through the cPanel?
Thanks.
First of all, you'll want to set up some firewall rules to allow access to that server. I'm hoping that you don't expose that server naked to the Internet.
If all you need is database access exposed on the Internet, I don't see why it can't be a secured web app deployed on a servlet/JSP engine and accessed via a web server. You can leverage basic auth for security, JDBC access to the database from the server, and servlets as controllers to accept requests in a nice REST API.
It'll save you the complications of sockets and inventing your own protocol (use HTTP), starting and stopping the application (now it's just a web server/servlet engine), and deployment (send a WAR file).
Does it really must be a 'standalone' application? I think that in your case the best match would be to use Spring container to load your application within some server (tomcat?) and expose services via standard controllers - with Spring you only have to add some annotations on services methods actually.
Then, your php site can interact with these controllers using for example ajax requests.
If your application is written already, you can easily transform it to run within Spring container. It's very non-invasive and promotes usage of POJOs.

Categories