Apache CXF 2.7上下文传递问题

问题描述 投票:1回答:1

我编写了一个日志记录筛选器,并使用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个回答
0
投票

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

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();
    context = new ContainerRequestContextImpl(message.getExchange().getInMessage(),
            false, true);
 if (context.getProperty("sampleProperty") != null) { 
 }
}
© www.soinside.com 2019 - 2024. All rights reserved.