zoukankan      html  css  js  c++  java
  • Springboot调用wsdl的webservice接口两种不常用方式

    import javax.xml.namespace.QName;
    import javax.xml.rpc.ParameterMode;
    
    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
    import org.apache.axis.encoding.XMLType;
    import org.apache.cxf.endpoint.Client;
    import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;    
    
    public String sendXml(String xml) {
     // 创建动态客户端
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient(System.getProperty("wsdl"));
            // 需要密码的情况需要加上用户名和密码
            // client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME, PASS_WORD));
            Object[] objects = new Object[0];
            try {
                // invoke("方法名",参数1,参数2,参数3....);
                objects = client.invoke("getUserName", xml);
                logger.debug("返回数据:" + objects[0]);
                return objects[0].toString();
            } catch (java.lang.Exception e) {
                e.printStackTrace();
            }
            return null;
        }
        
        public String sendXml2(String xml) throws Throwable {
            String url = System.getProperty("wsdl");
            Service serv = new Service();
            Call call = (Call) serv.createCall();
            call.setTargetEndpointAddress(url);
            call.setOperationName(new QName("http://webservice.rpc.other.web.demo.g4studio.org/","createsite"));
            call.addParameter(new QName("http://webservice.rpc.other.web.demo.g4studio.org/", "xmlContent"), 
                    XMLType.XSD_STRING, Class.forName("java.lang.String"), ParameterMode.IN );
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
            System.out.println("推送的xml---"+xml);
            String str=(String) call.invoke(new Object[] {xml});
            System.out.println(str+"----------------推送成功");
            return str;
        }
        
  • 相关阅读:
    npmcnpmyarn yarn 关于源和代理的问题
    react : umi 引入 antd 踩坑
    Ant Design Pro 学习笔记:数据流向
    dva + umi 学习笔记
    简单分析 ztree 源码
    X-Tag实战:给博客加一个隐藏侧栏的功能
    javascript中var,let,const的区别
    linq 延迟执行带来的困扰
    如何实现能像windows 窗体一样改变大小的控件 Silverlight
    一个循环递归遍历问题
  • 原文地址:https://www.cnblogs.com/liangblog/p/14184127.html
Copyright © 2011-2022 走看看