我正在爲我的webservices使用Apache CXF。我創建了一個AbstractSoapInterceptor
的實例。在我的public void handleMessage(SoapMessage message) throws Fault
方法中,我想將攔截消息的XML內容打印到控制檯。我怎樣才能做到這一點?打印SOAP消息的XML內容
0
A
回答
8
檢查this輸出並搜索INBOUND INTERCEPTOR。在這裏將其作爲參考......
public class InterceptorMensajeSOAPIn extends AbstractSoapInterceptor {
private static Logger log =
Logger.getLogger(InterceptorMensajeSOAPIn.class);
private SAAJInInterceptor saajIn = new SAAJInInterceptor();
public InterceptorMensajeSOAPIn(){
super(Phase.PRE_PROTOCOL);
getAfter().add(SAAJInInterceptor.class.getName());
}
public void handleMessage(SoapMessage message) throws Fault {
SOAPMessage soapMessage = getSOAPMessage(message);
try {
soapMessage.writeTo(System.out);
} catch (Exception e) {
e.printStackTrace();
}
}
private SOAPMessage getSOAPMessage(SoapMessage smsg){
SOAPMessage soapMessage = smsg.getContent(SOAPMessage.class);
if (soapMessage == null) {
saajIn.handleMessage(smsg);
soapMessage = smsg.getContent(SOAPMessage.class);
}
return soapMessage;
}
}
2
任何原因,你不能只使用隨機附帶的CXF LoggingInInterceptor
?你可以直接獲取代碼並以此作爲基礎,但在2.3版本中,LoggingInInterceptor
已得到增強,允許指定打印流等,以便它可以「正常工作」。
1
您也可以使用此功能:org.apache.cxf.feature.LoggingFeature
:
<jaxws:endpoint ...>
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature"/>
</jaxws:features>
</jaxws:endpoint>
相關問題
- 1. 如何打印SOAP請求消息?
- 2. 在Twig中打印XML的內容
- 3. Perl打印消息
- 4. 打印內容
- 5. 打印內容
- 6. 打印內容
- 7. 如何在打印WebBrowser內容時彈出JavaScript錯誤消息?
- 8. 打印 「消息」,VAR =的raw_input()
- 9. 打印iframe內容
- 10. 打印內容DefaultTreeModel
- 11. 打印ScrollViewer內容
- 12. 使用SOAP創建XML消息PHP
- 13. 在PyCUDA中打印消息
- 14. C++消息打印多次
- 15. 打印錯誤消息
- 16. 打印SQL查詢消息
- 17. 打印錯誤消息
- 18. 打印HWND到消息框
- 19. 消息未打印Tkinter
- 20. Spring Soap攔截器如何修改消息的內容?
- 21. 打印HTML DIV的內容
- 22. WPF - 打印ListView的內容?
- 23. 打印內容的Rails
- 24. div的打印內容
- 25. 打印WPF WebBrowser的內容
- 26. fancybox的打印內容
- 27. IFRAME的打印內容
- 28. picturebox的打印內容
- 29. 打印HttpParams/HttpUriRequest的內容?
- 30. 打印Silverlight 4 RichTextBox內容
將與CXF 3.x的這一解決方案的工作?我試了一下,getContent的調用總是返回null,但也許我做了一些其他的錯誤,或者api在3.0中改變了。 – bwfrieds 2016-02-12 17:52:26