gpt4 book ai didi

spring-boot - 检查响应对象是否没有返回数据

转载 作者:行者123 更新时间:2023-12-03 07:45:06 25 4
gpt4 key购买 nike

我有一个端点,用于检查数据库中是否存在标识符并返回状态。将调用此端点的 USSD API。当我使用不存在的标识符 (EcNumber) 发出请求时,响应会按我的预期返回消息。但是,当我传递数据库中的标识符时,我也会得到相同的状态message.I 需要帮助来使用 isEmpty()/null 来实现相同的目的:

ClientEndpoint.java

 @Endpoint
public class ClientEndpoint {
private static final String NAMESPACE_URI = "http://www.onewallet.org/webservices/disburse";
@Autowired
private IClientService clientService;

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getClientByEcNumRequest")
@ResponsePayload
public GetClienttByEcNumResponse getClient(@RequestPayload GetClientByEcNumRequest request) {
GetClienttByEcNumResponse response = new GetClienttByEcNumResponse();

ServiceStatus serviceStatus = new ServiceStatus();
ClientInfo clientInfo = new ClientInfo();
if ( clientInfo==null || clientInfo.getEcNumber()==null ){
serviceStatus.setMessage("EC# not registered with MCP");
} else {
BeanUtils.copyProperties(clientService.getClientByEcNumber(request.getEcNumber() ), clientInfo);
serviceStatus.setMessage("Welcome to MCP MobileLoans");
}
response.setServiceStatus(serviceStatus);
return response;

当我传递以下有效 EcNumber 请求时:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dis="http://www.onewallet.org/webservices/disburse">
<soapenv:Header/>
<soapenv:Body>
<dis:getClientByEcNumRequest>
<dis:ecNumber>5501900T</dis:ecNumber>
</dis:getClientByEcNumRequest>
</soapenv:Body>
</soapenv:Envelope>

我收到回复:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:getClienttByEcNumResponse xmlns:ns2="http://www.onewallet.org/webservices/disburse">
<ns2:serviceStatus>
<ns2:message>EC# not registered with MCP</ns2:message>
</ns2:serviceStatus>
</ns2:getClienttByEcNumResponse>

最佳答案

明白了。我传递了错误的对象进行检查。应该使用 entity 实例而不是 complexType 实例(来自架构定义):

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getClientByEcNumRequest")
@ResponsePayload
public GetClienttByEcNumResponse getClient(@RequestPayload GetClientByEcNumRequest request) {
GetClienttByEcNumResponse response = new GetClienttByEcNumResponse();

ServiceStatus serviceStatus = new ServiceStatus();
**Client client=clientService.getClientByEcNumber(request.getEcNumber));**
ClientInfo clientInfo = new ClientInfo();
if ( client=null){
serviceStatus.setMessage("EC# not registered with MCP");
} else {
BeanUtils.copyProperties(clientService.getClientByEcNumber(request.getEcNumber() ), clientInfo);
serviceStatus.setMessage("Welcome to MCP MobileLoans");
}
response.setServiceStatus(serviceStatus);
response.setClientInfo(clientInfo)
return response;

关于spring-boot - 检查响应对象是否没有返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52779633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com