2016-12-16 10 views
0

응답을 수정하기 위해 아웃 바운드 인터셉터를 작성해야합니다. 아웃 바운드 응답을위한 인터셉터를 작성했습니다. SEND 단계 전에 outStream을 수정할 수 없으므로 SEND 단계에 인터셉터가 추가됩니다.Apache CXF 인터셉터 : Out 인터셉터에서 응답 스트림을 수정할 수 없습니다.

org.apache.cxf.message.Message 객체의 기존 출력 스트림을 새로운 데이터 바이트로 변경하려고 시도했으며 Message 객체에 새 OutputStream을 추가하려고했습니다. 그러나 그들 중 누구도 일하지 않았습니다.

동일한 문제에 직면 해 있고 해결책이 있는지 알려주세요.

감사합니다.

public class SResponseInterceptor2 extends AbstractPhaseInterceptor<Message> { 

private static final Logger LOGGER = LogManager.getLogger(SResponseInterceptor2.class.getName()); 

public SResponseInterceptor2() { 
    super(Phase.SEND); 
    addBefore(MessageSenderInterceptor.class.getName()); 
    LOGGER.info(">>>>>>>>>>>>>>>>>>>>>>>>"); 
} 

public void handleMessage(Message message) throws Fault { 

    OutputStream outputStream = message.getContent(OutputStream.class); 
    if(outputStream!=null && outputStream instanceof CacheAndWriteOutputStream){ 
     CacheAndWriteOutputStream cachedOutputStream = (CacheAndWriteOutputStream)outputStream; 
     try{ 

      String inputMessage = new String(cachedOutputStream.getBytes()); 
      cachedOutputStream.flush(); 

      byte[] bytes = changeResponse(inputMessage).getBytes(); 

cachedOutputStream.write(bytes); 

    /* Tried adding a new Stream with the updated data too 

     OutputStream modifiedOutputStream = new ByteArrayOutputStream(); 
      CacheAndWriteOutputStream cWStream = new CacheAndWriteOutputStream(modifiedOutputStream); 
      cWStream.write(bytes, 0, bytes.length); 
      message.setContent(OutputStream.class, cWStream); 
*/ 
      message.setContent(OutputStream.class, cachedOutputStream); 
     } catch (IOException ioe) { 
      LOGGER.error("Error while changing the Response ." + ioe.getMessage()); 
      ioe.printStackTrace(); 
     }finally{ 

     } 


     private String changeResponse(String responseMessage) { 
      responseMessage = responseMessage.replaceAll("sResponse",       "sResponse??????"); 
      LOGGER.info("After change message is " + responseMessage); 
       return responseMessage; 
} 

}

+0

확인 내 생각이 대답 http://stackoverflow.com/a/12948702/6371459은 당신 – pedrofb

+0

감사와 동일합니다 그래서 많이. 그것은 효과가 있었다. 나는 아파치에 의한 문서 개선안을 제안한다. – vinr

+0

안녕 Pedroft .. 제안 작동하지만 CacheOutputStream 내에서 래핑 된 출력 스트림 (LoadingByteArrayOutputStream) 2046 바이트의 데이터 만 처리하도록 제한됩니다. message.getInterceptorChain(). doIntercept (message); 처리 할 거대한 데이터가있는 경우 출력 스트림에 데이터가없는 메시지를 반환합니다. 출력 스트림의 크기 제한을 변경했으나 도움이되지 않았습니다. 제안? 감사합니다. – vinr

답변

0

stackoverflow.com/a/12948702/6371459