2011-06-22 11 views
5

मैं परीक्षण के लिए एक इंटरसेप्टर लिखता हूं। लेकिन मुझे इंटरसेप्टर में साबुन संदेश निकाय हमेशा शून्य होता है।सीएक्सएफ आउटगोइंग इंटरसेप्टर साबुन प्रतिक्रिया शरीर प्राप्त करता है जो हमेशा शून्य होता है?

मेरे CXF Apache-CXF-2.4.0

bean.xml इस तरह है:

<cxf:bus> 
    <cxf:outInterceptors> 
     <ref bean="myOutSoapInterceptor"/> 
    </cxf:outInterceptors> 
</cxf:bus> 

इंटरसेप्टर फ़ाइल:

public class MySoapInterceptorImpl extends AbstractSoapInterceptor implements IMySoapInterceptor { 

public MySoapInterceptorImpl() 
{ 
    super(Phase.WRITE); 
    addAfter(SoapOutInterceptor.class.getName()); 
} 


public void handleMessage(SoapMessage msg) throws Fault { 
    // TODO Auto-generated method stub 
    String soapContent ; 
    SOAPMessage sm = msg.getContent(SOAPMessage.class); 

    /*sm is always null!*/ 
    } 
} 
+0

मुझे दे सकते हैं:

/** * @author asraf * [email protected] */ public class WSLoggingOutInterceptor extends AbstractLoggingInterceptor { public WSLoggingOutInterceptor() { super(Phase.PRE_STREAM); } @Override public void handleMessage (Message message) throws Fault { // TODO Auto-generated method stub OutputStream os = message.getContent (OutputStream.class); CacheAndWriteOutputStream cwos = new CacheAndWriteOutputStream (os); message.setContent (OutputStream.class, cwos); cwos.registerCallback (new LoggingOutCallBack ()); } @Override protected Logger getLogger () { // TODO Auto-generated method stub return null; } } class LoggingOutCallBack implements CachedOutputStreamCallback { @Override public void onClose (CachedOutputStream cos) { try { if (cos != null) { System.out.println ("Response XML in out Interceptor : " + IOUtils.toString (cos.getInputStream ())); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void onFlush (CachedOutputStream arg0) { } } 

अधिक जानकारी के लिए इस साइट पर एक नज़र डालें कुछ सुझाव? धन्यवाद! – user809965

+0

क्या आप एसओएपी सामग्री को स्ट्रिंग या ऑब्जेक्ट के रूप में ढूंढ रहे हैं? – ThomasRS

उत्तर

2

संदेश चरण आप कर रहे हैं पर निर्भर करता है इस पल। आप Interceptor doku में चरणों के साथ एक सूची पा सकते हैं। यदि आप संदेश सामग्री प्राप्त करने का प्रयास करते हैं तो आपको यह पता लगाने की आवश्यकता है कि संदेश किस प्रारूप में मौजूद है। getContentFormats में एक नज़र डालें। कुछ वस्तुएं आपको संदेश नहीं देगी। सबसे अधिक समय सीएक्सएफ धाराओं के साथ काम करता है। तो धारा वस्तु flushed किया जा सकता है।

साथ सादर ईसाई

2

आपका intercepter SAAJOutInterceptor होने लग जाते हैं किया जाना चाहिए(); उदाहरण के लिए Glen Mazza's Weblog

9

साबुन संदेश से प्रतिक्रिया xml प्राप्त करने के लिए, आप "कैश एंडवाइटऑटपुटस्ट्रीम" और "कैश आउटपुटस्ट्रीम कॉलबैक" का उपयोग कर सकते हैं। कॉलबैक क्लास में आप स्ट्रीम बंद करने से पहले संदेश प्राप्त कर सकते हैं। कहो, हमारे बाहर LoggingInterceptor "wsLoggingOutInterceptor" जो संदर्भ फ़ाइल में विन्यस्त किया जा सकता इस प्रकार है:

<bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/> 
<bean id="logOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> 
<bean id="wsLoggingOutInterceptor" class="org.jinouts.webservice.logging.WSLoggingOutInterceptor"></bean> 

    <cxf:bus> 
     <cxf:inInterceptors> 
      <ref bean="loggingInInterceptor"/>   
     </cxf:inInterceptors> 
     <cxf:outInterceptors> 
      <ref bean="logOutInterceptor"/> 
      <ref bean="wsLoggingOutInterceptor"/> 
     </cxf:outInterceptors> 
    </cxf:bus> 

ध्यान दें कि, यहाँ हम भी कुछ डिफ़ॉल्ट इंटरसेप्टर जो CXF जार के साथ उपलब्ध है। अब हमारे अपने इंटरसेप्टर में हम निम्नलिखित तरीके से लिखने के उत्पादन प्रतिक्रिया संदेश लॉग इन करने सकते हैं या आप भी यहां संपादित कर सकते हैं: http://cxf.apache.org/docs/interceptors.html

संबंधित मुद्दे