【问题标题】:Empty soap envelope in WSO2 axis2 moduleWSO2 轴 2 模块中的空肥皂信封
【发布时间】:2016-08-30 00:38:40
【问题描述】:

我正在为 wso2 esb 开发自定义 axis2 模块。现在我正在使用来自https://docs.wso2.com/display/ESB490/Writing+an+Axis2+Module 的代码 我对传入的请求有疑问。我发送什么请求并不重要,因为它总是如下所示:

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

另一方面,OutFlow 或多或少按应有的方式工作 - 响应看起来不错,但它的方向不是“out”,而是设置为“in”。如果我没记错的话,将调用调用方法来请求请求并撤销响应 - 我是对的吗?在我的情况下,两者都使用调用。任何想法我做错了什么?

编辑: 我的处理程序代码:

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 代理中,我使用 Payload Mediator 创建响应,然后使用 Respond Mediator 返回它。 对于给定的请求:

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

记录了两件事: 来自 InFlow 的请求

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

以及来自 OutFlow 的响应

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>

【问题讨论】:

  • 请分享您的代码并进行测试。

标签: wso2 axis2


【解决方案1】:

根据https://axis.apache.org/axis2/java/core/docs/modules.html#Step2_:_LogHandler ...

"公共无效调用(MessageContext ctx);"是被调用的方法 当控件传递给处理程序时,由 Axis2 引擎执行。 “上市 void revoke(MessageContext ctx);" 在处理程序被调用时调用 被 Axis2 引擎撤销。”

这意味着由于您在 InFlow 和 OutFlow 中调用相同的处理程序,因此应该为请求和响应触发相同的 invoke() 方法。如果您希望为请求和响应执行不同的逻辑,也许您应该为请求和响应编写单独的处理程序。

【讨论】:

  • 我不介意对流入和流出都使用一种方法——目前这不是我的主要问题。无论如何,我已经找到了解决办法。
【解决方案2】:

在调试完所有内容后,我发现在 InFlow 中解析请求时,并没有使用它的肥皂消息,而是创建了新的(空的)。值得庆幸的是,可以使用soap tracer 处理程序(或只是它的代码)访问正确的请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多