Get Host Alias through an API? - Websphere

This is a discussion on Get Host Alias through an API? - Websphere ; Is there a way to get the Host Alias through an API? We are using queryConfigObjects to get the Virtual Host like this. ObjectName oQueryPattern=ConfigServiceHelper.createObjectName (null, "VirtualHost", name); try{ ObjectName[] results = getConfig().queryConfigObjects(getSession(), getScope(), oQueryPattern, null); I tried "HostAlias" but ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Get Host Alias through an API?

  1. Get Host Alias through an API?

    Is there a way to get the Host Alias through an API?
    We are using queryConfigObjects to get the Virtual Host like this.
    ObjectName oQueryPattern=ConfigServiceHelper.createObjectName (null, "VirtualHost", name);
    try{
    ObjectName[] results = getConfig().queryConfigObjects(getSession(), getScope(), oQueryPattern, null);

    I tried "HostAlias" but nothing came back

  2. Re: Get Host Alias through an API?

    Hi John,

    "HostAlias" is the correct configuration type for host aliases (at least
    in WAS 6.1) so you should be able to locate then by querying for objects
    of that type. Associated host aliases hang off of the VirtualHost
    objects so you can also get there from there. Using the ConfigService
    to get the "aliases" attribute on a VirtualHost should give you a List
    of AttributeList objects, each representing a HostAlias.

    Hope that helps,

    Mark.

    john.peters@bcbsfl.com wrote:
    > Is there a way to get the Host Alias through an API?
    > We are using queryConfigObjects to get the Virtual Host like this.
    > ObjectName oQueryPattern=ConfigServiceHelper.createObjectName (null, "VirtualHost", name);
    > try{
    > ObjectName[] results = getConfig().queryConfigObjects(getSession(), getScope(), oQueryPattern, null);
    >
    > I tried "HostAlias" but nothing came back


  3. Re: Get Host Alias through an API?

    Do you mean like this?
    ObjectName oQueryPattern=ConfigServiceHelper.createObjectName (null, "VirtualHost", name);
    ObjectName[] results = getConfig().queryConfigObjects(getSession(), getScope(), oQueryPattern, null);

    String vHost = results[0].toString();

    oQueryPattern=ConfigServiceHelper.createObjectName (null, "aliases", vHost);
    ObjectName[] results = getConfig().queryConfigObjects(getSession(), getScope(), oQueryPattern, null);




  4. Re: Get Host Alias through an API?

    Hi John,

    You want something more like this (not tested!):

    ObjectName vHost = results[0];
    List hostAliases = (List)configService.getAttribute(session, vHost,
    "aliases");
    for (Iterator iter = hostAliases.iterator(); iter.hasNext(); )
    {
    AttributeList aliasAttribs = (AttributeList)iter.next();
    String hostname =
    (String)ConfigServiceHelper.getAttributeValue(alia sAttribs, "hostname");
    String port =
    (String)ConfigServiceHelper.getAttributeValue(alia sAttribs, "port");
    // Do something with the information here...
    }

    Be aware that there may be many (or even zero) virtual hosts in the
    'results' array so just using the first element may not be the best
    approach.

    You can use wsadmin to help find out the attribute names and types etc.
    For example:

    wsadmin>$AdminConfig attributes VirtualHost
    "aliases HostAlias*"
    "mimeTypes MimeEntry*"
    "name String"
    wsadmin>$AdminConfig attributes HostAlias
    "hostname String"
    "port String"

    So we can see that there is an attribute called 'aliases' on a
    VirtualHost object that contains a collection (the '*' indicates
    collection) of objects of type HostAlias. HostAlias objects have two
    attributes, 'hostname' and 'port', both of type String.

    Hope that helps,

    Mark.

    john.peters@bcbsfl.com wrote:
    > Do you mean like this?
    > ObjectName oQueryPattern=ConfigServiceHelper.createObjectName (null, "VirtualHost", name);
    > ObjectName[] results = getConfig().queryConfigObjects(getSession(), getScope(), oQueryPattern, null);
    >
    > String vHost = results[0].toString();
    >
    > oQueryPattern=ConfigServiceHelper.createObjectName (null, "aliases", vHost);
    > ObjectName[] results = getConfig().queryConfigObjects(getSession(), getScope(), oQueryPattern, null);


  5. Re: Get Host Alias through an API?

    Thank you Mark for your time and detailed reply.


+ Reply to Thread