spring boot 使用 idea 整合 WebService(消费方)

第一步:将 webservice 接口的文件获取下来

图一

图二
在这里插入图片描述

从而获取到了相关文件

在这里插入图片描述

第二步:将 url 放到配置文件中

wspmis.endpoint=http://xxxx:80/ormrpc/services/WSPMISWebServiceFacade?wsdl

第三步:写好配置类

package com.cmft.gurp.da.basic.config.webservice;

import com.cmft.gurp.da.service.PropertyWSDL.WSPMISWebServiceFacadeSoapBindingStub;
import com.cmft.gurp.da.service.PropertyWSDL.WSPMISWebServiceFacadeSrvProxyServiceLocator;
import com.cmft.gurp.da.service.easanalysis.EASLoginProxyServiceLocator;
import com.cmft.gurp.da.service.easanalysis.EASLoginSoapBindingStub;
import com.cmft.gurp.da.service.impl.benchmarkinganalysis.JIUQIFinanceServiceLocator;
import com.cmft.gurp.da.service.impl.benchmarkinganalysis.JIUQIFinanceServiceSoapBindingStub;
import org.apache.axis.AxisFault;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.rpc.ServiceException;
import java.net.MalformedURLException;
import java.net.URL;

@Configuration
public class WebServiceConfig {

    @Value("${wspmis.endpoint}")
    private String wspmisEndpoint;

    @Bean
    public WSPMISWebServiceFacadeSrvProxyServiceLocator getWSPMISWebServiceFacadeSrvProxyServiceLocator() throws ServiceException {
        WSPMISWebServiceFacadeSrvProxyServiceLocator locator = new WSPMISWebServiceFacadeSrvProxyServiceLocator();
        locator.setEndpointAddress("WSPMISWebServiceFacade",wspmisEndpoint);
        return locator;
    }

    @Bean
    public WSPMISWebServiceFacadeSoapBindingStub getWSPMISWebServiceFacadeSoapBindingStub() throws MalformedURLException, ServiceException, AxisFault {
        WSPMISWebServiceFacadeSoapBindingStub bindingStub = new WSPMISWebServiceFacadeSoapBindingStub(new URL(wspmisEndpoint),getWSPMISWebServiceFacadeSrvProxyServiceLocator());
        return bindingStub;
    }

}

最后,使用

package com.cmft.gurp.da.service.impl.propertyanalysis;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.cmft.gurp.da.entity.benchmarkinganalysis.ResponseBody;
import com.cmft.gurp.da.entity.propertyanalysis.PCompanyInfo;
import com.cmft.gurp.da.mapper.property.CompanyListMapper;
import com.cmft.gurp.da.service.PropertyWSDL.WSPMISWebServiceFacadeSoapBindingStub;
import com.cmft.gurp.da.service.propertyanalysis.CompanyDataAccessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.xml.rpc.ServiceException;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Map;


@Service
@Slf4j
public class CompanyServiceImpl{

    @Autowired
    private WSPMISWebServiceFacadeSoapBindingStub benchmarkingStub;

    @Autowired
    private CompanyListMapper companyListMapper;


    private int getCompany(int size, int begin, int end,String queryTime,String startTime) {
     
        JSONObject inParam = new JSONObject();
        inParam.put("查询关键字","");
        inParam.put("用户编码","");
        inParam.put("时间点",queryTime);
        inParam.put("开始条目",begin);
        inParam.put("结束条目",end);
        try {
            String result = benchmarkingStub.getCompany(JSON.toJSONString(inParam),v);
            if (result.contains("数据为空") || result.isEmpty()){
                log.info("benchmarkingStub.getCompany返回的数据为空");
                return size;
            }
            ResponseBody<Map<String, String>> responseBody = JSON.parseObject(result, new TypeReference<ResponseBody<Map<String, String>>>() {
            });
            if (responseBody == null || responseBody.getData().isEmpty()) {
                log.warn("入参:"+JSON.toJSONString(inParam)+"-->The return value of benchmarkingStub.getCompanyList() is null!");
            }else {
                List<Map<String, String>> companyLists = responseBody.getData();
                size = companyLists.size();
                for (Map<String, String> companyList : companyLists) {
                
                }
            }
        } catch (Exception e) {
            log.info("异常->传入参数为:" + JSON.toJSONString(inParam) + "异常->" ,e);
        }
        return size;
    }

 

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Spring Boot可以使用JAX-WS或者Spring Web Services(Spring-WS)来调用SOAP Web Service接口,也可以使用RestTemplate来调用RESTful Web Service接口。 以下是使用Spring-WS调用SOAP Web Service接口的步骤: 1. 引入Spring-WS和JAXB相关依赖 ```xml <dependency> <groupId>org.springframework.ws</groupId> <artifactId>spring-ws-core</artifactId> <version>3.0.7.RELEASE</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-core</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId> <version>3.0.0</version> </dependency> ``` 2. 配置WebServiceTemplate 在配置类添加WebServiceTemplate的Bean,并设置WebServiceTemplate的Marshaller和Unmarshaller,这里使用Jaxb2Marshaller ```java @Configuration public class WebServiceConfig { @Bean public Jaxb2Marshaller marshaller() { Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); marshaller.setContextPath("com.example.webservice.demo.wsdl"); return marshaller; } @Bean public WebServiceTemplate webServiceTemplate() { WebServiceTemplate template = new WebServiceTemplate(); template.setMarshaller(marshaller()); template.setUnmarshaller(marshaller()); template.setDefaultUri("http://localhost:8080/ws"); return template; } } ``` 3. 调用WebService 使用WebServiceTemplate的marshalSendAndReceive法来发送SOAP请求并接收响应,示例代码如下: ```java @Autowired private WebServiceTemplate webServiceTemplate; public void callWebService() { GetCountryRequest request = new GetCountryRequest(); request.setName("Spain"); GetCountryResponse response = (GetCountryResponse) webServiceTemplate.marshalSendAndReceive(request); System.out.println(response.getCountry().getCapital()); } ``` 以上就是使用Spring-WS调用SOAP Web Service接口的步骤。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值