Connection to Openshift Online 3 from JAVA code outside the cloud - java

Openshift 2 will not work from tomorrow. Online 3 version is available. I use starter type.For Openshift 2 I could write/read data to/from MySQL DB located on openshift from my application that located on my PC, I mean from the code outside of the cloud. But now, with version 3 I have no idea hot to do it.
How to it now?
Is it possible to connect my local MySQL WorkBench to MySQL DB on Openshift Online 3 as well?

Port forwarding is very common method to make secure connection to remote machines. Its like creating a secure connection from your machine to the host machine. Once connection is build, any tool like MYSQL workbench can connect via localhost:<localport> where would forward the connection to remote machine's port.
Please read more about this feature here.
The port forwarding can be setup via any shell client supporting the feature, e.g. in a putty configuration.
Openshift V3 also support port forwarding through its client tool oc
Step wise:
1) Download and install oc tool. Refer here.
2) Once install on your machine (windows/linux), you could use port forwarding feature to access it from local machine.
Please refer openshift document here to setup port forward.
Once port forward is setup, leave the console open on local and try connecting to localhost:<localport> and you should actually get connected to MYSQL on openshift.

Yes, you can do this with port-forwarding:
https://katacoda.com/graham.dumpleton/courses/intro-openshift/port-forwarding

Related

How to connect remotely via tcp to the h2 database?

I am trying to start H2 in server mode to connect an application from another computer. But no matter how hard I have tried, I have not succeeded.
I have seen the documentation and to start the server from the command line is executed:
java -cp h2-2.1.214.jar org.h2.tools.Server -tcpAllowOthers
output:
TCP server running at tcp://127.0.1.1:9092 (others can connect)
PG server running at pg://127.0.1.1:5435 (only local connections)
Web Console server running at https://127.0.1.1:8082 (others can connect)
now from the other pc, as I understand I must execute the connection in the following way:
jdbc:h2:tcp://[server][:port]/[path]/[databaseName]
then it should be:
jdbc:h2:tcp://127.0.1.1:9092/home/mateo/database
But I have read that 127.0.1.1 only works locally. I have also noticed that when I open H2 Console in the examples I have seen, the machine's ip appears, that is to say: 192.168.X.
What am I doing wrong?
(Update)
I am currently using Linux.
I have launched the server from Windows and managed to connect it from Linux successfully following the above steps. But, I still don't understand why it doesn't work in Linux, in Windows it loads the server with the IP address of the machine. It makes me think that I have to do some additional configuration for Linux.
server running
You need to replace local IP address in your JDBC URL with real non-local IP address of your server (jdbc:h2:tcp://127.0.1.1:9092/*** -> jdbc:h2:tcp://192.168.1.4:9092/***, for example). H2 listens all network interfaces of the host, it doesn't matter which address was reported in “runnig at …” message.
You also may need to protect ports 8082 and 9092 from connections from untrusted systems if you have them in your internal network and from connections from external network (make sure your router or whatever you have doesn't redirect connections to the host with database server).

Not able to connect localhost with system ip

I have deployed my java web application using apache tomcact in my system through Eclipse. I can access the same page with
https://localhost:8080/Home.jsp
as well
https://mysystemip:8080/Home.jsp
But the same page is not able to connect
https://mysystemip:8080/Home.jsp over the network through other systems. Previously it was working and now not. What issue causing this ?
Your Tomcat server is only bound to your local network interface. You need to bind it to all interfaces for it to be available.
There is already a solution (Can't access Tomcat using IP address):
Add address="0.0.0.0" to Connector string

database postgresql on apache tomcat server

I don't find the solution for my specific problem, therefore, I ask for you help.
I developed a java application using Spring, JPA/Hibernate and Vaadin. The database is on PostgreSQL.
The application on my computer run on localhost:8080 and bind the database on localhost:5432;
In order for my colleagues to use it, I need now to deploy my application on a virtal server Tomcat. The address of this Tomcat is like 10.152.487.12:8080...
I want to create a war of my application in java and deploy it on Tomcat. But, where I can put the database and how ?
Apache Tomcat allow the creation of a Postgresql server on 8080 port ?
Apache Tomcat allow the installation of a Postgresql server on 5432 like 10.152.487.12:5432 ?
Please, I need help, thank you in advance !
I found the solution !
Yes, I am a newbie, but I think another peoples can be in the same situation, therefore...
You open the "Remote Desktop" on windows if the server where Tomcat turn on is Windows Server. Then, you enter the IP address of the server (without the port 8080 of course). Then, you arrive on the server, you can go on Internet for download PostgreSQL (warning, desactivate the security of the browser, it not allow you to surf !).
Finally, install, enjoy !

Java server on OpenShift

At the moment i have an android client app which connects to my java server through socket - serversocket. It sends and receive strings. The java server is connected to a mysql database (actually mariadb) using the jdbc driver.
I succeed to create a jbossas application and upload the code of the java server to openshift, but i didn't find any detailed tutorial on how do i connect to this new uploaded server from my socket client (This one (RMI or socket connection to Java Program on OpenShift) gives some tips but i'm still stucked).
More on this, how do i know that my server runs just fine on openshift and how do i control de calls to the database after i connect it (found this: $ rhc app create MyApp jbossas-7
$ rhc cartridge add mysql-5.5 -a MyApp), using org.mariadb.jdbc.Driver and java.sql is still working ?
Any small guide or tip is highly appreciated. I'm new to these things so please don't be too heavy on comments.
You can only make connections to your OpenShift server on http/https or ws/wss ports. If you want to connect to your java application and pull data from it from an android device, I would suggest using a RESTful api or a servlet, etc.
I had similar problem: My app server originally was running as a ServerSocket listener, and any clients/devices connect to it directly via Socket binding.
To deploy it into OpenShift, my previous initial solution was to change its host:port configuration by following the suggestion as described in this link [Socket connection to Java Program on OpenShift]. It worked nice as far as my app server was successfully up and running. But it did not work well with the port forwarding approach in order to accept remote requests.
So for the final solution, I modified the app server by wrapping my original code with a RESTful webservice around it, and deploy it as a web service.

App Java and hosting mysql

I have a Java application and I have to connect to a MySQL DB host in aruba.it. If I make a connection, aruba.it refuses that. How to solve this?
To start, I assume that you're trying to run this Java application locally, or at least at a different machine than where the MySQL DB runs and that you got a SQLException: Connection Refused.
To fix the particular problem, all routers and firewalls in the complete network pipe between the client (where the Java application runs) and the server (where the MySQL DB runs) needs to be configured to allow/forward the port number which the DB uses. This is by default 3306. If this port is blocked, you cannot reach the DB from outside.
Another solution is just to upload the Java application in flavor of a webapplication and run it by HTTP. You'd normally use JSP/Servlet for this.
Apart from network, routers, firewall issues the reason can be that by default remote access to MySQL database server is disabled for security reasons. Mostly DB is hosted on the same server or on the trusted server. If you run java application from your desktop, you need to configure MySQL so it will accept this connections. See this manual for details how to do it.

Categories