4

How can I get server ip address in my JavaWS application, from which it was downloaded?

Thanks!

2
  • wouldn't it just be the client IP that you are running it on? I'm not sure what you mean by "which it was downloaded" Commented Mar 1, 2011 at 13:35
  • @JavaKungFu The server, not the client. (And you shouldn't be able to get the client IP address from the client unless privileged.) Commented Mar 1, 2011 at 13:36

2 Answers 2

2

I guess, use BasicService.getCodeBase.

Sign up to request clarification or add additional context in comments.

4 Comments

For a demo. & sample code of the BasicService, see my page at pscode.org/jws/api.html#bs
Thanks, but in my case it's don't work. ServiceManager.lookup("javax.jnlp.BasicService") throws exception. I use Spring and Spring rich client.
No ides what Spring is up to, but I did find this relevant page: spring-rich-c.sourceforge.net/1.1.0/apidocs/org/springframework/…
I try my app from IDEA, and run it as desktop application. That's why ServiceManager.lookup("javax.jnlp.BasicService") didn't worked. JnlpPropertyPlaceholderConfigurer help me. @Tom Hawtin thanks!
0

You'll need to get ahold of jnlp.jar and add it to your application. I had to find it in the JDK samples and demos, which are distributed separately from the JDK. I used this samples and demos question to find it. I was able to get ahold of it with a URL like http://download.oracle.com/otn-pub/java/jdk/8u11-b12-demos/jdk-8u11-windows-i586-demos.zip

With jnlp.jar on your classpath, use this code to get the URL of your application's codebase, which you can use to find the server hostname.

import javax.jnlp.*;

BasicService bs = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService");
URL codebase = bs.getCodeBase();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.