2016-08-26 58 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