【问题标题】:Apache CXF 2.7 context passing issuesApache CXF 2.7 上下文传递问题
【发布时间】:2020-06-01 10:36:13
【问题描述】:

我编写了一个日志过滤器,并使用 ContainerRequestContext 的 setProperty() 函数将某些信息从 ContainerRequestContext 传递到 WriterInterceptorContext。

在使用 Jersey 实现时,我能够检索我使用 getProperty 设置的属性。

但同样不适用于 Apache CXF 2.7。有输入吗?

public class LoggingFilter implements ContainerRequestFilter, ContainerResponseFilter,WriterInterceptor {

@Override
public void filter(ContainerRequestContext reqContext) throws IOException {
  reqContext.setProperty("sampleProperty", "sampleValue");
}

@Override
public void aroundWriteTo(WriterInterceptorContext context)
    throws IOException, WebApplicationException {
 if (context.getProperty("sampleProperty") != null) { -> passes for jersey, fails for Apache CXF 2.0
 }
}

【问题讨论】:

    标签: java filter jersey jax-rs cxf


    【解决方案1】:

    我找到了获取上下文的解决方案。

    public class LoggingFilter implements ContainerRequestFilter, ContainerResponseFilter,WriterInterceptor {
    
    @Override
    public void filter(ContainerRequestContext reqContext) throws IOException {
      reqContext.setProperty("sampleProperty", "sampleValue");
    }
    
    @Override
    public void aroundWriteTo(WriterInterceptorContext context)
        throws IOException, WebApplicationException {
        Message message = JAXRSUtils.getCurrentMessage();
        ContainerRequestContext reqContext = new ContainerRequestContextImpl(message.getExchange().getInMessage(),
                false, true);
     if (reqContext.getProperty("sampleProperty") != null) { 
     }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-02
      • 2014-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多