@@ -108,10 +108,8 @@ private static void trustAllHttpsCertificates() throws Exception {
108108
109109 private ManagedObjectReference SVC_INST_REF = new ManagedObjectReference ();
110110 private ManagedObjectReference propCollectorRef ;
111- private ManagedObjectReference rootRef ;
112111 private static VimService vimService ;
113112 private VimPortType vimPort ;
114- private ServiceContent serviceContent ;
115113 private String serviceCookie ;
116114 private final String SVC_INST_NAME = "ServiceInstance" ;
117115
@@ -139,7 +137,7 @@ public void connect(String url, String userName, String password) throws Excepti
139137 ctxt .put ("com.sun.xml.internal.ws.request.timeout" , 600000 );
140138 ctxt .put ("com.sun.xml.internal.ws.connect.timeout" , 600000 );
141139
142- serviceContent = vimPort .retrieveServiceContent (SVC_INST_REF );
140+ ServiceContent serviceContent = vimPort .retrieveServiceContent (SVC_INST_REF );
143141
144142 // Extract a cookie. See vmware sample program com.vmware.httpfileaccess.GetVMFiles
145143 Map <String , List <String >> headers = (Map <String , List <String >>) ((BindingProvider ) vimPort )
@@ -155,7 +153,6 @@ public void connect(String url, String userName, String password) throws Excepti
155153 isConnected = true ;
156154
157155 propCollectorRef = serviceContent .getPropertyCollector ();
158- rootRef = serviceContent .getRootFolder ();
159156 }
160157
161158 /**
@@ -165,7 +162,7 @@ public void connect(String url, String userName, String password) throws Excepti
165162 */
166163 public void disconnect () throws Exception {
167164 if (isConnected ) {
168- vimPort .logout (serviceContent .getSessionManager ());
165+ vimPort .logout (getServiceContent () .getSessionManager ());
169166 }
170167 isConnected = false ;
171168 }
@@ -181,7 +178,12 @@ public VimPortType getService() {
181178 * @return Service instance content
182179 */
183180 public ServiceContent getServiceContent () {
184- return serviceContent ;
181+
182+ try {
183+ return vimPort .retrieveServiceContent (SVC_INST_REF );
184+ } catch (RuntimeFaultFaultMsg e ) {
185+ }
186+ return null ;
185187 }
186188
187189 /**
@@ -202,7 +204,7 @@ public ManagedObjectReference getPropCol() {
202204 * @return Root folder
203205 */
204206 public ManagedObjectReference getRootFolder () {
205- return rootRef ;
207+ return getServiceContent (). getRootFolder () ;
206208 }
207209
208210 /**
0 commit comments