【问题标题】:Check if a response object returns no data检查响应对象是否没有返回数据
【发布时间】:2018-10-12 12:32:23
【问题描述】:

我有一个端点来检查数据库中是否存在标识符并返回状态。将调用此端点的 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>

【问题讨论】:

    标签: spring-boot soap spring-data-jpa jax-ws


    【解决方案1】:

    知道了。我为检查传递了不正确的对象。应该使用 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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 2021-04-30
      • 2022-06-21
      相关资源
      最近更新 更多