Java Apache CXF 2.7上下文传递问题
我编写了一个日志过滤器,并使用ContainerRequestContext的setProperty()函数将某些信息从ContainerRequestContext传递给WriterInterceptorContext 当与Jersey实现一起使用时,我能够检索使用getProperty设置的属性 但对于ApacheCXF2.7来说,这一点并不适用。有什么意见吗Java Apache CXF 2.7上下文传递问题,java,filter,jersey,jax-rs,cxf,Java,Filter,Jersey,Jax Rs,Cxf,我编写了一个日志过滤器,并使用ContainerRequestContext的setProperty()函数将某些信息从ContainerRequestContext传递给WriterInterceptorContext 当与Jersey实现一起使用时,我能够检索使用getProperty设置的属性 但对于ApacheCXF2.7来说,这一点并不适用。有什么意见吗 public class LoggingFilter implements ContainerRequestFilter, Cont
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
}
}
我找到了获取上下文的解决方案
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) {
}
}
我找到了获取上下文的解决方案
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) {
}
}