Quantcast
Channel: VMware Communities : Discussion List - vSphere Client SDK
Viewing all articles
Browse latest Browse all 2218

Web Services error with Web Client App

$
0
0


Howdy.  I'm trying to use web services ServiceContent and PropertyCollector in my vSphere Web Client application.  I've borrowed sample code from SimpleClient and PropertyCollector examples for my app.


I pass in hard coded parameters for server URL, username and password to get the ServiceContent object.  However, when I call retrieveServiceContent() (see below), I get 'Invalid Cookie' error, although vimPort does return a non null serviceContent.


                serviceContent = vimPort.retrieveServiceContent(SVC_INST_REF);


Later on, I try to use this serviceContent object along with PropertyCollector to try to retrieve a Host reference by hostname, yet the call to _vimPort.retrievePropertiesEx() fails with 'Connection Refused' error, possibly due to the invalid cookie.


Any ideas?


-Eric


more code details below:


private ServiceContent getServiceContent()

{

    /*

    

  • borrowed from SimpleClient example

     */

    

    // Server URL and credentials.

    String serverName = "10.128.111.222"; // args[0];

    String userName = "myuser"; // args[1];

    String password = "mypassword"; // args[2];

    String url = "https://" + serverName + "/sdk/vimService";  

    

    try

    {

        ManagedObjectReference SVC_INST_REF = new ManagedObjectReference();

        VimService vimService = null;

        VimPortType vimPort = null;

        ServiceContent serviceContent;

    

        HostnameVerifier hv = new HostnameVerifier() {

            public boolean verify(String urlHostName, SSLSession session) {

                return true;

            }

        };

        trustAll();

        HttpsURLConnection.setDefaultHostnameVerifier(hv);

 


        SVC_INST_REF.setType("ServiceInstance");
        SVC_INST_REF.setValue("ServiceInstance");
                
        vimService = new VimService();
        vimPort = vimService.getVimPort();
        Map<String, Object> ctxt = ((BindingProvider) vimPort).getRequestContext();
        
        ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
        ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);


/// ERROR here Invalid Cookie
        serviceContent = vimPort.retrieveServiceContent(SVC_INST_REF);
        
        vimPort.login(serviceContent.getSessionManager(), userName, password, null);
        
        return serviceContent;
    }
    catch(Exception ex)
    {
        ex.printStackTrace();
        return null;
    }
}


    public static List<ObjectContent> retrievePropertiesAllObjects(
            List<PropertyFilterSpec> listpfs, ServiceContent service)
            throws RuntimeFaultFaultMsg, InvalidPropertyFaultMsg {


       
        RetrieveOptions propObjectRetrieveOpts = new RetrieveOptions();


        List<ObjectContent> listobjcontent = new ArrayList<ObjectContent>();


        ManagedObjectReference propCollectorRef = service.getPropertyCollector();


        RetrieveResult rslts = _vimPort.retrievePropertiesEx(propCollectorRef,
                listpfs, propObjectRetrieveOpts);
        if (rslts != null && rslts.getObjects() != null
                && !rslts.getObjects().isEmpty()) {
            listobjcontent.addAll(rslts.getObjects());
        }
        String token = null;
        if (rslts != null && rslts.getToken() != null) {
            token = rslts.getToken();
        }
        while (token != null && !token.isEmpty()) {
/// ERROR here connection refused
            rslts = _vimPort.continueRetrievePropertiesEx(propCollectorRef,
                    token);
            token = null;
            if (rslts != null) {
                token = rslts.getToken();
                if (rslts.getObjects() != null && !rslts.getObjects().isEmpty()) {
                    listobjcontent.addAll(rslts.getObjects());
                }
            }
        }


        _logger.info("ManagedObjectService::retrievePropertiesAllObjects, return listobjcontent " );
        return listobjcontent;
    }


 


Viewing all articles
Browse latest Browse all 2218

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>