2016-07-26 4 views

答えて

2

あなたの迎撃は、プログラム

MyInterceptor myInterceptor = new MyInterceptor(); 

Server server = serverFactoryBean.create(); 
server.getEndpoint().getInInterceptor().add(myInterceptor); 

または使用した構成に

public class MyInterceptor extends AbstractPhaseInterceptor<Message> { 
    public MyInterceptor() { 
     super(Phase.RECEIVE); 
    } 

    public void handleMessage(Message message) { 
     //Get the message body into payload[] and set a new non-consumed inputStream into Message 
     InputStream in = message.getContent(InputStream.class); 
     byte payload[] = IOUtils.readBytesFromStream(in); 
     ByteArrayInputStream bin = new ByteArrayInputStream(payload); 
     message.setContent(InputStream.class, bin); 
    } 

    public void handleFault(Message messageParam) { 
     //Invoked when interceptor fails 
    } 
} 

はインターセプタを追加AbstractPhaseInterceptorまたはサブクラスから延長する必要が

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     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://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"> 

    <bean id="MyInterceptor" class="demo.interceptor.MyInterceptor"/> 

    <!-- We are adding the interceptors to the bus as we will have only one endpoint/service/bus. --> 

    <cxf:bus> 
     <cxf:inInterceptors> 
      <ref bean="MyInterceptor"/> 
     </cxf:inInterceptors> 
     <cxf:outInterceptors> 
      <ref bean="MyInterceptor"/> 
     </cxf:outInterceptors> 
    </cxf:bus> 
</beans> 

チェックドキュメントhere

+0

Stringとしてペイロードを取得するためにLoggingInInterceptorを使用することができます...私は見てみましょうCXF .. –

+0

で初心者午前CXFの 'LoggingInInceptor.handleMessage'と' LoggingOutInterceptor.handleMessage'のソースコードです。これらのクラスを使用すると、完全なメッセージをログに出力できます。そこからコピー&ペーストできます。http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cxf/cxf-core/3.1.1/org/apache/cxf/interceptor/LoggingInInterceptor.java #LoggingInInterceptor.handleMessage%28org.apache.cxf.message.Message%29 – pedrofb

+0

@ pedrofb LoggingInInterceptorとLoggingOutInterceptorを使用してログに完全なメッセージを出力しました。終了時にそのペイロードを抽出したいユーザーはデータを送信します....ここで何かが見つからない場合はごめんなさい... –

0

私はペイロードを得るためにのhandleMessage方法で書くんどのようなコードpedrofb @

public class CustomInInterceptor extends LoggingInInterceptor { 

    /** 
    * SLF4J Log Instance 
    */ 
    private final static Logger LOG = LoggerFactory.getLogger(CustomInInterceptor.class); 

    /** 
    * formats logging message and also attaches input xml to thread context 
    * 
    * @see org.apache.cxf.interceptor.LoggingInInterceptor#formatLoggingMessage(org.apache.cxf.interceptor.LoggingMessage) 
    */ 
    @Override 
    protected String formatLoggingMessage(final LoggingMessage loggingMessage) { 
    //The below line reads payload and puts into threads context, which I use later to save in db 
    KpContextHolder.setInputXml(loggingMessage.getPayload().toString()); 
     return super.formatLoggingMessage(loggingMessage); 
    } 

} 
関連する問題