From ed5768da1363742eee34c6c71db010099da6fad8 Mon Sep 17 00:00:00 2001
From: ludc <pUXmgxCf6A>
Date: 星期三, 17 五月 2023 21:55:07 +0800
Subject: [PATCH] 以及发布webservice接口功能搭建,将通通用接口移植过来

---
 Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/AttributeMapConfig.java  |   41 ++++++
 Source/UBCS/ubcs-service/ubcs-webservice/pom.xml                                                               |  113 ++++++++++++++++++
 Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/annotation/VciWebservice.java   |   36 ++++++
 Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/WsClientUtil.java               |   61 ++++++++++
 Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/VciCxfPublishConfig.java |   85 ++++++++++++++
 5 files changed, 336 insertions(+), 0 deletions(-)

diff --git a/Source/UBCS/ubcs-service/ubcs-webservice/pom.xml b/Source/UBCS/ubcs-service/ubcs-webservice/pom.xml
index e69de29..44f2496 100644
--- a/Source/UBCS/ubcs-service/ubcs-webservice/pom.xml
+++ b/Source/UBCS/ubcs-service/ubcs-webservice/pom.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>com.vci.ubcs</groupId>
+        <artifactId>ubcs-service</artifactId>
+        <version>3.0.1.RELEASE</version>
+    </parent>
+    <artifactId>ubcs-webservice</artifactId>
+    <name>${project.artifactId}</name>
+    <version>${bladex.project.version}</version>
+    <packaging>jar</packaging>
+
+    <modelVersion>4.0.0</modelVersion>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
+            <version>3.3.1</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-starter-logging</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>javax.validation</groupId>
+                    <artifactId>validation-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>javax.validation</groupId>
+            <artifactId>validation-api</artifactId>
+            <version>2.0.1.Final</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-core</artifactId>
+            <version>2.17.0</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.logging.log4j</groupId>
+                    <artifactId>log4j-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-api</artifactId>
+            <version>2.17.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-slf4j-impl</artifactId>
+            <version>2.17.0</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.logging.log4j</groupId>
+                    <artifactId>log4j-api</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.logging.log4j</groupId>
+                    <artifactId>log4j-core</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-jul</artifactId>
+            <version>2.17.0</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.apache.logging.log4j</groupId>
+                    <artifactId>log4j-api</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.logging.log4j</groupId>
+                    <artifactId>log4j-core</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>com.vci.ubcs</groupId>
+            <artifactId>ubcs-util-api</artifactId>
+            <version>3.0.1.RELEASE</version>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.spotify</groupId>
+                <artifactId>dockerfile-maven-plugin</artifactId>
+                <configuration>
+                    <username>${docker.username}</username>
+                    <password>${docker.password}</password>
+                    <repository>${docker.registry.url}/${docker.namespace}/${project.artifactId}</repository>
+                    <tag>${project.version}</tag>
+                    <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+                    <buildArgs>
+                        <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
+                    </buildArgs>
+                    <skip>false</skip>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-antrun-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git a/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/WsClientUtil.java b/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/WsClientUtil.java
index e69de29..19965ff 100644
--- a/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/WsClientUtil.java
+++ b/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/WsClientUtil.java
@@ -0,0 +1,61 @@
+/*
+package com.vci.ubcs.webservice;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.commons.lang3.StringUtils;
+
+public class WsClientUtil {
+
+    */
+/**
+     * axis2璋冪敤瀹㈡埛绔�
+     *
+     * @param url                   璇锋眰鏈嶅姟鍦板潃
+     * @param nameSpace             鍛藉悕绌洪棿
+     * @param soapAction soapAction
+     * @param method                鏂规硶鍚�
+     * @param paramName                鍙傛暟鍚嶇О
+     * @param sendData                璇锋眰鎶ユ枃
+     * @param timeOutInMilliSeconds 瓒呮椂鏃堕棿
+     * @return String 绫诲瀷鐨勫搷搴旀姤鏂�
+     *//*
+
+    public static String sendMsg(String url, String nameSpace,String soapAction, String method, String paramName, String sendData, long timeOutInMilliSeconds) throws Exception {
+        ServiceClient serviceClient = new ServiceClient();
+        Options option = new Options();
+        option.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+        option.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
+        // 鍊间负targetNamespace+methodName
+        if(StringUtils.isEmpty(soapAction)){
+            soapAction = nameSpace+method;
+        }
+        option.setAction(soapAction);
+
+        EndpointReference epfs = new EndpointReference(url);
+        option.setTo(epfs);
+        serviceClient.setOptions(option);
+
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMNamespace namespaceOM = fac.createOMNamespace(nameSpace, "");
+        OMElement element = fac.createOMElement(method, namespaceOM);
+        OMElement theCityCode = fac.createOMElement(paramName, namespaceOM);
+        theCityCode.setText(sendData);
+        element.addChild(theCityCode);
+
+
+        OMElement resultOM = serviceClient.sendReceive(element);
+
+        String result = resultOM.getFirstElement().getText();
+        return result;
+    }
+}
+*/
diff --git a/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/annotation/VciWebservice.java b/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/annotation/VciWebservice.java
index e69de29..af6a79f 100644
--- a/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/annotation/VciWebservice.java
+++ b/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/annotation/VciWebservice.java
@@ -0,0 +1,36 @@
+package com.vci.ubcs.webservice.annotation;
+
+import org.springframework.core.annotation.AliasFor;
+import org.springframework.stereotype.Component;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * webservice鐨勫疄鐜扮被
+ * @author weidy
+ * @date 2022-08-27
+ */
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Component
+public @interface VciWebservice {
+
+	/**
+	 * bean鐨勫悕绉�
+	 * @return
+	 */
+	@AliasFor(
+		annotation = Component.class
+	)
+	String value() default "";
+
+	/**
+	 * 璺緞锛岄粯璁ょ瓑浜庡綋鍓峛ean鐨勫悕瀛�
+	 * @return 璺緞
+	 */
+	String path() default "";
+
+}
diff --git a/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/AttributeMapConfig.java b/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/AttributeMapConfig.java
index e69de29..89d1203 100644
--- a/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/AttributeMapConfig.java
+++ b/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/AttributeMapConfig.java
@@ -0,0 +1,41 @@
+package com.vci.ubcs.webservice.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+
+@ConfigurationProperties(prefix="attrconfig")
+@Component
+public class AttributeMapConfig {
+    private Map<String,String> system_attrmap;
+
+    /****
+     * 鏃犱汉鏈轰富鏁版嵁涓嶦RP闆嗘垚瀛楁鍊艰浆鎹�
+     */
+    private Map<String,String> attrKey1ToKey2Map;
+    public Map<String, String> getSystem_attrmap() {
+        return system_attrmap;
+    }
+    public void setSystem_attrmap(Map<String, String> system_attrmap) {
+        this.system_attrmap = system_attrmap;
+    }
+
+
+    public Map<String, String> getAttrKey1ToKey2Map() {
+        return attrKey1ToKey2Map;
+    }
+
+    public void setAttrKey1ToKey2Map(Map<String, String> attrKey1ToKey2Map) {
+        this.attrKey1ToKey2Map = attrKey1ToKey2Map;
+    }
+
+	@Override
+	public String toString() {
+		return "AttributeMapConfig{" +
+			"system_attrmap=" + system_attrmap +
+			", attrKey1ToKey2Map=" + attrKey1ToKey2Map +
+			'}';
+	}
+}
diff --git a/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/VciCxfPublishConfig.java b/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/VciCxfPublishConfig.java
index e69de29..0825566 100644
--- a/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/VciCxfPublishConfig.java
+++ b/Source/UBCS/ubcs-service/ubcs-webservice/src/main/java/com/vci/ubcs/webservice/config/VciCxfPublishConfig.java
@@ -0,0 +1,85 @@
+package com.vci.ubcs.webservice.config;
+
+import com.alibaba.cloud.commons.lang.StringUtils;
+import com.vci.ubcs.starter.web.util.ApplicationContextProvider;
+import com.vci.ubcs.starter.web.util.VciBaseUtil;
+import com.vci.ubcs.webservice.annotation.VciWebservice;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.cxf.Bus;
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.springframework.aop.support.AopUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.util.CollectionUtils;
+
+import java.util.Map;
+
+/**
+ * 鍙戝竷鏈嶅姟绫�
+ * @author weidy
+ * @date 2020/3/27
+ */
+@Configuration
+@Slf4j
+public class VciCxfPublishConfig {
+
+    /**
+     * 娉ㄥ叆cxf鐨刡us
+     */
+    @Autowired(required = false)
+    private Bus bus;
+
+
+    /**
+     * 鍙戝竷绔欑偣鏈嶅姟
+     * @return 绔欑偣鏈嶅姟
+     */
+    @Bean
+    public void autoPushCxf(){
+		log.info("寮�濮嬭繘琛岃嚜鍔ㄥ彂甯僿ebService鎺ュ彛");
+		Map<String, Object> beansWithAnnotation =   ApplicationContextProvider.getApplicationContext().getBeansWithAnnotation(VciWebservice.class);
+        if(!CollectionUtils.isEmpty(beansWithAnnotation)){
+            //鎵捐繖浜沚ean鐨�
+            beansWithAnnotation.forEach((beanName,bean)->{
+                Class<?> targetClass = AopUtils.getTargetClass(bean);
+                VciWebservice annotation = targetClass.getDeclaredAnnotation(VciWebservice.class);
+                if(annotation == null){
+                    targetClass.getAnnotation(VciWebservice.class);
+                }
+                if(annotation!=null){
+                    //鎴戜滑鍘绘壘璺緞鍜屽悕绉�
+                    String name = annotation.value();
+                    if(StringUtils.isBlank(name)){
+                        name = VciBaseUtil.toLowForFirst(targetClass.getSimpleName()).replace(".class","");
+                    }
+                    String path = annotation.path();
+                    if(StringUtils.isBlank(path)){
+                        path = "/" + name;
+                    }
+                    //娉ㄥ唽
+                    EndpointImpl endpoint = new EndpointImpl(bus,bean);
+                    endpoint.publish(path);
+					log.info(String.format("鍙戝竷鎺ュ彛鍦板潃锛歔%s]", path));
+                    registerBean(endpoint,name + "_EndPoint");
+                }
+            });
+        }
+		log.info("weBservice鎺ュ彛鑷姩鍙戝竷缁撴潫");
+    }
+
+    /**
+     *  鍔ㄦ�佹敞鍏ean
+     * @param singletonObject 娉ㄥ叆瀵硅薄
+     * @param beanName bean鍚嶇О
+     */
+    public  void registerBean(Object singletonObject,String beanName) {
+
+        //鑾峰彇BeanFactory
+        DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) ApplicationContextProvider.getApplicationContext().getAutowireCapableBeanFactory();
+
+        //鍔ㄦ�佹敞鍐宐ean.
+        defaultListableBeanFactory.registerSingleton(beanName, singletonObject);
+    }
+}

--
Gitblit v1.9.3