Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI & java.rmi.server.hostname

 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I tested my application over the real network and it didn't work - for some reason the remote stub that I used wanted to connect to localhost. After giving this a thought (it rang a bell, I had seen that before) I remembered and I restarted the server with java.rmi.server.hostame with the ip of the server, and then the client worked just fine.
My assignment says that I cannot require the tester setting any properties. Does this mean that they will test it locally (works fine) and for remote tests, they will set the property themselves?
My tests used a stub downloaded from the server, not the pre-generated stub, that's why the setting is important. Unfortunately, I didn't have the time to test with the pre-generated stub, maybe it will work differently (I am still thinking whether to include the stub or let it be downloaded dynamically, but if I test and pre-generated stub doesn't require this property, it will be an easy desicion).

I know at least some of you, Roberto Perillo in particular, did _not_ include the pre-generated stubs. How did you handle the case described by my, and the property? Or did you set the property in code - but then you need the external ip somehow?

Raf
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raf,

No extra properties may be used to start a client or server application. So java -jar runme.jar [alone|server] should dot the job. And it does, because I was able to run my server and client in my home network and connect. Could you post the code snippet you use for creating the rmi registry and also the snippet you use to obtain the stub from the server?

Regarding the generating: it is not necessary to generate them since JDK 5.0 but it is a must requirement. Roberto passed without generating them and he explained this decision in choices.txt + on the essay exam, so normally the assessor should have been aware he violated the must requirement, but didn't fail him. So I guess it would be ok not to generate them and still pass (although I didn't want to take that risk, so I generated them --> 1 additional line in my build script). Also some others passed without generating them.

Kind regards,
Roel
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Server:


Client:

And the dbRemote stub at the client has its ip set to 127.0.1.1. Here is a snippet from my /etc/hosts:

127.0.0.1 localhost
127.0.1.1 studio

(studio is the name of my laptop)
So if I change studio to point to 192.168.1.17 (my private netwoek ip) it will also work in a private network, gracefully failing in the real world nonetheless. Maybe that is the difference? Have you tried it outside your home network? If you are using windows, I don't know what the hosts file looks like there, maybe it has the network ip (192.... or similar?). The one that I have comes by default, I didn't change it.
When I issue InetAddress.getLocalHost() I get: studio/127.0.1.1. Maybe you get something different.

Of course, take a look at my code first, maybe I am missing something there.

Raf
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raf,

First of all: your code is just fine I have similar code, so that's not the problem.

Secondly I only have windows machines, and I had no problems in my home network. I even believe I tried it on the network of the company I was working, but it didn't work (due to security restrictions: to access a running tomcat application server on the pc of a colleague you need permissions you don't have ). But I can remember people using Linux having some difficulties, due to their host file I believe. But I'm a complete Linux newbie, so I can't do more than point you in the direction of some threads about this issue, like this one or this one. And you certainly can use the search engine.

Hope it helps!
Kind regards,
Roel
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, it is all very sensitive to the settings of the OS you are running it on and its networking.
And you never tested your app outside of local network (company is still an intranet, just bigger) - I would venture to say that it would fail for you as well. I will test on Monday how it behaves with the pregenerated stub, but I guess there will be no difference the same.
Thanks.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's true: I didn't test my app outside a local network.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:Roberto passed without generating them and he explained this decision in choices.txt + on the essay exam, so normally the assessor should have been aware he violated the must requirement, but didn't fail him.


This always makes me feel bad
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto Perillo wrote:This always makes me feel bad

I think it's time Sun/Oracle changes their instructions and skip this must requirement, so I never have to mention it again
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto how about your tests in the wild and the problem I described?
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, champion!

Well, the tests are related to the locking mechanism... or, which tests do you mean? I guess I didn't get your question
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean tests of the server - client in the internet, without setting the java.rmi.server.hostname property.
As mentioned, it works locally by accident - the stubs are 'stamped' with the server ip which is the local host anyways. When testing in local network, I can make it work by configuring my network settings a bit, but in the internet it doesn't work - I have to set java.rmi.server.hostname to the ip of my router (which also performs NAT to the computer that runs the server, but this is irrelevant here) to make it work - only this way the (dynamic) stub downloaded from the server has the correct ip to connect to.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh! You mean, how I tested my server? Well champ, my code also looks pretty much like yours. I remember when I was developing the assignment I was working for Avaya, so one day I tested the application on their network. And gladly everything worked well. The thing is, you don't have to worry if it doesn't work on the internet, because it doesn't have to. You just have to make sure that it works on a local network. No properties should be necessary.
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I tested again, this time with remote stubs pre-generated and read from the jar file, and the bahaviour is the same - it doesn't work without the java.rmi.server.hostname property. But I will keep the pregenerated one in the result jar as it is safer for the assignment.

Roberto Perillo wrote:The thing is, you don't have to worry if it doesn't work on the internet, because it doesn't have to. You just have to make sure that it works on a local network.

Well, my assignment is not that lenient and doesn't mention a thing about it, so I guess if I am making a network server, it has to work in the Internet, too.

Roberto Perillo wrote:No properties should be necessary.

And they are not - you can start the server and the client and they will work, it's just the networking will not But I think I will just leave it as it is and be of good faith that the assessor will know how to start it so that it works over the Internet.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Raf!

Well, my assignment is not that lenient and doesn't mention a thing about it, so I guess if I am making a network server, it has to work in the Internet, too.


So it doesn't mention that it has to work on the internet, right? So, there you go. One of the things I mentioned in my choices.txt file was that, since nothing was mentioned about the server having to work on the internet, my server only worked in a local network.

Is your server working without command line properties in a local network? If so, then that's it, champion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic