• java使用CXF动态调用webservice接口


     1 package com.webservice.client.config;
     2 
     3 import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
     4 import javax.xml.namespace.QName;
     5 
     6 /**
     7  * @author liuwenlong
     8  * @create 2022-02-20 11:20:13
     9  */
    10 @SuppressWarnings("all")
    11 public class CxfClientTester {
    12 
    13     public static final String serviceUrl = "http://地址/api/insertUserInfo?wsdl";
    14     public static final String methodName = "insertUserInfo";
    15     public static final String nameSpaceUrl = "http://service.api.spring.com/";
    16     public static final String param = "请求xml";
    17 
    18     public static void main(String[] args) throws Exception {
    19         try {
    20             System.out.println("反馈结果:" + webserviceInterface(serviceUrl, nameSpaceUrl, methodName, param));
    21         } catch (Exception e) {
    22             System.out.println("ERROR:" + e.getMessage());
    23         }
    24     }
    25 
    26     public static String webserviceInterface(String serviceUrl, String nameSpaceUrl, String methodName, String param) throws Exception {
    27         JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
    28         org.apache.cxf.endpoint.Client client = dcf
    29                 .createClient(serviceUrl);
    30         // url为调用webService的wsdl地址
    31         QName name = new QName(nameSpaceUrl, methodName);
    32         // namespace是命名空间,methodName是方法名
    33         String xmlStr = param;
    34         // paramvalue为参数值
    35         Object[] objects;
    36         try {
    37             objects = client.invoke(name, xmlStr);
    38             return objects[0].toString().toString();
    39         } catch (Exception e) {
    40             e.printStackTrace();
    41         }
    42         return "";
    43     }
    44 }

  • 相关阅读:
    Luogu P3703 [SDOI2017]树点涂色
    好吧,又建了一个博客
    JDI tutorial (trace example)
    【译文】Java Logging
    openjdk 完全编译指南
    入门: 使用JNI 从C++代码中调用Java的静态方法
    使用JVMTI创建调试和监控代理
    【译文】 GC 安全点 和安全区域
    Java虚拟机 safepoints 初探
    NoClassDefFoundError vs ClassNotFoundException
  • 原文地址:https://www.cnblogs.com/lwl80/p/15915186.html
Copyright © 2020-2023  润新知