好友
阅读权限10
听众
最后登录1970-1-1
|
cf8
发表于 2017-9-17 10:48
//拦截器
package me.yourname.webservice.cxfinterceptor;
import java.lang.reflect.Method;
import org.apache.cxf.frontend.MethodDispatcher;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.service.Service;
import org.apache.cxf.service.model.BindingOperationInfo;
public class MethodToInvokeInterceptor extends AbstractPhaseInterceptor<Message> {
//至少要一个带参的构造函数
public MethodToInvokeInterceptor(String phase) {
super(phase);
}
public MethodToInvokeInterceptor() {
super(Phase.USER_LOGICAL);
}
public void handleMessage(Message message) throws Fault {
Exchange exchange = message.getExchange();
BindingOperationInfo bop = exchange.get(BindingOperationInfo.class);
MethodDispatcher md = (MethodDispatcher) exchange.get(Service.class)
.get(MethodDispatcher.class.getName());
Method method = md.getMethod(bop);
System.out.println("********method name:" + method.getName());
}
}
//handler
package me.yourname.webservice.handler;
import java.lang.reflect.Method;
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPMessageContext;
import org.apache.cxf.frontend.MethodDispatcher;
import org.apache.cxf.jaxws.context.WrappedMessageContext;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
import org.apache.cxf.service.Service;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@Component("methodToInvokeHandler")
public class MethodToInvokeHandler implements Handler<SOAPMessageContext> {
private static Logger log = Logger.getLogger(MethodToInvokeHandler.class);
public void close(MessageContext messageContext) {
log.info("MethodToInvokeHandler close");
}
public boolean handleFault(SOAPMessageContext messageContext) {
log.error("MethodToInvokeHandler error");
return false;
}
public boolean handleMessage(SOAPMessageContext messageContext) {
WrappedMessageContext wmc = (WrappedMessageContext) messageContext;
Message m = wmc.getWrappedMessage();
Exchange exchange = m.getExchange();
BindingOperationInfo bop = exchange.get(BindingOperationInfo.class);
MethodDispatcher md = (MethodDispatcher) exchange.get(Service.class)
.get(MethodDispatcher.class.getName());
Method method = md.getMethod(bop);
System.out.println("invoke method:"+method.getName());
return true;
}
} |
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|