Home > vSphere API > How to Set Up Proxy With VI Java API?

How to Set Up Proxy With VI Java API?

February 27th, 2011 Leave a comment Go to comments

It’s common for companies to proxy HTTP traffics to external Web site, but not so for internal sites. Therefore, you rarely need to set up proxy for using vSphere API calls with an internal vCenter server. The uncommon cases do come up sometimes. This post explains how to set it up for vSphere API. Note that this is not really for VI Java API only but applicable for all Java applications.

There are two options and you can pick either of them per your use case:

Time to learn how to "Google" and manage your VMware and clouds in a fast and secure

HTML5 App

1. Use JVM command line to pass in the proxy parameters, as shown below:

$java -Dhttp.proxyHost=proxyhostIP -Dhttp.proxyPort=proxyPortNumber -Dhttp.proxyUser=myUserName -Dhttp.proxyPassword=myPassword HelloVM

You don’t need to change a single line of your application here. If you are using IDEs like Eclipse, you can set it up in the Run – Open Run Dialog…. In the dialog, choose the arguments tab and copy the following to the VM arguments editor (not the Program arguments!)

-Dhttp.proxyHost=proxyhostIP -Dhttp.proxyPort=proxyPortNumber -Dhttp.proxyUser=myUserName -Dhttp.proxyPassword=myPassword

2. Set it up in your code like the following. It does not include user name and password as the above, but you can add your own.

System.<em>setProperty</em>("https.proxyHost", "127.0.0.1");
System.<em>setProperty</em>("https.proxyPort", "3128");

Now here are something you should pay attention for vSpehre API. By default, you use HTTPS instead of HTTP. So make sure you use the set of parameters with https.

Categories: vSphere API Tags: ,
  1. No comments yet.
  1. No trackbacks yet.