在 JBoss EAP 7 上注册服务器 javax.ws.rs.client.ClientRequestFilter

register server wide javax.ws.rs.client.ClientRequestFilter on JBoss EAP 7

是否可以在 JBoss EAP 7 上注册一个 javax.ws.rs.client.ClientRequestFilter 服务器范围?我想拦截所有出站 JAX-RS 调用以在 HTTP headers.

中动态添加一些上下文信息

对于 JAX-WS 个调用,我可以使用 https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.0/html-single/developing_web_services_applications/#jax_ws_handler_chains 完成此操作。我找不到任何关于 JAX-RS.

类似机制的文档

或者,是否有另一种方法来拦截一般的出站 HTTP 调用?

对于每服务器解决方案,根据 Using HttpHandler class in Undertow "you need to package your handler(s) into a module, and configure custom-filter in undertow subsystem."

module.xml示例和undertow配置以及过滤器源代码已给出!

更新 有一个使用 HTTPExchange here though I dont really care much for that site. SO also has this slightly related example - it does look like it can work similarly to the JAX-WS Handlers/Interceptor How to properly read post request body in a handler 的例子

另一个很好的例子 我知道它们与处理 JAX-RS 不同,但仍然适用。

我通过创建一个包含以下内容的模块来实现它:

package be.fgov.kszbcss.tracer.jaxrs;

import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;

public class TracerResteasyClientBuilder extends ResteasyClientBuilder {
    @Override
    public ResteasyClient build() {
        return super.build().register(TracerJaxRsClientRequestFilter.class);
    }
}

/META-INF/services/javax.ws.rs.client.ClientBuilder

be.fgov.kszbcss.tracer.jaxrs.TracerResteasyClientBuilder

并在 JBoss EAP 上将其注册为全局模块。