您可以在服務器上使用傳入攔截器或在客戶端上使用傳出攔截器,並在解組發生之前清理xml。
傳入階段
------------------------------------------------------------------------------
|Phase | Functions |
------------------------------------------------------------------------------
|RECEIVE | Transport level processing |
|(PRE/USER/POST)_STREAM | Stream level processing/transformations |
|READ | | This is where header reading typically occurs |
|(PRE/USER/POST)_PROTOCOL | Protocol processing, such as JAX-WS SOAP handlers|
|UNMARSHAL | Unmarshalling of the request |
|(PRE/USER/POST)_LOGICAL | Processing of the umarshalled request |
|PRE_INVOKE | Pre invocation actions |
|INVOKE | Invocation of the service |
|POST_INVOKE | Invocation of the outgoing chain if there is one |
------------------------------------------------------------------------------
引出相位
---------------------------------------------------------------------------------------
|Phase | Functions |
---------------------------------------------------------------------------------------
|SETUP | Any set up for the following phases |
|(PRE/USER/POST)_LOGICAL | Processing of objects about to marshalled |
|PREPARE_SEND | Opening of the connection |
|PRE_STREAM | |
|PRE_PROTOCOL | Misc protocol actions |
|WRITE | Writing of the protocol message, such as the SOAP Envelope|
|MARSHAL | Marshalling of the objects |
|(USER/POST)_PROTOCOL | Processing of the protocol message |
|(USER/POST)_STREAM | Processing of the byte level message |
|SEND | |
---------------------------------------------------------------------------------------
請記住,你將不得不解編(進入)之前或編組(離開)之後做到這一點。
Here你可以找到所有的細節,以及使用inteceptors的必要示例。
更新
一些調查研究後,我發現這些:
- Solution with spring
- Solution without spring
複製,並從第二個鏈接粘貼(第一個是SO回答)
package tmp;
public class MyWstxOutputFatory extends WstxOutputFactory {
public MyWstxOutputFatory() {
setProperty(com.ctc.wstx.api.WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER,
new
com.ctc.wstx.api.InvalidCharHandler.ReplacingHandler(' '));
}
}
,並用它在你的JAXWS配置
<bean id="outStaxFactory" class="tmp.MyWstxOutputFatory"/>
<!-- jaxws:client or server -->
...
<jaxws:properties>
<entry key="javax.xml.stream.XMLOutputFactory">
<ref bean="outStaxFactory"/>
</entry>
</jaxws:properties>
...
有喜歡MessageBodyReaders和作家接口。我確信CXF必須有一些可以插入的選項,通過它你可以指定你的messagebodywriter。此郵件正文編寫者可以使用您的自定義代碼 – Sikorski