2014-11-25 2 views
1

MDF (Outbound Interceptor) SLF4J 매핑 된 진단 컨텍스트 (MDC)를 정리하기 위해 Apache CXF 단계를 권장합니까?CXF MDC 정리를위한 인터셉터 단계

code available publicly on GitHubPhase.PRE_STREAM에서 로깅 컨텍스트를 지우는 것을 보았습니다. 내 첫 번째 생각은 마지막으로 Phase.SETUP_ENDING에서 호출하는 것이 었습니다.

편집 : 배포 한 후에도 outFaultInterceptors에 연결해야한다는 것을 깨달았습니다. 그것을 작동 시키려면 Phase.SETUP_ENDINGPhase.MARSHALL으로 변경해야했습니다. 그러나 나는 그것이 왜 최선의 단계인지 전혀 모른다.

저는 Apache CXF를 처음 접했고 잘못된 단계를 사용하여 무언가를 깨뜨리지 않길 바랍니다.

여기에 내 코드

import org.apache.cxf.message.Message; 
import org.apache.cxf.phase.AbstractPhaseInterceptor; 
import org.apache.cxf.phase.Phase; 
import org.slf4j.MDC; 

public class MdcCleanUpInterceptor extends AbstractPhaseInterceptor<Message> { 

    public MdcCleanUpInterceptor() { 
     super(Phase.MARSHAL); 
    } 

    @Override 
    public void handleMessage(Message message) { 
     MDC.clear(); 
    } 
} 

나의 봄 정의 내가 POST_MARSHALL으로 갔어요

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
     xmlns:cxf="http://cxf.apache.org/core" 
     xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
      http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd 
      http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> 
    <cxf:bus> 
     <cxf:outInterceptors> 
      <ref bean="mdcCleanUpInterceptor"/> 
     </cxf:outInterceptors> 
     <cxf:outFaultInterceptors> 
      <ref bean="mdcCleanUpInterceptor"/> 
     </cxf:outFaultInterceptors> 
    </cxf:bus> 

    <bean id="mdcCleanUpInterceptor" class="MdcCleanUpInterceptor"/> 
</beans> 
+0

누군가가 인터셉터 단계에 대한 훌륭한 문서를 알고 있다면 크게 감사 할 것입니다. – Kirby

답변

0

입니다. MDC는 출력이 마샬 단계를 거치며 여전히 outFaultInterceptor으로 작동 할 때 컨텍스트 상태입니다.