2016-08-26 60 views
1

我正在爲wso2 esb定製axis2模塊。現在我正在使用https://docs.wso2.com/display/ESB490/Writing+an+Axis2+Module 中的代碼,並且傳入的請求有問題。不要緊,什麼要求我送,因爲它總是看起來是這樣的:WSO2 axis2模塊中的空soap信封

<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope> 

在另一方面流出的作品或多或少因爲它應該 - 響應看起來不錯,但不是「出」的方向被設置爲「在」。如果我沒有錯誤調用方法將被調用請求並撤銷響應 - 我是對的嗎?在我的情況下,都使用invoke。任何想法我做錯了什麼?

編輯: 我的處理代碼:

public class LogHandler extends AbstractHandler implements Handler { 
    private Logger log = Logger.getLogger(LogHandler.class.toString()); 

    @Override 
    public void init(HandlerDescription handlerDescription) { 
     super.init(handlerDescription); 
    } 

    public InvocationResponse invoke(MessageContext msgContext) throws AxisFault { 
     System.out.println("invoked: " + msgContext.getEnvelope().toString() + "\n"); 
     log.info("invoked: " + msgContext.getEnvelope().toString() + "\n"); 
     return InvocationResponse.CONTINUE; 
    } 

    public void revoke(MessageContext msgContext) { 
     log.info("revoked: " + msgContext.getEnvelope().toString() + "\n"); 
    } 

} 

模塊:

public class LoggingModule implements Module { 
    private static final Log log = LogFactory.getLog(LoggingModule.class); 

    // initialize the module 
    public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault { 
    } 

    public void engageNotify(AxisDescription axisDescription) throws AxisFault { 
    } 

    // shutdown the module 
    public void shutdown(ConfigurationContext configurationContext) throws AxisFault { 
    } 

    public String[] getPolicyNamespaces() { 
     return null; 
    } 

    public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault { 
    } 

    public boolean canSupportAssertion(Assertion assertion) { 
     return true; 
    } 
} 

module.xml:

<module name="sample-logging" class="pl.wso2.logging.LoggingModule"> 
    <InFlow> 
     <handler name="InFlowLogHandler" class="pl.wso2.logging.LogHandler"> 
      <order phase="loggingPhase"/> 
     </handler> 
    </InFlow> 
    <OutFlow> 
     <handler name="OutFlowLogHandler" class="pl.wso2.logging.LogHandler"> 
      <order phase="loggingPhase"/> 
     </handler> 
    </OutFlow> 
</module> 

在我WSO2代理我採用負載中保創建響應和然後使用Respond Mediator將其返回。 對於給定的要求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
    <aa>blahblah</aa> 
    </soapenv:Body> 
</soapenv:Envelope> 

有兩種東西記錄:從流入

invoked: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlso 
ap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope> 

請求,並從流出

invoked: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlso 
ap.org/soap/envelope/"><soapenv:Body><m:checkpriceresponse xmlns:m="http://services.samples/xsd"><m: 
code>dsadsa</m:code></m:checkpriceresponse></soapenv:Body></soapenv:Envelope> 
+0

請分享你的代碼和測試。 –

回答

0

調試完所有的東西后,我發現雖然請求在InFlow中被解析,而不是使用它的soap消息,新的一個(空)被創建。幸運的是可以使用肥皂示蹤處理程序(或其代碼)訪問正確的請求。

0

按照https://axis.apache.org/axis2/java/core/docs/modules.html#Step2_:_LogHandler響應...

「public void invoke(MessageContext ctx);」是當控件傳遞給處理程序時,Axis2引擎稱爲 的方法。 「public void revoke(MessageContext ctx);」當處理程序是 由Axis2引擎撤銷被稱爲」

這意味着,因爲你是調用都流入和流出相同的處理同樣的invoke()方法應該得到觸發請求和響應都。如果你想爲請求和響應執行不同的邏輯,也許你應該爲請求和響應編寫單獨的處理程序。

+0

我不介意使用一種方法進行流入和流出 - 這不是我目前的主要問題。無論如何,我找到了解決辦法。 – KapitanKopytko