商城网站建设推广,全文wordpress主题,室内设计学习,python爬虫源码下载这几天wms对接lbpm系统#xff0c;给我的接口是webservice的#xff0c;老实说#xff0c;这个技术很早#xff0c;奈何人家只支持这个。 环境说明#xff1a;JDK17 springboot2.6.6。网上很多教程是基于jdk8的#xff0c;所以很多在17上面跑不起来。折腾两天#xff0c…这几天wms对接lbpm系统给我的接口是webservice的老实说这个技术很早奈何人家只支持这个。 环境说明JDK17 springboot2.6.6。网上很多教程是基于jdk8的所以很多在17上面跑不起来。折腾两天直接给答案。 因为springboot版本不是3.0用不了cxf-spring-boot-starter-jaxws 的4版本会各种稀奇报错或许是我姿势不对就没继续折腾了。如果你是springboot3请用4版本
动态代理调用的时候需要一个参数一个参数排列传不是一个对象。
pom文件需要引入版本按照这个测试通过的版本。
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web-services/artifactId/dependencydependencygroupIdorg.apache.cxf/groupIdartifactIdcxf-spring-boot-starter-jaxws/artifactIdversion3.5.6/version/dependencydependencygroupIdcom.sun.xml.bind/groupIdartifactIdjaxb-xjc/artifactIdversion2.3.8/version/dependencyproperties配置
#这个是webservice访问的路径
#http://localhost:8899/webservice?wsdl
cxf.path/webservice
cxf.servlet.enabledtrue
cxf.servlet.init.services-list-pathwebservice配置文件 import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;Configuration
public class WebServiceConfig {Autowiredprivate Bus bus;Beanpublic EndpointImpl endpoint() {EndpointImpl endpoint new EndpointImpl(bus, new WebService());endpoint.publish(/api);return endpoint;}
}
服务端写法
package com.zxy.mom.product.wms2.web.bpm;import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import java.util.HashMap;
import java.util.Map;/*** LBPM webservice调用* 将接口信息注册到接口平台上soap接口调用接口平台配置实现透传*/
Component
javax.jws.WebService(serviceName WebService, targetNamespace http://product.mom.zxy.com/)
public class WebService {private final static Logger logger LoggerFactory.getLogger(WebService.class);Resourceprivate ProjectServiceImp projectServiceImp;/*** 获取指定异构系统的表单模板集合** param sysId 异构系统标识此为异构系统配置中的唯一标识sysId* param language 语种默认为空即中文* return 表单模板集合。返回值示例[{systemId:系统标识,modelId:模块标识,modelName:* 模块名称* ,templateFormId:表单模板标识,templateFormName:表单模板名,formUrl* :表单Url}]*/WebMethod(operationName getTemplateFormList)WebResult(targetNamespace http://product.mom.zxy.com/)public String getTemplateFormList(WebParam(name sysId, targetNamespace ) String sysId,WebParam(name language, targetNamespace ) String language) {MapString, String paramMap new HashMap(2);paramMap.put(sysId, sysId);paramMap.put(language, language);return projectServiceImp.getTemplateFormList(sysId, language);}/*** 获取指定异构系统的指定模块指定表单模板的字段元数据描述集合** param sysId 异构系统标识此为异构系统配置中的唯一标识sysId* param modelId 异构系统模块ID* param templateFormId 异构系统表单模板ID* param language 语种默认为空即中文* return 字段元数据描述集合。返回值示例[{fieldId:字段ID,fieldName:字段名,type:字段类型* }]*/WebMethod(operationName getFormFieldList)WebResult(targetNamespace http://product.mom.zxy.com/)public String getFormFieldList(WebParam(name sysId) String sysId,WebParam(name modelId) String modelId,WebParam(name templateFormId) String templateFormId,WebParam(name language) String language) {MapString, String paramMap new HashMap(4);paramMap.put(sysId, sysId);paramMap.put(modelId, modelId);paramMap.put(templateFormId, templateFormId);paramMap.put(language, language);return projectServiceImp.getFormFieldList(sysId, modelId, templateFormId, language);}/*** 查询流程事件调用的业务函数信息** param sysId 异构系统标识此为异构系统配置中的唯一标识sysId* param modelId 异构系统模块ID* param templateFormId 异构系统表单模板ID* param language 语种默认为空即中文* return 业务函数信息集。返回值示例[{{functionId:函数标识,functionName:函数标识,functionDes* :函数描述}]*/WebMethod(operationName getMethodInfo)WebResult(targetNamespace http://product.mom.zxy.com/)public String getMethodInfo(WebParam(name sysId) String sysId,WebParam(name modelId) String modelId,WebParam(name templateFormId) String templateFormId,WebParam(name language) String language) {MapString, String paramMap new HashMap(4);paramMap.put(sysId, sysId);paramMap.put(modelId, modelId);paramMap.put(templateFormId, templateFormId);paramMap.put(language, language);return projectServiceImp.getMethodInfo(sysId, modelId, templateFormId, language);}/*** 获取异构系统指定表单实例的指定字段的值** param sysId 异构系统标识此为异构系统配置中的唯一标识fdCode* param modelId 异构系统模块ID* param templateFormId 异构系统表单模板ID* param formInstanceId 异构系统表单实例ID* param fieldIds 表单字段ID集多值以逗号分隔* param language 语种默认为空即中文* return 指定字段的值集合。返回值示例[{fieldId:字段ID,fieldValue:字段值}]*/WebMethod(operationName getFormFieldValueList)WebResult(targetNamespace http://product.mom.zxy.com/)public String getFormFieldValueList(WebParam(name sysId) String sysId,WebParam(name modelId) String modelId,WebParam(name templateFormId) String templateFormId,WebParam(name formInstanceId) String formInstanceId,WebParam(name fieldIds) String fieldIds,WebParam(name language) String language) {MapString, String paramMap new HashMap(6);paramMap.put(sysId, sysId);paramMap.put(modelId, modelId);paramMap.put(templateFormId, templateFormId);paramMap.put(formInstanceId, formInstanceId);paramMap.put(fieldIds, fieldIds);paramMap.put(language, language);return projectServiceImp.getFormFieldValueList(sysId, modelId, templateFormId, formInstanceId, fieldIds, language);}/*** 执行指定函数的业务逻辑** param formId 异构系统表单信息。格式{sysId:异构系统标识,modelId:模块ID,* templateFormId:表单模板ID, formInstanceId:表单实例ID}* param functionId 函数ID* param processData 流程运行时信息。格式暂定。* param language 语种默认为空即中文* return 是否执行成功。返回值示例T 或 F:错误信息*/WebMethod(operationName doMethodProcess)WebResult(targetNamespace http://product.mom.zxy.com/)public String doMethodProcess(WebParam(name formId) String formId,WebParam(name functionId) String functionId,WebParam(name processData) String processData,WebParam(name language) String language) {MapString, String paramMap new HashMap(4);paramMap.put(formId, formId);paramMap.put(functionId, functionId);paramMap.put(processData, processData);paramMap.put(language, language);return projectServiceImp.doMethodProcess(formId, functionId, processData, language);}
}
客户端写法用动态代理的方式不然类太多了
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;Configuration
public class WsClientConfig {private final static Logger logger LoggerFactory.getLogger(WsClientConfig.class);Value(${wms.bpmUrl:http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl})private String wsdlUrl;Bean(LbpmWsClient)public Client client() {// 创建动态客户端JaxWsDynamicClientFactory clientFactory JaxWsDynamicClientFactory.newInstance();//根据WebServices接口地址创建clientClient client clientFactory.createClient(wsdlUrl);HTTPConduit conduit (HTTPConduit) client.getConduit();HTTPClientPolicy policy new HTTPClientPolicy();policy.setAllowChunking(false);// 连接服务器超时时间 10秒policy.setConnectionTimeout(10000);// 等待服务器响应超时时间 20秒policy.setReceiveTimeout(20000);conduit.setClient(policy);return client;}
} import com.zxy.mom.product.wms2.web.bpm.entity.*;
import com.zxy.mom.sdk.common.exception.ConditionException;
import com.zxy.mom.sdk.common.util.JsonUtil;
import org.apache.cxf.endpoint.Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;/*** 调用bpm 客户端*/
Service
public class WebClientImpl {private final static Logger log LoggerFactory.getLogger(WsClientConfig.class);//注入Autowired(required false)Qualifier(LbpmWsClient)private Client client;/*** 统一处理方法*/public String handler(String method, Object... obj) {try {//invoke(接口中的方法名称方法的参数)Object[] objects client.invoke(method, obj);if (objects ! null objects.length 0) {return handlerBody(objects);}} catch (Exception e) {log.error(抛出了异常{}, e.getMessage());throw new ConditionException(webservice调用异常 e.getMessage());}return null;}/*** 处理响应报文*/public String handlerBody(Object[] objects) {return JsonUtil.toJSONString(objects);}/*** test*/public String test(String qq) {return handler(qqCheckOnline, qq);}/*** 创建*/public String createProcess(CreateProcess createProcess) {return handler(CreateProcess,createProcess.getFlowTemplateId(),createProcess.getFormId(),createProcess.getCreator(),createProcess.getExParam(),createProcess.getLanguage());}/*** 审批*/public String approveProcess(ApproveProcess approveProcess) {return handler(ApproveProcess,approveProcess.getFormId(),approveProcess.getProcessId(),approveProcess.getHandler(),approveProcess.getFormData(),approveProcess.getProcessParam(),approveProcess.getLanguage());}/*** 可审批*/public String canApprovalProcess(CanApprovalProcess canApprovalProcess) {return handler(CanApprovalProcess,canApprovalProcess.getFormId(),canApprovalProcess.getActionUid(),canApprovalProcess.getLanguage());}/*** 当前节点的信息*/public String getCurrentNodesInfo(GetCurrentNodesInfo getCurrentNodesInfo) {return handler(GetCurrentNodesInfo,getCurrentNodesInfo.getFormId(),getCurrentNodesInfo.getProcessId(),getCurrentNodesInfo.getLanguage());}/*** 当前用户操作集*/public String getOperationList(GetOperationList getOperationList) {return handler(GetOperationList,getOperationList.getFormId(),getOperationList.getProcessId(),getOperationList.getActionUid(),getOperationList.getLanguage());}/*** 当前处理人列表*/public String getApproverList(GetApproverList getApproverList) {return handler(GetApproverList,getApproverList.getFormId(),getApproverList.getProcessId(),getApproverList.getLanguage());}
}
错误提示
Caused by: java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC这个需要引入jaxb-xjc。如果这个版本不行多试验几个jdk8以后就需要这个jdk17我用这个好了不行多试验几个版本 dependencygroupIdcom.sun.xml.bind/groupIdartifactIdjaxb-xjc/artifactIdversion2.3.8/version/dependency