How to Set Up Proxy With VI Java API?

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:

Lost VMs or Containers? Too Many Consoles? Too Slow GUI? 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.

This entry was posted in vSphere API and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  • NEED HELP?


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__ doublecloud.org.

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.