WSO2 axis2 模块中的空肥皂信封
Empty soap envelope in WSO2 axis2 module
我正在为 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 或多或少地工作 - 响应看起来不错,但它的方向设置为 "in" 而不是 "out"。如果我没记错的话,将调用 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 代理中,我使用 Payload Mediator 创建响应,然后 return 使用 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>
根据 https://axis.apache.org/axis2/java/core/docs/modules.html#Step2_:_LogHandler ...
"public void invoke(MessageContext ctx);" is the method that is called
by the Axis2 engine when the control is passed to the handler. "public
void revoke(MessageContext ctx);" is called when the handlers are
revoked by the Axis2 engine."
这意味着由于您在 InFlow 和 OutFlow 中调用相同的处理程序,因此应该为请求和响应触发相同的 invoke() 方法。如果您希望为请求和响应执行不同的逻辑,也许您应该为请求和响应编写单独的处理程序。
调试完所有内容后,我发现在 InFlow 中解析请求时,没有使用它的 soap 消息,而是创建了新的(空的)消息。值得庆幸的是,可以使用 soap 跟踪器处理程序(或仅使用其代码)访问正确的请求。
我正在为 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 或多或少地工作 - 响应看起来不错,但它的方向设置为 "in" 而不是 "out"。如果我没记错的话,将调用 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 代理中,我使用 Payload Mediator 创建响应,然后 return 使用 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>
根据 https://axis.apache.org/axis2/java/core/docs/modules.html#Step2_:_LogHandler ...
"public void invoke(MessageContext ctx);" is the method that is called by the Axis2 engine when the control is passed to the handler. "public void revoke(MessageContext ctx);" is called when the handlers are revoked by the Axis2 engine."
这意味着由于您在 InFlow 和 OutFlow 中调用相同的处理程序,因此应该为请求和响应触发相同的 invoke() 方法。如果您希望为请求和响应执行不同的逻辑,也许您应该为请求和响应编写单独的处理程序。
调试完所有内容后,我发现在 InFlow 中解析请求时,没有使用它的 soap 消息,而是创建了新的(空的)消息。值得庆幸的是,可以使用 soap 跟踪器处理程序(或仅使用其代码)访问正确的请求。