- import org.apache.cxf.endpoint.Client;
- import org.apache.cxf.jaxws.JaxWsProxyfactorybean;
- import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicclientFactory;
- import org.springframework.core.io.ClassPathResource;
- import org.springframework.core.io.Resource;
- /**
- * <p>
- * Title: WebServiceClientHelper.java
- * </p>
- * <p>
- * Description:
- * </p>
- * <p>
- * copyright: copyright (c) 2009-2011
- * </p>
- * <p>
- * Company:
- * </p>
- *
- * @author erdp
- * @date 2011-8-7
- * @version 1.0
- */
- public class WebServiceClientHelper {
- /**
- * webservice 公共接口类
- *
- * @param url webservice远程地址
- *
- * @param cls 接口参数
- *
- * @return
- */
- public static <T> T getService(String url, Class<T> cls) {
- JaxWsProxyfactorybean factory = new JaxWsProxyfactorybean();
- factory.setServiceClass(cls);
- factory.setAddress(url);
- @SuppressWarnings("unchecked")
- T service = (T) factory.create();
- return service;
- }
- public static String callService(String wsMethod , Object[] objArr) throws Exception {
- Resource resource = new ClassPathResource(Constants.NC_WEBSERVICE_URL);
- org.codehaus.xfire.client.Client client = new org.codehaus.xfire.client.Client(resource.getInputStream(), null);
- Object[] results = client.invoke(wsMethod, objArr);
- System.out.println((String)results[0]);
- return (String)results[0];
- }
- /**
- *
- * @param wsUrl
- * @param method
- * @param arg
- * @return
- */
- public static String callService(String wsUrl, String method, Object arg) {
- JaxWsDynamicclientFactory dcf = JaxWsDynamicclientFactory.newInstance();
- Client client = dcf.createClient(wsUrl);
- Object[] res = null;
- try {
- res = client.invoke(method, arg);
- client.destroy();
- System.out.println((String) res[0]);
- } catch (Exception e) {
- e.printstacktrace();
- }
- return (String) res[0];
- }
- }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。