Package com.sun.enterprise.admin.util

Examples of com.sun.enterprise.admin.util.HostAndPort


    public static void setHostAndPort(DeploymentRequest req)
            throws ServerInstanceException, ConfigException {

        String virtualServers = (String) req.getOptionalAttributes().get(ServerTags.VIRTUAL_SERVERS);
        if (virtualServers==null) {
            HostAndPort hap = getHostAndPort(false);
            if(hap != null) {
                req.setHttpHostName(getHostName(hap));
                req.setHttpPort(getPort(hap, false));
            }
            hap = getHostAndPort(true);
            if(hap != null) {
                req.setHttpsHostName(getHostName(hap));
                req.setHttpsPort(getPort(hap, true));
            }
        } else {
            StringTokenizer st = new StringTokenizer(virtualServers,",");
            if (st.hasMoreTokens()) {
                String aVirtualServer = st.nextToken();
                HostAndPort hap = getVirtualServerHostAndPort(aVirtualServer, false);
                if(hap != null) {
                    req.setHttpHostName(getHostName(hap));

                    req.setHttpPort(getPort(hap, false));
                }
View Full Code Here


    private static HostAndPort findNonadminListener(ConfigContext configContext, HttpListener[] listeners, boolean securityEnabled) throws ConfigException {
        /*
         *Find a listener that is enabled, not the admin listener, with the
         *the requested security setting.
         */
        HostAndPort result = null;
        for (HttpListener listener : listeners) {
            if (listener.isEnabled()
                && ! listener.getDefaultVirtualServer().equals(
                    com.sun.enterprise.web.VirtualServer.ADMIN_VS)
                && listener.isSecurityEnabled() == securityEnabled) {

                String serverName = listener.getServerName();
                if (serverName == null || serverName.trim().equals("")) {
                    serverName = getDefaultHostName();
                }
               
                String portStr = listener.getPort();
                String redirectPortStr = listener.getRedirectPort();
                if (redirectPortStr != null && ! redirectPortStr.trim().equals("")) {
                    portStr = redirectPortStr;
                }
                /*
                 *Resolve any property expression to an integer.
                 */
                String resolvedPortStr =
                    new PropertyResolver(configContext,
                        getInstanceName()).resolve(portStr);
                int port = Integer.parseInt(resolvedPortStr);
               
                result = new HostAndPort(serverName, port, listener.isSecurityEnabled());
                break;
            }
        }
        return result;
    }
View Full Code Here

                            }
                            final String resolvedPort =
                                    new PropertyResolver(getConfigContext(),
                                        getInstanceName()).resolve(portStr);
                            port = Integer.parseInt(resolvedPort);
                            return new HostAndPort(serverName, port);
                        }
                    }
                }
            }
        } catch (Exception e) {
View Full Code Here

    /**
     * @param securityEnabled
     * @throws ServerInstanceException
     */
    public HostAndPort getHostAndPort(boolean securityEnabled) throws ServerInstanceException {
        HostAndPort hAndp = null;
        try {
            MBeanServer mbs = MBeanServerFactory.getMBeanServer();
            ObjectName objectName = new ObjectName(getDomainName()+":type=configs,category=config");
            String operationName1 = "getConfig";
            ObjectName[] configs = (ObjectName[])mbs.invoke(objectName,operationName1, emptyParams,emptySignature);
            String configName = (String)mbs.getAttribute(configs[0], "name");
            ObjectName httpService = new ObjectName(getDomainName()+":type=http-service,config="+configName+",category=config");
            String operationName2 = "getHttpListener";
            ObjectName[] httpListener = (ObjectName[])mbs.invoke(httpService, operationName2,emptyParams,emptySignature);

            String serverName = null;
            int port = 0;
            for (int i = 0; i < httpListener.length; i++) {
                AttributeList attrs = mbs.getAttributes(httpListener[i],
                        httpListenerAttrNames);
                Boolean bb = Boolean.valueOf((String)getNamedAttributeValue(
                        attrs, LISTENER_ENABLED));
                boolean enabled = ((bb == null) ? false : bb.booleanValue());
                if (!enabled) {
                    // Listener is not enabled
                    continue;
                }
                String vs = (String)getNamedAttributeValue(attrs, DEF_VS);
                if (ADMIN_VS.equals(vs)) {
                    // Listener is reserved for administration
                    continue;
                }
                bb = Boolean.valueOf((String)getNamedAttributeValue(
                        attrs, SEC_ENABLED));
                boolean sec_on = ((bb == null) ? false : bb.booleanValue());
                if (securityEnabled == sec_on) {
                    serverName = (String)getNamedAttributeValue(attrs,
                            SERVER_NAME);
                    if (serverName == null || serverName.trim().equals("")) {
                        serverName = getDefaultHostName();
                    }
                    String portStr = (String)getNamedAttributeValue(attrs,
                            PORT);
                    String redirPort = (String)getNamedAttributeValue(attrs,
                            REDIRECT_PORT);
                    if (redirPort != null && !redirPort.trim().equals("")) {
                        portStr = redirPort;
                    }
                    String resolvedPort =
                        new PropertyResolver(getConfigContext(),
                            getInstanceName()).resolve(portStr);
                    port = Integer.parseInt(resolvedPort);
                    break;
                }
            }
            hAndp = new HostAndPort(serverName, port);
        }
        catch (Exception e) {
            ServerInstanceException sie =
                new ServerInstanceException(e.getLocalizedMessage());
            sie.initCause(e);
View Full Code Here

     * @throws ServerInstanceException
     */
    public HostAndPort getHostAndPort(String standAloneModuleId, boolean securityEnabled)
  throws ServerInstanceException {

        HostAndPort hAndp = null;
  boolean setHP = false;

        try {

      // Application Ref element for the given module

      String appRefXPath = ServerXPathHelper.getServerIdXpath(getInstanceName())
         + ServerXPathHelper.XPATH_SEPARATOR
         + ServerTags.APPLICATION_REF + "[@"
         + ServerTags.REF + "='" + standAloneModuleId + "']";

      ApplicationRef appRef = (ApplicationRef) ConfigBeansFactory.getConfigBeanByXPath(
                             getConfigContext(), appRefXPath);

            // if no virtual server, pick up first
            if (appRef.getVirtualServers()!=null) {
                return getHostAndPort(securityEnabled);
            }
           
      // Get the list of virtual servers from the Application Ref

      String appRefvs = null;
            List vsList = StringUtils.parseStringList(appRef.getVirtualServers(), " ,");
            if (vsList==null) {
                return getHostAndPort(securityEnabled);
            }
      ListIterator vsListIter = vsList.listIterator();

      // Iterate for each of the virtual servers

      while(vsListIter.hasNext()) {
                String virtualServer = (String) vsListIter.next();
                HostAndPort hp = getVirtualServerHostAndPort(virtualServer, securityEnabled);
                if (hp!=null) {
                    return hp;
                }
            }
        } catch (Exception e) {
View Full Code Here

                            }
                            final String resolvedPort =
                                    new PropertyResolver(getConfigContext(),
                                        getInstanceName()).resolve(portStr);
                            port = Integer.parseInt(resolvedPort);
                            return new HostAndPort(serverName, port);
                        }
                    }
                }
            }
        } catch (Exception e) {
View Full Code Here

    private void setHostAndPort(DeploymentRequest req)
            throws ServerInstanceException {
               
        String virtualServers = (String) req.getOptionalAttributes().get(ServerTags.VIRTUAL_SERVERS);
        if (virtualServers==null) {
            HostAndPort hap = getHostAndPort(false);
            if(hap != null) {
                req.setHttpHostName(getHostName(hap));
                req.setHttpPort(getPort(hap, false));
            }
            hap = getHostAndPort(true);
            if(hap != null) {
                req.setHttpsHostName(getHostName(hap));
                req.setHttpsPort(getPort(hap, true));
            }
        } else {
            StringTokenizer st = new StringTokenizer(virtualServers,",");
            if (st.hasMoreTokens()) {
                String aVirtualServer = st.nextToken();
                HostAndPort hap = getVirtualServerHostAndPort(aVirtualServer, false);
                if(hap != null) {
                    req.setHttpHostName(getHostName(hap));
                    req.setHttpPort(getPort(hap, false));
                }
                hap = getVirtualServerHostAndPort(aVirtualServer, true);
View Full Code Here

    private void addToTargetModuleIDs(String[] moduleIDs, ModuleType type, SunTarget sunTarget, Collection resultingTMIDsthrows IOException {

        for (int j = 0;j < moduleIDs.length;j++) {
           
            // Get the host name and port where the application was deployed
            HostAndPort webHost = getHostPort(moduleIDs[j], sunTarget);

            /*
             *Prepare a new target module ID object, initialize it, and add it to the result list.
             */
            SunTargetModuleID tmid = new SunTargetModuleID(moduleIDs[j], sunTarget);
View Full Code Here

        /*
         *Iterate through the available virtual servers.  Stop when one has a legitimate
         *(non-null) host and port value.
         */
        HostAndPort answer = null;
        for (int i = 0; (i < vsList.length) && (answer == null); i++) {
            /*
             *FIXME - need to find the resolver for this virtual server and then pass it as the 2nd
             *argument next in order to use proxy-based template resolution.
             */
 
View Full Code Here

     *Return the HostAndPort for the specified virtual server name.
     *@param the virtual server name
     *@return HostAndPort for the virtual server
     */
    private HostAndPort getVirtualServerHostAndPortUsingMBeans(String vs) throws IOException, MalformedObjectNameException, InstanceNotFoundException, MBeanException, ReflectionException {
        HostAndPort result = null;
       
        MBeanServerConnection mbsc = getMBeanServerConnection();

        Object[] params = new Object[] {vs, Boolean.FALSE};
        String[] signature = new String[]{ "java.lang.String", "boolean"}; //NOI18N
View Full Code Here

TOP

Related Classes of com.sun.enterprise.admin.util.HostAndPort

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.