Apache Проблемы передачи контекста в CXF 2.7 - PullRequest
1 голос
/ 17 февраля 2020

Я написал фильтр ведения журнала и передал определенную информацию из ContainerRequestContext в WriterInterceptorContext с помощью функции setProperty () ContainerRequestContext.

Я могу получить свойство, которое я установил с помощью 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
 }
}

1 Ответ

0 голосов
/ 19 февраля 2020

Я нашел решение, чтобы получить контекст.

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) { 
 }
}
...