FileDocCategorySizeDatePackage
WsTxUtils.javaAPI DocGlassfish v2 API5487Fri May 04 22:36:12 BST 2007com.sun.enterprise.webservice

WsTxUtils

public class WsTxUtils extends Object
This class contains utility code used by the WS-TX system apps (such as calculating the addresses of their ws endpoints).
author
Ryan.Shoemaker@Sun.COM
version
$Revision: 1.3 $
since
1.0

Fields Summary
private static Logger
logger
Constructors Summary
Methods Summary
public static java.lang.StringgetDefaultVirtualServerHostAndPort(boolean secure)
Get the hostname and port of the secure or non-secure http listener for the default virtual server in this server instance. The string representation will be of the form 'hostname:port'.

param
secure true if you want the secure port, false if you want the non-secure port
return
the 'hostname:port' combination or null if there were any errors calculating the address

    
                                                                      
         
        final String host = getHostName();
        final String port = getPort(secure);
        if ((host == null) || (port == null)) {
            return null;
        }
        return host + ":" + port;
    
private static java.lang.StringgetHostName()
Lookup the canonical host name of the system this server instance is running on.

return
the canonical host name or null if there was an error retrieving it

        // this value is calculated from InetAddress.getCanonicalHostName when the AS is
        // installed.  asadmin then passes this value as a system property when the server
        // is started.
        return System.getProperty(SystemPropertyConstants.HOST_NAME_PROPERTY);
    
private static java.lang.StringgetPort(boolean secure)
Get the http/https port number for the default virtual server of this server instance.

If the 'secure' parameter is true, then return the secure http listener port, otherwise return the non-secure http listener port.

param
secure true if you want the secure port, false if you want the non-secure port
return
the port or null if there was an error retrieving it.

        try {
            ConfigContext configContext = ApplicationServer.getServerContext().getConfigContext();
            final String serverName = System.getProperty(SystemPropertyConstants.SERVER_NAME);
            Config config = ServerHelper.getConfigForServer(configContext, serverName);
            final HttpListener[] listeners = config.getHttpService().getHttpListener();
            for (HttpListener listener : listeners) {
                if ((secure) && (listener.isSecurityEnabled())) {
                    return listener.getPort();
                } else if ((!secure) && (!listener.isSecurityEnabled())) {
                    return listener.getPort();
                }
            }
        } catch (Throwable t) {
            // error condition handled in wsit code
            logger.log(Level.FINEST, "Exception occurred retrieving port " +
                "configuration for WSTX service", t);
        }
        return null;