一、自定义module
---com.mywebservice.ws.module
---AuditLogModule.java
---AuditInHandler.java
---AuditOutHandler.java
AuditLogModule.java
public class AuditLogModule implements Module {
// initialize the module
public void init(ConfigurationContext configContext, AxisModule module)
throws AxisFault {
System.out.println("initializing AuditLogModule");
}
public void engageNotify(AxisDescription axisDescription) throws AxisFault {
}
// shutdown the module
public void shutdown(ConfigurationContext configurationContext)
throws AxisFault {
System.out.println("shutdown AuditLogModule");
}
public String[] getPolicyNamespaces() {
return null;
}
public void applyPolicy(Policy policy, AxisDescription axisDescription)
throws AxisFault {
}
public boolean canSupportAssertion(Assertion assertion) {
return true;
}
}
AuditInHandler.java
public class AuditInHandler extends AbstractHandler implements Handler {
public InvocationResponse invoke(MessageContext msgContext)
throws AxisFault {
// get http request
HttpServletRequest request = (HttpServletRequest) msgContext
.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
System.out.println("AuditInHandler beginning...");
return InvocationResponse.CONTINUE;
}
}
AuditOutHandler.java
public class AuditOutHandler extends AbstractHandler implements Handler {
@Override
public InvocationResponse invoke(MessageContext msgContext)
throws AxisFault {
System.out.println("AuditOutHandler beginning...");
return InvocationResponse.CONTINUE;
}
}
二、编译并copy build/classes mode文件到WebConten/WEB-INF/modules下,并创建module.xml
---mymodule
---com
---...
---META-INF
---module.xml
三、修改axis2.xml
打开/conf/axis2.xml,增加module的配置:
class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher">
class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher">
class="org.apache.axis2.dispatchers.AddressingBasedDispatcher">
class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/>
class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/>
class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/>
class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/>
class="org.apache.axis2.jaxws.dispatchers.GenericProviderDispatcher"/>
class="org.apache.axis2.jaxws.dispatchers.MustUnderstandValidationDispatcher"/>
class="org.apache.axis2.jaxws.dispatchers.MustUnderstandChecker">
class="org.apache.axis2.dispatchers.AddressingBasedDispatcher">
class="org.apache.axis2.dispatchers.RequestURIBasedDispatcher"/>
class="org.apache.axis2.dispatchers.SOAPActionBasedDispatcher"/>
class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher"/>
class="org.apache.axis2.dispatchers.HTTPLocationBasedDispatcher"/>
class="org.apache.axis2.jaxws.dispatchers.GenericProviderDispatcher"/>
class="org.apache.axis2.jaxws.dispatchers.MustUnderstandValidationDispatcher"/>
其中 为自定义的。
四、修改services.xml
增加
com.axis2.ws.skeleton.OnepassServicesSkeleton
true
true
urn:getUserProfile
urn:getUserProfileResponse
五:deploy工程
以Tomcat为例
六:测试,run the test
OnePassTester.java/@Test testGetUserProfile1()
测试结果:
后台打印信息
--- initializing AuditLogModule
--- AuditInHandler beginning...
--- AuditOutHandler beginning...