读书人

[WebService课程]编写Axis2模块(Modu

发布时间: 2012-11-04 10:42:42 作者: rapoo

[WebService教程]编写Axis2模块(Module)- 9

package service;public class MyService{ public String getGreeting(String name) { return "您好 " + name; }}

? package module;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 LoggingModule implements Module{ // initialize the module public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault { System.out.println("init"); } public void engageNotify(AxisDescription axisDescription) throws AxisFault { } // shutdown the module public void shutdown(ConfigurationContext configurationContext) throws AxisFault { System.out.println("shutdown"); } public String[] getPolicyNamespaces() { return null; } public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault { } public boolean canSupportAssertion(Assertion assertion) { return true; }}

?package module;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 LogHandler extends AbstractHandler implements Handler{ private static final Log log = LogFactory.getLog(LogHandler.class); private String name; public String getName() { return name; } public InvocationResponse invoke(MessageContext msgContext) throws AxisFault { // 向Tomcat控制台输出请求和响应SOAP消息 log.info(msgContext.getEnvelope().toString()); return InvocationResponse.CONTINUE; } public void revoke(MessageContext msgContext) { log.info(msgContext.getEnvelope().toString()); } public void setName(String name) { this.name = name; }}

? <module name="logging" name="code"><phaseOrder type="InFlow"> <phase name="soapmonitorPhase"/> <phase name="loggingPhase"/></phaseOrder><phaseOrder type="OutFlow"> <phase name="Security"/> <phase name="loggingPhase"/></phaseOrder><phaseOrder type="InFaultFlow"> <phase name="soapmonitorPhase"/> <phase name="loggingPhase"/></phaseOrder><phaseOrder type="OutFaultFlow"> <phase name="Security"/> <phase name="loggingPhase"/></phaseOrder>

? <service name="myService"> <description> 使用logging模块 </description> <!-- 引用logging模块 --> <module ref="logging"/> <parameter name="ServiceClass"> service.MyService </parameter> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" /> </messageReceivers></service>

?// async是引用MyService的服务名async.myService my = new WSC.asyn.myService();MessageBox.Show(my.getGreeting("中国"));MessageBox.Show("完成调用");

?

读书人网 >Web前端

热点推荐