Java Springboot项目调用wsdl 接口

Java Springboot项目

 

如下函数是一个post接口,它用于接收xml格式字符串,并将该串发送至wsdlUrl

    @RequestMapping(value="/gggg", method = RequestMethod.POST)
    public String test3(@RequestBody String xmlString){
    //public String test2(@RequestParam(value ="yy", required = true) String yy){
    	System.out.println(xmlString);
		String wsdlUrl ="https://220.249.107.184/GYSServer/services/btmpSupplierInterface?wsdl";
		//看具体响应的WSDL中的namespace
		String nameSpaceUri ="http://service.btmp.com/";    
		Service service = new Service();
		Call call;
		String returnvalue = "";
		try {
			call = (Call)service.createCall();
			call.setTargetEndpointAddress(wsdlUrl);
			 //设置operation 名称,
			call.setOperationName(new QName(nameSpaceUri, "getDCGH"));
			call.addParameter("gysbm", org.apache.axis.Constants.XSD_STRING,ParameterMode.IN);
			call.addParameter("authdata",org.apache.axis.Constants.XSD_STRING,ParameterMode.IN);
			call.addParameter("xmlString",org.apache.axis.Constants.XSD_STRING,ParameterMode.IN);
			//设置返回类型为对象数组
			call.setReturnClass(Object[].class);
			SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
			String pwd = getMd5_16("11"+"11"+sf.format(new Date()));//账户&密码&当天日期
			System.out.println(sf.format(new Date()));
			System.out.println("pwd=" + pwd);
			Object[] objs = (Object[]) call.invoke(new Object[]{"M107530000",pwd, xmlString });//M107530000
			
			//System.out.println("objs="+objs);
			
			System.out.println((String)objs[0]);
			System.out.println((String)objs[1]);
			returnvalue = (String)objs[0];
			
			String result = (String)objs[2];
			
			System.out.println("result="+result);
		} catch (ServiceException e1) {
			
			e1.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
        return returnvalue;
    }

 

使用Axis2,需要在springboot中进行如下依赖配置。

//声明:该模块来源于https://blog.csdn.net/qq_36688143/java/article/details/86527357

1、在当前项目的pom.xml中添加下述依赖

 

<!-- axis 1.4 jar start -->

        <dependency>

            <groupId>org.apache.axis</groupId>

            <artifactId>axis</artifactId>

            <version>1.4</version>

        </dependency>

        <dependency>

            <groupId>commons-discovery</groupId>

            <artifactId>commons-discovery</artifactId>

            <version>0.2</version>

            <exclusions>

                <exclusion>

                    <groupId>commons-logging</groupId>

                    <artifactId>commons-logging</artifactId>

                </exclusion>

            </exclusions>

        </dependency>

        <dependency>

            <groupId>org.apache.axis</groupId>

            <artifactId>axis-jaxrpc</artifactId>

            <version>1.4</version>

        </dependency>

        <dependency>

            <groupId>org.apache.axis</groupId>

            <artifactId>axis-saaj</artifactId>

            <version>1.4</version>

        </dependency>

        <dependency>

            <groupId>wsdl4j</groupId>

            <artifactId>wsdl4j</artifactId>

            <version>1.4</version>

        </dependency>

        <!-- axis 1.4 jar end -->

另外,可能还需要添加mail和httpclient依赖

		<!-- mail.jar和activation.jar依赖 -->
		<dependency>
		    <groupId>javax.activation</groupId>
		    <artifactId>activation</artifactId>
		    <version>1.1.1</version>
		</dependency>
		<!-- 邮件start -->
		<dependency>
			<groupId>javax.mail</groupId>
			<artifactId>mail</artifactId>
			<version>1.4.7</version>
		</dependency>
		<!-- 邮件end -->
		
		<!-- httpclient 依赖 -->
		<dependency>
		   <groupId>org.apache.httpcomponents</groupId>
		   <artifactId>httpclient</artifactId>
		   <version>4.5.6</version>
		</dependency>

 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值