5.6. 配置 Jakarta Enterprise Beans 客户端地址
您可以使用 SessionContext 界面确定 Jakarta Enterprise Beans 客户端地址,如下例所示。
public class HelloBean implements HelloBeanRemote {
@Resource
SessionContext ctx;
private Long counter;
public HelloBean() {
}
@PostConstruct
public void init() {
counter = 0L;
}
@Override
@RolesAllowed("users")
public String hello() {
final String message = "method hello() invoked by user " + ctx.getCallerPrincipal().getName()
+ ", source addr = " + ctx.getContextData().get("jboss.source-address").toString();
System.out.println(message);
return message;
}
}独立客户端配置
您可以在 wildfly 元素。-config.xml 文件中带有 namespace addressesurn:xnio:3.5 的 worker 元素中配置 outbound-bind-bind-address 子元素取 匹配、bind-address 和 的属性,如下定义。
bind- port
以下是使用 wildfly-config.xml 文件的独立客户端配置示例:
<configuration>
<worker xmlns="urn:xnio:3.5">
<worker-name value="default"/>
<outbound-bind-addresses>
<bind-address bind-address=IP_ADDRESS_TO_BIND_TO bind-port=OPTIONAL_SOURCE_PORT_NUMBER match=CIDR_BLOCK />
</outbound-bind-addresses>
</worker>
</configuration>
outbound -bind-address 需要以下属性:
-
match是一个无类别域间路由(CIDR)块,如10.0.0.0/8,ff00::\8,0.0.0.0/0,::/0。 -
bind-address指定目标地址与match参数中指定的 CIDR 块匹配时要绑定的 IP 地址。它应当与 CIDR 块相同的地址系列。 bind-port是一个可选的源端口号,默认为0。如果没有匹配的表达式,则不会显式绑定出站套接字。
基于容器的配置
基于容器的 Jakarta Enterprise Beans 客户端地址的配置与 wildfly-config.xml 文件中定义的独立客户端配置类似。
以下示例在 io 子系统的默认 worker 元素上配置 outbound -bind-address,ej b3 子系统默认使用它。
/subsystem=io/worker=default/outbound-bind-address=SPECIFY_OUTBOUND_BIND_ADDRESS:add(bind-address=IP_ADDRESS_TO_BIND_TO, bind-port=OPTIONAL_SOURCE_PORT_NUMBER, match=CIDR_BLOCK)