我正在扩展AbstractPhaseInterceptor
,我希望在INVOKE或PRE_INVOKE阶段获取JAXWS Web服务对象。我该怎么做?
要清楚,我需要获得对实现Web服务方法的对象的引用,所以:
@WebService(...) public class ExampleWebService { @WebMethod(...) public void doSomething(...) { } } public class MyInterceptor extends AbstractPhaseInterceptor<Message> { public MyInterceptor() { super(Phase.INVOKE); } @Override public void handleMessage(Message message) throws Fault { ExampleWebService serviceObject = getServiceObject(message); } private static ExampleWebService getServiceObject(Message messsage) { // how do I implement this? } }
答案 0 :(得分:1)
我不测试代码,但这样的东西可能有用。
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.frontend.ServerFactoryBean;
...
Server server = serverFactoryBean.create();
MyInterceptor myInterceptor = new MyInterceptor(server.getEndpoint());
server.getEndpoint().getInInterceptor().add(myInterceptor);