您的位置:首页 > 汽车 > 时评 > 网页上一页下一页代码_国家企业信息信用系统_朋友圈网络营销_百度站长中心

网页上一页下一页代码_国家企业信息信用系统_朋友圈网络营销_百度站长中心

2024/12/26 10:17:09 来源:https://blog.csdn.net/Gemini1995/article/details/143961816  浏览:    关键词:网页上一页下一页代码_国家企业信息信用系统_朋友圈网络营销_百度站长中心
网页上一页下一页代码_国家企业信息信用系统_朋友圈网络营销_百度站长中心

目标

暴露相关接口给第三方对接

接口

人员列表接口:支持按照姓名进行模糊搜索

服务端 项目

springBoot+mybatis-plus+webService

结构

在这里插入图片描述

WebServiceConfig

import org.gin.webservice.AdminService;
import org.springframework.context.annotation.Configuration;import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.xml.ws.Endpoint;@Configuration
public class WebServiceConfig {@Resourceprivate AdminService adminService;/*** 使用 JAX-WS Endpoint 发布服务*/@PostConstructpublic void publishEndpoint() {String address = "http://localhost:2334/ws/admin"; // 服务发布地址Endpoint.publish(address, adminService); // 发布服务}
}

AdminService

import org.gin.entity.MainAdmin;import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import java.util.List;@WebService(name = "AdminService",serviceName = "AdminService",endpointInterface = "org.gin.webservice.AdminService",targetNamespace = "http://webservice.gin.org/")
public interface AdminService {@WebMethodpublic List<MainAdmin> getAdmins(@WebParam(name = "name")String name);@WebMethodMainAdmin getAdminById(@WebParam(name = "id")Long id);}

AdminServiceImpl

@Slf4j
@Service
@WebService(name = "AdminService",serviceName = "AdminService",endpointInterface = "org.gin.webservice.AdminService",
targetNamespace = "http://webservice.gin.org/")
public class AdminServiceImpl implements AdminService {@Resourceprivate MainAdminMapper mainAdminMapper;@Overridepublic List<MainAdmin> getAdmins(String name) {log.info("name:" + name);return mainAdminMapper.selectList(Wrappers.lambdaQuery(MainAdmin.class).like(name != null && !name.isEmpty(), MainAdmin::getName, "%" + name + "%"));}@Overridepublic MainAdmin getAdminById(Long id) {return mainAdminMapper.selectById(id);}
}

请求

curl --location --request POST 'http://127.0.0.1:2334/ws/admin' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Content-Type: text/xml' \
--data-raw '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://webservice.gin.org/"><soapenv:Header/><soapenv:Body><ws:getAdmins><name>超级</name></ws:getAdmins></soapenv:Body>
</soapenv:Envelope>'

响应

在这里插入图片描述

客户端

结构

在这里插入图片描述

可使用wsimport工具生成webservice的调用代码

 wsimport -keep http://127.0.0.1:2334/ws/admin?wsdl

WebServiceClient

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.stereotype.Service;@Service
@Getter
@Slf4j
public class WebServiceClient {private final AdminService adminService;public WebServiceClient() {this.adminService =  (AdminService) callService("http://127.0.0.1:2334/ws/admin?wsdl",AdminService.class);;}/*** 调用服务,生成客户端的服务代理** @param address      WebService的URL* @param serviceClass 服务接口的Class* @return 服务代理对象*/private static Object callService(String address, Class<?> serviceClass) {JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();// 记录入站消息factory.getInInterceptors().add(new LoggingInInterceptor());// 记录出站消息factory.getOutInterceptors().add(new LoggingOutInterceptor());factory.setServiceClass(serviceClass);factory.setAddress(address);try {return factory.create();} catch (Exception e) {log.error("WebService调用失败: {}", e.getMessage(), e);throw new RuntimeException("无法创建服务代理", e);}}
}

AdminService


import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService; 
import javax.xml.ws.Action;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;/*** This class was generated by the JAX-WS RI.* JAX-WS RI 2.2.9-b130926.1035* Generated source version: 2.2* */
@WebService(name = "AdminService", targetNamespace = "http://webservice.gin.org/")
public interface AdminService {/*** * @param id* @return*     returns org.gin.webservice.MainAdmin*/@WebMethod@WebResult(targetNamespace = "")@RequestWrapper(localName = "getAdminById", targetNamespace = "http://webservice.gin.org/", className = "org.gin.webservice.GetAdminById")@ResponseWrapper(localName = "getAdminByIdResponse", targetNamespace = "http://webservice.gin.org/", className = "org.gin.webservice.GetAdminByIdResponse")@Action(input = "http://webservice.gin.org/AdminService/getAdminByIdRequest", output = "http://webservice.gin.org/AdminService/getAdminByIdResponse")public MainAdmin getAdminById(@WebParam(name = "id", targetNamespace = "")Long id);/*** * @param name* @return*     returns java.util.List<org.gin.webservice.MainAdmin>*/@WebMethod@WebResult(targetNamespace = "")@RequestWrapper(localName = "getAdmins", targetNamespace = "http://webservice.gin.org/", className = "org.gin.webservice.GetAdmins")@ResponseWrapper(localName = "getAdminsResponse", targetNamespace = "http://webservice.gin.org/", className = "org.gin.webservice.GetAdminsResponse")@Action(input = "http://webservice.gin.org/AdminService/getAdminsRequest", output = "http://webservice.gin.org/AdminService/getAdminsResponse")public List<MainAdmin> getAdmins(@WebParam(name = "name", targetNamespace = "")String name);}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com