zoukankan      html  css  js  c++  java
  • 使用cxf调用webservice

    1、引入maven包

    <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-frontend-jaxws</artifactId>
                <version>${cxf.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-transports-http</artifactId>
                <version>${cxf.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-transports-http-jetty</artifactId>
                <version>${cxf.version}</version>
            </dependency>
    View Code

    2、创建Client对象

    public static Client getDynamicClient(String wsdlUrl) {
            if (client == null) {
                synchronized (this.class) {
                    if (client == null) {
                        DynamicClientFactory dcf = DynamicClientFactory.newInstance();
                        client = dcf.createClient(wsdlUrl);
                    }
                }
            }
            return client;
        }
    View Code

    3、请求远程方法

        private String getResult(String reqXml, String wsdlUrl, String method) {
            String result = null;
            Object[] objects = null;
            try {
                LOGGER.debug("reqXml={}.", reqXml);
                objects = getDynamicClient(wsdlUrl).invoke(method, reqXml);
                result = (String) objects[0];
                LOGGER.debug("GbotExecutor.getResult response={}.", result);
            }
            catch (Exception e) {
                LOGGER.error("invoke gbot getResult failed!", e);
            }
            return result;
        }
    View Code
  • 相关阅读:
    webstorm 自定义代码模板
    HTML5 manifest ApplicationCache
    WebStorm 快捷键收藏
    函数内巧用注释实现多行文本拼接
    图片剪裁上传插件
    将json转为复杂url参数
    CSS3实现半像素边框
    打造自己的3D全景漫游
    自适应rem布局
    header页头内容整理
  • 原文地址:https://www.cnblogs.com/BensonHe/p/5612117.html
Copyright © 2011-2022 走看看