Glassfish, EC2, Swing Application not connecting to #remote interface - java

I have Glassfish with an EAR deployed that includes a swing application that I run through Java Web Start which connects to my EJB through the #remote interface.
We have a server set up with a static IP and all I need to do is set /etc/hostname to my hostname (x.x.com) and in my /etc/hosts I have:
127.0.0.1 localhost
x.x.x.x x.x.com
Pretty simple. The application runs fine.
However, we want to migrate to EC2. I have a server up with Glassfish and everything is great. I have an Elastic IP pointed to it and my domain name pointed to that. All good.
The program downloads and updates fine also through Java Web Start.
The problem comes when trying to connect from my swing app to the server. It connects through CORBA, which I don't know much about.
I can't set the /etc/hosts file because the Elastic IP isn't the IP Address. Amazon assigns local addresses to the servers. I can't set /etc/hosts to one of those because if they were restarted it would change. And I don't want to edit it every time.
Does anyone know how to bypass this or fix it so Glassfish doesn't need it? It is killing me.

You should still be able to add an entry to your hosts file for your eIP - have you tried that?
EC2 instances all have a public IP and a private 10.X.X.X address. The eIP replaces the public IP address and is fixed (until you disassociate it).
The alternative with AWS, which will allow you to have a fixed private IP too, is to deploy to a VPC. Amazon have some very good documentation on VPCs.
What you're getting, in a nutshell, is comparable to a local network, so you can just pick your CIDR block and create subnets, for example 10.0.1.0/24. Now, when you launch an EC2 instance, you can launch into that VPC subnet and choose the private IP. Along with your eIP, you now have both IP addresses (public and private) set permanently, unless you decide to change them yourself (for whatever reason).
You can even add secondary IP addresses if you want.

Related

How can I connect remotely to a WebSphere Server running on localhost?

So I wanted to try to let one person connect to my WebSphere Application Server remotely. I've already opened up a port on my router, but I don't really know what is the port that WebSphere uses. I couldn't really find much on the internet, and WebSphere is a hell of a complex thing to handle.
I've already tested it on https://www.portchecktool.com/ so the port is not blocked by any firewall.
By connecting remotely I mean that I have a java web application up and running and I want this other person that is not inside my house to be able to get into the application and use it.
I'm using RAD IDE just in case it might help out knowing it.
So where can I find the port that my server uses, in order to then configure to forward connections to that port?
I don't know RAD, but there are a couple ways to find out looking at WebSphere itself. If you are already in the admin console, you can to go to Servers in the left pane, click on your server's name, look for the ports link on the right column, and expand that. Look for the defaulthost_secure (or plain defaulthost if not using https.) If you don't, find where WebSphere is installed on your filesystem. There is a file WAS_INSTALL_ROOT/profiles/profileName/logs/AboutThisProfile.txt that lists some common ports including defaulthost and defaulthost_secure.

Share my local webapp project

I have started doing work with spring/hibernate to make webapps with java. I have made a basic app which is running on my localhost:8080 and I was wondering if there was an easy way to make it visible to someone else so they can see and use the webpage from their machine.
If They are on same network (ie a Home Network or Corporate Network) you just need to send them you ip and port (ie http://192.168.0.150:8080).
If you want to open your computer by the internet you need to setup you modem to open you 8080 port and need to discover you public IP ou contract a DDNS, like no-ip.
Maybe you can need to change some firewall configurations
If you don't want to configure firewall, port forward. you can try some dynamic dns service like www.no-ip.com, dyn, duck dns, freedns etc.
they will create a public url which will forward.
however at application level you may still need to configure the access permission like white list ip or address to listen
Can't access Tomcat using IP address

Spring : How to remove localhost from url

I am working on some project for that using spring 3.2.0. Whenever I run project it looks like
http://IpAddressWithPortNo.com/myprojectName.com/
IpAddressWithPortNo = localhost : 8080
I want to hide localhost:8080 or ip address.
Is there any method available to map this ip to my project?
http://myprojectName.com
I am using apache tomcat 7.0 and fedora 17.
The solution doesn't involve configuring Spring, but the hosts file of your operating system. On Ubuntu, it is found at /etc/hosts, I'm not sure if its the same for Fedora, but it should be.
You just need to add a line in the hosts file that looks like the following:
127.0.0.1 myprojectName.com
That's it. You then access the myprojectName.com address in your browser and it will look at your localhost, behind the scenes.
The above solution works if you only need name resolution for your local machine.
If you'd like to expand to your local or external network, the answer is less trivial:
for your local network, you need to register a custom domain on your network DNS server (see this and this for more information); if you have a network administrator, direct this requirement to him, explaining that you want to expose your local ip through a custom domain name
if you want to expose this name to the entire internet, you have to register the custom domain to a DNS registration service (you can find free DNS services as well, unfortunately I haven't used any lately and dyndns.org doesn't provide free dns service anymore, try searching free dns service on google and lookup some reviews)
The :8080 will go if you configure Tomcat to respond on port 80, or https on port 443.
You can use any host name that resolves to your network address. For instance if your machine name on the local network is athena.mycompany.com then http://athena.mycompany.com/myProjectName should work fine - but only within the local network.
To get to http://myprojectName.com you will need to configure a firewall/router to forward an incoming request (presumably from the Internet) to your machine. Internal access will likely not resolve this URL.
Gabriel has just posted an answer that should work from your machine, but other machines within your intranet would also require entries to map that name to your machine.
For doing exactly what you want, you need to configure apache tomcat to listen on port 80 and tell your operating system that myproject.com resolves to localhost.
To resolve myproject.com to localhost, add the following to your /etc/hosts file:
127.0.0.1 myproject.com
To change the port number to 80, open /usr/share/tomcat7/confserver.xml or /etc/tomcat7/server.xml (whichever applies to your system) and change Connector port = 8080 to Connector port = 80.

Amazon EC2 server TCP Socket Connection

I have developed a Java server using Eclipse that accepts TCP socket connection from android client, performs some computations, and returns the result to the android phone using this socket. I tried it on Wi-Fi.
I want now to move the Java server to the cloud - basically amazon EC2. Is this possible? I am just using a simple tcp socket connection. I have checked and couldn't find an example but came across "elastic beanstalk". Any help is appreciated, maybe a link or tutorial with such an example.
can i convert my java project to .war and use it or can i install eclipse on the cloud and run it as i do locally?
It is definitely possible. And you don't have to convert your project to a .war, unless you want to.
All you have to do is:
Pick the Amazon Image (AMI) you want to use - Amazon Linux is a good place to start, but there are plenty of other options, including Ubuntu and Windows.
Set up a security group - you need to set an incoming rule for your server's port number. It is pretty easy to do this from the Amazon web-based console.
Start a machine and assign it to the security group you created. Again, this is easily accomplished from the amazon web console.
Once the machine is up, log in (using ssh for Linux or Remote Desktop for windows) and install your server.
A few things to remember:
Since you are now running on a public server, sooner or later your server will be attacked. EVERYONE gets attacked. If all you are opening is your single application port, make sure it is secured.
An Amazon server has a private and public IP. Your client application will connect to the public IP.
Servers can fail, and new servers get new public IPs! You need to prepare for this. Either make the IP in the client configurable, or look into something like Amazon Elastic IPs or dynamic DNS.

Whats my hostname on my local MySQL server?

I just set up a MySQL server on my PC for testing Java with JDBC.
At the moment "localhost" works perfectly as hostname for my applications, when running them on the same system.
However what would be the hostname for my MySQL server for applications that are running on different computers? Something like "my_ip:port" would work? I was thinking of writing an applet, which I could upload on a web server and try to connect to my database here. Is it possible to achieve that?
Something like "my_ip:port" would work?
If the MySQL instance has bound to your public interface, and if your firewall allows it, yes. If you connect to the 'net via a router that does NAT (for instance, a combined DSL modem and wireless router allowing you to connect multiple computers), you'll have to set up forwarding rules in the router to tell it which of the local machines to forward requests to.
You don't have to use an IP address. Your machine will also probably have a host name of some kind (either one you've assigned or, if you connect through an ISP, more likely one they've assigned). That would work too.
I was thinking of writing an applet, which I could upload on a web server and try to connect to my database here. Is it possible to achieve that?
With a signed Java applet, yes; otherwise, no. That's because the security sandbox that Java applets run in doesn't let them access servers other than the one they were loaded from (the web server).
A much better approach is to have your client-side code (Java applet, or just DHTML+Ajax stuff) talk to server-side code on the web server, which in turn talks to your DB. That way, the DB is never directly exposed to the outside world, and you don't have to do things like signed applets.
You can always use the ip address of the server running mysql as the hostname or its fully qualified domain name.
That should work, but you also should consider port-forwarding through your firewall.
Go here to get your IP: http://www.whatsmyip.org/
The port is the port mysql is setup on.

Categories