org.smart4j.plugin.soap.SoapHelper Maven / Gradle / Ivy
package org.smart4j.plugin.soap;
import java.util.ArrayList;
import java.util.List;
import org.apache.cxf.frontend.ClientProxyFactoryBean;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.message.Message;
import org.smart4j.framework.core.ConfigHelper;
public class SoapHelper {
private static final List> inInterceptorList = new ArrayList>();
private static final List> outInterceptorList = new ArrayList>();
static {
// 添加 Logging Interceptor
boolean log = ConfigHelper.getConfigBoolean("soap.log");
if (log) {
LoggingInInterceptor loggingInInterceptor = new LoggingInInterceptor();
inInterceptorList.add(loggingInInterceptor);
LoggingOutInterceptor loggingOutInterceptor = new LoggingOutInterceptor();
outInterceptorList.add(loggingOutInterceptor);
}
}
// 发布 SOAP 服务
public static void publishService(String wsdl, Class> interfaceClass, Object implementInstance) {
ServerFactoryBean factory = new ServerFactoryBean();
factory.setAddress(wsdl);
factory.setServiceClass(interfaceClass);
factory.setServiceBean(implementInstance);
factory.setInInterceptors(inInterceptorList);
factory.setOutInterceptors(outInterceptorList);
factory.create();
}
// 创建 SOAP 客户端
public static T createClient(String wsdl, Class extends T> interfaceClass) {
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setAddress(wsdl);
factory.setServiceClass(interfaceClass);
factory.setInInterceptors(inInterceptorList);
factory.setOutInterceptors(outInterceptorList);
return factory.create(interfaceClass);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy