Menu

#21 allow user to provide WSClient

open
nobody
API (21)
5
2012-12-15
2011-01-13
Anonymous
No

I'd like to use my own implementation of WSClient. I can do this with reflection, but it would be nice not to.

Are you ok with something like below?

1. remove final modifier from WSClientl
2. Change WSClient to an interface (optional)
3. open a constructor on ServiceInstance where we can specify a WSClient object

Discussion

  • Anonymous

    Anonymous - 2011-01-16

    This is the constructor we need

    public ServiceInstance\(WSClient wsc, String username, String password\)
        throws RemoteException, MalformedURLException 
    \{
        if\(username==null\)
        \{
            throw new NullPointerException\("username cannot be null."\);
        \}
    
        setMOR\(SERVICE\_INSTANCE\_MOR\);
    
        VimPortType vimService = new VimPortType\(wsc\);
    
        serviceContent = vimService.retrieveServiceContent\(SERVICE\_INSTANCE\_MOR\);
        vimService.getWsc\(\).setSoapActionOnApiVersion\(serviceContent.getAbout\(\).getApiVersion\(\)\);
        setServerConnection\(new ServerConnection\(wsc.getBaseUrl\(\), vimService, this\)\);
    
        // escape 5 special chars 
        // http://en.wikipedia.org/wiki/List\_of\_XML\_and\_HTML\_character\_entity\_references
        password = password.replace\("&", "&"\)
                           .replace\("<", "<"\)
                           .replace\(">", ">"\)
                           .replace\("\"", """\)
                           .replace\("'", "'"\);
    
        UserSession userSession = getSessionManager\(\).login\(username, password, null\);
        getServerConnection\(\).setUserSession\(userSession\);
    \}
    
     
  • Anonymous

    Anonymous - 2011-01-16

    Note: currently, constructing the ServiceInstance object also implies making a connection. This makes it more difficult to wire up dependencies and unit test them. Can you please make some sort of postConstruct method for adding state like this, or make state an argument, decoration, etc?