服务端拦截器:
package com.xh.ws.test;
import javax.xml.ws.Endpoint;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.jaxws.EndpointImpl;
import com.xh.ws.sei.TestServerImpl;
public class Test {
public static void main(String[] args) {
Endpoint endpoint=Endpoint.publish("http://127.0.0.1:54321/cxf/test", new TestServerImpl());
System.out.println(endpoint);
EndpointImpl endpointImpl=(EndpointImpl) endpoint;
//服务端日志入拦截器
endpointImpl.getInInterceptors().add(new LoggingInInterceptor());
//服务端日志出拦截器
endpointImpl.getOutInterceptors().add(new LoggingInInterceptor());
System.out.println("发布成功");
}
}
客户端拦截器:
package com.xh.ws.test;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import com.xh.ws.sei.TestServer;
import com.xh.ws.sei.TestServerImplService;
public class Testclient {
public static void main(String[] args) {
TestServerImplService factory=new TestServerImplService();
TestServer testserver=factory.getTestServerImplPort();
Client client=ClientProxy.getClient(testserver);
//客户端日志出拦截器
client.getOutInterceptors().add(new LoggingOutInterceptor());
//客户端日志入拦截器
client.getInInterceptors().add(new LoggingInInterceptor());
System.out.println(testserver.sayHello("nana"));
}
}