手順
[1] 元になるソースを作成
1-0) Axis2のJarファイルを追加する
1-1) Moduleインターフェイスを継承したクラスの作成 ... 【サンプル】SoapLoggingModule.java
1-2) Handlerインターフェイスを継承したクラスの作成 ... 【サンプル】SoapLogHandler.java
[2] module.xmlを作成 ... 【サンプル】module.xml
[3] axis2.xmlの修正 ... 【サンプル】services.xml
[4] services.xmlの修正 ... 【サンプル】services.xml
[5] marファイルの作成
[6] 作成したモジュールをAxis2にデプロイ
サンプル
SoapLoggingModule.java
package sample.loggingmodules;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.AxisDescription;
import org.apache.axis2.description.AxisModule;
import org.apache.axis2.modules.Module;
import org.apache.neethi.Assertion;
import org.apache.neethi.Policy;
public class SoapLoggingModule implements Module {
// To initialize
public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault {
}
public void engageNotify(AxisDescription axisDescription) throws AxisFault {
}
// To shutdown
public void shutdown(ConfigurationContext configurationContext) throws AxisFault {
}
public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault {
}
public boolean canSupportAssertion(Assertion assertion) {
return true;
}
}
SoapLogHandler.java
package sample.loggingmodules;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.engine.Handler;
import org.apache.axis2.handlers.AbstractHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class SoapLogHandler extends AbstractHandler implements Handler {
private static final Log log = LogFactory.getLog(SoapLogHandler.class);
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
log.info(msgContext.getEnvelope().toString());
return InvocationResponse.CONTINUE;
}
public void revoke(MessageContext msgContext) {
log.info(msgContext.getEnvelope().toString());
}
}
module.xml
<module name="sample-logging" class="sample.loggingmodules.LoggingModule">
<InFlow>
<handler name="InFlowLogHandler" class="sample.loggingmodules.SoapLogHandler">
<order phase="loggingPhase"/>
</handler>
</InFlow>
<OutFlow>
<handler name="OutFlowLogHandler" class="sample.loggingmodules.SoapLogHandler">
<order phase="loggingPhase"/>
</handler>
</OutFlow>
<OutFaultFlow>
<handler name="FaultOutFlowLogHandler" class="sample.loggingmodules.SoapLogHandler">
<order phase="loggingPhase"/>
</handler>
</OutFaultFlow>
<InFaultFlow>
<handler name="FaultInFlowLogHandler" class="sample.loggingmodules.SoapLogHandler">
<order phase="loggingPhase"/>
</handler>
</InFaultFlow>
</module>
<!-- ================================================= -->
<!-- Phases -->
<!-- ================================================= -->
<phaseOrder type="InFlow">
<!-- 略 -->
<phase name="soapmonitorPhase"/>
<phase name="loggingPhase"/><!-- !!Add!! -->
</phaseOrder>
<phaseOrder type="OutFlow">
<!-- 略 -->
<phase name="loggingPhase"/><!-- !!Add!! -->
</phaseOrder>
<phaseOrder type="InFaultFlow">
<!-- 略 -->
<phase name="soapmonitorPhase"/>
<phase name="loggingPhase"/><!-- !!Add!! -->
</phaseOrder>
<phaseOrder type="OutFaultFlow">
<phase name="soapmonitorPhase"/>
<phase name="loggingPhase"/><!-- !!Add!! -->
<phase name="OperationOutFaultPhase"/>
<!-- 略 -->
</phaseOrder>
services.xml
"Axis2_HOME/samples/userguide/src/userguide/example2"にも同じファイルがある
<service name="XxxxxXxxx">
<module ref="logging"/><!-- !!Add!! -->
<!-- 略 -->
</service>