How to access REST API from a remote machine? - java

I am writting spring service(rest) for mobile app.I am writing test service with localhost and running on virtual machine(windows) but i can see http://localhost:8080/restonly on the same computer.What should i do to use my rest api from another machine?ip
aplication properties
spring.data.mongodb.host=localhost
spring.data.mongodb.port=
spring.data.mongodb.database=mongoTest

You are talking about two different things.
Your property file is about connection to your mongodb instance.
localhost is only a shortcut "saying" that the application can be found on your local machine.
having localhost in this property file means that the application server and the database server are on the same physical machine.
If you want to access your API from another machine, you can use the IP address of the server.
On Windows, you can know this address by typing ipconfig in a command line.
On Linux, it would be ifconfig.
Later, you can try to work with machine name instead of the IP address.

Related

Dockerized tomcat webapp throwing 404 exception when connecting to another localhost URL

I've got an application running in tomcat 8.5 in a docker container. Java version is jdk 8. There is a properties file that the app uses that points to another running service. In this case, I have the service running on my host machine and the property is set to point to my localhost:
my.external.service.url=http://localhost:8080/my-api-service
When my tomcat app is also running on the host machine, this works fine. But when my app runs in the docker container, I get a 404 error when it tries to call this service.
I tried switching the URL to point to my machine name:
my.external.service.url=http://my.pc.url.com:8080/my-api-service
But in this case, even though it still works if the tomcat app is running on the host instead of the docker container, I get a different error:
java.net.UnknownHostException: my.pc.url.com: No address associated with hostname
How do I configure the container so that I can get this to work?
Looking at the specific error you got - No address associated with the hostname - that means it cannot resolve the hostname to an IP. So you can find you local host IP and then pass an argument to the docker run command to add that host to the container lookup. Eg: -add-host="my.pc.url.com:X.X.X.X"
Docker networking is a potentially complex thing. Basically, if you run two separate containers they will not 'see' each other. You could have them both expose ports on the host machine and have then 'connect' that way, but you are better using the networking features of docker to ensure the containers talk to each other.
For a simple example like you have - say just two containers running tomcats that you would like to talk to each other - you might be best to just run them both via docker-compose so that they are in the same network.
There are many resources on the internet to explain the further details of docker networking if you wish to explore.

Can a Java program access a specific port on a Guacamole connection?

Can I use the Apache Guacamole API to allow a Java program to access a specific port on a Guacamole server's connection? When I say connection, I mean a machine that the Guacamole server is connected to - a machine that would show up in the Guacamole web interface.
Background:
I set up an Ubuntu virtual machine as a local Guacamole server/client. The virtual machine also runs a series of centOS (LXD) containers, each with a respective IP address. Outside of the virtual machine, on the host machine on the same network, I am able to access the Guacamole web interface via a web browser and SSH into the centOS containers just fine.
Let's say I have a Java program on my host machine that needs to communicate with one of those centOS containers. Is it possible to use the Guacamole API to allow the Java program on the host machine to programmatically access a specific port on one of the Guacamole connections/centOS containers?
If so, how would I go about doing that? I'd appreciate any specific examples or documentation related to this. If there's a better way to go about this, please let me know.
Thanks.

Can I use Rundeck from its .jar file without DNS configuration?

I am trying to use Rundeck from the .jar file. I use a Java command to start it up on my Linux (CentOS) server. From a work station, I open a web browser and go to the IP address of the Linux server over port 4440. After I log into the web UI, the URL changes from an IP address to the host name of the Linux server. The web browser displays "ERR_NAME_NOT_RESOLVED."
My authentication is successful. But I do not have a record on my DNS server for the host name. I will not be able to get the systems administrator to update the DNS server either. I do not have administrator permissions on the workstation with the web browser that I use to connect to the Rundeck server. I therefore cannot update the local hosts file.
Is it possible to use the .jar file for Rundeck without resolution of the host name of the Linux server from the workstations that try to use the web UI of Rundeck? If so, how? I try to re-type in the IP address. But I am unable to get the web UI to work. The IP address keeps changing to the hostname. The hostname never resolves to an IP address.
Modify the rundeck-config.properties file:
grails.serverURL=http://<ip-address>:4440

How to connect to MySQL database from a different computer? [duplicate]

This question already has answers here:
How to access MySQL from a remote computer (not localhost)?
(3 answers)
Closed 7 years ago.
So I haven successfully set up a database in MySQL and can connect to it from the same laptop I set it up on with a small java program. This is fine as it is running on the local host. However, I would like to see if I could now connect to the same database from a different Laptop. The Laptops would be running on the same network.
I can only find information online about connecting with Local host and am starting to feel out of my depth.
What should I do?
Check MYSQL tutorial
Get your IP address: first You need to know what the IP address you are connecting from.
Granting Access: Granting access to a user from a remote host is fairly simple and can be accomplished from just a few steps. First you will need to login to your MySQL server as the root user.
For Linux (check this site for windows) you can do this by typing the following command:
# mysql -u root -p
mysql> GRANT ALL ON fooDatabase.* TO fooUser#'1.2.3.4' IDENTIFIED BY 'my_password';
Now you can test your connection remotely. You can access your MySQL server from another server by placing the IP instead of localhost.
Check all non-java related system properties, like firewall etc.
Test with a general MySQL client.
Replace localhost or whatever you have in the connection string with the host name or ip-address of the remote machine.
Google for jdbc connection string to find more examples.
EDIT: If you could show your current code, we may be able to help you further.
Another option without exposing your database to network and defining remote users, is to set up an ssh tunnel. You redirect one port on remote machine to mysql's local port and connect to your database like you were connecting on localhost.
Putty is a popular ssh client. For an ssh server, there are different setups based on your operating system where mysql resides.

Can't open web application made with Java EE on other local computers

I am trying to look the web application I made with Java EE. The server and database is up and running. It works on localhost:8080, but when I replace localhost with the local IP address all I get is a 404 error. Do I need to configure something?
On windows 7 open the firewall to allow incoming and outgoing traffic on port 8080. Then from the remote machine make sure that you can ping the server's ip address and then try to browse to the address.

Categories

Resources