zoukankan      html  css  js  c++  java
  • 获取 web 服务器 port

    Tomcat:

    public static String getServerPort(boolean secure) throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException {  
            MBeanServer mBeanServer = null;  
            if (MBeanServerFactory.findMBeanServer(null).size() > 0) {  
                mBeanServer = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);  
            }  
              
            if (mBeanServer == null) {  
                System.out.println("调用findMBeanServer查询到的结果为null");  
                return "";  
            }  
              
            Set<ObjectName> names = null;  
            try {  
                names = mBeanServer.queryNames(new ObjectName("Catalina:type=Connector,*"), null);  
            } catch (Exception e) {  
                return "";  
            }  
            Iterator<ObjectName> it = names.iterator();  
            ObjectName oname = null;  
            while (it.hasNext()) {  
                oname = (ObjectName)it.next();  
                String protocol = (String)mBeanServer.getAttribute(oname, "protocol");  
                String scheme = (String)mBeanServer.getAttribute(oname, "scheme");  
                Boolean secureValue = (Boolean)mBeanServer.getAttribute(oname, "secure");  
                Boolean SSLEnabled = (Boolean)mBeanServer.getAttribute(oname, "SSLEnabled");  
                if (SSLEnabled != null && SSLEnabled) {// tomcat6开始用SSLEnabled  
                    secureValue = true;// SSLEnabled=true但secure未配置的情况  
                    scheme = "https";  
                }  
                if (protocol != null && ("HTTP/1.1".equals(protocol) || protocol.contains("http"))) {  
                    if (secure && "https".equals(scheme) && secureValue) {  
                        return ((Integer)mBeanServer.getAttribute(oname, "port")).toString();  
                    } else if (!secure && !"https".equals(scheme) && !secureValue) {  
                        return ((Integer)mBeanServer.getAttribute(oname, "port")).toString();  
                    }  
                }  
            }  
            return "";  
        }  

    Weblogic参考:

    http://blog.csdn.net/yunzhu666/article/details/8662039
  • 相关阅读:
    CTFHub_技能树_文件上传
    QT入门-重载的信号槽
    QT入门-自定义信号
    C++: xx does not name a type报错
    HDU1166 敌兵布阵
    洛谷P2574 XOR的艺术(线段树)
    P3373 【模板】线段树 2(板子好题)
    SP1716 GSS3
    QT入门-自定义槽函数
    Educational Codeforces Round 87 (Rated for Div. 2) D. Multiset(树状数组/好题)
  • 原文地址:https://www.cnblogs.com/xiluhua/p/6719788.html
Copyright © 2011-2022 走看看