mirror of
https://github.com/Weasley-J/chinaport-data-signature.git
synced 2024-04-21 12:41:53 +00:00
[feature] Add reactor 'WebClient' to report data
This commit is contained in:
@@ -78,6 +78,11 @@
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package cn.alphahub.eport.signature.base.exception;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* The eport web client exception
|
||||
*
|
||||
* @author weasley
|
||||
* @version 1.1.0
|
||||
*/
|
||||
@Getter
|
||||
public class EportWebClientException extends RuntimeException {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 异常消息
|
||||
*/
|
||||
private String msg;
|
||||
/**
|
||||
* 错误码, 默认: 500
|
||||
*/
|
||||
private int code = 500;
|
||||
|
||||
public EportWebClientException(String msg) {
|
||||
super(msg);
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public EportWebClientException(String msg, Throwable e) {
|
||||
super(msg, e);
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public EportWebClientException(String msg, int code, Throwable e) {
|
||||
super(msg, e);
|
||||
this.msg = msg;
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
package cn.alphahub.eport.signature.config;
|
||||
|
||||
import cn.alphahub.eport.signature.base.exception.EportWebClientException;
|
||||
import cn.alphahub.eport.signature.core.web.EportCebMessageHttpClient;
|
||||
import cn.alphahub.eport.signature.core.web.EportCustoms179HttpClient;
|
||||
import cn.alphahub.eport.signature.core.web.WebfluxDemoHttpClient;
|
||||
import cn.alphahub.eport.signature.support.OriginalPropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.tomcat.util.codec.binary.Base64;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||
import org.springframework.web.reactive.function.client.ClientRequest;
|
||||
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
|
||||
import org.springframework.web.reactive.function.client.ExchangeStrategies;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
|
||||
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static cn.alphahub.eport.signature.core.ChinaEportReportClient.EPORT_CEBMESSAGE_SERVER_ENCODE;
|
||||
import static cn.alphahub.eport.signature.core.ChinaEportReportClient.REPORT_PROD_ENV_179_URL_ENCODE;
|
||||
|
||||
/**
|
||||
* The WebClient Configuration
|
||||
*
|
||||
* @author weasley
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({Customs179Properties.class, ChinaEportProperties.class})
|
||||
public class WebClientConfiguration {
|
||||
public static final ThreadLocal<Consumer<HttpHeaders>> HTTP_HEADERS = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* @return A proxy bean of EportCebMessageHttpClient
|
||||
*/
|
||||
@Bean
|
||||
public EportCebMessageHttpClient eportCebMessageHttpClient(ObjectMapper objectMapper, ChinaEportProperties chinaEportProperties) {
|
||||
WebClient webClient = WebClient.builder()
|
||||
.exchangeStrategies(customExchangeStrategies(objectMapper))
|
||||
.filter(((request, next) -> next.exchange(Objects.requireNonNull(injectHeader(request).block()))))
|
||||
.filters(exchangeFilters -> {
|
||||
exchangeFilters.add(logRequest());
|
||||
exchangeFilters.add(logResponse());
|
||||
})
|
||||
.defaultStatusHandler(HttpStatusCode::isError, resp -> Mono.just(new EportWebClientException("Web Client 调用发生异常!")))
|
||||
.baseUrl(StringUtils.defaultIfBlank(chinaEportProperties.getServer(), new String(Base64.decodeBase64(EPORT_CEBMESSAGE_SERVER_ENCODE))))
|
||||
.build();
|
||||
HttpServiceProxyFactory httpServiceProxyFactory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(webClient))
|
||||
.build();
|
||||
return httpServiceProxyFactory.createClient(EportCebMessageHttpClient.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return A proxy bean of EportCustoms179HttpClient
|
||||
*/
|
||||
@Bean
|
||||
public EportCustoms179HttpClient eportCustoms179HttpClient(ObjectMapper objectMapper, Customs179Properties customs179Properties) {
|
||||
WebClient webClient = WebClient.builder()
|
||||
.exchangeStrategies(ExchangeStrategies.builder().codecs(configurer -> {
|
||||
configurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(enhanceSourceMapper(objectMapper)));
|
||||
}).build())
|
||||
.filters(exchangeFilters -> {
|
||||
exchangeFilters.add(((request, next) -> next.exchange(Objects.requireNonNull(injectHeader(request).block()))));
|
||||
exchangeFilters.add(logRequest());
|
||||
exchangeFilters.add(logResponse());
|
||||
})
|
||||
.defaultStatusHandler(HttpStatusCode::isError, resp -> Mono.just(new EportWebClientException("Web Client 调用发生异常!")))
|
||||
.baseUrl(StringUtils.defaultIfBlank(customs179Properties.getServer(), new String(Base64.decodeBase64(REPORT_PROD_ENV_179_URL_ENCODE))))
|
||||
.build();
|
||||
HttpServiceProxyFactory httpServiceProxyFactory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(webClient)).build();
|
||||
return httpServiceProxyFactory.createClient(EportCustoms179HttpClient.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A proxy bean of WebfluxDemoHttpClient
|
||||
*/
|
||||
@Bean
|
||||
public WebfluxDemoHttpClient webfluxDemoHttpClient(ObjectMapper objectMapper) {
|
||||
WebClient webClient = WebClient.builder()
|
||||
.exchangeStrategies(customExchangeStrategies(objectMapper))
|
||||
.filters(exchangeFilters -> {
|
||||
exchangeFilters.add(((request, next) -> next.exchange(Objects.requireNonNull(injectHeader(request).block()))));
|
||||
exchangeFilters.add(logRequest());
|
||||
exchangeFilters.add(logResponse());
|
||||
})
|
||||
.defaultStatusHandler(HttpStatusCode::isError, resp -> Mono.just(new EportWebClientException("Web Client 调用发生异常!")))
|
||||
.baseUrl("http://127.0.0.1:8080")
|
||||
.build();
|
||||
WebClientAdapter clientAdapter = WebClientAdapter.forClient(webClient);
|
||||
HttpServiceProxyFactory httpServiceProxyFactory = HttpServiceProxyFactory.builder(clientAdapter).build();
|
||||
return httpServiceProxyFactory.createClient(WebfluxDemoHttpClient.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* To inject headers
|
||||
*/
|
||||
public Mono<ClientRequest> injectHeader(final ClientRequest clientRequest) {
|
||||
if (null != HTTP_HEADERS.get()) {
|
||||
Mono<ClientRequest> clientRequestMono = Mono.just(ClientRequest.from(clientRequest)
|
||||
.headers(HTTP_HEADERS.get())
|
||||
.build());
|
||||
clearHttpHeaders();
|
||||
return clientRequestMono;
|
||||
}
|
||||
return Mono.just(ClientRequest.from(clientRequest)
|
||||
.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear Http Headers
|
||||
*/
|
||||
public void clearHttpHeaders() {
|
||||
if (null != HTTP_HEADERS.get()) {
|
||||
HTTP_HEADERS.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom exchange strategies
|
||||
*/
|
||||
public ExchangeStrategies customExchangeStrategies(ObjectMapper objectMapper) {
|
||||
return ExchangeStrategies.builder()
|
||||
.codecs(configurer -> {
|
||||
configurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(enhanceSourceMapper(objectMapper)));
|
||||
}).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* To enhance mapper
|
||||
*/
|
||||
private ObjectMapper enhanceSourceMapper(ObjectMapper objectMapper) {
|
||||
ObjectMapper enhanceMapper = objectMapper.copy();
|
||||
enhanceMapper.setPropertyNamingStrategy(new OriginalPropertyNamingStrategy());
|
||||
return enhanceMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* log web request
|
||||
*/
|
||||
private ExchangeFilterFunction logRequest() {
|
||||
return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("Request URL: " + clientRequest.url());
|
||||
log.info("Request Method: " + clientRequest.method());
|
||||
log.info("Request Headers: " + clientRequest.headers());
|
||||
if (clientRequest.method() == HttpMethod.POST || clientRequest.method() == HttpMethod.PUT) {
|
||||
log.info("Request Body: " + clientRequest.body());
|
||||
}
|
||||
}
|
||||
return Mono.just(clientRequest);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* log web response
|
||||
*/
|
||||
private ExchangeFilterFunction logResponse() {
|
||||
return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("Response status: {}", clientResponse.statusCode());
|
||||
log.info("Response headers: {}", clientResponse.headers().asHttpHeaders());
|
||||
}
|
||||
return Mono.just(clientResponse);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+3
-2
@@ -8,6 +8,7 @@ import cn.alphahub.eport.signature.entity.SignRequest;
|
||||
import cn.alphahub.eport.signature.entity.SignResult;
|
||||
import cn.alphahub.eport.signature.support.CommandClient;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
@@ -44,7 +45,7 @@ public class EportTestController {
|
||||
* @response {"message":"操作成功","success":true,"timestamp":"2023-07-31 17:42:58","code":200,"data":{"success":true,"certNo":"03000000000cde6f","x509Certificate":"MIIEoDCCBESgAwIBAgIIAwAAAAAM3m8wDAYIKoEcz1UBg3UFADCBmDELMAkGA1UEBhMCQ04xDzANBgNVBAgMBuWMl+S6rDEPMA0GA1UEBwwG5YyX5LqsMRswGQYDVQQKDBLkuK3lm73nlLXlrZDlj6PlsrgxGzAZBgNVBAsMEuivgeS5pueuoeeQhuS4reW/gzEtMCsGA1UEAwwk5Lit5Zu955S15a2Q5Lia5Yqh6K+B5Lmm566h55CG5Lit5b+DMB4XDTIzMDMyOTAwMDAwMFoXDTMzMDMyOTAwMDAwMFowVjELMAkGA1UEBhMCQ04xMzAxBgNVBAsMKua1t+WNl+ecgeiNo+iqiei/m+WHuuWPo+i0uOaYk+aciemZkOWFrOWPuDESMBAGA1UEAwwJ5p2o5aaC6YeRMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE0vOQmplAr9igPZrA8F1msqnFd0U++6G6NhG5rNuIUWft0BwQn7eSJkt5/fvSSoe7pUg2/awHUWPnzkeeQc7oVqOCArUwggKxMBEGCWCGSAGG+EIBAQQEAwIFoDAOBgNVHQ8BAf8EBAMCBsAwCQYDVR0TBAIwADApBgNVHSUEIjAgBggrBgEFBQcDAgYIKwYBBQUHAwQGCisGAQQBgjcUAgIwHwYDVR0jBBgwFoAURCQxt0wEvoAVXmuo4N1bjKXTh0UwHQYDVR0OBBYEFAytGob5L0WqhOCZ5l6Lf2jUdNrAMGgGA1UdIARhMF8wXQYEVR0gADBVMFMGCCsGAQUFBwIBFkdodHRwczovL3d3dy5jaGluYXBvcnQuZ292LmNuL3RjbXNmaWxlL3UvY21zL3d3dy8yMDIyMDQvMTIxMzI5NDh4dDZwLnBkZjB/BgNVHR8EeDB2MHSgcqBwhm5sZGFwOi8vbGRhcC5jaGluYXBvcnQuZ292LmNuOjM4OS9jbj1jcmwwMzAwMDAsb3U9Y3JsMDAsb3U9Y3JsLGM9Y24/Y2VydGlmaWNhdGVSZXZvY2F0aW9uTGlzdD9iYXNlP2NuPWNybDAzMDAwMDA+BggrBgEFBQcBAQQyMDAwLgYIKwYBBQUHMAGGImh0dHA6Ly9vY3NwLmNoaW5hcG9ydC5nb3YuY246ODgwMC8wOgYKKwYBBAGpQ2QFAQQsDCrmtbfljZfnnIHojaPoqonov5vlh7rlj6PotLjmmJPmnInpmZDlhazlj7gwEgYKKwYBBAGpQ2QFAwQEDAIwMTAiBgorBgEEAalDZAUIBBQMEjUxMjMyNDE5NjQxMDE3Mjk3WDAgBgorBgEEAalDZAUJBBIMEDAzLUpKMEc5MDAyMjA3NTIwGQYKKwYBBAGpQ2QFCwQLDAlNQTVUTkZHWTkwEgYKKwYBBAGpQ2QFDAQEDAIwMDASBgorBgEEAalDZAIBBAQMAjEyMBIGCisGAQQBqUNkAgQEBAwCMTQwDAYIKoEcz1UBg3UFAANIADBFAiBM4OVAc8aaCZU4XFfcVMkC7bWIIenRnPLxrnwVeYO3CQIhANQ767YIurkJCoLtwyqQPbUZe/+3BjGZcIWqB1mAl9T+","digestValue":"/uy5whbEnIhnrSkF7hSAJNm8ISI=","signatureValue":"lziAtii3Ibn4UaHMAZ5MI90PLlQvn8Qm7m06gjRM/TcCI5pCtCbBGsZ+UoMmjbSjk4KP90wugL5DV5PXKVwYlA==","signatureNode":"<ds:SignedInfo xmlns:ceb=\"http://www.chinaport.gov.cn/ceb\" xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><ds:CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sm2-sm3\"></ds:SignatureMethod><ds:Reference URI=\"\"><ds:Transforms><ds:Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"></ds:DigestMethod><ds:DigestValue>/uy5whbEnIhnrSkF7hSAJNm8ISI=</ds:DigestValue></ds:Reference></ds:SignedInfo>"}}
|
||||
*/
|
||||
@GetMapping("/cebmessage/signature")
|
||||
public Result<SignResult> signCebMessage() {
|
||||
public Result<SignResult> signCebMessage(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
|
||||
@SuppressWarnings({"all"}) String sourceXml = "<ceb:CEB621Message xmlns:ceb=\"http://www.chinaport.gov.cn/ceb\" guid=\"CEB621_HNZB_FXJK_20220208175054_0035\" version=\"v1.0\">\n" +
|
||||
" <ceb:Inventory>\n" +
|
||||
" <ceb:InventoryHead>\n" +
|
||||
@@ -137,7 +138,7 @@ public class EportTestController {
|
||||
* }
|
||||
*/
|
||||
@GetMapping("/179/signature")
|
||||
public Result<SignResult> sign179Report() {
|
||||
public Result<SignResult> sign179Report(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
|
||||
String sign179String = "\"sessionID\":\"ad2254-8hewyf32-55616249\"||\"payExchangeInfoHead\":\"{\"guid\":\"9D55BA71-22DE-41F4-8B50-C36C83B3B530\",\"initalRequest\":\"原始请求\",\"initalResponse\":\"ok\",\"ebpCode\":\"4404840022\",\"payCode\":\"312226T001\",\"payTransactionId\":\"2018121222001354081010726129\",\"totalAmount\":100,\"currency\":\"142\",\"verDept\":\"3\",\"payType\":\"1\",\"tradingTime\":\"20181212041803\",\"note\":\"批量订单,测试订单优化,生成多个so订单\"}\"||\"payExchangeInfoLists\":\"[{\"orderNo\":\"SO1710301150602574003\",\"goodsInfo\":[{\"gname\":\"lhy-gnsku3\",\"itemLink\":\"http://m.yunjiweidian.com/yunjibuyer/static/vue-buyer/idc/index.html#/detail?itemId=999761&shopId=453\"},{\"gname\":\"lhy-gnsku2\",\"itemLink\":\"http://m.yunjiweidian.com/yunjibuyer/static/vue-buyer/idc/index.html#/detail?itemId=999760&shopId=453\"}],\"recpAccount\":\"OSA571908863132601\",\"recpCode\":\"\",\"recpName\":\"YUNJIHONGKONGLIMITED\"}]\"||\"serviceTime\":\"1544519952469\"";
|
||||
SignRequest request = new SignRequest(sign179String);
|
||||
String payload = signHandler.getSignDataParameter(request);
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package cn.alphahub.eport.signature.core.web;
|
||||
|
||||
import io.github.weasleyj.china.eport.sign.model.request.MessageRequest;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.service.annotation.HttpExchange;
|
||||
import org.springframework.web.service.annotation.PostExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Eport ceb message http client
|
||||
*
|
||||
* @author weasley
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@HttpExchange(accept = "application/json", contentType = "application/json")
|
||||
public interface EportCebMessageHttpClient {
|
||||
/**
|
||||
* 上报海关总署 CEBMessage XML 数据
|
||||
*/
|
||||
@PostExchange(value = "/cebcmsg")
|
||||
Mono<String> reportCebMessage(@RequestBody MessageRequest messageRequest);
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package cn.alphahub.eport.signature.core.web;
|
||||
|
||||
import cn.alphahub.eport.signature.entity.Capture179DataResponse;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.service.annotation.HttpExchange;
|
||||
import org.springframework.web.service.annotation.PostExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Eport customs 179 http client
|
||||
*
|
||||
* @author weasley
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@HttpExchange(accept = "application/json")
|
||||
public interface EportCustoms179HttpClient {
|
||||
/**
|
||||
* 海关 179 数据抓取
|
||||
*
|
||||
* @param formData 表达数据
|
||||
*/
|
||||
@PostExchange(value = "/ceb2grab/grab/realTimeDataUpload", contentType = "application/x-www-form-urlencoded")
|
||||
Mono<Capture179DataResponse> report179Data(@RequestParam Map<String, Object> formData);
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package cn.alphahub.eport.signature.core.web;
|
||||
|
||||
import cn.alphahub.eport.signature.base.domain.Result;
|
||||
import cn.alphahub.eport.signature.entity.SignResult;
|
||||
import org.springframework.web.service.annotation.GetExchange;
|
||||
import org.springframework.web.service.annotation.HttpExchange;
|
||||
|
||||
/**
|
||||
* Local Demo Http Client
|
||||
*
|
||||
* @author weasley
|
||||
* @version 1.0.0
|
||||
*/
|
||||
@HttpExchange(accept = "application/json", contentType = "application/json")
|
||||
public interface WebfluxDemoHttpClient {
|
||||
/**
|
||||
* 海关总署XML数据加签
|
||||
*/
|
||||
@GetExchange("/rpc/eport/test/cebmessage/signature")
|
||||
Result<SignResult> signCebMessage();
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package cn.alphahub.eport.signature.support;
|
||||
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.fasterxml.jackson.databind.cfg.MapperConfig;
|
||||
import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
|
||||
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
|
||||
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
|
||||
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/**
|
||||
* The Jackson original property naming strategy
|
||||
*
|
||||
* @author weasley
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public class OriginalPropertyNamingStrategy extends PropertyNamingStrategies.NamingBase {
|
||||
|
||||
public static List<AnnotatedField> getAnnotatedFields(AnnotatedMethod method) {
|
||||
@SuppressWarnings("deprecation") Iterable<AnnotatedField> fields = ((AnnotatedClass) method.getTypeContext()).fields();
|
||||
return StreamSupport.stream(fields.spliterator(), false).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translate(String propertyName) {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nameForGetterMethod(MapperConfig<?> config, AnnotatedMethod method, String defaultName) {
|
||||
List<AnnotatedField> annotatedFields = getAnnotatedFields(method);
|
||||
for (AnnotatedField annotatedField : annotatedFields) {
|
||||
if (defaultName.equalsIgnoreCase(annotatedField.getName())) {
|
||||
return annotatedField.getName();
|
||||
}
|
||||
}
|
||||
return super.nameForGetterMethod(config, method, defaultName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nameForField(MapperConfig<?> config, AnnotatedField field, String defaultName) {
|
||||
return super.nameForField(config, field, defaultName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nameForSetterMethod(MapperConfig<?> config, AnnotatedMethod method, String defaultName) {
|
||||
List<AnnotatedField> annotatedFields = getAnnotatedFields(method);
|
||||
for (AnnotatedField annotatedField : annotatedFields) {
|
||||
if (defaultName.equalsIgnoreCase(annotatedField.getName())) {
|
||||
return annotatedField.getName();
|
||||
}
|
||||
}
|
||||
return super.nameForSetterMethod(config, method, defaultName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nameForConstructorParameter(MapperConfig<?> config, AnnotatedParameter ctorParam, String defaultName) {
|
||||
return super.nameForConstructorParameter(config, ctorParam, defaultName);
|
||||
}
|
||||
}
|
||||
+36
File diff suppressed because one or more lines are too long
+8
-4
@@ -3,12 +3,12 @@ package cn.alphahub.eport.signature.controller.rpc;
|
||||
import cn.alphahub.eport.signature.config.ChinaEportProperties;
|
||||
import cn.alphahub.eport.signature.core.ChinaEportReportClient;
|
||||
import cn.alphahub.eport.signature.core.SignHandler;
|
||||
import cn.alphahub.eport.signature.core.web.EportCebMessageHttpClient;
|
||||
import cn.alphahub.eport.signature.entity.SignRequest;
|
||||
import cn.alphahub.eport.signature.entity.SignResult;
|
||||
import cn.alphahub.eport.signature.entity.UkeyRequest;
|
||||
import cn.alphahub.eport.signature.entity.UkeyResponse.Args;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.http.ContentType;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
@@ -18,7 +18,6 @@ import io.github.weasleyj.china.eport.sign.model.request.MessageRequest;
|
||||
import io.github.weasleyj.china.eport.sign.util.GUIDUtil;
|
||||
import io.github.weasleyj.china.eport.sign.util.JAXBUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,8 +29,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static cn.alphahub.eport.signature.core.ChinaEportReportClient.EPORT_CEBMESSAGE_SERVER_ENCODE;
|
||||
|
||||
/**
|
||||
* Eport Sign Controller Test
|
||||
*/
|
||||
@@ -46,6 +43,8 @@ class EportSignControllerTest {
|
||||
ChinaEportProperties chinaEportProperties;
|
||||
@Autowired
|
||||
ChinaEportReportClient chinaEportReportClient;
|
||||
@Autowired
|
||||
EportCebMessageHttpClient cebMessageHttpClient;
|
||||
|
||||
@Test
|
||||
@DisplayName("海关XML数据加签+验正签名结果")
|
||||
@@ -153,6 +152,7 @@ class EportSignControllerTest {
|
||||
ceb311Message.getOrder().getOrderHead().setGuid(guid);
|
||||
chinaEportReportClient.buildBaseTransfer(ceb311Message.getBaseTransfer());
|
||||
MessageRequest messageRequest = chinaEportReportClient.buildMessageRequest(ceb311Message, MessageType.CEB311Message);
|
||||
/*
|
||||
String requestServer = StringUtils.defaultIfBlank(chinaEportProperties.getServer(), Base64.decodeStr(EPORT_CEBMESSAGE_SERVER_ENCODE));
|
||||
String requestBody = JSONUtil.toJsonStr(messageRequest);
|
||||
log.info("数据上报海关请求入参 {}\nRequest Server: {}", requestBody, requestServer);
|
||||
@@ -161,6 +161,10 @@ class EportSignControllerTest {
|
||||
.body(requestBody)
|
||||
.execute();
|
||||
log.info("开始上报,Http响应结果: {}", httpResponse.body());
|
||||
*/
|
||||
cebMessageHttpClient.reportCebMessage(messageRequest).subscribe(data -> {
|
||||
log.info("开始申报数据,Http响应结果: {}", data);
|
||||
});
|
||||
|
||||
// 睡8秒,开始查询回执
|
||||
LocalDateTime uploadTime = LocalDateTime.now();
|
||||
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package cn.alphahub.eport.signature.core.web;
|
||||
|
||||
import cn.alphahub.dtt.plus.util.JacksonUtil;
|
||||
import cn.alphahub.eport.signature.base.domain.Result;
|
||||
import cn.alphahub.eport.signature.config.WebClientConfiguration;
|
||||
import cn.alphahub.eport.signature.entity.SignResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static cn.alphahub.eport.signature.config.AuthenticationProperties.AUTHENTICATION_HEADER;
|
||||
|
||||
@Slf4j
|
||||
@SpringBootTest
|
||||
class WebfluxDemoHttpClientTest {
|
||||
|
||||
@Autowired
|
||||
private WebfluxDemoHttpClient webfluxDemoHttpClient;
|
||||
|
||||
@Test
|
||||
@DisplayName("验证WebClient调用")
|
||||
void signCebMessage() {
|
||||
String headerValue = DigestUtils.md5DigestAsHex("chinaport-data-signature".getBytes(StandardCharsets.UTF_8));
|
||||
WebClientConfiguration.HTTP_HEADERS.set(headers -> {
|
||||
headers.add(AUTHENTICATION_HEADER, headerValue);
|
||||
});
|
||||
Result<SignResult> result = webfluxDemoHttpClient.signCebMessage();
|
||||
log.info("Sign ceb message: {}", JacksonUtil.toPrettyJson(result));
|
||||
Assertions.assertNotNull(webfluxDemoHttpClient);
|
||||
}
|
||||
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package cn.alphahub.eport.signature.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Sample Bean
|
||||
*/
|
||||
@Data
|
||||
public class SampleBean {
|
||||
private String FirstName;
|
||||
private String LastNAME;
|
||||
private int age;
|
||||
}
|
||||
Reference in New Issue
Block a user