如何列出 Wildfly 部署的 http servlet

Posted

技术标签:

【中文标题】如何列出 Wildfly 部署的 http servlet【英文标题】:how to list wildfly deployed http servlets 【发布时间】:2021-07-03 15:49:42 【问题描述】:

如何列出 Wildfly(版本 16)部署的 http servlet?从 web 控制台端口 8080 或 cli ? 我已经部署了一个工作示例:

2021-04-07 19:10:28,579 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0027: Starting deployment of "h2-console.war" (runtime-name: "h2-console.war")
2021-04-07 19:10:28,719 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 124) WFLYUT0021: Registered web context: '/h2-console' for server 'default-server'

这行得通:http://172.21.93.102:8080/h2-console/console/login.jsp?jsessionid=bf0d51b655f42eb956ba4f2bf98a1de9

是否可以列出已部署的 http servlet,类似于已部署的 EJB 列表? 是否必须部署 EJB,而 http servlet 可以说在 web.xml "load-on-startup" 中启动时关闭:

<servlet>
    <servlet-name>H2Console</servlet-name>
    <servlet-class>org.h2.server.web.WebServlet</servlet-class>
    
    <init-param>
        <param-name>webAllowOthers</param-name>
        <param-value></param-value>
    </init-param>
    <init-param>
        <param-name>trace</param-name>
        <param-value></param-value>
    </init-param>
    
    <load-on-startup>1</load-on-startup>
</servlet>

在 Web 控制台的配置/运行时选项卡中,有一些用于“undertow”http 服务器会话的内容,但我找不到 servlet 列表

配置选项卡:

运行时选项卡:

已部署的 EJB 列表(它还显示了哪个 jar/war):

更新:

运行时 -> 服务器 -> Web -> 部署 -> 部署 -> 视图确实显示了已部署的 servlet,如正确答案所示,除此之外,我需要从 servlet 调用 EJB 3.0 bean,但我有这个错误:

javax.naming.NameNotFoundException: MFProLoginBean/remote -- 服务 jboss.naming.context.java.MFProLoginBean.remote

此 EJB 列在 wildfly 16 的 Web 控制台中,可通过 wget 获取:http://wildfly:8080//TServerXmlRpc/login/PreLoginServlet

EJB(似乎是 EJB 3.0?):

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.jboss.annotation.ejb.Clustered;
import org.jboss.annotation.ejb.RemoteBinding;
import org.jboss.annotation.ejb.RemoteBindings;

@Clustered
@Stateless
@RemoteBindings(
        @RemoteBinding(jndiBinding = "MFProLoginBean/remote"),
        @RemoteBinding(jndiBinding = "MFProLoginBean/httpremote", clientBindUrl = "servlet://$tserver.ejb3.client.address$tserver.ejb3.client.port$tserver.ejb3.client.url", factory = it.company.tserver.ejb3.StatelessClusterProxyFactory.class) )
public class MFProLoginBean implements MFProLogin, MFProLoginLocal 

servlet 中失败的调用:

公共类 LoginServlet 扩展 HttpServlet

private void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

javax.naming.Context ctx = InitialContextFactory.create(); MFProLogin loginBean = (MFProLogin) ctx.lookup("MFProLoginBean/remote");

TUserSession userSession = loginBean.loginUser(authReq, new TInfoRequest(launcherVersion, descriptorVersion, environmentPath));

这些变量在 wildfly 启动脚本中设置:

JBoss 引导环境

JBOSS_HOME: /opt/wildfly

JAVA: /usr/bin/java

JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n -Dtserver.ejb3.client.address=jbosscollaudomfpro.classlocale.it -Dtserver.ejb3.client.port=:8080 -Dtserver.ejb3.client.url=//unified-invoker/Ejb3ServerInvokerServlet?return-exception=true -Dtserver.http.client.address=jbosscollaudomfpro.classlocale.it -Dtserver.http.client.port=8080 -Dtserver.jms.http.client.url=/jmsmessaging/connector -Dorg.jboss.logging.Log4jService.catchSystemOut=false -Dlogmanager.log4jimpl.properties=tserver-log4j.properties -DpropsDomain=

自 AS 7 起不再使用“unified-invoker.sar”?

这似乎替代了 java 变量? :

package it.company.tserver.ejb3;

import org.jboss.annotation.ejb.RemoteBinding;
import org.jboss.annotation.ejb.RemoteBindingImpl;

public class StatelessClusterProxyFactory extends org.jboss.ejb3.stateless.StatelessClusterProxyFactory 

    @Override
    public void setRemoteBinding(RemoteBinding binding) 
        String uri = binding.clientBindUrl();
        if (uri!=null && uri.indexOf("$")>=0) 
            uri = ReplacePropertiesUtil.replace(uri);
            RemoteBindingImpl b = new RemoteBindingImpl(binding.jndiBinding(), binding.interceptorStack(), uri, binding.factory());
            super.setRemoteBinding(b);
        
        else
            super.setRemoteBinding(binding);
    

【问题讨论】:

【参考方案1】:

在 Web 控制台中,转到运行时 -> 服务器 -> Web -> 部署,然后选择所需的部署并单击“查看”。从那里您可以从左侧的 Servlet 选项卡中看到 servlet。

在 CLI 中,您可以执行以下操作来列出名称。

/deployment=YOUR.war/subsystem=undertow:read-children-names(child-type=servlet)

或类似以下内容以列出更多详细信息:

/deployment=helloworld-html5.war/subsystem=undertow:read-children-resources(child-type=servlet, include-runtime=true)

【讨论】:

这在 Wildfly Web 控制台中有效:address:9990/console/… 它列出了 servlet,如何测试列出的 servlet 是否可访问,例如 linux 命令 wget 该 url 它在某些地方给出 302“找到”在另一个上找不到“404”? 对于列为“H2Console”的 servlet 这适用 wget address:8080/h2-console,如何找到 servlet 的实际 url? 如何为带有 wildfly 服务器(版本 16)的 http servlet 设置最大请求时间 15 毫秒最小请求时间 0 毫秒?是否有可能来自 /WEB-INF/web.xml (of .war)? 是否可以像这样使用 web.xml 部署“HttpServlet”servlet:mastertheboss.com/javaee/servlet-30/… on wildfly 16 我收到此错误 2021-04-10 20:42:15,464 TRACE [io.undertow. server.handlers.resource.PathResourceManager] (默认 I/O-4) 无法从路径资源管理器中获取路径资源 PreLoginServlet/ /opt/jboss6/standalone/tmp/vfs/temp/temp3ae92316f0524924/content-2e8fc046b2b07891/,如路径不存在 是的,您可以在 web.xml 中定义 servlet。我不知道那条路会从哪里来。它看起来很奇怪,因为它是“jboss6”。

以上是关于如何列出 Wildfly 部署的 http servlet的主要内容,如果未能解决你的问题,请参考以下文章

在 Wildfly/Jboss 中部署 ear 期间如何防止 HTTP 404

在 WildFly 中的重新部署之间保持 HTTP 会话

如何在 Linux 机器上的 Wildfly 8.2.1 中编辑 http 连接

如何配置从 Eclipse 到 Wildfly 的部署

如何减少 Wildfly 部署所需的时间?

如何在 WildFly 10 中将爆炸战争部署为文件夹