{"record":{"id":"c612964d3129c64d","repo":"apache/shenyu","slug":"failed-to-get-the-http-port-of-the-current-tomcat","errorCode":null,"errorMessage":"failed to get the HTTP port of the current tomcat","messagePattern":"failed to get the HTTP port of the current tomcat","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/utils/PortUtils.java","lineNumber":108,"sourceCode":"     */\n    public static Integer getPort() throws Exception {\n        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();\n        Set<ObjectName> objectNames = mBeanServer.queryNames(new ObjectName(\"*:type=Connector,*\"), null);\n        if (CollectionUtils.isEmpty(objectNames)) {\n            throw new IllegalStateException(\"Cannot get the names of MBeans controlled by the MBean server.\");\n        }\n        //This method is not supported when there are multiple instances of external Tomcat\n        if (objectNames.size() > 1) {\n            throw new IllegalStateException(\"Not supported when there are multiple instances of external Tomcat.\");\n        }\n        ObjectName objectName = objectNames.iterator().next();\n        String protocol = String.valueOf(mBeanServer.getAttribute(objectName, \"protocol\"));\n        String port = String.valueOf(mBeanServer.getAttribute(objectName, \"port\"));\n        // The property name is HTTP1.1, org.apache.coyote.http11.Http11NioProtocol under linux\n        if (\"HTTP/1.1\".equals(protocol) || \"org.apache.coyote.http11.Http11NioProtocol\".equals(protocol)) {\n            return Integer.parseInt(port);\n        }\n        throw new IllegalStateException(\"failed to get the HTTP port of the current tomcat\");\n    }\n\n}\n","sourceCodeStart":90,"sourceCodeEnd":112,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/utils/PortUtils.java#L90-L112","documentation":"PortUtils.getPort() found exactly one Tomcat Connector MBean, but its 'protocol' attribute was neither 'HTTP/1.1' nor 'org.apache.coyote.http11.Http11NioProtocol'. That means the sole connector is not an HTTP connector (e.g. AJP), so there is no HTTP port to report and the method throws.","triggerScenarios":"Calling PortUtils.getPort() when the only Connector MBean is an AJP connector or a non-standard protocol connector, so the protocol attribute check fails and the fall-through throw executes.","commonSituations":"Tomcat configured with only an AJP connector (mod_jk/proxy_ajp setups); custom protocol connector classes; older/newer Tomcat versions reporting an unexpected protocol string.","solutions":["Ensure a standard HTTP/1.1 (NIO) connector is configured in server.xml or embedded setup","Explicitly set the port in the ShenYu client config (shenyu.client.<type>.props.port) to bypass JMX discovery","Check the Connector protocol attribute in server.xml; change AJP-only setups to include an HTTP connector","Catch IllegalStateException and use a configured default port"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"Set<ObjectName> names = ManagementFactory.getPlatformMBeanServer()\n        .queryNames(new ObjectName(\"*:type=Connector,*\"), null);\nboolean hasHttp = names.stream().anyMatch(n -> {\n    try { String p = String.valueOf(ManagementFactory.getPlatformMBeanServer().getAttribute(n, \"protocol\"));\n          return p.equals(\"HTTP/1.1\") || p.equals(\"org.apache.coyote.http11.Http11NioProtocol\"); }\n    catch (Exception e) { return false; }\n});\nif (!hasHttp) { /* configure explicit port */ }","typeGuard":null,"tryCatchPattern":"try { port = PortUtils.getPort(); }\ncatch (IllegalStateException e) { port = configuredPort; }","preventionTips":["Configure a standard HTTP/1.1 NIO connector","Set the port explicitly in shenyu client props","Don't run AJP-only Tomcat setups with the gateway client"],"tags":["tomcat","jmx","port-discovery","ajp"],"backgroundTag":"missing-config-value","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}